Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef KLFSEARCHBAR_H
00026 #define KLFSEARCHBAR_H
00027
00028 #include <QObject>
00029 #include <QWidget>
00030 #include <QFrame>
00031 #include <QMovie>
00032 #include <QLabel>
00033 #include <QTime>
00034
00035 #include <klfdefs.h>
00036
00037 class QLineEdit;
00038 class KLFWaitAnimationOverlay;
00039
00040 class KLFSearchBar;
00041 class KLFSearchableProxy;
00042 namespace Ui { class KLFSearchBar; }
00043
00045
00062 class KLF_EXPORT KLFSearchable
00063 {
00064 public:
00065 KLFSearchable();
00066 virtual ~KLFSearchable();
00067
00069
00081 virtual bool searchFind(const QString& queryString, bool forward) = 0;
00082
00084
00090 inline bool searchFind(const QString& queryString) { return searchFind(queryString, true); }
00091
00093
00102 virtual bool searchFindNext(bool forward) = 0;
00103
00105
00109 virtual void searchAbort() = 0;
00110
00111 private:
00112 QList<KLFSearchBar*> pTargetOf;
00113 QList<KLFSearchableProxy*> pTargetOfProxy;
00114
00115 friend class KLFSearchBar;
00116 friend class KLFSearchableProxy;
00117 };
00118
00120
00123 class KLF_EXPORT KLFSearchableProxy : public KLFSearchable
00124 {
00125 public:
00126 KLFSearchableProxy() : pTarget(NULL) { }
00127 virtual ~KLFSearchableProxy();
00128
00129 void setSearchTarget(KLFSearchable *target);
00130
00131 virtual bool searchFind(const QString& queryString, bool forward);
00132 virtual bool searchFindNext(bool forward);
00133 virtual void searchAbort();
00134
00135 private:
00136 KLFSearchable *pTarget;
00137
00138 friend class KLFSearchable;
00139 };
00140
00141
00142
00144
00172 class KLF_EXPORT KLFSearchBar : public QFrame
00173 {
00174 Q_OBJECT
00175
00176 Q_PROPERTY(QString currentSearchText READ currentSearchText WRITE setSearchText) ;
00177 Q_PROPERTY(bool showOverlayMode READ showOverlayMode WRITE setShowOverlayMode) ;
00178 Q_PROPERTY(QRect showOverlayRelativeGeometry READ showOverlayRelativeGeometry
00179 WRITE setShowOverlayRelativeGeometry ) ;
00180 Q_PROPERTY(QString focusOutText READ focusOutText WRITE setFocusOutText) ;
00181 Q_PROPERTY(QColor colorFound READ colorFound WRITE setColorFound) ;
00182 Q_PROPERTY(QColor colorNotFound READ colorNotFound WRITE setColorNotFound) ;
00183 Q_PROPERTY(bool showHideButton READ hideButtonShown WRITE setShowHideButton) ;
00184 public:
00185 KLFSearchBar(QWidget *parent = NULL);
00186 virtual ~KLFSearchBar();
00187 virtual void registerShortcuts(QWidget *parent);
00188
00191 virtual void setSearchTarget(KLFSearchable *object);
00192
00193 QString currentSearchText() const;
00194 inline bool showOverlayMode() const { return pShowOverlayMode; }
00195 inline QRect showOverlayRelativeGeometry() const { return pShowOverlayRelativeGeometry; }
00196 inline QString focusOutText() const { return pFocusOutText; }
00198 QColor colorFound() const;
00200 QColor colorNotFound() const;
00201 bool hideButtonShown() const;
00202
00203 void setShowOverlayMode(bool showOverlayMode);
00204 void setShowOverlayRelativeGeometry(const QRect& relativeGeometryPercent);
00205 void setShowOverlayRelativeGeometry(int widthPercent, int heightPercent,
00206 int positionXPercent, int positionYPercent);
00207 void setColorFound(const QColor& color);
00208 void setColorNotFound(const QColor& color);
00209 void setShowHideButton(bool showHideButton);
00210
00211 virtual bool eventFilter(QObject *obj, QEvent *ev);
00212
00213 QLineEdit * editor();
00214
00215 signals:
00216 void searchPerformed(bool found);
00217 void found();
00218 void found(const QString& queryString, bool forward);
00219 void didNotFind();
00220 void didNotFind(const QString& queryString, bool forward);
00221 void searchAborted();
00222 void escapePressed();
00223
00224 public slots:
00226 void clear();
00230 void focusOrNext(bool forward = true);
00233 void focusOrPrev() { focusOrNext(false); }
00234 void find(const QString& string) { find(string, pSearchForward); }
00235 void find(const QString& string, bool forward);
00236 void findNext(bool forward = true);
00237 void findPrev() { findNext(false); }
00238 void abortSearch();
00239
00240 void focus();
00241
00242 virtual void setSearchText(const QString& text);
00243 void setFocusOutText(const QString& focusOutText);
00244
00245 protected:
00246 Ui::KLFSearchBar *u;
00247
00248 virtual void slotSearchFocusIn();
00249 virtual void slotSearchFocusOut();
00250 virtual void updateSearchFound(bool found);
00251
00252 enum SearchState { Default, FocusOut, Found, NotFound, Aborted };
00253
00254 virtual void displayState(SearchState state);
00255
00256 void emitFoundSignals(bool found, const QString& searchstring, bool forward);
00257
00260 void showSearchBarText(const QString& text);
00261
00263 bool searchBarHasFocus();
00264
00265 virtual bool event(QEvent *event);
00266
00267
00268 private:
00269
00270 KLFSearchable *pTarget;
00271
00274 bool pSearchForward;
00275 QString pSearchText;
00276 QString pLastSearchText;
00277
00278 KLFWaitAnimationOverlay *pWaitLabel;
00279
00280 bool pShowOverlayMode;
00281 QRect pShowOverlayRelativeGeometry;
00282
00283 QString pFocusOutText;
00284
00285 QString palettePropName(SearchState state) const;
00286 QString statePropValue(SearchState state) const;
00287
00288 friend class KLFSearchable;
00289
00290 KLF_DEBUG_DECLARE_ASSIGNABLE_REF_INSTANCE()
00291 };
00292
00293
00294
00295
00296 #endif