[LyX/master] FancyLineEdit: use QLineEdit's own clear button with Qt >= 5.2

Juergen Spitzmueller spitz at lyx.org
Tue Feb 23 15:50:08 UTC 2021


commit 55da675efa725a37604988917f436bce058d1583
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Tue Feb 23 16:53:15 2021 +0100

    FancyLineEdit: use QLineEdit's own clear button with Qt >= 5.2
---
 src/frontends/qt/FancyLineEdit.cpp |   18 ++++++++++++++++++
 src/frontends/qt/FancyLineEdit.h   |    3 +++
 src/frontends/qt/GuiBibtex.cpp     |    5 +----
 src/frontends/qt/GuiCitation.cpp   |    5 +----
 src/frontends/qt/GuiDocument.cpp   |    5 +----
 src/frontends/qt/GuiLyXFiles.cpp   |    5 +----
 src/frontends/qt/GuiRef.cpp        |    5 +----
 src/frontends/qt/PanelStack.cpp    |    6 +-----
 8 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/src/frontends/qt/FancyLineEdit.cpp b/src/frontends/qt/FancyLineEdit.cpp
index 9b17a9a..c3b597c 100644
--- a/src/frontends/qt/FancyLineEdit.cpp
+++ b/src/frontends/qt/FancyLineEdit.cpp
@@ -15,6 +15,10 @@
 
 #include "FancyLineEdit.h"
 
+#if QT_VERSION < 0x050200
+#include "GuiApplication.h"
+#endif
+
 #if QT_VERSION >= 0x040600
 
 #include <QEvent>
@@ -135,6 +139,20 @@ void FancyLineEdit::checkButtons(const QString &text)
 }
 
 
+void FancyLineEdit::setClearButton(bool visible)
+{
+// QLineEdit::setClearButtonEnabled() has been implemented in Qt 5.2.
+// In earlier Qt versions, we roll our own button
+#if QT_VERSION < 0x050200
+	setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png"));
+	setButtonVisible(FancyLineEdit::Right, visible);
+	setAutoHideButton(FancyLineEdit::Right, true);
+#else
+	setClearButtonEnabled(visible);
+#endif
+}
+
+
 void FancyLineEdit::setButtonVisible(Side side, bool visible)
 {
 	m_d->m_iconbutton[side]->setVisible(visible);
diff --git a/src/frontends/qt/FancyLineEdit.h b/src/frontends/qt/FancyLineEdit.h
index c28a028..5d55640 100644
--- a/src/frontends/qt/FancyLineEdit.h
+++ b/src/frontends/qt/FancyLineEdit.h
@@ -71,6 +71,9 @@ public:
 	explicit FancyLineEdit(QWidget *parent = 0);
 	~FancyLineEdit() {}
 
+	/// Set a button to clear contents
+	void setClearButton(bool visible);
+
 	QPixmap buttonPixmap(Side side) const;
 	void setButtonPixmap(Side side, const QPixmap &pixmap);
 
diff --git a/src/frontends/qt/GuiBibtex.cpp b/src/frontends/qt/GuiBibtex.cpp
index a9b5fad..64bb987 100644
--- a/src/frontends/qt/GuiBibtex.cpp
+++ b/src/frontends/qt/GuiBibtex.cpp
@@ -64,10 +64,7 @@ GuiBibtex::GuiBibtex(GuiView & lv)
 
 	// The filter bar
 	filter_ = new FancyLineEdit(this);
-	filter_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png"));
-	filter_->setButtonVisible(FancyLineEdit::Right, true);
-	filter_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
-	filter_->setAutoHideButton(FancyLineEdit::Right, true);
+	filter_->setClearButton(true);
 	filter_->setPlaceholderText(qt_("All avail. databases"));
 
 	filterBarL->addWidget(filter_, 0);
diff --git a/src/frontends/qt/GuiCitation.cpp b/src/frontends/qt/GuiCitation.cpp
index b60718d..4b55488 100644
--- a/src/frontends/qt/GuiCitation.cpp
+++ b/src/frontends/qt/GuiCitation.cpp
@@ -98,10 +98,7 @@ GuiCitation::GuiCitation(GuiView & lv)
 
 	// The filter bar
 	filter_ = new FancyLineEdit(this);
-	filter_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png"));
-	filter_->setButtonVisible(FancyLineEdit::Right, true);
-	filter_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
-	filter_->setAutoHideButton(FancyLineEdit::Right, true);
+	filter_->setClearButton(true);
 	filter_->setPlaceholderText(qt_("All avail. citations"));
 
 	filterBarL->addWidget(filter_, 0);
diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp
index 413169d..85564bd 100644
--- a/src/frontends/qt/GuiDocument.cpp
+++ b/src/frontends/qt/GuiDocument.cpp
@@ -1656,10 +1656,7 @@ GuiDocument::GuiDocument(GuiView & lv)
 		this, SLOT(modulesChanged()));
 	// The filter bar
 	filter_ = new FancyLineEdit(this);
-	filter_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png"));
-	filter_->setButtonVisible(FancyLineEdit::Right, true);
-	filter_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
-	filter_->setAutoHideButton(FancyLineEdit::Right, true);
+	filter_->setClearButton(true);
 	filter_->setPlaceholderText(qt_("All avail. modules"));
 	modulesModule->moduleFilterBarL->addWidget(filter_, 0);
 	modulesModule->findModulesLA->setBuddy(filter_);
diff --git a/src/frontends/qt/GuiLyXFiles.cpp b/src/frontends/qt/GuiLyXFiles.cpp
index afed230..ee02d7b 100644
--- a/src/frontends/qt/GuiLyXFiles.cpp
+++ b/src/frontends/qt/GuiLyXFiles.cpp
@@ -186,10 +186,7 @@ GuiLyXFiles::GuiLyXFiles(GuiView & lv)
 
 	// The filter bar
 	filter_ = new FancyLineEdit(this);
-	filter_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png"));
-	filter_->setButtonVisible(FancyLineEdit::Right, true);
-	filter_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
-	filter_->setAutoHideButton(FancyLineEdit::Right, true);
+	filter_->setClearButton(true);
 	filter_->setPlaceholderText(qt_("All available files"));
 	filter_->setToolTip(qt_("Enter string to filter the list of available files"));
 #if (QT_VERSION < 0x050000)
diff --git a/src/frontends/qt/GuiRef.cpp b/src/frontends/qt/GuiRef.cpp
index 77ab515..2836190 100644
--- a/src/frontends/qt/GuiRef.cpp
+++ b/src/frontends/qt/GuiRef.cpp
@@ -56,10 +56,7 @@ GuiRef::GuiRef(GuiView & lv)
 
 	// The filter bar
 	filter_ = new FancyLineEdit(this);
-	filter_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png"));
-	filter_->setButtonVisible(FancyLineEdit::Right, true);
-	filter_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
-	filter_->setAutoHideButton(FancyLineEdit::Right, true);
+	filter_->setClearButton(true);
 	filter_->setPlaceholderText(qt_("All available labels"));
 	filter_->setToolTip(qt_("Enter string to filter the list of available labels"));
 #if (QT_VERSION < 0x050000)
diff --git a/src/frontends/qt/PanelStack.cpp b/src/frontends/qt/PanelStack.cpp
index 22eab2a..745442b 100644
--- a/src/frontends/qt/PanelStack.cpp
+++ b/src/frontends/qt/PanelStack.cpp
@@ -73,11 +73,7 @@ PanelStack::PanelStack(QWidget * parent)
 
 	// Configure the search box
 	search_->setPlaceholderText(qt_("Search"));
-	search_->setButtonPixmap(FancyLineEdit::Right,
-	                         getPixmap("images/", "editclear", "svgz,png"));
-	search_->setButtonVisible(FancyLineEdit::Right, true);
-	search_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
-	search_->setAutoHideButton(FancyLineEdit::Right, true);
+	search_->setClearButton(true);
 	connect(search_, SIGNAL(rightButtonClicked()),
 	        this, SLOT(resetSearch()));
 	connect(search_, SIGNAL(textEdited(QString)),


More information about the lyx-cvs mailing list