diff --git a/src/frontends/qt/FancyLineEdit.cpp b/src/frontends/qt/FancyLineEdit.cpp index 9b17a9a7f6..c3b597c9e1 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 @@ -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 c28a028a11..5d55640e95 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 a9b5fade51..64bb987137 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 b60718d383..4b5548803b 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 413169d643..85564bd539 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 afed230da1..ee02d7bebb 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 77ab51535d..28361906ea 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 22eab2a6ce..745442b653 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)),