• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kleopatra

searchbar.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset:4 -*-
00002     view/searchbar.cpp
00003 
00004     This file is part of Kleopatra, the KDE keymanager
00005     Copyright (c) 2007 Klarälvdalens Datakonsult AB
00006 
00007     Kleopatra is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     Kleopatra is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021     In addition, as a special exception, the copyright holders give
00022     permission to link the code of this program with any edition of
00023     the Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), and distribute linked
00025     combinations including the two.  You must obey the GNU General
00026     Public License in all respects for all of the code used other than
00027     Qt.  If you modify this file, you may extend this exception to
00028     your version of the file, but you are not obligated to do so.  If
00029     you do not wish to do so, delete this exception statement from
00030     your version.
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, /*stretch=*/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 // slot
00123 void SearchBar::setStringFilter( const QString & filter ) {
00124     d->lineEdit->setText( filter );
00125 }
00126 
00127 // slot
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 // slot
00137 void SearchBar::setChangeStringFilterEnabled( bool on ) {
00138     d->lineEdit->setEnabled( on );
00139 }
00140 
00141 // slot
00142 void SearchBar::setChangeKeyFilterEnabled( bool on ) {
00143     d->combo->setEnabled( on );
00144 }
00145 
00146 #include "moc_searchbar.cpp"
00147 

kleopatra

Skip menu "kleopatra"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal