commit 96d9e748cf25dc704edba7fe07efd3d9ea274f11
Author: Juergen Spitzmueller <[email protected]>
Date: Wed Aug 17 14:59:50 2022 +0200
Polish status bar statistics
---
lib/ui/stdcontext.inc | 4 +-
src/LyXAction.cpp | 24 ++++---
src/frontends/qt/GuiView.cpp | 135 +++++++++++++++++++++++++++---------------
src/frontends/qt/GuiView.h | 13 ++++-
4 files changed, 115 insertions(+), 61 deletions(-)
diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc
index 554798c..8eb8ddd 100644
--- a/lib/ui/stdcontext.inc
+++ b/lib/ui/stdcontext.inc
@@ -732,7 +732,9 @@ Menuset
Item "Show Zoom Level|Z" "ui-toggle zoomlevel"
Item "Show Zoom Slider|S" "ui-toggle zoomslider"
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
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index ae8245d..6c80fb1 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -4091,16 +4091,20 @@ void LyXAction::init()
* \var lyx::FuncCode lyx::LFUN_UI_TOGGLE
* \li Action: Various UI visibility-toggling actions.
* \li Syntax: ui-toggle <statusbar|menubar|scrollbar|frame|fullscreen>
- * \li Params: statusbar : Toggle visibility of the statusbar.\n
- menubar : Toggle visibility of the menubar.\n
- scrollbar : Toggle visibility of the scrollbar.\n
- frame : Toggle visibility of the frames around editing
window.\n
- zoomslider : Toggle visibility of the zoom slider 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
- 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 Params: statusbar : Toggle visibility of the statusbar.\n
+ menubar : Toggle visibility of the menubar.\n
+ scrollbar : Toggle visibility of the scrollbar.\n
+ frame : Toggle visibility of the frames around editing
window.\n
+ zoomslider : Toggle visibility of the zoom slider in
statusbar.\n
+ zoomlevel : Toggle visibility of the zoom level display in
statusbar.\n
+ statistics-w : Toggle visibility of the document word count in
statusbar.\n
+ statistics-cb : Toggle visibility of the document character
count (incl. blanks)
+ in statusbar.\n
+ 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
* \endvar
*/
diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp
index d03fe3b..edcc999 100644
--- a/src/frontends/qt/GuiView.cpp
+++ b/src/frontends/qt/GuiView.cpp
@@ -568,7 +568,8 @@ QSet<Buffer const *> GuiView::GuiViewPrivate::busyBuffers;
GuiView::GuiView(int id)
: 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)
{
connect(this, SIGNAL(bufferViewChanged()),
@@ -645,12 +646,14 @@ GuiView::GuiView(int id)
busySVG, SLOT(hide()));
connect(busySVG, SIGNAL(pressed()), this,
SLOT(checkCancelBackground()));
- stat_counts_ = new QLabel(statusBar());
+ stat_counts_ = new GuiClickableLabel(statusBar());
stat_counts_->setAlignment(Qt::AlignCenter);
stat_counts_->setFrameStyle(QFrame::StyledPanel);
stat_counts_->hide();
statusBar()->addPermanentWidget(stat_counts_);
+ connect(stat_counts_, SIGNAL(clicked()), this, SLOT(statsPressed()));
+
QFontMetrics const fm(statusBar()->fontMetrics());
@@ -820,6 +823,11 @@ void GuiView::checkCancelBackground()
Systemcall::killscript();
}
+void GuiView::statsPressed()
+{
+ DispatchResult dr;
+ dispatch(FuncRequest(LFUN_STATISTICS), dr);
+}
void GuiView::zoomSliderMoved(int value)
{
@@ -977,7 +985,9 @@ void GuiView::saveLayout() const
settings.setValue("icon_size", toqstr(d.iconSize(iconSize())));
settings.setValue("zoom_value_visible", zoom_value_->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_out_->setVisible(show_zoom_slider);
- stat_counts_enabled_ = settings.value("document_stats_enabled",
true).toBool();
- stat_counts_->setVisible(stat_counts_enabled_);
+ word_count_enabled_ = settings.value("word_count_enabled",
true).toBool();
+ 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") {
QPoint pos = settings.value("pos", QPoint(50, 50)).toPoint();
@@ -1408,56 +1420,69 @@ void GuiView::clearMessage()
void GuiView::showStats()
{
- if (!stat_counts_enabled_)
+ if (!statsEnabled())
return;
-
d.time_to_update -= d.timer_rate;
BufferView * bv = currentBufferView();
Buffer * buf = bv ? &bv->buffer() : nullptr;
- 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) {
+ if (!buf) {
+ stat_counts_->hide();
+ return;
+ }
- DocIterator from, to;
+ Cursor const & cur = bv->cursor();
- 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;
- }
+ // we start new selection and need faster update
+ if (!d.already_in_selection_ && cur.selection())
+ d.time_to_update = 0;
- buf->updateStatistics(from, to);
+ if (d.time_to_update > 0)
+ return;
- int const words = buf->wordCount();
- int const chars = buf->charCount(false);
- int const chars_with_blanks = buf->charCount(true);
+ 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;
+ }
- 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();
+ buf->updateStatistics(from, to);
- 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;
- }
+ 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();
- } else
- stat_counts_->hide();
+ 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)
{
switch (e->type())
@@ -2503,8 +2534,12 @@ bool GuiView::getStatus(FuncRequest const & cmd,
FuncStatus & flag)
flag.setOnOff(zoom_value_ ? zoom_value_->isVisible() :
false);
} else if (cmd.argument() == "zoomslider") {
flag.setOnOff(zoom_slider_ ? zoom_slider_->isVisible()
: false);
- } else if (cmd.argument() == "statistics") {
- flag.setOnOff(stat_counts_enabled_);
+ } else if (cmd.argument() == "statistics-w") {
+ 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
flag.setOnOff(isFullScreen());
break;
@@ -4993,10 +5028,13 @@ bool GuiView::lfunUiToggle(string const & ui_component)
zoom_slider_->setVisible(!zoom_slider_->isVisible());
zoom_in_->setVisible(zoom_slider_->isVisible());
zoom_out_->setVisible(zoom_slider_->isVisible());
- } else if (ui_component == "statistics") {
- stat_counts_enabled_ = !stat_counts_enabled_;
- stat_counts_->setVisible(stat_counts_enabled_);
- } else if (ui_component == "frame") {
+ } else if (ui_component == "statistics-w")
+ word_count_enabled_ = !word_count_enabled_;
+ else if (ui_component == "statistics-cb")
+ 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();
//are the frames in default state?
@@ -5017,6 +5055,7 @@ bool GuiView::lfunUiToggle(string const & ui_component)
toggleFullScreen();
} else
return false;
+ stat_counts_->setVisible(statsEnabled());
return true;
}
diff --git a/src/frontends/qt/GuiView.h b/src/frontends/qt/GuiView.h
index 2f7c34e..7b89370 100644
--- a/src/frontends/qt/GuiView.h
+++ b/src/frontends/qt/GuiView.h
@@ -251,6 +251,8 @@ private Q_SLOTS:
///
void checkCancelBackground();
///
+ void statsPressed();
+ ///
void zoomSliderMoved(int);
///
void zoomValueChanged(int);
@@ -489,6 +491,8 @@ private:
void dispatchToBufferView(FuncRequest const & cmd, DispatchResult & dr);
///
void showMessage();
+ /// Check whether any of the stats is enabled in status bar
+ bool statsEnabled() const;
/// This view ID.
int id_;
@@ -514,8 +518,13 @@ private:
QLabel * version_control_;
/// Statusbar widget that document count statistics
QLabel * stat_counts_;
- /// Stats info feature can be disabled by context menu
- bool stat_counts_enabled_;
+ /// Word count info feature can be disabled by context menu
+ 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
QLabel * zoom_value_;
/// The zoom slider widget
--
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs