32 #include <QToolButton>
33 #include <QApplication>
42 , Button_ (new QToolButton (edit))
45 const bool isRtl = QApplication::layoutDirection () == Qt::RightToLeft;
46 const auto& icon = proxy->GetIcon (isRtl ?
47 "edit-clear-locationbar-ltr" :
48 "edit-clear-locationbar-rtl");
50 Button_->setIconSize (QSize (16, 16));
51 Button_->setIcon (icon);
52 Button_->setCursor (Qt::ArrowCursor);
53 Button_->setStyleSheet (
"QToolButton { border: none; padding: 0px; }");
61 SIGNAL (textChanged (QString)),
63 SLOT (updateButton (QString)));
65 const int frameWidth = edit->style ()->pixelMetric (QStyle::PM_DefaultFrameWidth);
66 edit->setStyleSheet (QString (
"QLineEdit { padding-right: %1px; }")
67 .arg (Button_->sizeHint ().width () + frameWidth + 1));
68 const auto msz = edit->minimumSizeHint ();
69 edit->setMinimumSize (qMax (msz.width (), Button_->sizeHint ().height () + frameWidth * 2 + 2),
70 qMax (msz.height(), Button_->sizeHint ().height () + frameWidth * 2 + 2));
74 edit->installEventFilter (
this);
75 updateButton (edit->text ());
80 if (event->type () == QEvent::Resize ||
81 event->type () == QEvent::Move)
84 return QObject::eventFilter (obj, event);
87 void ClearLineEditAddon::UpdatePos ()
89 const auto& hint = Button_->sizeHint ();
90 const auto& rect = Edit_->rect ();
91 const int frameWidth = Edit_->style ()->pixelMetric (QStyle::PM_DefaultFrameWidth);
92 Button_->move (rect.right () - frameWidth - hint.width (),
93 (rect.bottom () + 1 - hint.height ()) / 2);
96 void ClearLineEditAddon::updateButton (
const QString& text)
98 Button_->setVisible (!text.isEmpty ());
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
ClearLineEditAddon(ICoreProxy_ptr proxy, QLineEdit *edit)
Creates the addon and installs it on the given edit.
bool eventFilter(QObject *, QEvent *)