[LyX/master] GuiSearch: make search options visible/accessible in minimal mode

Juergen Spitzmueller spitz at lyx.org
Thu Feb 18 06:30:16 UTC 2021


commit a7e6dcc31dc8b49ad27c16558c8634880a1f6002
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Thu Feb 18 07:33:26 2021 +0100

    GuiSearch: make search options visible/accessible in minimal mode
---
 lib/Makefile.am                       |    6 ++
 lib/images/search-case-sensitive.svgz |  Bin 0 -> 1542 bytes
 lib/images/search-instant.svgz        |  Bin 0 -> 848 bytes
 lib/images/search-options.svgz        |  Bin 0 -> 929 bytes
 lib/images/search-selection.svgz      |  Bin 0 -> 1660 bytes
 lib/images/search-whole-words.svgz    |  Bin 0 -> 1566 bytes
 lib/images/search-wrap.svgz           |  Bin 0 -> 1071 bytes
 src/frontends/qt/GuiSearch.cpp        |  152 +++++++++++++++++++++++++++++++++
 src/frontends/qt/GuiSearch.h          |   23 +++++
 9 files changed, 181 insertions(+), 0 deletions(-)

diff --git a/lib/Makefile.am b/lib/Makefile.am
index 18761f0..038b33c 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -658,6 +658,12 @@ dist_images_DATA1X = \
 	images/paste.svgz \
 	images/redo.svgz \
 	images/reload.svgz \
+	images/search-case-sensitive.svgz \
+	images/search-instant.svgz \
+	images/search-options.svgz \
+	images/search-selection.svgz \
+	images/search-whole-words.svgz \
+	images/search-wrap.svgz \
 	images/script-insert_subscript.svgz \
 	images/script-insert_superscript.svgz \
 	images/specialchar-insert_latex.svgz \
diff --git a/lib/images/search-case-sensitive.svgz b/lib/images/search-case-sensitive.svgz
new file mode 100644
index 0000000..4d76a01
Binary files /dev/null and b/lib/images/search-case-sensitive.svgz differ
diff --git a/lib/images/search-instant.svgz b/lib/images/search-instant.svgz
new file mode 100644
index 0000000..741f7cc
Binary files /dev/null and b/lib/images/search-instant.svgz differ
diff --git a/lib/images/search-options.svgz b/lib/images/search-options.svgz
new file mode 100644
index 0000000..c702107
Binary files /dev/null and b/lib/images/search-options.svgz differ
diff --git a/lib/images/search-selection.svgz b/lib/images/search-selection.svgz
new file mode 100644
index 0000000..358e6bb
Binary files /dev/null and b/lib/images/search-selection.svgz differ
diff --git a/lib/images/search-whole-words.svgz b/lib/images/search-whole-words.svgz
new file mode 100644
index 0000000..858dae9
Binary files /dev/null and b/lib/images/search-whole-words.svgz differ
diff --git a/lib/images/search-wrap.svgz b/lib/images/search-wrap.svgz
new file mode 100644
index 0000000..e5379b7
Binary files /dev/null and b/lib/images/search-wrap.svgz differ
diff --git a/src/frontends/qt/GuiSearch.cpp b/src/frontends/qt/GuiSearch.cpp
index 0eeaf8d..11cda70 100644
--- a/src/frontends/qt/GuiSearch.cpp
+++ b/src/frontends/qt/GuiSearch.cpp
@@ -33,6 +33,7 @@
 #include "frontends/Clipboard.h"
 
 #include <QClipboard>
+#include <QPainter>
 #include <QLineEdit>
 #include <QSettings>
 #include <QShowEvent>
@@ -82,6 +83,36 @@ GuiSearchWidget::GuiSearchWidget(QWidget * parent)
 
 	setFocusProxy(findCO);
 
