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

kleopatra

  • sources
  • kde-4.12
  • kdepim
  • kleopatra
  • view
searchbar.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  view/searchbar.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2007 Klarälvdalens Datakonsult AB
6 
7  Kleopatra is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  Kleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #include <config-kleopatra.h>
34 
35 #include "searchbar.h"
36 
37 #include <kleo/keyfilter.h>
38 #include <kleo/keyfiltermanager.h>
39 
40 #include <KLocale>
41 #include <KLineEdit>
42 
43 #include <QLabel>
44 #include <QComboBox>
45 #include <QHBoxLayout>
46 
47 #include <cassert>
48 
49 using namespace Kleo;
50 using namespace boost;
51 
52 class SearchBar::Private {
53  friend class ::Kleo::SearchBar;
54  SearchBar * const q;
55 public:
56  explicit Private( SearchBar * qq );
57  ~Private();
58 
59 private:
60  void slotKeyFilterChanged( int idx ) {
61  emit q->keyFilterChanged( keyFilter( idx ) );
62  }
63 
64  shared_ptr<KeyFilter> keyFilter( int idx ) const {
65  const QModelIndex mi = KeyFilterManager::instance()->model()->index( idx, 0 );
66  return KeyFilterManager::instance()->fromModelIndex( mi );
67  }
68 
69  shared_ptr<KeyFilter> currentKeyFilter() const {
70  return keyFilter( combo->currentIndex() );
71  }
72 
73  QString currentKeyFilterID() const {
74  if ( const shared_ptr<KeyFilter> f = currentKeyFilter() )
75  return f->id();
76  else
77  return QString();
78  }
79 
80 private:
81  KLineEdit * lineEdit;
82  QComboBox * combo;
83 };
84 
85 SearchBar::Private::Private( SearchBar * qq )
86  : q( qq )
87 {
88  QHBoxLayout * layout = new QHBoxLayout( q );
89  layout->setMargin( 0 );
90  QLabel * label = new QLabel( i18n("&Find:"), q );
91  layout->addWidget( label );
92  lineEdit = new KLineEdit( q );
93  lineEdit->setClearButtonShown( true );
94  label->setBuddy( lineEdit );
95  layout->addWidget( lineEdit, /*stretch=*/1 );
96  combo = new QComboBox( q );
97  layout->addWidget( combo );
98 
99  combo->setModel( KeyFilterManager::instance()->model() );
100 
101  KDAB_SET_OBJECT_NAME( layout );
102  KDAB_SET_OBJECT_NAME( label );
103  KDAB_SET_OBJECT_NAME( lineEdit );
104  KDAB_SET_OBJECT_NAME( combo );
105 
106  connect( lineEdit, SIGNAL(textChanged(QString)),
107  q, SIGNAL(stringFilterChanged(QString)) );
108  connect( combo, SIGNAL(currentIndexChanged(int)),
109  q, SLOT(slotKeyFilterChanged(int)) );
110 }
111 
112 SearchBar::Private::~Private() {}
113 
114 SearchBar::SearchBar( QWidget * parent, Qt::WindowFlags f )
115  : QWidget( parent, f ), d( new Private( this ) )
116 {
117 
118 }
119 
120 SearchBar::~SearchBar() {}
121 
122 // slot
123 void SearchBar::setStringFilter( const QString & filter ) {
124  d->lineEdit->setText( filter );
125 }
126 
127 // slot
128 void SearchBar::setKeyFilter( const shared_ptr<KeyFilter> & kf ) {
129  const QModelIndex idx = KeyFilterManager::instance()->toModelIndex( kf );
130  if ( idx.isValid() )
131  d->combo->setCurrentIndex( idx.row() );
132  else
133  d->combo->setCurrentIndex( 0 );
134 }
135 
136 // slot
137 void SearchBar::setChangeStringFilterEnabled( bool on ) {
138  d->lineEdit->setEnabled( on );
139 }
140 
141 // slot
142 void SearchBar::setChangeKeyFilterEnabled( bool on ) {
143  d->combo->setEnabled( on );
144 }
145 
146 KLineEdit * SearchBar::lineEdit() const {
147  return d->lineEdit;
148 }
149 
150 #include "moc_searchbar.cpp"
151 
Kleo::SearchBar::setChangeKeyFilterEnabled
void setChangeKeyFilterEnabled(bool enable)
Definition: searchbar.cpp:142
QWidget
Kleo::SearchBar
Definition: searchbar.h:48
Kleo::SearchBar::setStringFilter
void setStringFilter(const QString &text)
Definition: searchbar.cpp:123
Kleo::SearchBar::lineEdit
KLineEdit * lineEdit() const
Definition: searchbar.cpp:146
boost::shared_ptr< KeyFilter >
Kleo::SearchBar::~SearchBar
~SearchBar()
Definition: searchbar.cpp:120
Kleo::SearchBar::setKeyFilter
void setKeyFilter(const boost::shared_ptr< Kleo::KeyFilter > &filter)
Definition: searchbar.cpp:128
d
#define d
Definition: adduseridcommand.cpp:90
KDAB_SET_OBJECT_NAME
#define KDAB_SET_OBJECT_NAME(x)
Definition: kdtoolsglobal.h:66
searchbar.h
q
#define q
Definition: adduseridcommand.cpp:91
Kleo::SearchBar::SearchBar
SearchBar(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: searchbar.cpp:114
Kleo::SearchBar::setChangeStringFilterEnabled
void setChangeStringFilterEnabled(bool enable)
Definition: searchbar.cpp:137
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:42 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal