1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : QtxSearchTool.h
21 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
23 #ifndef QTXSEARCHTOOL_H
24 #define QTXSEARCHTOOL_H
30 #include <QPersistentModelIndex>
40 class QTX_EXPORT QtxSearchTool : public QFrame
44 //! Find operation type
46 fAny, //!< find any appropriate
47 fNext, //!< find next appropriate
48 fPrevious, //!< find previous appropriate
49 fFirst, //!< find first appropriate
50 fLast //!< find last appropriate
56 //! Search tool controls
58 Search = 0x00000001, //!< line edit field for searched text
59 Next = 0x00000002, //!< 'find next' button
60 Prev = 0x00000004, //!< 'find previous' button
61 First = 0x00000008, //!< 'find first' button
62 Last = 0x00000010, //!< 'find last' button
63 Close = 0x00000020, //!< 'close' button
64 Case = 0x00000040, //!< 'case sensitive search' check box
65 RegExp = 0x00000080, //!< 'regular expression' check box
66 Wrap = 0x00000100, //!< 'wrap search' check box
67 Basic = Search | Next | Prev | Close, //!< basic controls: text field, "next", "prev" and "close" buttons
68 Standard = Basic | First | Last, //!< standard controls: same as Basic plus "first" and "last" buttons
69 Modifiers = Case | RegExp | Wrap, //!< search modifiers check boxes
70 All = Standard | Modifiers //!< all controls
74 None = 0x00000000, //!< search tool can be activated programmatically only
75 HotKey = 0x00000001, //!< search tool is activated by hot key
76 SlashKey = 0x00000002, //!< search tool is activated by splash key ( / )
77 StandardKey = 0x00000004, //!< search tool is activated by standard key combination (e.g. F3)
78 PrintKey = 0x00000008, //!< search tool is activated when user types any print key
79 Any = HotKey | SlashKey | StandardKey | PrintKey //!< search tool is activated by any of above mentioned ways
82 QtxSearchTool( QWidget*, QWidget* = 0, int = All, Qt::Orientation = Qt::Vertical );
83 QtxSearchTool( QWidget*, int = All, Qt::Orientation = Qt::Vertical );
84 virtual ~QtxSearchTool();
86 QWidget* watchedWidget() const;
87 void setWatchedWidget( QWidget* );
89 Searcher* searcher() const;
90 void setSearcher( Searcher* );
92 int activators() const;
93 void setActivators( const int );
96 void setControls( const int );
98 QList<QKeySequence> shortcuts() const;
99 void setShortcuts( const QKeySequence& );
100 void setShortcuts( const QList<QKeySequence>& );
102 int addCustomWidget( QWidget*, int = -1 );
103 QWidget* customWidget( int ) const;
104 int customWidgetId( QWidget* ) const;
106 bool isAutoHideEnabled() const;
107 void enableAutoHide( bool );
109 bool isCaseSensitive() const;
110 bool isRegExpSearch() const;
111 bool isSearchWrapped() const;
113 void setCaseSensitive( bool );
114 void setRegExpSearch( bool );
115 void setSearchWrapped( bool );
117 virtual bool event( QEvent* );
118 virtual bool eventFilter( QObject*, QEvent* );
122 virtual void findNext();
123 virtual void findPrevious();
124 virtual void findFirst();
125 virtual void findLast();
128 void find( const QString&, int = fAny );
129 void modifierSwitched();
132 void init( Qt::Orientation );
133 bool focused() const;
134 void clearShortcuts();
135 void initShortcuts( const QList<QKeySequence>& );
136 void updateShortcuts();
137 void updateControls();
140 typedef QPointer<QShortcut> ShortcutPtr;
141 typedef QList<ShortcutPtr> ShortcutList;
144 QWidget* myBtnWidget;
145 QWidget* myModWidget;
147 QToolButton* myToFirst;
148 QToolButton* myToLast;
151 QToolButton* myClose;
152 QCheckBox* myIsCaseSens;
153 QCheckBox* myIsRegExp;
156 Searcher* mySearcher;
159 ShortcutList myShortcuts;
160 QTimer* myAutoHideTimer;
161 bool myAutoHideEnabled;
162 QMap<int, QWidget*> myWidgets;
165 class QTX_EXPORT QtxSearchTool::Searcher
171 virtual bool find( const QString&, QtxSearchTool* ) = 0;
172 virtual bool findNext( const QString&, QtxSearchTool* ) = 0;
173 virtual bool findPrevious( const QString&, QtxSearchTool* ) = 0;
174 virtual bool findFirst( const QString&, QtxSearchTool* ) = 0;
175 virtual bool findLast( const QString&, QtxSearchTool* ) = 0;
178 class QTX_EXPORT QtxTreeViewSearcher : public QtxSearchTool::Searcher
181 QtxTreeViewSearcher( QTreeView*, int = 0 );
182 virtual ~QtxTreeViewSearcher();
184 int searchColumn() const;
185 void setSearchColumn( int );
187 virtual bool find( const QString&, QtxSearchTool* );
188 virtual bool findNext( const QString&, QtxSearchTool* );
189 virtual bool findPrevious( const QString&, QtxSearchTool* );
190 virtual bool findFirst( const QString&, QtxSearchTool* );
191 virtual bool findLast( const QString&, QtxSearchTool* );
194 virtual Qt::MatchFlags matchFlags( QtxSearchTool* ) const;
197 QModelIndexList findItems( const QString&, QtxSearchTool* );
198 QModelIndex findNearest( const QModelIndex&, const QModelIndexList&, bool );
199 void showItem( const QModelIndex& );
200 QString getId( const QModelIndex& );
201 int compareIndices( const QModelIndex&, const QModelIndex& );
206 QPersistentModelIndex myIndex;
209 #endif // QTXSEARCHTOOL_H