[KLF Backend][KLF Tools][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$ */
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#include <klfutil.h>
38
39class QLineEdit;
41
42class KLFSearchBar;
44namespace Ui { class KLFSearchBar; }
45
46
47
49
74{
75public:
76
97 struct Pos {
124 struct PosData {
125 PosData() : r(0) { }
126 virtual ~PosData() { }
127
129 virtual bool equals(PosData *other) const = 0;
130
133 virtual QString toDebug() { return QLatin1String("<PosData>"); }
134
135 int ref() { return ++r; }
136 int deref() { return --r; }
137
140 virtual bool wantAutoDelete() { return true; }
141 private:
142 int r;
143 };
144
146 Pos() : posdata()
147 {
148 }
149
150 Pos(const Pos& other) : posdata(other.posdata)
151 {
152 }
153
155 {
156 if (posdata != NULL)
157 posdata.setAutoDelete(posdata->wantAutoDelete());
158 }
159
160 Pos& operator=(const Pos& other)
161 {
162 KLF_DEBUG_BLOCK(KLF_FUNC_NAME) ;
163 posdata = other.posdata;
164 return *this;
165 }
166
168 bool valid() const {
169 KLF_DEBUG_BLOCK(KLF_FUNC_NAME) ;
170 klfDbg("posdata="<<posdata) ;
171 return (posdata != NULL) ;
172 };
180 bool equals(const Pos& other) const {
181 if (valid() && other.valid())
182 return posdata->equals(other.data<PosData>());
183 // if both are invalid, they are equal. If one only is valid, they are not equal.
184 return (valid() == other.valid());
185 }
186
188
197
211 template<class TT>
212 inline TT * data() const
213 {
214 TT *ptr = posdata.dyn_cast<TT*>();
215 KLF_ASSERT_NOT_NULL(ptr, "accessing a posdata that is NULL or of incompatible type!", return NULL;) ;
216 return ptr;
217 }
218 };
219
232 virtual Pos searchStartFrom(bool forward);
233
252 virtual Pos searchFind(const QString& queryString, const Pos& fromPos, bool forward) = 0;
253
256 virtual void searchMoveToPos(const Pos& pos) { Q_UNUSED(pos); }
257
262 virtual void searchPerformed(const QString& queryString, bool found, const Pos& pos)
263 { Q_UNUSED(queryString); Q_UNUSED(found); Q_UNUSED(pos); }
264
267 virtual void searchAborted() = 0;
268
272 virtual void searchReinitialized() { }
273
274
279 virtual QString searchQueryString() const { klfDbg("pQString="<<pQString) ; return pQString; }
280
284 virtual void setSearchQueryString(const QString& s) { klfDbg("pQString="<<pQString<<"; setting to "<<s) ; pQString = s; }
285
286 virtual bool searchHasInterruptRequested() { return pInterruptRequested; }
287
288 virtual void setSearchInterruptRequested(bool on);
289
290private:
291 QString pQString;
292 bool pInterruptRequested;
293};
294
296
297
299{
300public:
302 virtual ~KLFPosSearchableProxy();
303
304 virtual Pos searchStartFrom(bool forward);
305 virtual Pos searchFind(const QString& queryString, const Pos& fromPos, bool forward);
306 virtual void searchMoveToPos(const Pos& pos);
307 virtual void searchPerformed(const QString& queryString, bool found, const Pos& pos);
308 virtual void searchAborted();
309 virtual void searchReinitialized();
310 virtual QString searchQueryString() const;
311 virtual void setSearchQueryString(const QString& s);
312 virtual bool searchHasInterruptRequested();
313 virtual void setSearchInterruptRequested(bool on);
314
315 virtual void setSearchTarget(KLFPosSearchable *t) { setTarget(t); }
316
317protected:
318 virtual KLFPosSearchable *target() { return dynamic_cast<KLFPosSearchable*>(pTarget); }
319 virtual const KLFPosSearchable *target() const { return dynamic_cast<KLFPosSearchable*>(pTarget); }
320};
321
322
323
324
326
347{
348public:
350 virtual ~KLFSearchable();
351
353
365 virtual bool searchFind(const QString& queryString, bool forward) = 0;
366
368
374 inline bool searchFind(const QString& queryString) { return searchFind(queryString, true); }
375
377
386 virtual bool searchFindNext(bool forward) = 0;
387
389
393 virtual void searchAbort() = 0;
394
395
396 virtual Pos searchFind(const QString& queryString, const Pos& fromPos, bool forward);
397 virtual void searchMoveToPos(const Pos& pos)
398 { Q_UNUSED(pos); }
399 virtual void searchPerformed(const QString& queryString, bool found, const Pos& pos)
400 { Q_UNUSED(queryString); Q_UNUSED(found); Q_UNUSED(pos); }
401 virtual void searchAborted() { searchAbort(); }
402};
403
404
406
413{
414public:
416 virtual ~KLFSearchableProxy();
417
418 void setSearchTarget(KLFPosSearchable *target) { setTarget(target); }
419 virtual void setTarget(KLFTarget *target);
420
421 virtual bool searchFind(const QString& queryString, bool forward);
422 virtual bool searchFindNext(bool forward);
423 virtual void searchAbort();
424
425protected:
426 virtual KLFSearchable *target() { return dynamic_cast<KLFSearchable*>(pTarget); }
427};
428
429
430
431
432struct KLFSearchBarPrivate;
433
435
464class KLF_EXPORT KLFSearchBar : public QFrame, public KLFTargeter
465{
466 Q_OBJECT
467
468 Q_PROPERTY(QString currentSearchText READ currentSearchText) ;
469 Q_PROPERTY(bool autoHide READ autoHide WRITE setAutoHide) ;
470 Q_PROPERTY(bool showOverlayMode READ showOverlayMode WRITE setShowOverlayMode) ;
471 Q_PROPERTY(QRect showOverlayRelativeGeometry READ showOverlayRelativeGeometry
472 WRITE setShowOverlayRelativeGeometry ) ;
473 Q_PROPERTY(QString focusOutText READ focusOutText WRITE setFocusOutText) ;
474 Q_PROPERTY(QColor colorFound READ colorFound WRITE setColorFound) ;
475 Q_PROPERTY(QColor colorNotFound READ colorNotFound WRITE setColorNotFound) ;
476 Q_PROPERTY(bool showHideButton READ hideButtonShown WRITE setShowHideButton) ;
477 Q_PROPERTY(bool showSearchLabel READ showSearchLabel WRITE setShowSearchLabel) ;
478 Q_PROPERTY(bool emacsStyleBackspace READ emacsStyleBackspace WRITE setEmacsStyleBackspace) ;
479 Q_PROPERTY(int resetTimeout READ resetTimeout WRITE setResetTimeout) ;
480public:
481
482 enum SearchState { Default, FocusOut, Found, NotFound, Aborted };
483
484 KLFSearchBar(QWidget *parent = NULL);
485 virtual ~KLFSearchBar();
488 virtual void registerShortcuts(QWidget *parent);
489
492 virtual void setSearchTarget(KLFPosSearchable *target) { setTarget(target); }
493 virtual void setTarget(KLFTarget *target);
494
495 QString currentSearchText() const;
496 bool autoHide() const;
497 bool showOverlayMode() const;
498 QRect showOverlayRelativeGeometry() const;
499 QString focusOutText() const;
501 QColor colorFound() const;
503 QColor colorNotFound() const;
504 bool hideButtonShown() const;
505 bool showSearchLabel() const;
506 bool emacsStyleBackspace() const;
507 int resetTimeout() const;
508
511 KLFPosSearchable::Pos currentSearchPos() const;
512
513 SearchState currentState() const;
514
517 void setAutoHide(bool autohide);
518
524 void setShowOverlayMode(bool showOverlayMode);
525 void setShowOverlayRelativeGeometry(const QRect& relativeGeometryPercent);
526 void setShowOverlayRelativeGeometry(int widthPercent, int heightPercent,
527 int positionXPercent, int positionYPercent);
528 void setColorFound(const QColor& color);
529 void setColorNotFound(const QColor& color);
530 void setShowHideButton(bool showHideButton);
531 void setShowSearchLabel(bool show);
532 void setEmacsStyleBackspace(bool on);
537 void setResetTimeout(int ms);
538
539 virtual bool eventFilter(QObject *obj, QEvent *ev);
540
541 QLineEdit * editor();
542
543signals:
545 void searchPerformed(bool found);
546 void searchPerformed(const QString& queryString, bool found);
547 void found();
548 void found(const QString& queryString, bool forward);
549 void found(const QString& queryString, bool forward, const KLFPosSearchable::Pos& pos);
551 void didNotFind(const QString& queryString, bool forward);
555
557
560 void hasMatch(bool hasmatch);
561
562 void visibilityChanged(bool isShown);
563
564public slots:
566 void clear();
570 void focusOrNext(bool forward = true);
573 void focusOrPrev() { focusOrNext(false); }
574 void find(const QString& string);
575 void find(const QString& string, bool forward);
576 void findNext(bool forward = true);
577 void findPrev() { findNext(false); }
578 void abortSearch();
579
580 void focus();
581
582 virtual void setSearchText(const QString& text);
583 void setFocusOutText(const QString& focusOutText);
584
585protected:
586 Ui::KLFSearchBar *u;
587
589 bool searchBarHasFocus();
590
591 virtual bool event(QEvent *event);
592
593
595 friend class KLFSearchBarDesPlugin;
596
597protected slots:
598
599 virtual void slotSearchFocusIn();
600 virtual void slotSearchFocusOut();
601 virtual void slotSearchReset();
602 virtual void updateSearchFound(bool found);
603
604 void promptEmptySearch();
605
607 virtual void displayState(SearchState state);
608
610 void setCurrentState(SearchState state);
611
612 void emitFoundSignals(const KLFPosSearchable::Pos& pos, const QString& searchstring, bool forward);
613
616 void showSearchBarText(const QString& text);
617
618private:
619
620 inline KLFPosSearchable *target() { return dynamic_cast<KLFPosSearchable*>(pTarget); }
621
622 KLFSearchBarPrivate *d;
623
624 void adjustOverlayGeometry();
625
626 QString palettePropName(SearchState state) const;
627 QString statePropValue(SearchState state) const;
628
629 // Needed so that KLFSearchable's can ensure \ref pTarget is valid, and set it to NULL
630 // when appropriate
631 friend class KLFSearchable;
632
633 void performFind(bool forward, bool isFindNext = false);
634
636};
637
638
639
640
641#endif
An object that can be searched with a KLFSearchBar.
virtual bool searchHasInterruptRequested()
virtual void searchMoveToPos(const Pos &pos)
virtual void searchAborted()=0
virtual QString searchQueryString() const
The current query string.
virtual Pos searchFind(const QString &queryString, const Pos &fromPos, bool forward)=0
virtual void searchPerformed(const QString &queryString, bool found, const Pos &pos)
virtual void setSearchQueryString(const QString &s)
virtual void searchReinitialized()
virtual const KLFPosSearchable * target() const
virtual void setSearchTarget(KLFPosSearchable *t)
virtual KLFPosSearchable * target()
Stores a pointer to an object with refcount.
Definition klfutil.h:614
OtherPtr dyn_cast()
Definition klfutil.h:717
An Search Bar for Incremental Search.
void searchPerformed(const QString &queryString, bool found)
void hasMatch(bool hasmatch)
Reflects whether the search is currently pointing on a valid result.
Ui::KLFSearchBar * u
void found(const QString &queryString, bool forward, const KLFPosSearchable::Pos &pos)
void visibilityChanged(bool isShown)
void found(const QString &queryString, bool forward)
void escapePressed()
void didNotFind()
void searchAborted()
void stateChanged(SearchState state)
void searchPerformed(bool found)
void focusOrPrev()
void didNotFind(const QString &queryString, bool forward)
virtual void setSearchTarget(KLFPosSearchable *target)
void searchReinitialized()
An interface for objects that can be I-searched with a KLFSearchBar (OBSOLETE)
virtual void searchMoveToPos(const Pos &pos)
bool searchFind(const QString &queryString)
Find the first occurence of a query string.
virtual bool searchFindNext(bool forward)=0
Find next or previous occurence of query string.
virtual void searchAbort()=0
Abort I-Search.
virtual void searchPerformed(const QString &queryString, bool found, const Pos &pos)
virtual bool searchFind(const QString &queryString, bool forward)=0
Find the first occurence of a query string.
virtual void searchAborted()
A proxy class that relays search queries to another searchable object (OBSOLETE)
virtual KLFSearchable * target()
void setSearchTarget(KLFPosSearchable *target)
An animation display.
Definition klfguiutil.h:413
#define KLF_DEBUG_DECLARE_ASSIGNABLE_REF_INSTANCE()
Declare that this class has an assignable debugging ref-instance.
Definition klfdebug.h:146
#define KLF_DEBUG_BLOCK(msg)
Utility to debug the execution of a block.
Definition klfdebug.h:152
#define KLF_ASSERT_NOT_NULL(ptr, msg, failaction)
Asserting Non-NULL pointers (NON-FATAL)
Definition klfdebug.h:210
#define klfDbg(streamableItems)
print debug stream items
Definition klfdebug.h:158
Base declarations for klatexformula and some utilities.
#define KLF_EXPORT
Definition klfdefs.h:41
KLF_EXPORT QDebug & operator<<(QDebug &str, const KLFPosSearchable::Pos &pos)
A Base class for storing abstract position data.
virtual bool equals(PosData *other) const =0
An abstract position in a searchable object.
TT * data() const
A shorthand for retrieving the posdata cast into the custom type.
bool equals(const Pos &other) const
Pos & operator=(const Pos &other)
KLFRefPtr< PosData > posdata
Stores the actual position data, see PosData.
Pos(const Pos &other)

Generated by doxygen 1.11.0