kleopatra
searchbar.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <config-kleopatra.h>
00034
00035 #include "searchbar.h"
00036
00037 #include <kleo/keyfilter.h>
00038 #include <kleo/keyfiltermanager.h>
00039
00040 #include <KLocale>
00041 #include <KLineEdit>
00042
00043 #include <QLabel>
00044 #include <QComboBox>
00045 #include <QHBoxLayout>
00046
00047 #include <cassert>
00048
00049 using namespace Kleo;
00050 using namespace boost;
00051
00052 class SearchBar::Private {
00053 friend class ::Kleo::SearchBar;
00054 SearchBar * const q;
00055 public:
00056 explicit Private( SearchBar * qq );
00057 ~Private();
00058
00059 private:
00060 void slotKeyFilterChanged( int idx ) {
00061 emit q->keyFilterChanged( keyFilter( idx ) );
00062 }
00063
00064 shared_ptr<KeyFilter> keyFilter( int idx ) const {
00065 const QModelIndex mi = KeyFilterManager::instance()->model()->index( idx, 0 );
00066 return KeyFilterManager::instance()->fromModelIndex( mi );
00067 }
00068
00069 shared_ptr<KeyFilter> currentKeyFilter() const {
00070 return keyFilter( combo->currentIndex() );
00071 }
00072
00073 QString currentKeyFilterID() const {
00074 if ( const shared_ptr<KeyFilter> f = currentKeyFilter() )
00075 return f->id();
00076 else
00077 return QString();
00078 }
00079
00080 private:
00081 KLineEdit * lineEdit;
00082 QComboBox * combo;
00083 };
00084
00085 SearchBar::Private::Private( SearchBar * qq )
00086 : q( qq )
00087 {
00088 QHBoxLayout * layout = new QHBoxLayout( q );
00089 layout->setMargin( 0 );
00090 QLabel * label = new QLabel( i18n("&Find:"), q );
00091 layout->addWidget( label );
00092 lineEdit = new KLineEdit( q );
00093 lineEdit->setClearButtonShown( true );
00094 label->setBuddy( lineEdit );
00095 layout->addWidget( lineEdit, 1 );
00096 combo = new QComboBox( q );
00097 layout->addWidget( combo );
00098
00099 combo->setModel( KeyFilterManager::instance()->model() );
00100
00101 KDAB_SET_OBJECT_NAME( layout );
00102 KDAB_SET_OBJECT_NAME( label );
00103 KDAB_SET_OBJECT_NAME( lineEdit );
00104 KDAB_SET_OBJECT_NAME( combo );
00105
00106 connect( lineEdit, SIGNAL(textChanged(QString)),
00107 q, SIGNAL(stringFilterChanged(QString)) );
00108 connect( combo, SIGNAL(currentIndexChanged(int)),
00109 q, SLOT(slotKeyFilterChanged(int)) );
00110 }
00111
00112 SearchBar::Private::~Private() {}
00113
00114 SearchBar::SearchBar( QWidget * parent, Qt::WFlags f )
00115 : QWidget( parent, f ), d( new Private( this ) )
00116 {
00117
00118 }
00119
00120 SearchBar::~SearchBar() {}
00121
00122
00123 void SearchBar::setStringFilter( const QString & filter ) {
00124 d->lineEdit->setText( filter );
00125 }
00126
00127
00128 void SearchBar::setKeyFilter( const shared_ptr<KeyFilter> & kf ) {
00129 const QModelIndex idx = KeyFilterManager::instance()->toModelIndex( kf );
00130 if ( idx.isValid() )
00131 d->combo->setCurrentIndex( idx.row() );
00132 else
00133 d->combo->setCurrentIndex( 0 );
00134 }
00135
00136
00137 void SearchBar::setChangeStringFilterEnabled( bool on ) {
00138 d->lineEdit->setEnabled( on );
00139 }
00140
00141
00142 void SearchBar::setChangeKeyFilterEnabled( bool on ) {
00143 d->combo->setEnabled( on );
00144 }
00145
00146 #include "moc_searchbar.cpp"
00147