Skip to content
Permalink
Browse files
option to show a search icon in QgsFilterLineEdit
  • Loading branch information
3nids committed Feb 11, 2017
1 parent fe75e1f commit f3102bbf8f92484e0f06148fabc429ab411f2d39
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 0 deletions.
@@ -554,6 +554,7 @@
<file>themes/default/processingModel.svg</file>
<file>themes/default/processingScript.svg</file>
<file>themes/default/processingAlgorithm.svg</file>
<file>themes/default/search.svg</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -68,6 +68,19 @@ class QgsFilterLineEdit : QLineEdit
*/
QString nullValue() const;

/** Define if a search icon shall be shown on the left of the image
* when no text is entered
* @param visible set to false to hide the search icon
* @note added in QGIS 3.0
*/
void setShowSearchIcon( bool visible );

/** Returns if a search icon shall be shown on the left of the image
* when no text is entered
* @note added in QGIS 3.0
*/
bool showSearchIcon() const;

/** Sets the default value for the widget. The default value is a value
* which the widget will be reset to if it is cleared and the clearMode()
* is equal to ClearToDefault.
@@ -26,6 +26,7 @@
QgsFilterLineEdit::QgsFilterLineEdit( QWidget* parent, const QString& nullValue )
: QLineEdit( parent )
, mClearButtonVisible( true )
, mSearchIconVisible( false )
, mClearMode( ClearToNull )
, mNullValue( nullValue )
, mFocusInEvent( false )
@@ -40,6 +41,10 @@ QgsFilterLineEdit::QgsFilterLineEdit( QWidget* parent, const QString& nullValue
QIcon hoverIcon = QgsApplication::getThemeIcon( "/mIconClearTextHover.svg" );
mClearHoverPixmap = hoverIcon.pixmap( mClearIconSize );

QIcon searchIcon = QgsApplication::getThemeIcon( "/search.svg" );
mSearchIconSize = QSize( 16, 16 );
mSearchIconPixmap = searchIcon.pixmap( mSearchIconSize );

connect( this, SIGNAL( textChanged( const QString& ) ), this,
SLOT( onTextChanged( const QString& ) ) );
}
@@ -55,6 +60,16 @@ void QgsFilterLineEdit::setShowClearButton( bool visible )
update();
}

void QgsFilterLineEdit::setShowSearchIcon( bool visible )
{
bool changed = mSearchIconVisible != visible;
if ( changed )
{
mSearchIconVisible = visible;
update();
}
}

void QgsFilterLineEdit::mousePressEvent( QMouseEvent* e )
{
if ( !mFocusInEvent )
@@ -134,6 +149,13 @@ void QgsFilterLineEdit::paintEvent( QPaintEvent* e )
else
p.drawPixmap( r.left() , r.top() , mClearIconPixmap );
}

if ( mSearchIconVisible && !shouldShowClear() )
{
QRect r = searchRect();
QPainter p( this );
p.drawPixmap( r.left() , r.top() , mSearchIconPixmap );
}
}

void QgsFilterLineEdit::leaveEvent( QEvent* e )
@@ -191,3 +213,12 @@ QRect QgsFilterLineEdit::clearRect() const
mClearIconSize.width(),
mClearIconSize.height() );
}

QRect QgsFilterLineEdit::searchRect() const
{
int frameWidth = style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
return QRect( rect().left() + frameWidth * 2,
( rect().bottom() + 1 - mSearchIconSize.height() ) / 2,
mSearchIconSize.width(),
mSearchIconSize.height() );
}
@@ -41,6 +41,7 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
Q_PROPERTY( QString defaultValue READ defaultValue WRITE setDefaultValue )
Q_PROPERTY( QString value READ value WRITE setValue NOTIFY valueChanged )
Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )
Q_PROPERTY( bool showSearchIcon READ showSearchIcon WRITE setShowSearchIcon )

public:

@@ -98,6 +99,19 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
*/
QString nullValue() const { return mNullValue; }

/** Define if a search icon shall be shown on the left of the image
* when no text is entered
* @param visible set to false to hide the search icon
* @note added in QGIS 3.0
*/
void setShowSearchIcon( bool visible );

/** Returns if a search icon shall be shown on the left of the image
* when no text is entered
* @note added in QGIS 3.0
*/
bool showSearchIcon() const { return mSearchIconVisible; }

/** Sets the default value for the widget. The default value is a value
* which the widget will be reset to if it is cleared and the clearMode()
* is equal to ClearToDefault.
@@ -179,6 +193,7 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
private:

bool mClearButtonVisible;
bool mSearchIconVisible;

ClearMode mClearMode;

@@ -192,10 +207,14 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
QPixmap mClearIconPixmap;
QPixmap mClearHoverPixmap;

QSize mSearchIconSize;
QPixmap mSearchIconPixmap;

//! Returns true if clear button should be shown
bool shouldShowClear() const;

QRect clearRect() const;
QRect searchRect() const;
};

/// @cond PRIVATE

0 comments on commit f3102bb

Please sign in to comment.