+	// Use a FancyLineEdit due to the indicator icons
+	findLE_ = new FancyLineEdit(this);
+	findCO->setLineEdit(findLE_);
+
+	// And a menu in minimal mode
+	menu_ = new QMenu();
+	act_casesense_ = new QAction(qt_("&Case sensitive[[search]]"), this);
+	act_casesense_->setCheckable(true);
+	act_wholewords_ = new QAction(qt_("Wh&ole words"), this);
+	act_wholewords_->setCheckable(true);
+	act_selection_ = new QAction(qt_("Selection onl&y"), this);
+	act_selection_->setCheckable(true);
+	act_immediate_ = new QAction(qt_("Search as yo&u type"), this);
+	act_immediate_->setCheckable(true);
+	act_wrap_ = new QAction(qt_("&Wrap"), this);
+	act_wrap_->setCheckable(true);
+
+	menu_->addAction(act_casesense_);
+	menu_->addAction(act_wholewords_);
+	menu_->addAction(act_selection_);
+	menu_->addAction(act_immediate_);
+	menu_->addAction(act_wrap_);
+	findLE_->setButtonMenu(FancyLineEdit::Right, menu_);
+
+	connect(act_casesense_, SIGNAL(triggered()), this, SLOT(caseSenseActTriggered()));
+	connect(act_wholewords_, SIGNAL(triggered()), this, SLOT(wholeWordsActTriggered()));
+	connect(act_selection_, SIGNAL(triggered()), this, SLOT(searchSelActTriggered()));
+	connect(act_immediate_, SIGNAL(triggered()), this, SLOT(immediateActTriggered()));
+	connect(act_wrap_, SIGNAL(triggered()), this, SLOT(wrapActTriggered()));
+
 	findCO->setCompleter(nullptr);
 	replaceCO->setCompleter(nullptr);
 
@@ -148,9 +179,18 @@ void GuiSearchWidget::minimizeClicked(bool const toggle)
 	replacePrevPB->setHidden(minimized_);
 	replaceallPB->setHidden(minimized_);
 	CBFrame->setHidden(minimized_);
+
 	if (minimized_) {
 		minimizePB->setText(qt_("Ex&pand"));
 		minimizePB->setToolTip(qt_("Show replace and option widgets"));
+		// update menu items
+		blockSignals(true);
+		act_casesense_->setChecked(caseCB->isChecked());
+		act_immediate_->setChecked(instantSearchCB->isChecked());
+		act_selection_->setChecked(selectionCB->isChecked());
+		act_wholewords_->setChecked(wordsCB->isChecked());
+		act_wrap_->setChecked(wrapCB->isChecked());
+		blockSignals(false);
 	} else {
 		minimizePB->setText(qt_("&Minimize"));
 		minimizePB->setToolTip(qt_("Hide replace and option widgets"));
@@ -158,6 +198,113 @@ void GuiSearchWidget::minimizeClicked(bool const toggle)
 
 	Q_EMIT needSizeUpdate();
 	Q_EMIT needTitleBarUpdate();
+	handleIndicators();
+}
+
+
+void GuiSearchWidget::handleIndicators()
+{
+	findLE_->setButtonVisible(FancyLineEdit::Right, minimized_);
+
+	QString tip;
+
+	if (minimized_) {
+		int pms = 0;
+		if (caseCB->isChecked())
+			++pms;
+		if (wordsCB->isChecked())
+			++pms;
+		if (selectionCB->isChecked())
+			++pms;
+		if (instantSearchCB->isChecked())
+			++pms;
+		if (wrapCB->isChecked())
+			++pms;
+
+		QPixmap bpixmap = getPixmap("images/", "search-options", "svgz,png");
+
+		if (pms > 0) {
+			int const gap = 3;
+			QPixmap tpixmap(pms * (bpixmap.width() + gap), bpixmap.height());
+			tpixmap.fill();
+			QPainter painter(&tpixmap);
+			int x = 0;
+			
+			tip = qt_("Active options:");
+			tip += "<ul>";
+			if (caseCB->isChecked()) {
+				tip += "<li>" + qt_("Case sensitive search");
+				QPixmap spixmap = getPixmap("images/", "search-case-sensitive", "svgz,png");
+				painter.drawPixmap(x, 0, spixmap);
+				x += spixmap.width() + gap;
+			}
+			if (wordsCB->isChecked()) {
+				tip += "<li>" + qt_("Whole words only");
+				QPixmap spixmap = getPixmap("images/", "search-whole-words", "svgz,png");
+				painter.drawPixmap(x, 0, spixmap);
+				x += spixmap.width() + gap;
+			}
+			if (selectionCB->isChecked()) {
+				tip += "<li>" + qt_("Search only in selection");
+				QPixmap spixmap = getPixmap("images/", "search-selection", "svgz,png");
+				painter.drawPixmap(x, 0, spixmap);
+				x += spixmap.width() + gap;
+			}
+			if (instantSearchCB->isChecked()) {
+				tip += "<li>" + qt_("Search as you type");
+				QPixmap spixmap = getPixmap("images/", "search-instant", "svgz,png");
+				painter.drawPixmap(x, 0, spixmap);
+				x += spixmap.width() + gap;
+			}
+			if (wrapCB->isChecked()) {
+				tip += "<li>" + qt_("Wrap search");
+				QPixmap spixmap = getPixmap("images/", "search-wrap", "svgz,png");
+				painter.drawPixmap(x, 0, spixmap);
+				x += spixmap.width() + gap;
+			}
+			tip += "</ul>";
+			findLE_->setButtonPixmap(FancyLineEdit::Right, tpixmap);
+		} else {
+			tip = qt_("Click here to change search options");
+			findLE_->setButtonPixmap(FancyLineEdit::Right, bpixmap);
+		}
+	}
+	findLE_->setButtonToolTip(FancyLineEdit::Right, tip);
+}
+
+
+void GuiSearchWidget::caseSenseActTriggered()
+{
+	caseCB->setChecked(act_casesense_->isChecked());
+	handleIndicators();
+}
+
+
+void GuiSearchWidget::wholeWordsActTriggered()
+{
+	wordsCB->setChecked(act_wholewords_->isChecked());
+	handleIndicators();
+}
+
+
+void GuiSearchWidget::searchSelActTriggered()
+{
+	selectionCB->setChecked(act_selection_->isChecked());
+	handleIndicators();
+}
+
+
+void GuiSearchWidget::immediateActTriggered()
+{
+	instantSearchCB->setChecked(act_immediate_->isChecked());
+	handleIndicators();
+}
+
+
+void GuiSearchWidget::wrapActTriggered()
+{
+	wrapCB->setChecked(act_wrap_->isChecked());
+	handleIndicators();
 }
 
 
