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

messageviewer

  • sources
  • kde-4.12
  • kdepim
  • messageviewer
  • findbar
findbarbase.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2010 Torgny Nyblom <nyblom@kde.org>
2  * Copyright (C) 2010,2011, 2012, 2013 Laurent Montel <montel@kde.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #include "findbarbase.h"
21 
22 #include <kicon.h>
23 #include <klocale.h>
24 #include <kpushbutton.h>
25 #include <klineedit.h>
26 #include <kmessagebox.h>
27 #include <KColorScheme>
28 
29 #include <QtCore/QTimer>
30 #include <QLabel>
31 #include <QLayout>
32 #include <QMenu>
33 #include <QToolButton>
34 #include <QEvent>
35 #include <QKeyEvent>
36 
37 using namespace MessageViewer;
38 
39 FindBarBase::FindBarBase( QWidget * parent )
40  : QWidget( parent )
41 {
42  QHBoxLayout * lay = new QHBoxLayout( this );
43  lay->setMargin( 2 );
44 
45  QToolButton * closeBtn = new QToolButton( this );
46  closeBtn->setIcon( KIcon( QLatin1String("dialog-close") ) );
47  closeBtn->setIconSize( QSize( 16, 16 ) );
48  closeBtn->setToolTip( i18n( "Close" ) );
49 
50 #ifndef QT_NO_ACCESSIBILITY
51  closeBtn->setAccessibleName( i18n( "Close" ) );
52 #endif
53 
54  closeBtn->setAutoRaise( true );
55  lay->addWidget( closeBtn );
56 
57  QLabel * label = new QLabel( i18nc( "Find text", "F&ind:" ), this );
58  lay->addWidget( label );
59 
60  mSearch = new KLineEdit( this );
61  mSearch->setToolTip( i18n( "Text to search for" ) );
62  mSearch->setClearButtonShown( true );
63  label->setBuddy( mSearch );
64  lay->addWidget( mSearch );
65 
66  mFindNextBtn = new QPushButton( KIcon( QLatin1String("go-down-search") ), i18nc( "Find and go to the next search match", "Next" ), this );
67  mFindNextBtn->setToolTip( i18n( "Jump to next match" ) );
68  lay->addWidget( mFindNextBtn );
69  mFindNextBtn->setEnabled( false );
70 
71  mFindPrevBtn = new QPushButton( KIcon( QLatin1String("go-up-search") ), i18nc( "Find and go to the previous search match", "Previous" ), this );
72  mFindPrevBtn->setToolTip( i18n( "Jump to previous match" ) );
73  lay->addWidget( mFindPrevBtn );
74  mFindPrevBtn->setEnabled( false );
75 
76  QPushButton * optionsBtn = new QPushButton( this );
77  optionsBtn->setText( i18n( "Options" ) );
78  optionsBtn->setToolTip( i18n( "Modify search behavior" ) );
79  mOptionsMenu = new QMenu( optionsBtn );
80  mCaseSensitiveAct = mOptionsMenu->addAction( i18n( "Case sensitive" ) );
81  mCaseSensitiveAct->setCheckable( true );
82 
83  optionsBtn->setMenu( mOptionsMenu );
84  lay->addWidget( optionsBtn );
85 
86  connect( closeBtn, SIGNAL(clicked()), this, SLOT(closeBar()) );
87  connect( mFindNextBtn, SIGNAL(clicked()), this, SLOT(findNext()) );
88  connect( mFindPrevBtn, SIGNAL(clicked()), this, SLOT(findPrev()) );
89  connect( mCaseSensitiveAct, SIGNAL(toggled(bool)), this, SLOT(caseSensitivityChanged(bool)) );
90  connect( mSearch, SIGNAL(textChanged(QString)), this, SLOT(autoSearch(QString)) );
91  connect( mSearch, SIGNAL(clearButtonClicked()), this, SLOT(slotClearSearch()) );
92  setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ) );
93  hide();
94 }
95 
96 FindBarBase::~FindBarBase()
97 {
98 }
99 
100 QMenu* FindBarBase::optionsMenu()
101 {
102  return mOptionsMenu;
103 }
104 
105 QString FindBarBase::text() const
106 {
107  return mSearch->text();
108 }
109 
110 void FindBarBase::setText( const QString&text )
111 {
112  mSearch->setText( text );
113 }
114 
115 void FindBarBase::focusAndSetCursor()
116 {
117  setFocus();
118  mSearch->selectAll();
119  mSearch->setFocus();
120 }
121 
122 void FindBarBase::slotClearSearch()
123 {
124  clearSelections();
125 }
126 
127 void FindBarBase::autoSearch( const QString& str )
128 {
129  const bool isNotEmpty = ( !str.isEmpty() );
130  mFindPrevBtn->setEnabled( isNotEmpty );
131  mFindNextBtn->setEnabled( isNotEmpty );
132  if ( isNotEmpty )
133  QTimer::singleShot( 0, this, SLOT(slotSearchText()) );
134  else
135  clearSelections();
136 }
137 
138 void FindBarBase::slotSearchText( bool backward, bool isAutoSearch )
139 {
140  searchText( backward, isAutoSearch );
141 }
142 
143 void FindBarBase::messageInfo( bool backward, bool isAutoSearch, bool found )
144 {
145  if ( !found && !isAutoSearch ) {
146  if ( backward ) {
147  KMessageBox::information( this, i18n( "Beginning of message reached.\nPhrase '%1' could not be found." ,mLastSearchStr ) );
148  } else {
149  KMessageBox::information( this, i18n( "End of message reached.\nPhrase '%1' could not be found.", mLastSearchStr ) );
150  }
151  }
152 }
153 
154 
155 void FindBarBase::setFoundMatch( bool match )
156 {
157 #ifndef QT_NO_STYLE_STYLESHEET
158  QString styleSheet;
159 
160  if (!mSearch->text().isEmpty()) {
161  if (mNegativeBackground.isEmpty()) {
162  KStatefulBrush bgBrush(KColorScheme::View, KColorScheme::PositiveBackground);
163  mPositiveBackground = QString::fromLatin1("QLineEdit{ background-color:%1 }").arg(bgBrush.brush(mSearch).color().name());
164  bgBrush = KStatefulBrush(KColorScheme::View, KColorScheme::NegativeBackground);
165  mNegativeBackground = QString::fromLatin1("QLineEdit{ background-color:%1 }").arg(bgBrush.brush(mSearch).color().name());
166  }
167  if (match)
168  styleSheet = mPositiveBackground;
169  else
170  styleSheet = mNegativeBackground;
171  }
172  mSearch->setStyleSheet(styleSheet);
173 #endif
174 
175 }
176 
177 void FindBarBase::searchText( bool backward, bool isAutoSearch )
178 {
179  Q_UNUSED( backward );
180  Q_UNUSED( isAutoSearch );
181 }
182 
183 
184 void FindBarBase::findNext()
185 {
186  searchText( false, false );
187 }
188 
189 void FindBarBase::findPrev()
190 {
191  searchText( true, false );
192 }
193 
194 void FindBarBase::caseSensitivityChanged(bool b)
195 {
196  updateSensitivity( b );
197 }
198 
199 void FindBarBase::updateSensitivity( bool )
200 {
201 }
202 
203 void FindBarBase::slotHighlightAllChanged(bool b)
204 {
205  updateHighLight(b);
206 }
207 
208 void FindBarBase::updateHighLight( bool )
209 {
210 }
211 
212 void FindBarBase::clearSelections()
213 {
214  setFoundMatch( false );
215 }
216 
217 void FindBarBase::closeBar()
218 {
219  // Make sure that all old searches are cleared
220  mSearch->setText( QString() );
221  clearSelections();
222  hide();
223 }
224 
225 bool FindBarBase::event(QEvent* e)
226 {
227  // Close the bar when pressing Escape.
228  // Not using a QShortcut for this because it could conflict with
229  // window-global actions (e.g. Emil Sedgh binds Esc to "close tab").
230  // With a shortcut override we can catch this before it gets to kactions.
231  const bool shortCutOverride = (e->type() == QEvent::ShortcutOverride);
232  if ( shortCutOverride || e->type() == QEvent::KeyPress ) {
233  QKeyEvent* kev = static_cast<QKeyEvent* >(e);
234  if (kev->key() == Qt::Key_Escape) {
235  if ( shortCutOverride ) {
236  e->accept();
237  return true;
238  }
239  e->accept();
240  closeBar();
241  return true;
242  } else if ( kev->key() == Qt::Key_Enter ||
243  kev->key() == Qt::Key_Return ) {
244  e->accept();
245  if ( shortCutOverride ) {
246  return true;
247  }
248  if (mSearch->text().isEmpty())
249  return true;
250  if ( kev->modifiers() & Qt::ShiftModifier )
251  findPrev();
252  else if ( kev->modifiers() == Qt::NoModifier )
253  findNext();
254  return true;
255  }
256  }
257  return QWidget::event(e);
258 }
259 
260 #include "findbarbase.moc"
MessageViewer::FindBarBase::updateSensitivity
virtual void updateSensitivity(bool)
Definition: findbarbase.cpp:199
MessageViewer::FindBarBase::searchText
virtual void searchText(bool backward, bool isAutoSearch)
Definition: findbarbase.cpp:177
MessageViewer::FindBarBase::clearSelections
virtual void clearSelections()
Definition: findbarbase.cpp:212
MessageViewer::FindBarBase::autoSearch
void autoSearch(const QString &str)
Definition: findbarbase.cpp:127
MessageViewer::FindBarBase::setFoundMatch
void setFoundMatch(bool match)
Definition: findbarbase.cpp:155
MessageViewer::FindBarBase::closeBar
void closeBar()
Definition: findbarbase.cpp:217
MessageViewer::FindBarBase::findPrev
void findPrev()
Definition: findbarbase.cpp:189
MessageViewer::FindBarBase::mLastSearchStr
QString mLastSearchStr
Definition: findbarbase.h:69
QWidget
MessageViewer::FindBarBase::slotSearchText
void slotSearchText(bool backward=false, bool isAutoSearch=true)
Definition: findbarbase.cpp:138
MessageViewer::FindBarBase::messageInfo
void messageInfo(bool backward, bool isAutoSearch, bool found)
Definition: findbarbase.cpp:143
MessageViewer::FindBarBase::event
virtual bool event(QEvent *e)
Definition: findbarbase.cpp:225
MessageViewer::FindBarBase::~FindBarBase
virtual ~FindBarBase()
Definition: findbarbase.cpp:96
MessageViewer::FindBarBase::mNegativeBackground
QString mNegativeBackground
Definition: findbarbase.h:68
MessageViewer::FindBarBase::FindBarBase
FindBarBase(QWidget *parent=0)
Definition: findbarbase.cpp:39
MessageViewer::FindBarBase::mFindPrevBtn
QPushButton * mFindPrevBtn
Definition: findbarbase.h:73
MessageViewer::FindBarBase::mPositiveBackground
QString mPositiveBackground
Definition: findbarbase.h:67
MessageViewer::FindBarBase::mFindNextBtn
QPushButton * mFindNextBtn
Definition: findbarbase.h:74
MessageViewer::FindBarBase::setText
void setText(const QString &text)
Definition: findbarbase.cpp:110
MessageViewer::FindBarBase::mOptionsMenu
QMenu * mOptionsMenu
Definition: findbarbase.h:75
QLabel
MessageViewer::FindBarBase::mCaseSensitiveAct
QAction * mCaseSensitiveAct
Definition: findbarbase.h:71
MessageViewer::FindBarBase::mSearch
KLineEdit * mSearch
Definition: findbarbase.h:70
MessageViewer::FindBarBase::findNext
void findNext()
Definition: findbarbase.cpp:184
findbarbase.h
MessageViewer::FindBarBase::optionsMenu
QMenu * optionsMenu()
Definition: findbarbase.cpp:100
MessageViewer::FindBarBase::focusAndSetCursor
void focusAndSetCursor()
Definition: findbarbase.cpp:115
MessageViewer::FindBarBase::text
QString text() const
Definition: findbarbase.cpp:105
MessageViewer::FindBarBase::updateHighLight
virtual void updateHighLight(bool)
Definition: findbarbase.cpp:208
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messageviewer

Skip menu "messageviewer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

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