FancyLineEdit: use QLineEdit's own clear button with Qt >= 5.2

This commit is contained in:
Juergen Spitzmueller 2021-02-23 16:53:15 +01:00
parent 2e79e8e884
commit 55da675efa
8 changed files with 27 additions and 25 deletions

View File

@ -15,6 +15,10 @@
#include "FancyLineEdit.h" #include "FancyLineEdit.h"
#if QT_VERSION < 0x050200
#include "GuiApplication.h"
#endif
#if QT_VERSION >= 0x040600 #if QT_VERSION >= 0x040600
#include <QEvent> #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) void FancyLineEdit::setButtonVisible(Side side, bool visible)
{ {
m_d->m_iconbutton[side]->setVisible(visible); m_d->m_iconbutton[side]->setVisible(visible);

View File

@ -71,6 +71,9 @@ public:
explicit FancyLineEdit(QWidget *parent = 0); explicit FancyLineEdit(QWidget *parent = 0);
~FancyLineEdit() {} ~FancyLineEdit() {}
/// Set a button to clear contents
void setClearButton(bool visible);
QPixmap buttonPixmap(Side side) const; QPixmap buttonPixmap(Side side) const;
void setButtonPixmap(Side side, const QPixmap &pixmap); void setButtonPixmap(Side side, const QPixmap &pixmap);

View File

@ -64,10 +64,7 @@ GuiBibtex::GuiBibtex(GuiView & lv)
// The filter bar // The filter bar
filter_ = new FancyLineEdit(this); filter_ = new FancyLineEdit(this);
filter_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png")); filter_->setClearButton(true);
filter_->setButtonVisible(FancyLineEdit::Right, true);
filter_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
filter_->setAutoHideButton(FancyLineEdit::Right, true);
filter_->setPlaceholderText(qt_("All avail. databases")); filter_->setPlaceholderText(qt_("All avail. databases"));
filterBarL->addWidget(filter_, 0); filterBarL->addWidget(filter_, 0);

View File

@ -98,10 +98,7 @@ GuiCitation::GuiCitation(GuiView & lv)
// The filter bar // The filter bar
filter_ = new FancyLineEdit(this); filter_ = new FancyLineEdit(this);
filter_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png")); filter_->setClearButton(true);
filter_->setButtonVisible(FancyLineEdit::Right, true);
filter_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
filter_->setAutoHideButton(FancyLineEdit::Right, true);
filter_->setPlaceholderText(qt_("All avail. citations")); filter_->setPlaceholderText(qt_("All avail. citations"));
filterBarL->addWidget(filter_, 0); filterBarL->addWidget(filter_, 0);

View File

@ -1656,10 +1656,7 @@ GuiDocument::GuiDocument(GuiView & lv)
this, SLOT(modulesChanged())); this, SLOT(modulesChanged()));
// The filter bar // The filter bar
filter_ = new FancyLineEdit(this); filter_ = new FancyLineEdit(this);
filter_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png")); filter_->setClearButton(true);
filter_->setButtonVisible(FancyLineEdit::Right, true);
filter_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
filter_->setAutoHideButton(FancyLineEdit::Right, true);
filter_->setPlaceholderText(qt_("All avail. modules")); filter_->setPlaceholderText(qt_("All avail. modules"));
modulesModule->moduleFilterBarL->addWidget(filter_, 0); modulesModule->moduleFilterBarL->addWidget(filter_, 0);
modulesModule->findModulesLA->setBuddy(filter_); modulesModule->findModulesLA->setBuddy(filter_);

View File

@ -186,10 +186,7 @@ GuiLyXFiles::GuiLyXFiles(GuiView & lv)
// The filter bar // The filter bar
filter_ = new FancyLineEdit(this); filter_ = new FancyLineEdit(this);
filter_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png")); filter_->setClearButton(true);
filter_->setButtonVisible(FancyLineEdit::Right, true);
filter_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
filter_->setAutoHideButton(FancyLineEdit::Right, true);
filter_->setPlaceholderText(qt_("All available files")); filter_->setPlaceholderText(qt_("All available files"));
filter_->setToolTip(qt_("Enter string to filter the list of available files")); filter_->setToolTip(qt_("Enter string to filter the list of available files"));
#if (QT_VERSION < 0x050000) #if (QT_VERSION < 0x050000)

View File

@ -56,10 +56,7 @@ GuiRef::GuiRef(GuiView & lv)
// The filter bar // The filter bar
filter_ = new FancyLineEdit(this); filter_ = new FancyLineEdit(this);
filter_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png")); filter_->setClearButton(true);
filter_->setButtonVisible(FancyLineEdit::Right, true);
filter_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
filter_->setAutoHideButton(FancyLineEdit::Right, true);
filter_->setPlaceholderText(qt_("All available labels")); filter_->setPlaceholderText(qt_("All available labels"));
filter_->setToolTip(qt_("Enter string to filter the list of available labels")); filter_->setToolTip(qt_("Enter string to filter the list of available labels"));
#if (QT_VERSION < 0x050000) #if (QT_VERSION < 0x050000)

View File

@ -73,11 +73,7 @@ PanelStack::PanelStack(QWidget * parent)
// Configure the search box // Configure the search box
search_->setPlaceholderText(qt_("Search")); search_->setPlaceholderText(qt_("Search"));
search_->setButtonPixmap(FancyLineEdit::Right, search_->setClearButton(true);
getPixmap("images/", "editclear", "svgz,png"));
search_->setButtonVisible(FancyLineEdit::Right, true);
search_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
search_->setAutoHideButton(FancyLineEdit::Right, true);
connect(search_, SIGNAL(rightButtonClicked()), connect(search_, SIGNAL(rightButtonClicked()),
this, SLOT(resetSearch())); this, SLOT(resetSearch()));
connect(search_, SIGNAL(textEdited(QString)), connect(search_, SIGNAL(textEdited(QString)),