@@ -293,10 +440,15 @@ void GuiSearchWidget::restoreSession(QString const & session_key)
 {
 	QSettings settings;
 	caseCB->setChecked(settings.value(session_key + "/casesensitive", false).toBool());
+	act_casesense_->setChecked(settings.value(session_key + "/casesensitive", false).toBool());
 	wordsCB->setChecked(settings.value(session_key + "/words", false).toBool());
+	act_wholewords_->setChecked(settings.value(session_key + "/words", false).toBool());
 	instantSearchCB->setChecked(settings.value(session_key + "/instant", false).toBool());
+	act_immediate_->setChecked(settings.value(session_key + "/instant", false).toBool());
 	wrapCB->setChecked(settings.value(session_key + "/wrap", false).toBool());
+	act_wrap_->setChecked(settings.value(session_key + "/wrap", false).toBool());
 	selectionCB->setChecked(settings.value(session_key + "/selection", false).toBool());
+	act_selection_->setChecked(settings.value(session_key + "/selection", false).toBool());
 	minimized_ = settings.value(session_key + "/minimized", false).toBool();
 	// initialize hidings
 	minimizeClicked(false);
diff --git a/src/frontends/qt/GuiSearch.h b/src/frontends/qt/GuiSearch.h
index 440e277..a6d1fd8 100644
--- a/src/frontends/qt/GuiSearch.h
+++ b/src/frontends/qt/GuiSearch.h
@@ -15,7 +15,9 @@
 
 #include "GuiDialog.h"
 #include "DockView.h"
+#include "FancyLineEdit.h"
 
+#include <QMenu>
 #include <QDockWidget>
 
 #include "ui_SearchUi.h"
@@ -51,6 +53,11 @@ private Q_SLOTS:
 	void replacePrevClicked();
 	void replaceallClicked();
 	void minimizeClicked(bool const toggle = true);
+	void caseSenseActTriggered();
+	void wholeWordsActTriggered();
+	void searchSelActTriggered();
+	void immediateActTriggered();
+	void wrapActTriggered();
 Q_SIGNALS:
 	void needTitleBarUpdate() const;
 	void needSizeUpdate() const;
@@ -74,9 +81,25 @@ private:
 		     bool casesensitive, bool matchword,
 		     bool forward, bool all, bool wrap, bool onlysel);
 	///
+	void handleIndicators();
+	///
 	BufferView const * bv_ = nullptr;
 	///
 	bool minimized_ = false;
+	/// contains the search box
+	FancyLineEdit * findLE_;
+	/// The options menu
+	QMenu * menu_;
+	/// And its actions
+	QAction * act_casesense_ = new QAction(this);
+	///
+	QAction * act_wholewords_ = new QAction(this);
+	///
+	QAction * act_selection_ = new QAction(this);
+	///
+	QAction * act_immediate_ = new QAction(this);
+	///
+	QAction * act_wrap_ = new QAction(this);
 };
 
 


More information about the lyx-cvs mailing list