32 #include <QToolButton> 33 #include <QApplication> 51 , Button_ {
new QToolButton { edit } }
53 , EscShortcut_ {
new QShortcut { Qt::Key_Escape, edit, SLOT (clear ()),
nullptr, Qt::WidgetShortcut } }
55 const bool isRtl = QApplication::layoutDirection () == Qt::RightToLeft;
56 const auto& icon = proxy->GetIconThemeManager ()->GetIcon (isRtl ?
57 "edit-clear-locationbar-ltr" :
58 "edit-clear-locationbar-rtl");
60 Button_->setIconSize (QSize (16, 16));
61 Button_->setIcon (icon);
62 Button_->setCursor (Qt::ArrowCursor);
63 Button_->setStyleSheet (
"QToolButton { border: none; padding: 0px; }");
71 SIGNAL (textChanged (QString)),
73 SLOT (updateButton (QString)));
75 updateButton (edit->text ());
80 void ClearLineEditAddon::updateButton (
const QString& text)
82 Button_->setVisible (!text.isEmpty ());
87 EscShortcut_->setEnabled (clears);
ClearLineEditAddon(ICoreProxy_ptr proxy, QLineEdit *edit)
Creates the addon and installs it on the given edit.
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
void SetEscClearsEdit(bool clears)
Toggles whether Esc button clears the line edit.
Provides a "clear text" action for line edits.