SearchLineEdit::SearchLineEdit( QWidget *parent ) : QLineEdit( parent ) { clearButton = new QFramelessButton( this ); clearButton->setIcon( QIcon( ":/search_clear" ) ); clearButton->setIconSize( QSize( 16, 16 ) ); clearButton->setCursor( Qt::ArrowCursor ); clearButton->setToolTip( qfu(vlc_pgettext("Tooltip|Clear", "Clear")) ); clearButton->hide(); CONNECT( clearButton, clicked(), this, clear() ); int frameWidth = style()->pixelMetric( QStyle::PM_DefaultFrameWidth, 0, this ); QFontMetrics metrics( font() ); QString styleSheet = QString( "min-height: %1px; " "padding-top: 1px; " "padding-bottom: 1px; " "padding-right: %2px;" ) .arg( metrics.height() + ( 2 * frameWidth ) ) .arg( clearButton->sizeHint().width() + 6 ); setStyleSheet( styleSheet ); setMessageVisible( true ); CONNECT( this, textEdited( const QString& ), this, updateText( const QString& ) ); CONNECT( this, editingFinished(), this, searchEditingFinished() ); }
void SearchLineEdit::clear() { setText( QString() ); m_clearButton->hide(); setMessageVisible( true ); }
SearchLineEdit::SearchLineEdit( QWidget *parent ) : QLineEdit( parent ) { m_clearButton = new FramelessButton( this ); m_clearButton->setIcon( QIcon( ":/images/clear" ) ); m_clearButton->setIconSize( QSize( 16, 16 ) ); m_clearButton->setCursor( Qt::ArrowCursor ); m_clearButton->setToolTip( tr( "Clear" ) ); m_clearButton->hide(); connect( m_clearButton, SIGNAL( clicked() ), this, SLOT( clear() ) ); int frameWidth = style()->pixelMetric( QStyle::PM_DefaultFrameWidth, 0, this ); QFontMetrics metrics( font() ); QString styleSheet = QString( "min-height: %1px; " "padding-top: 1px; " "padding-bottom: 1px; " "padding-right: %2px;" ) .arg( metrics.height() + ( 2 * frameWidth ) ) .arg( m_clearButton->sizeHint().width() + 1 ); setStyleSheet( styleSheet ); setMessageVisible( true ); connect( this, SIGNAL( textEdited( const QString& ) ), this, SLOT( updateText( const QString& ) ) ); }
void SearchLineEdit::focusOutEvent( QFocusEvent *event ) { if( text().isEmpty() ) { setMessageVisible( true ); } QLineEdit::focusOutEvent( event ); }
void SearchLineEdit::focusInEvent( QFocusEvent *event ) { if( message ) { setMessageVisible( false ); } QLineEdit::focusInEvent( event ); }
void SearchLineEdit::updateText( const QString& text ) { /* if reset() won't be focused out */ if ( !text.isEmpty() ) setMessageVisible( false ); clearButton->setVisible( !text.isEmpty() ); }