OpenWalnut  1.5.0dev
WQtMenuFiltered.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WQTMENUFILTERED_H
26 #define WQTMENUFILTERED_H
27 
28 #include <QKeyEvent>
29 #include <QMenu>
30 #include <QLineEdit>
31 #include <QLabel>
32 #include <QWidget>
33 #include <QWidgetAction>
34 #include <QHBoxLayout>
35 
36 /**
37  * A menu derived from QMenu with additional filtering.
38  */
39 class WQtMenuFiltered: public QMenu
40 {
41  Q_OBJECT
42 public:
43  /**
44  * Create filtered menu.
45  *
46  * \param parent parent widget
47  * \param config the optional configure action
48  */
49  WQtMenuFiltered( QAction* config = 0, QWidget* parent = 0 );
50 
51  /**
52  * Create filtered menu.
53  *
54  * \param title the menu title
55  * \param parent the parent
56  * \param config the optional configure action
57  */
58  WQtMenuFiltered( const QString& title, QAction* config = 0, QWidget* parent = 0 );
59 
60  /**
61  * Destructor.
62  */
63  virtual ~WQtMenuFiltered();
64 
65 public slots:
66  /**
67  * Updates the filter
68  */
69  void filterUpdate();
70 
71  /**
72  * Resets the filter. All elements are visible again.
73  */
74  void resetFilter();
75 protected:
76  /**
77  * Grab key events. Used for filtering.
78  *
79  * \param e the key event
80  */
81  virtual void keyPressEvent( QKeyEvent* e );
82 
83  /**
84  * Called when hiding the menu. Used to reset the filter.
85  *
86  * \param e the event
87  */
88  void hideEvent( QHideEvent* e );
89 private:
90  /**
91  * Setup filter on given menu
92  *
93  * \param to the menu
94  * \param config optional config action shown in the filter
95  */
96  static void setupFilter( WQtMenuFiltered* to, QAction* config = 0 );
97 
98  /**
99  * Filter textfield
100  */
101  QLineEdit* m_edit;
102 };
103 
104 #endif // WQTMENUFILTERED_H
105 
A menu derived from QMenu with additional filtering.
void hideEvent(QHideEvent *e)
Called when hiding the menu.
virtual ~WQtMenuFiltered()
Destructor.
WQtMenuFiltered(QAction *config=0, QWidget *parent=0)
Create filtered menu.
virtual void keyPressEvent(QKeyEvent *e)
Grab key events.
static void setupFilter(WQtMenuFiltered *to, QAction *config=0)
Setup filter on given menu.
void resetFilter()
Resets the filter.
void filterUpdate()
Updates the filter.
QLineEdit * m_edit
Filter textfield.