[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project
klfsearchbar.h
Go to the documentation of this file.
1 /***************************************************************************
2  * file klfsearchbar.h
3  * This file is part of the KLatexFormula Project.
4  * Copyright (C) 2011 by Philippe Faist
5  * philippe.faist at bluewin.ch
6  * *
7  * This program 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  * This program 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 *
15  * GNU 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 *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 /* $Id: klfsearchbar.h 603 2011-02-26 23:14:55Z phfaist $ */
23 
24 
25 #ifndef KLFSEARCHBAR_H
26 #define KLFSEARCHBAR_H
27 
28 #include <QObject>
29 #include <QWidget>
30 #include <QFrame>
31 #include <QMovie>
32 #include <QLabel>
33 #include <QTime>
34 
35 #include <klfdefs.h>
36 
37 class QLineEdit;
39 
40 class KLFSearchBar;
41 class KLFSearchableProxy;
42 namespace Ui { class KLFSearchBar; }
43 
45 
62 class KLF_EXPORT KLFSearchable
63 {
64 public:
65  KLFSearchable();
66  virtual ~KLFSearchable();
67 
69 
81  virtual bool searchFind(const QString& queryString, bool forward) = 0;
82 
84 
90  inline bool searchFind(const QString& queryString) { return searchFind(queryString, true); }
91 
93 
102  virtual bool searchFindNext(bool forward) = 0;
103 
105 
109  virtual void searchAbort() = 0;
110 
111 private:
112  QList<KLFSearchBar*> pTargetOf;
113  QList<KLFSearchableProxy*> pTargetOfProxy;
114 
115  friend class KLFSearchBar;
116  friend class KLFSearchableProxy;
117 };
118 
120 
123 class KLF_EXPORT KLFSearchableProxy : public KLFSearchable
124 {
125 public:
126  KLFSearchableProxy() : pTarget(NULL) { }
127  virtual ~KLFSearchableProxy();
128 
129  void setSearchTarget(KLFSearchable *target);
130 
131  virtual bool searchFind(const QString& queryString, bool forward);
132  virtual bool searchFindNext(bool forward);
133  virtual void searchAbort();
134 
135 private:
136  KLFSearchable *pTarget;
137 
138  friend class KLFSearchable;
139 };
140 
141 
142 
144 
172 class KLF_EXPORT KLFSearchBar : public QFrame
173 {
174  Q_OBJECT
175 
176  Q_PROPERTY(QString currentSearchText READ currentSearchText WRITE setSearchText) ;
177  Q_PROPERTY(bool showOverlayMode READ showOverlayMode WRITE setShowOverlayMode) ;
178  Q_PROPERTY(QRect showOverlayRelativeGeometry READ showOverlayRelativeGeometry
179  WRITE setShowOverlayRelativeGeometry ) ;
180  Q_PROPERTY(QString focusOutText READ focusOutText WRITE setFocusOutText) ;
181  Q_PROPERTY(QColor colorFound READ colorFound WRITE setColorFound) ;
182  Q_PROPERTY(QColor colorNotFound READ colorNotFound WRITE setColorNotFound) ;
183  Q_PROPERTY(bool showHideButton READ hideButtonShown WRITE setShowHideButton) ;
184 public:
185  KLFSearchBar(QWidget *parent = NULL);
186  virtual ~KLFSearchBar();
187  virtual void registerShortcuts(QWidget *parent);
188 
191  virtual void setSearchTarget(KLFSearchable *object);
192 
193  QString currentSearchText() const;
194  inline bool showOverlayMode() const { return pShowOverlayMode; }
195  inline QRect showOverlayRelativeGeometry() const { return pShowOverlayRelativeGeometry; }
196  inline QString focusOutText() const { return pFocusOutText; }
198  QColor colorFound() const;
200  QColor colorNotFound() const;
201  bool hideButtonShown() const;
202 
203  void setShowOverlayMode(bool showOverlayMode);
204  void setShowOverlayRelativeGeometry(const QRect& relativeGeometryPercent);
205  void setShowOverlayRelativeGeometry(int widthPercent, int heightPercent,
206  int positionXPercent, int positionYPercent);
207  void setColorFound(const QColor& color);
208  void setColorNotFound(const QColor& color);
209  void setShowHideButton(bool showHideButton);
210 
211  virtual bool eventFilter(QObject *obj, QEvent *ev);
212 
213  QLineEdit * editor();
214 
215 signals:
216  void searchPerformed(bool found);
217  void found();
218  void found(const QString& queryString, bool forward);
219  void didNotFind();
220  void didNotFind(const QString& queryString, bool forward);
221  void searchAborted();
222  void escapePressed();
223 
224 public slots:
226  void clear();
230  void focusOrNext(bool forward = true);
233  void focusOrPrev() { focusOrNext(false); }
234  void find(const QString& string) { find(string, pSearchForward); }
235  void find(const QString& string, bool forward);
236  void findNext(bool forward = true);
237  void findPrev() { findNext(false); }
238  void abortSearch();
239 
240  void focus();
241 
242  virtual void setSearchText(const QString& text);
243  void setFocusOutText(const QString& focusOutText);
244 
245 protected:
246  Ui::KLFSearchBar *u;
247 
248  virtual void slotSearchFocusIn();
249  virtual void slotSearchFocusOut();
250  virtual void updateSearchFound(bool found);
251 
252  enum SearchState { Default, FocusOut, Found, NotFound, Aborted };
253 
254  virtual void displayState(SearchState state);
255 
256  void emitFoundSignals(bool found, const QString& searchstring, bool forward);
257 
260  void showSearchBarText(const QString& text);
261 
263  bool searchBarHasFocus();
264 
265  virtual bool event(QEvent *event);
266 
267 
268 private:
269 
270  KLFSearchable *pTarget;
271 
274  bool pSearchForward;
275  QString pSearchText;
276  QString pLastSearchText;
277 
278  KLFWaitAnimationOverlay *pWaitLabel;
279 
280  bool pShowOverlayMode;
281  QRect pShowOverlayRelativeGeometry;
282 
283  QString pFocusOutText;
284 
285  QString palettePropName(SearchState state) const;
286  QString statePropValue(SearchState state) const;
287 
288  friend class KLFSearchable;
289 
291 };
292 
293 
294 
295 
296 #endif
An interface for objects that can be I-searched with a KLFSearchBar.
Definition: klfsearchbar.h:62
virtual bool searchFindNext(bool forward)=0
Find next or previous occurence of query string.
An Search Bar for Incremental Search.
Definition: klfsearchbar.h:172
virtual void searchAbort()=0
Abort I-Search.
bool showOverlayMode() const
Definition: klfsearchbar.h:194
#define KLF_DEBUG_DECLARE_ASSIGNABLE_REF_INSTANCE()
virtual bool searchFind(const QString &queryString, bool forward)=0
Find the first occurence of a query string.
A proxy class that relays search queries to another searchable object.
Definition: klfsearchbar.h:123
bool searchFind(const QString &queryString)
Find the first occurence of a query string.
Definition: klfsearchbar.h:90
An animation display.
Definition: klfguiutil.h:412
void findPrev()
Definition: klfsearchbar.h:237
Ui::KLFSearchBar * u
Definition: klfsearchbar.h:246
void focusOrPrev()
Definition: klfsearchbar.h:233
QString focusOutText() const
Definition: klfsearchbar.h:196
QRect showOverlayRelativeGeometry() const
Definition: klfsearchbar.h:195
void find(const QString &string)
Definition: klfsearchbar.h:234

Generated by doxygen 1.8.5