libyui-qt  2.53.0
YQMenuButton.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQMenuButton.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef YQMenuButton_h
27 #define YQMenuButton_h
28 
29 #include <qwidget.h>
30 #include <yui/YMenuButton.h>
31 #include <QHash>
32 
33 class QAction;
34 class QPushButton;
35 class QMenu;
36 
37 class YQMenuButton : public QWidget, public YMenuButton
38 {
39  Q_OBJECT
40 
41 public:
42  /**
43  * Constructor.
44  **/
45  YQMenuButton( YWidget * parent,
46  const std::string & label );
47 
48  /**
49  * Destructor.
50  **/
51  virtual ~YQMenuButton();
52 
53  /**
54  * Change the label on the button.
55  *
56  * Reimplemented from YMenuButton / YSelectionWidget.
57  **/
58  virtual void setLabel( const std::string & label );
59 
60  /**
61  * Rebuild the displayed menu tree from the internally stored YMenuItems.
62  *
63  * Implemented from YMenuButton.
64  **/
65  virtual void rebuildMenuTree();
66 
67  /**
68  * Set enabled / disabled state.
69  *
70  * Reimplemented from YWidget.
71  **/
72  virtual void setEnabled( bool enabled );
73 
74  /**
75  * Preferred width of the widget.
76  *
77  * Reimplemented from YWidget.
78  **/
79  virtual int preferredWidth();
80 
81  /**
82  * Preferred height of the widget.
83  *
84  * Reimplemented from YWidget.
85  **/
86  virtual int preferredHeight();
87 
88  /**
89  * Set the new size of the widget.
90  *
91  * Reimplemented from YWidget.
92  **/
93  virtual void setSize( int newWidth, int newHeight );
94 
95  /**
96  * Accept the keyboard focus.
97  **/
98  virtual bool setKeyboardFocus();
99 
100  /**
101  * Activate the item selected in the tree. Can be used in tests to simulate user input.
102  *
103  * Derived classes are required to implement this.
104  **/
105  virtual void activateItem( YMenuItem * item );
106 
107 protected slots:
108 
109  /**
110  * Triggered when any menu item is activated.
111  **/
112  void menuEntryActivated( QAction * menuItem );
113 
114  /**
115  * Triggered via menuEntryActivated() by zero timer to get back in sync
116  * with the Qt event loop.
117  **/
118  void returnNow();
119 
120 
121 protected:
122 
123  /**
124  * Recursively insert menu items into 'menu' from iterator 'begin' to iterator 'end'.
125  **/
126  void rebuildMenuTree( QMenu * menu, YItemIterator begin, YItemIterator end );
127 
128 
129  //
130  // Data members
131  //
132 
133  YMenuItem * _selectedItem;
134  QPushButton * _qt_button;
135  QHash<QAction*,int> _serials;
136 };
137 
138 #endif // YQMenuButton_h
virtual void setLabel(const std::string &label)
Change the label on the button.
Definition: YQMenuButton.cc:64
virtual void activateItem(YMenuItem *item)
Activate the item selected in the tree.
YQMenuButton(YWidget *parent, const std::string &label)
Constructor.
Definition: YQMenuButton.cc:42
virtual int preferredHeight()
Preferred height of the widget.
virtual bool setKeyboardFocus()
Accept the keyboard focus.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
virtual int preferredWidth()
Preferred width of the widget.
virtual void setEnabled(bool enabled)
Set enabled / disabled state.
void returnNow()
Triggered via menuEntryActivated() by zero timer to get back in sync with the Qt event loop.
virtual void rebuildMenuTree()
Rebuild the displayed menu tree from the internally stored YMenuItems.
Definition: YQMenuButton.cc:72
void menuEntryActivated(QAction *menuItem)
Triggered when any menu item is activated.
virtual ~YQMenuButton()
Destructor.
Definition: YQMenuButton.cc:57