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
@@ -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>
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
height="16"
version="1.1"
viewBox="0 0 16 16"
width="16"
id="svg2"
inkscape:version="0.91 r13725"
sodipodi:docname="search.svg">
<metadata
id="metadata15">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1732"
inkscape:window-height="977"
id="namedview13"
showgrid="false"
inkscape:zoom="11.313708"
inkscape:cx="3.1800974"
inkscape:cy="-12.185144"
inkscape:window-x="414"
inkscape:window-y="64"
inkscape:window-maximized="0"
inkscape:current-layer="svg2" />
<desc
id="desc6" />
<defs
id="defs8" />
<g
id="Page-1"
style="fill:none;fill-rule:evenodd;stroke:none;stroke-width:1"
transform="matrix(0.56015021,0,0,0.56015021,-1.3609013,-1.3602825)">
<g
id="icon-111-search"
style="fill:#929292">
<path
d="M 19.427116,21.427116 C 18.03725,22.41748 16.336652,23 14.5,23 9.8055794,23 6,19.194421 6,14.5 6,9.8055794 9.8055794,6 14.5,6 c 4.694421,0 8.5,3.8055794 8.5,8.5 0,1.836652 -0.58252,3.53725 -1.572884,4.927116 l 5.584802,5.584802 c 0.550201,0.550201 0.545613,1.430551 -2e-4,1.976363 l -0.02344,0.02344 c -0.544416,0.544417 -1.430661,0.545902 -1.976363,2e-4 l -5.584802,-5.584802 0,0 z M 14.5,21 C 18.089851,21 21,18.089851 21,14.5 21,10.910149 18.089851,8 14.5,8 10.910149,8 8,10.910149 8,14.5 8,18.089851 10.910149,21 14.5,21 l 0,0 z"
id="search"
inkscape:connector-curvature="0" />
</g>
</g>
</svg>
@@ -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.
You can’t perform that action at this time.