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

kleopatra

  • sources
  • kde-4.14
  • 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 <KLocalizedString>
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  lineEdit = new KLineEdit( q );
91  lineEdit->setClearButtonShown( true );
92  lineEdit->setClickMessage(i18n("Search..."));
93  layout->addWidget( lineEdit, /*stretch=*/1 );
94  combo = new QComboBox( q );
95  layout->addWidget( combo );
96 
97  combo->setModel( KeyFilterManager::instance()->model() );
98 
99  KDAB_SET_OBJECT_NAME( layout );
100  KDAB_SET_OBJECT_NAME( lineEdit );
101  KDAB_SET_OBJECT_NAME( combo );
102 
103  connect( lineEdit, SIGNAL(textChanged(QString)),
104  q, SIGNAL(stringFilterChanged(QString)) );
105  connect( combo, SIGNAL(currentIndexChanged(int)),
106  q, SLOT(slotKeyFilterChanged(int)) );
107 }
108 
109 SearchBar::Private::~Private() {}
110 
111 SearchBar::SearchBar( QWidget * parent, Qt::WindowFlags f )
112  : QWidget( parent, f ), d( new Private( this ) )
113 {
114 
115 }
116 
117 SearchBar::~SearchBar() {}
118 
119 
120 void SearchBar::updateClickMessage(const QString &shortcutStr)
121 {
122  d->lineEdit->setClickMessage(i18n("Search...<%1>", shortcutStr));
123 }
124 
125 // slot
126 void SearchBar::setStringFilter( const QString & filter ) {
127  d->lineEdit->setText( filter );
128 }
129 
130 // slot
131 void SearchBar::setKeyFilter( const shared_ptr<KeyFilter> & kf ) {
132  const QModelIndex idx = KeyFilterManager::instance()->toModelIndex( kf );
133  if ( idx.isValid() )
134  d->combo->setCurrentIndex( idx.row() );
135  else
136  d->combo->setCurrentIndex( 0 );
137 }
138 
139 // slot
140 void SearchBar::setChangeStringFilterEnabled( bool on ) {
141  d->lineEdit->setEnabled( on );
142 }
143 
144 // slot
145 void SearchBar::setChangeKeyFilterEnabled( bool on ) {
146  d->combo->setEnabled( on );
147 }
148 
149 KLineEdit * SearchBar::lineEdit() const {
150  return d->lineEdit;
151 }
152 
153 #include "moc_searchbar.cpp"
154 
QWidget::layout
QLayout * layout() const
Kleo::SearchBar::setChangeKeyFilterEnabled
void setChangeKeyFilterEnabled(bool enable)
Definition: searchbar.cpp:145
QModelIndex
QWidget
QAbstractItemModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
Kleo::SearchBar
Definition: searchbar.h:50
Kleo::SearchBar::setStringFilter
void setStringFilter(const QString &text)
Definition: searchbar.cpp:126
QHBoxLayout
Kleo::SearchBar::updateClickMessage
void updateClickMessage(const QString &shortcutStr)
Definition: searchbar.cpp:120
Kleo::SearchBar::lineEdit
KLineEdit * lineEdit() const
Definition: searchbar.cpp:149
QModelIndex::isValid
bool isValid() const
boost::shared_ptr< KeyFilter >
Kleo::SearchBar::~SearchBar
~SearchBar()
Definition: searchbar.cpp:117
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
Kleo::SearchBar::setKeyFilter
void setKeyFilter(const boost::shared_ptr< Kleo::KeyFilter > &filter)
Definition: searchbar.cpp:131
d
#define d
Definition: adduseridcommand.cpp:89
QModelIndex::row
int row() const
KDAB_SET_OBJECT_NAME
#define KDAB_SET_OBJECT_NAME(x)
Definition: kdtoolsglobal.h:66
QString
QLayout::setMargin
void setMargin(int margin)
QModelIndex::model
const QAbstractItemModel * model() const
searchbar.h
q
#define q
Definition: adduseridcommand.cpp:90
Kleo::SearchBar::SearchBar
SearchBar(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: searchbar.cpp:111
Qt::WindowFlags
typedef WindowFlags
Kleo::SearchBar::setChangeStringFilterEnabled
void setChangeStringFilterEnabled(bool enable)
Definition: searchbar.cpp:140
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QComboBox
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:11 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
  • pimprint

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