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 #ifndef QTXSEARCHTOOL_H
00024 #define QTXSEARCHTOOL_H
00025
00026 #include "Qtx.h"
00027 #include <QFrame>
00028 #include <QList>
00029 #include <QMap>
00030 #include <QPersistentModelIndex>
00031 #include <QPointer>
00032
00033 class QCheckBox;
00034 class QLineEdit;
00035 class QShortcut;
00036 class QTimer;
00037 class QToolButton;
00038 class QTreeView;
00039
00040 class QTX_EXPORT QtxSearchTool : public QFrame
00041 {
00042 Q_OBJECT
00043
00045 enum {
00046 fAny,
00047 fNext,
00048 fPrevious,
00049 fFirst,
00050 fLast
00051 };
00052
00053 public:
00054 class Searcher;
00055
00057 typedef enum {
00058 Search = 0x00000001,
00059 Next = 0x00000002,
00060 Prev = 0x00000004,
00061 First = 0x00000008,
00062 Last = 0x00000010,
00063 Close = 0x00000020,
00064 Case = 0x00000040,
00065 RegExp = 0x00000080,
00066 Wrap = 0x00000100,
00067 Basic = Search | Next | Prev | Close,
00068 Standard = Basic | First | Last,
00069 Modifiers = Case | RegExp | Wrap,
00070 All = Standard | Modifiers
00071 } Controls;
00072
00073 typedef enum {
00074 None = 0x00000000,
00075 HotKey = 0x00000001,
00076 SlashKey = 0x00000002,
00077 StandardKey = 0x00000004,
00078 PrintKey = 0x00000008,
00079 Any = HotKey | SlashKey | StandardKey | PrintKey
00080 } Activator;
00081
00082 QtxSearchTool( QWidget*, QWidget* = 0, int = All );
00083 QtxSearchTool( QWidget*, int = All );
00084 virtual ~QtxSearchTool();
00085
00086 QWidget* watchedWidget() const;
00087 void setWatchedWidget( QWidget* );
00088
00089 Searcher* searcher() const;
00090 void setSearcher( Searcher* );
00091
00092 int activators() const;
00093 void setActivators( const int );
00094
00095 int controls() const;
00096 void setControls( const int );
00097
00098 QList<QKeySequence> shortcuts() const;
00099 void setShortcuts( const QKeySequence& );
00100 void setShortcuts( const QList<QKeySequence>& );
00101
00102 int addCustomWidget( QWidget*, int = -1 );
00103 QWidget* customWidget( int ) const;
00104 int customWidgetId( QWidget* ) const;
00105
00106 bool isAutoHideEnabled() const;
00107 void enableAutoHide( bool );
00108
00109 bool isCaseSensitive() const;
00110 bool isRegExpSearch() const;
00111 bool isSearchWrapped() const;
00112
00113 void setCaseSensitive( bool );
00114 void setRegExpSearch( bool );
00115 void setSearchWrapped( bool );
00116
00117 virtual bool event( QEvent* );
00118 virtual bool eventFilter( QObject*, QEvent* );
00119
00120 public slots:
00121 virtual void find();
00122 virtual void findNext();
00123 virtual void findPrevious();
00124 virtual void findFirst();
00125 virtual void findLast();
00126
00127 private slots:
00128 void find( const QString&, int = fAny );
00129 void modifierSwitched();
00130
00131 private:
00132 void init();
00133 bool focused() const;
00134 void clearShortcuts();
00135 void initShortcuts( const QList<QKeySequence>& );
00136 void updateShortcuts();
00137 void updateControls();
00138
00139 private:
00140 typedef QPointer<QShortcut> ShortcutPtr;
00141 typedef QList<ShortcutPtr> ShortcutList;
00142
00143 private:
00144 QWidget* myBtnWidget;
00145 QWidget* myModWidget;
00146 QLineEdit* myData;
00147 QToolButton* myToFirst;
00148 QToolButton* myToLast;
00149 QToolButton* myNext;
00150 QToolButton* myPrev;
00151 QToolButton* myClose;
00152 QCheckBox* myIsCaseSens;
00153 QCheckBox* myIsRegExp;
00154 QCheckBox* myWrap;
00155 QWidget* myWatched;
00156 Searcher* mySearcher;
00157 int myControls;
00158 int myActivators;
00159 ShortcutList myShortcuts;
00160 QTimer* myAutoHideTimer;
00161 bool myAutoHideEnabled;
00162 QMap<int, QWidget*> myWidgets;
00163 };
00164
00165 class QTX_EXPORT QtxSearchTool::Searcher
00166 {
00167 public:
00168 Searcher();
00169 virtual ~Searcher();
00170
00171 virtual bool find( const QString&, QtxSearchTool* ) = 0;
00172 virtual bool findNext( const QString&, QtxSearchTool* ) = 0;
00173 virtual bool findPrevious( const QString&, QtxSearchTool* ) = 0;
00174 virtual bool findFirst( const QString&, QtxSearchTool* ) = 0;
00175 virtual bool findLast( const QString&, QtxSearchTool* ) = 0;
00176 };
00177
00178 class QTX_EXPORT QtxTreeViewSearcher : public QtxSearchTool::Searcher
00179 {
00180 public:
00181 QtxTreeViewSearcher( QTreeView*, int = 0 );
00182 virtual ~QtxTreeViewSearcher();
00183
00184 int searchColumn() const;
00185 void setSearchColumn( int );
00186
00187 virtual bool find( const QString&, QtxSearchTool* );
00188 virtual bool findNext( const QString&, QtxSearchTool* );
00189 virtual bool findPrevious( const QString&, QtxSearchTool* );
00190 virtual bool findFirst( const QString&, QtxSearchTool* );
00191 virtual bool findLast( const QString&, QtxSearchTool* );
00192
00193 protected:
00194 virtual Qt::MatchFlags matchFlags( QtxSearchTool* ) const;
00195
00196 private:
00197 QModelIndexList findItems( const QString&, QtxSearchTool* );
00198 QModelIndex findNearest( const QModelIndex&, const QModelIndexList&, bool );
00199 void showItem( const QModelIndex& );
00200 QString getId( const QModelIndex& );
00201 int compareIndices( const QModelIndex&, const QModelIndex& );
00202
00203 private:
00204 QTreeView* myView;
00205 int myColumn;
00206 QPersistentModelIndex myIndex;
00207 };
00208
00209 #endif // QTXSEARCHTOOL_H