mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-03 08:28:25 +00:00
Polish status bar statistics
This commit is contained in:
parent
e6b93f7489
commit
96d9e748cf
@ -732,7 +732,9 @@ Menuset
|
|||||||
Item "Show Zoom Level|Z" "ui-toggle zoomlevel"
|
Item "Show Zoom Level|Z" "ui-toggle zoomlevel"
|
||||||
Item "Show Zoom Slider|S" "ui-toggle zoomslider"
|
Item "Show Zoom Slider|S" "ui-toggle zoomslider"
|
||||||
Separator
|
Separator
|
||||||
Item "Show Statistics|t" "ui-toggle statistics"
|
Item "Show Word Count|W" "ui-toggle statistics-w"
|
||||||
|
Item "Show Character Count (Incl. Blanks)|C" "ui-toggle statistics-cb"
|
||||||
|
Item "Show Character Count (Without Blanks)|h" "ui-toggle statistics-c"
|
||||||
End
|
End
|
||||||
|
|
||||||
End
|
End
|
||||||
|
@ -4091,16 +4091,20 @@ void LyXAction::init()
|
|||||||
* \var lyx::FuncCode lyx::LFUN_UI_TOGGLE
|
* \var lyx::FuncCode lyx::LFUN_UI_TOGGLE
|
||||||
* \li Action: Various UI visibility-toggling actions.
|
* \li Action: Various UI visibility-toggling actions.
|
||||||
* \li Syntax: ui-toggle <statusbar|menubar|scrollbar|frame|fullscreen>
|
* \li Syntax: ui-toggle <statusbar|menubar|scrollbar|frame|fullscreen>
|
||||||
* \li Params: statusbar : Toggle visibility of the statusbar.\n
|
* \li Params: statusbar : Toggle visibility of the statusbar.\n
|
||||||
menubar : Toggle visibility of the menubar.\n
|
menubar : Toggle visibility of the menubar.\n
|
||||||
scrollbar : Toggle visibility of the scrollbar.\n
|
scrollbar : Toggle visibility of the scrollbar.\n
|
||||||
frame : Toggle visibility of the frames around editing window.\n
|
frame : Toggle visibility of the frames around editing window.\n
|
||||||
zoomslider : Toggle visibility of the zoom slider in statusbar.\n
|
zoomslider : Toggle visibility of the zoom slider in statusbar.\n
|
||||||
zoomlevel : Toggle visibility of the zoom level display in statusbar.\n
|
zoomlevel : Toggle visibility of the zoom level display in statusbar.\n
|
||||||
statistics : Toggle visibility of the document statistics count in statusbar.\n
|
statistics-w : Toggle visibility of the document word count in statusbar.\n
|
||||||
fullscreen : Toggle fullscreen mode. This also covers calling the
|
statistics-cb : Toggle visibility of the document character count (incl. blanks)
|
||||||
previous functions. However #LFUN_TOOLBAR_TOGGLE for the
|
in statusbar.\n
|
||||||
custom tweaks of the toolbars should be used.
|
statistics-c : Toggle visibility of the document character count (excl. blanks)
|
||||||
|
in statusbar.\n
|
||||||
|
fullscreen : Toggle fullscreen mode. This also covers calling the
|
||||||
|
previous functions. However #LFUN_TOOLBAR_TOGGLE for the
|
||||||
|
custom tweaks of the toolbars should be used.
|
||||||
* \li Origin: sanda, 9 Feb 2007
|
* \li Origin: sanda, 9 Feb 2007
|
||||||
* \endvar
|
* \endvar
|
||||||
*/
|
*/
|
||||||
|
@ -568,7 +568,8 @@ QSet<Buffer const *> GuiView::GuiViewPrivate::busyBuffers;
|
|||||||
|
|
||||||
GuiView::GuiView(int id)
|
GuiView::GuiView(int id)
|
||||||
: d(*new GuiViewPrivate(this)), id_(id), closing_(false), busy_(0),
|
: d(*new GuiViewPrivate(this)), id_(id), closing_(false), busy_(0),
|
||||||
command_execute_(false), minibuffer_focus_(false), stat_counts_enabled_(true),
|
command_execute_(false), minibuffer_focus_(false), word_count_enabled_(true),
|
||||||
|
char_count_enabled_(true), char_nb_count_enabled_(false),
|
||||||
toolbarsMovable_(true), devel_mode_(false)
|
toolbarsMovable_(true), devel_mode_(false)
|
||||||
{
|
{
|
||||||
connect(this, SIGNAL(bufferViewChanged()),
|
connect(this, SIGNAL(bufferViewChanged()),
|
||||||
@ -645,12 +646,14 @@ GuiView::GuiView(int id)
|
|||||||
busySVG, SLOT(hide()));
|
busySVG, SLOT(hide()));
|
||||||
connect(busySVG, SIGNAL(pressed()), this, SLOT(checkCancelBackground()));
|
connect(busySVG, SIGNAL(pressed()), this, SLOT(checkCancelBackground()));
|
||||||
|
|
||||||
stat_counts_ = new QLabel(statusBar());
|
stat_counts_ = new GuiClickableLabel(statusBar());
|
||||||
stat_counts_->setAlignment(Qt::AlignCenter);
|
stat_counts_->setAlignment(Qt::AlignCenter);
|
||||||
stat_counts_->setFrameStyle(QFrame::StyledPanel);
|
stat_counts_->setFrameStyle(QFrame::StyledPanel);
|
||||||
stat_counts_->hide();
|
stat_counts_->hide();
|
||||||
statusBar()->addPermanentWidget(stat_counts_);
|
statusBar()->addPermanentWidget(stat_counts_);
|
||||||
|
|
||||||
|
connect(stat_counts_, SIGNAL(clicked()), this, SLOT(statsPressed()));
|
||||||
|
|
||||||
|
|
||||||
QFontMetrics const fm(statusBar()->fontMetrics());
|
QFontMetrics const fm(statusBar()->fontMetrics());
|
||||||
|
|
||||||
@ -820,6 +823,11 @@ void GuiView::checkCancelBackground()
|
|||||||
Systemcall::killscript();
|
Systemcall::killscript();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GuiView::statsPressed()
|
||||||
|
{
|
||||||
|
DispatchResult dr;
|
||||||
|
dispatch(FuncRequest(LFUN_STATISTICS), dr);
|
||||||
|
}
|
||||||
|
|
||||||
void GuiView::zoomSliderMoved(int value)
|
void GuiView::zoomSliderMoved(int value)
|
||||||
{
|
{
|
||||||
@ -977,7 +985,9 @@ void GuiView::saveLayout() const
|
|||||||
settings.setValue("icon_size", toqstr(d.iconSize(iconSize())));
|
settings.setValue("icon_size", toqstr(d.iconSize(iconSize())));
|
||||||
settings.setValue("zoom_value_visible", zoom_value_->isVisible());
|
settings.setValue("zoom_value_visible", zoom_value_->isVisible());
|
||||||
settings.setValue("zoom_slider_visible", zoom_slider_->isVisible());
|
settings.setValue("zoom_slider_visible", zoom_slider_->isVisible());
|
||||||
settings.setValue("document_stats_enabled", stat_counts_enabled_);
|
settings.setValue("word_count_enabled", word_count_enabled_);
|
||||||
|
settings.setValue("char_count_enabled", char_count_enabled_);
|
||||||
|
settings.setValue("char_nb_count_enabled", char_nb_count_enabled_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1027,8 +1037,10 @@ bool GuiView::restoreLayout()
|
|||||||
zoom_in_->setVisible(show_zoom_slider);
|
zoom_in_->setVisible(show_zoom_slider);
|
||||||
zoom_out_->setVisible(show_zoom_slider);
|
zoom_out_->setVisible(show_zoom_slider);
|
||||||
|
|
||||||
stat_counts_enabled_ = settings.value("document_stats_enabled", true).toBool();
|
word_count_enabled_ = settings.value("word_count_enabled", true).toBool();
|
||||||
stat_counts_->setVisible(stat_counts_enabled_);
|
char_count_enabled_ = settings.value("char_count_enabled", true).toBool();
|
||||||
|
char_nb_count_enabled_ = settings.value("char_nb_count_enabled", true).toBool();
|
||||||
|
stat_counts_->setVisible(word_count_enabled_ || char_count_enabled_ || char_nb_count_enabled_);
|
||||||
|
|
||||||
if (guiApp->platformName() == "qt4x11" || guiApp->platformName() == "xcb") {
|
if (guiApp->platformName() == "qt4x11" || guiApp->platformName() == "xcb") {
|
||||||
QPoint pos = settings.value("pos", QPoint(50, 50)).toPoint();
|
QPoint pos = settings.value("pos", QPoint(50, 50)).toPoint();
|
||||||
@ -1408,56 +1420,69 @@ void GuiView::clearMessage()
|
|||||||
|
|
||||||
void GuiView::showStats()
|
void GuiView::showStats()
|
||||||
{
|
{
|
||||||
if (!stat_counts_enabled_)
|
if (!statsEnabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
d.time_to_update -= d.timer_rate;
|
d.time_to_update -= d.timer_rate;
|
||||||
|
|
||||||
BufferView * bv = currentBufferView();
|
BufferView * bv = currentBufferView();
|
||||||
Buffer * buf = bv ? &bv->buffer() : nullptr;
|
Buffer * buf = bv ? &bv->buffer() : nullptr;
|
||||||
if (buf) {
|
if (!buf) {
|
||||||
|
|
||||||
Cursor const & cur = bv->cursor();
|
|
||||||
|
|
||||||
//we start new selection and need faster update
|
|
||||||
if (!d.already_in_selection_ && cur.selection())
|
|
||||||
d.time_to_update = 0;
|
|
||||||
|
|
||||||
if (d.time_to_update <= 0) {
|
|
||||||
|
|
||||||
DocIterator from, to;
|
|
||||||
|
|
||||||
if (cur.selection()) {
|
|
||||||
from = cur.selectionBegin();
|
|
||||||
to = cur.selectionEnd();
|
|
||||||
d.already_in_selection_ = true;
|
|
||||||
} else {
|
|
||||||
from = doc_iterator_begin(buf);
|
|
||||||
to = doc_iterator_end(buf);
|
|
||||||
d.already_in_selection_ = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf->updateStatistics(from, to);
|
|
||||||
|
|
||||||
int const words = buf->wordCount();
|
|
||||||
int const chars = buf->charCount(false);
|
|
||||||
int const chars_with_blanks = buf->charCount(true);
|
|
||||||
|
|
||||||
QString stats = toqstr(_("w:[[words]]")) + QString::number(words) + " " +
|
|
||||||
toqstr(_("c:[[characters]]")) + QString::number(chars) + " " +
|
|
||||||
toqstr(_("cb:[[characters with blanks]]")) + QString::number(chars_with_blanks);
|
|
||||||
stat_counts_->setText(stats);
|
|
||||||
stat_counts_->show();
|
|
||||||
|
|
||||||
d.time_to_update = d.default_stats_rate;
|
|
||||||
//fast updates for small selections
|
|
||||||
if (chars_with_blanks < d.max_sel_chars && cur.selection())
|
|
||||||
d.time_to_update = d.timer_rate;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else
|
|
||||||
stat_counts_->hide();
|
stat_counts_->hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Cursor const & cur = bv->cursor();
|
||||||
|
|
||||||
|
// we start new selection and need faster update
|
||||||
|
if (!d.already_in_selection_ && cur.selection())
|
||||||
|
d.time_to_update = 0;
|
||||||
|
|
||||||
|
if (d.time_to_update > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
DocIterator from, to;
|
||||||
|
if (cur.selection()) {
|
||||||
|
from = cur.selectionBegin();
|
||||||
|
to = cur.selectionEnd();
|
||||||
|
d.already_in_selection_ = true;
|
||||||
|
} else {
|
||||||
|
from = doc_iterator_begin(buf);
|
||||||
|
to = doc_iterator_end(buf);
|
||||||
|
d.already_in_selection_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf->updateStatistics(from, to);
|
||||||
|
|
||||||
|
QStringList stats;
|
||||||
|
if (word_count_enabled_) {
|
||||||
|
int const words = buf->wordCount();
|
||||||
|
if (words == 1)
|
||||||
|
stats << toqstr(bformat(_("%1$d Word"), words));
|
||||||
|
else
|
||||||
|
stats << toqstr(bformat(_("%1$d Words"), words));
|
||||||
|
}
|
||||||
|
int const chars_with_blanks = buf->charCount(true);
|
||||||
|
if (char_count_enabled_) {
|
||||||
|
if (chars_with_blanks == 1)
|
||||||
|
stats << toqstr(bformat(_("%1$d Character"), chars_with_blanks));
|
||||||
|
else
|
||||||
|
stats << toqstr(bformat(_("%1$d Characters"), chars_with_blanks));
|
||||||
|
}
|
||||||
|
if (char_nb_count_enabled_) {
|
||||||
|
int const chars = buf->charCount(false);
|
||||||
|
if (chars == 1)
|
||||||
|
stats << toqstr(bformat(_("%1$d Character (no Blanks)"), chars));
|
||||||
|
else
|
||||||
|
stats << toqstr(bformat(_("%1$d Characters (no Blanks)"), chars));
|
||||||
|
}
|
||||||
|
stat_counts_->setText(stats.join(qt_(", [[stats separator]]")));
|
||||||
|
stat_counts_->show();
|
||||||
|
|
||||||
|
d.time_to_update = d.default_stats_rate;
|
||||||
|
// fast updates for small selections
|
||||||
|
if (chars_with_blanks < d.max_sel_chars && cur.selection())
|
||||||
|
d.time_to_update = d.timer_rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1599,6 +1624,12 @@ void GuiView::showMessage()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool GuiView::statsEnabled() const
|
||||||
|
{
|
||||||
|
return word_count_enabled_ || char_count_enabled_ || char_nb_count_enabled_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool GuiView::event(QEvent * e)
|
bool GuiView::event(QEvent * e)
|
||||||
{
|
{
|
||||||
switch (e->type())
|
switch (e->type())
|
||||||
@ -2503,8 +2534,12 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
|
|||||||
flag.setOnOff(zoom_value_ ? zoom_value_->isVisible() : false);
|
flag.setOnOff(zoom_value_ ? zoom_value_->isVisible() : false);
|
||||||
} else if (cmd.argument() == "zoomslider") {
|
} else if (cmd.argument() == "zoomslider") {
|
||||||
flag.setOnOff(zoom_slider_ ? zoom_slider_->isVisible() : false);
|
flag.setOnOff(zoom_slider_ ? zoom_slider_->isVisible() : false);
|
||||||
} else if (cmd.argument() == "statistics") {
|
} else if (cmd.argument() == "statistics-w") {
|
||||||
flag.setOnOff(stat_counts_enabled_);
|
flag.setOnOff(word_count_enabled_);
|
||||||
|
} else if (cmd.argument() == "statistics-cb") {
|
||||||
|
flag.setOnOff(char_count_enabled_);
|
||||||
|
} else if (cmd.argument() == "statistics-c") {
|
||||||
|
flag.setOnOff(char_nb_count_enabled_);
|
||||||
} else
|
} else
|
||||||
flag.setOnOff(isFullScreen());
|
flag.setOnOff(isFullScreen());
|
||||||
break;
|
break;
|
||||||
@ -4993,10 +5028,13 @@ bool GuiView::lfunUiToggle(string const & ui_component)
|
|||||||
zoom_slider_->setVisible(!zoom_slider_->isVisible());
|
zoom_slider_->setVisible(!zoom_slider_->isVisible());
|
||||||
zoom_in_->setVisible(zoom_slider_->isVisible());
|
zoom_in_->setVisible(zoom_slider_->isVisible());
|
||||||
zoom_out_->setVisible(zoom_slider_->isVisible());
|
zoom_out_->setVisible(zoom_slider_->isVisible());
|
||||||
} else if (ui_component == "statistics") {
|
} else if (ui_component == "statistics-w")
|
||||||
stat_counts_enabled_ = !stat_counts_enabled_;
|
word_count_enabled_ = !word_count_enabled_;
|
||||||
stat_counts_->setVisible(stat_counts_enabled_);
|
else if (ui_component == "statistics-cb")
|
||||||
} else if (ui_component == "frame") {
|
char_count_enabled_ = !char_count_enabled_;
|
||||||
|
else if (ui_component == "statistics-c")
|
||||||
|
char_nb_count_enabled_ = !char_nb_count_enabled_;
|
||||||
|
else if (ui_component == "frame") {
|
||||||
int const l = contentsMargins().left();
|
int const l = contentsMargins().left();
|
||||||
|
|
||||||
//are the frames in default state?
|
//are the frames in default state?
|
||||||
@ -5017,6 +5055,7 @@ bool GuiView::lfunUiToggle(string const & ui_component)
|
|||||||
toggleFullScreen();
|
toggleFullScreen();
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
|
stat_counts_->setVisible(statsEnabled());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,6 +251,8 @@ private Q_SLOTS:
|
|||||||
///
|
///
|
||||||
void checkCancelBackground();
|
void checkCancelBackground();
|
||||||
///
|
///
|
||||||
|
void statsPressed();
|
||||||
|
///
|
||||||
void zoomSliderMoved(int);
|
void zoomSliderMoved(int);
|
||||||
///
|
///
|
||||||
void zoomValueChanged(int);
|
void zoomValueChanged(int);
|
||||||
@ -489,6 +491,8 @@ private:
|
|||||||
void dispatchToBufferView(FuncRequest const & cmd, DispatchResult & dr);
|
void dispatchToBufferView(FuncRequest const & cmd, DispatchResult & dr);
|
||||||
///
|
///
|
||||||
void showMessage();
|
void showMessage();
|
||||||
|
/// Check whether any of the stats is enabled in status bar
|
||||||
|
bool statsEnabled() const;
|
||||||
|
|
||||||
/// This view ID.
|
/// This view ID.
|
||||||
int id_;
|
int id_;
|
||||||
@ -514,8 +518,13 @@ private:
|
|||||||
QLabel * version_control_;
|
QLabel * version_control_;
|
||||||
/// Statusbar widget that document count statistics
|
/// Statusbar widget that document count statistics
|
||||||
QLabel * stat_counts_;
|
QLabel * stat_counts_;
|
||||||
/// Stats info feature can be disabled by context menu
|
/// Word count info feature can be disabled by context menu
|
||||||
bool stat_counts_enabled_;
|
bool word_count_enabled_;
|
||||||
|
/// Char count info feature can be disabled by context menu
|
||||||
|
bool char_count_enabled_;
|
||||||
|
/// Char count info feature can be disabled by context menu
|
||||||
|
/// This excludes blanks
|
||||||
|
bool char_nb_count_enabled_;
|
||||||
/// Statusbar widget that shows zoom value
|
/// Statusbar widget that shows zoom value
|
||||||
QLabel * zoom_value_;
|
QLabel * zoom_value_;
|
||||||
/// The zoom slider widget
|
/// The zoom slider widget
|
||||||
|
Loading…
Reference in New Issue
Block a user