libyui-qt  2.56.2
YQMenuBar.h
1 /*
2  Copyright (C) 2020 SUSE LLC
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: YQMenuBar.h
20 
21  Author: Stefan Hundhammer <shundhammer@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef YQMenuBar_h
27 #define YQMenuBar_h
28 
29 #include <QMenuBar>
30 #include <yui/YMenuBar.h>
31 #include <QHash>
32 
33 class QAction;
34 class QPushButton;
35 class QMenu;
36 
37 class YQMenuBar : public QMenuBar, public YMenuBar
38 {
39  Q_OBJECT
40 
41 public:
42  /**
43  * Constructor.
44  **/
45  YQMenuBar( YWidget * parent );
46 
47  /**
48  * Destructor.
49  **/
50  virtual ~YQMenuBar();
51 
52  /**
53  * Rebuild the displayed menu tree from the internally stored YMenuItems.
54  *
55  * Implemented from YMenuWidget.
56  **/
57  virtual void rebuildMenuTree();
58 
59  /**
60  * Set enabled / disabled state.
61  *
62  * Reimplemented from YWidget.
63  **/
64  virtual void setEnabled( bool enabled );
65 
66  /**
67  * Preferred width of the widget.
68  *
69  * Reimplemented from YWidget.
70  **/
71  virtual int preferredWidth();
72 
73  /**
74  * Preferred height of the widget.
75  *
76  * Reimplemented from YWidget.
77  **/
78  virtual int preferredHeight();
79 
80  /**
81  * Set the new size of the widget.
82  *
83  * Reimplemented from YWidget.
84  **/
85  virtual void setSize( int newWidth, int newHeight );
86 
87  /**
88  * Accept the keyboard focus.
89  **/
90  virtual bool setKeyboardFocus();
91 
92  /**
93  * Enable or disable an item.
94  *
95  * Reimplemented from YMenuWidget.
96  **/
97  virtual void setItemEnabled( YMenuItem * item, bool enabled );
98 
99  /**
100  * Show or hide an item.
101  *
102  * Reimplemented from YMenuWidget.
103  **/
104  virtual void setItemVisible( YMenuItem * item, bool visible );
105 
106  /**
107  * Activate the item selected in the tree. Can be used in tests to simulate
108  * user input.
109  **/
110  virtual void activateItem( YMenuItem * item );
111 
112  /**
113  * Notification that some shortcut was changed.
114  *
115  * Reimplemented from YSelectionWidget.
116  **/
117  virtual void shortcutChanged();
118 
119 protected slots:
120 
121  /**
122  * Triggered when any menu item is activated.
123  **/
124  void menuEntryActivated( QAction * menuItem );
125 
126  /**
127  * Triggered via menuEntryActivated() by zero timer to get back in sync
128  * with the Qt event loop.
129  **/
130  void returnNow();
131 
132 
133 protected:
134 
135  /**
136  * Recursively insert menu items into 'menu' from iterator 'begin' to
137  * iterator 'end'.
138  **/
139  void rebuildMenuTree( QMenu * menu,
140  YItemIterator begin,
141  YItemIterator end );
142 
143 
144  //
145  // Data members
146  //
147 
148  YMenuItem * _selectedItem;
149  QMap<QAction *,YMenuItem *> _actionMap;
150 };
151 
152 #endif // YQMenuBar_h
YQMenuBar::menuEntryActivated
void menuEntryActivated(QAction *menuItem)
Triggered when any menu item is activated.
Definition: YQMenuBar.cc:144
YQMenuBar::setEnabled
virtual void setEnabled(bool enabled)
Set enabled / disabled state.
Definition: YQMenuBar.cc:233
YQMenuBar::setSize
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQMenuBar.cc:252
YQMenuBar::preferredHeight
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQMenuBar.cc:245
YQMenuBar::preferredWidth
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQMenuBar.cc:239
YQMenuBar::setKeyboardFocus
virtual bool setKeyboardFocus()
Accept the keyboard focus.
Definition: YQMenuBar.cc:259
YQMenuBar::setItemEnabled
virtual void setItemEnabled(YMenuItem *item, bool enabled)
Enable or disable an item.
Definition: YQMenuBar.cc:185
YQMenuBar::setItemVisible
virtual void setItemVisible(YMenuItem *item, bool visible)
Show or hide an item.
Definition: YQMenuBar.cc:209
YQMenuBar::shortcutChanged
virtual void shortcutChanged()
Notification that some shortcut was changed.
Definition: YQMenuBar.cc:276
YQMenuBar::activateItem
virtual void activateItem(YMenuItem *item)
Activate the item selected in the tree.
Definition: YQMenuBar.cc:268
YQMenuBar
Definition: YQMenuBar.h:38
YQMenuBar::rebuildMenuTree
virtual void rebuildMenuTree()
Rebuild the displayed menu tree from the internally stored YMenuItems.
Definition: YQMenuBar.cc:57
YQMenuBar::~YQMenuBar
virtual ~YQMenuBar()
Destructor.
Definition: YQMenuBar.cc:50
YQMenuBar::returnNow
void returnNow()
Triggered via menuEntryActivated() by zero timer to get back in sync with the Qt event loop.
Definition: YQMenuBar.cc:174
YQMenuBar::YQMenuBar
YQMenuBar(YWidget *parent)
Constructor.
Definition: YQMenuBar.cc:41