1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : QtxSearchTool.h
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 #ifndef QTXSEARCHTOOL_H
26 #define QTXSEARCHTOOL_H
32 #include <QPersistentModelIndex>
42 class QTX_EXPORT QtxSearchTool : public QFrame
46 //! Find operation type
48 fAny, //!< find any appropriate
49 fNext, //!< find next appropriate
50 fPrevious, //!< find previous appropriate
51 fFirst, //!< find first appropriate
52 fLast //!< find last appropriate
58 //! Search tool controls
60 Search = 0x00000001, //!< line edit field for searched text
61 Next = 0x00000002, //!< 'find next' button
62 Prev = 0x00000004, //!< 'find previous' button
63 First = 0x00000008, //!< 'find first' button
64 Last = 0x00000010, //!< 'find last' button
65 Close = 0x00000020, //!< 'close' button
66 Case = 0x00000040, //!< 'case sensitive search' check box
67 RegExp = 0x00000080, //!< 'regular expression' check box
68 Wrap = 0x00000100, //!< 'wrap search' check box
69 Basic = Search | Next | Prev | Close, //!< basic controls: text field, "next", "prev" and "close" buttons
70 Standard = Basic | First | Last, //!< standard controls: same as Basic plus "first" and "last" buttons
71 Modifiers = Case | RegExp | Wrap, //!< search modifiers check boxes
72 All = Standard | Modifiers //!< all controls
76 None = 0x00000000, //!< search tool can be activated programmatically only
77 HotKey = 0x00000001, //!< search tool is activated by hot key
78 SlashKey = 0x00000002, //!< search tool is activated by splash key ( / )
79 StandardKey = 0x00000004, //!< search tool is activated by standard key combination (e.g. F3)
80 PrintKey = 0x00000008, //!< search tool is activated when user types any print key
81 Any = HotKey | SlashKey | StandardKey | PrintKey //!< search tool is activated by any of above mentioned ways
84 QtxSearchTool( QWidget*, QWidget* = 0, int = All );
85 QtxSearchTool( QWidget*, int = All );
86 virtual ~QtxSearchTool();
88 QWidget* watchedWidget() const;
89 void setWatchedWidget( QWidget* );
91 Searcher* searcher() const;
92 void setSearcher( Searcher* );
94 int activators() const;
95 void setActivators( const int );
98 void setControls( const int );
100 QList<QKeySequence> shortcuts() const;
101 void setShortcuts( const QKeySequence& );
102 void setShortcuts( const QList<QKeySequence>& );
104 int addCustomWidget( QWidget*, int = -1 );
105 QWidget* customWidget( int ) const;
106 int customWidgetId( QWidget* ) const;
108 bool isAutoHideEnabled() const;
109 void enableAutoHide( bool );
111 bool isCaseSensitive() const;
112 bool isRegExpSearch() const;
113 bool isSearchWrapped() const;
115 void setCaseSensitive( bool );
116 void setRegExpSearch( bool );
117 void setSearchWrapped( bool );
119 virtual bool event( QEvent* );
120 virtual bool eventFilter( QObject*, QEvent* );
124 virtual void findNext();
125 virtual void findPrevious();
126 virtual void findFirst();
127 virtual void findLast();
130 void find( const QString&, int = fAny );
131 void modifierSwitched();
135 bool focused() const;
136 void clearShortcuts();
137 void initShortcuts( const QList<QKeySequence>& );
138 void updateShortcuts();
139 void updateControls();
142 typedef QPointer<QShortcut> ShortcutPtr;
143 typedef QList<ShortcutPtr> ShortcutList;
146 QWidget* myBtnWidget;
147 QWidget* myModWidget;
149 QToolButton* myToFirst;
150 QToolButton* myToLast;
153 QToolButton* myClose;
154 QCheckBox* myIsCaseSens;
155 QCheckBox* myIsRegExp;
158 Searcher* mySearcher;
161 ShortcutList myShortcuts;
162 QTimer* myAutoHideTimer;
163 bool myAutoHideEnabled;
164 QMap<int, QWidget*> myWidgets;
167 class QTX_EXPORT QtxSearchTool::Searcher
173 virtual bool find( const QString&, QtxSearchTool* ) = 0;
174 virtual bool findNext( const QString&, QtxSearchTool* ) = 0;
175 virtual bool findPrevious( const QString&, QtxSearchTool* ) = 0;
176 virtual bool findFirst( const QString&, QtxSearchTool* ) = 0;
177 virtual bool findLast( const QString&, QtxSearchTool* ) = 0;
180 class QTX_EXPORT QtxTreeViewSearcher : public QtxSearchTool::Searcher
183 QtxTreeViewSearcher( QTreeView*, int = 0 );
184 virtual ~QtxTreeViewSearcher();
186 int searchColumn() const;
187 void setSearchColumn( int );
189 virtual bool find( const QString&, QtxSearchTool* );
190 virtual bool findNext( const QString&, QtxSearchTool* );
191 virtual bool findPrevious( const QString&, QtxSearchTool* );
192 virtual bool findFirst( const QString&, QtxSearchTool* );
193 virtual bool findLast( const QString&, QtxSearchTool* );
196 virtual Qt::MatchFlags matchFlags( QtxSearchTool* ) const;
199 QModelIndexList findItems( const QString&, QtxSearchTool* );
200 QModelIndex findNearest( const QModelIndex&, const QModelIndexList&, bool );
201 void showItem( const QModelIndex& );
202 QString getId( const QModelIndex& );
203 int compareIndices( const QModelIndex&, const QModelIndex& );
208 QPersistentModelIndex myIndex;
211 #endif // QTXSEARCHTOOL_H