21 #include <QToolButton> 23 #include <QFocusEvent> 28 , mClearButtonVisible( true )
29 , mClearMode( ClearToNull )
30 , mNullValue( nullValue )
31 , mFocusInEvent( false )
32 , mClearHover( false )
39 mClearIconSize =
QSize( size, size );
40 mClearIconPixmap = clearIcon.
pixmap( mClearIconSize );
42 mClearHoverPixmap = hoverIcon.
pixmap( mClearIconSize );
48 SLOT( onTextChanged(
const QString& ) ) );
53 bool changed = mClearButtonVisible !=
visible;
67 mFocusInEvent =
false;
69 if ( shouldShowClear() && clearRect().contains( e->
pos() ) )
78 if ( shouldShowClear() && clearRect().contains( e->
pos() ) )
87 else if ( mClearHover )
100 mFocusInEvent =
true;
107 switch ( mClearMode )
132 if ( shouldShowClear() )
134 QRect r = clearRect();
154 void QgsFilterLineEdit::onTextChanged(
const QString &
text )
167 if ( mClearHover && !shouldShowClear() )
174 bool QgsFilterLineEdit::shouldShowClear()
const 179 switch ( mClearMode )
185 return value() != mDefaultValue;
190 QRect QgsFilterLineEdit::clearRect()
const 193 return QRect(
rect().right() - frameWidth * 2 - mClearIconSize.
width(),
195 mClearIconSize.
width(),
196 mClearIconSize.
height() );
void valueChanged(const QString &value)
Same as textChanged() but with support for null values.
void leaveEvent(QEvent *e) override
QMargins textMargins() const
void mouseMoveEvent(QMouseEvent *e) override
void setText(const QString &)
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const=0
void paintEvent(QPaintEvent *e) override
void textChanged(const QString &text)
QPixmap pixmap(const QSize &size, Mode mode, State state) const
Qt::FocusReason reason() const
void mousePressEvent(QMouseEvent *e) override
Reset value to default value (see defaultValue() )
virtual void clearValue()
Clears the widget and resets it to the null value.
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
void setTextMargins(int left, int top, int right, int bottom)
virtual void paintEvent(QPaintEvent *)
QgsFilterLineEdit(QWidget *parent=nullptr, const QString &nullValue=QString::null)
Constructor for QgsFilterLineEdit.
virtual void mouseMoveEvent(QMouseEvent *e)
void focusInEvent(QFocusEvent *e) override
virtual void focusInEvent(QFocusEvent *e)
void cleared()
Emitted when the widget is cleared.
bool isNull() const
Determine if the current text represents null.
const QPoint & pos() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setShowClearButton(bool visible)
Sets whether the widget's clear button is visible.
virtual void mousePressEvent(QMouseEvent *e)
QString value() const
Returns the text of this edit with support for handling null values.