qmenubar.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qmenubar.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include <qmenubar.h>-
41-
42#include <qstyle.h>-
43#include <qlayout.h>-
44#include <qapplication.h>-
45#include <qdesktopwidget.h>-
46#ifndef QT_NO_ACCESSIBILITY-
47# include <qaccessible.h>-
48#endif-
49#include <qpainter.h>-
50#include <qstylepainter.h>-
51#include <qevent.h>-
52#include <qmainwindow.h>-
53#include <qtoolbar.h>-
54#include <qtoolbutton.h>-
55#include <qwhatsthis.h>-
56#include <qpa/qplatformtheme.h>-
57#include "private/qguiapplication_p.h"-
58#include "qpa/qplatformintegration.h"-
59-
60#ifndef QT_NO_MENUBAR-
61-
62-
63#include "qmenu_p.h"-
64#include "qmenubar_p.h"-
65#include "qdebug.h"-
66-
67#ifdef Q_OS_WINCE-
68extern bool qt_wince_is_mobile(); //defined in qguifunctions_wce.cpp-
69#endif-
70-
71QT_BEGIN_NAMESPACE-
72-
73class QMenuBarExtension : public QToolButton-
74{-
75public:-
76 explicit QMenuBarExtension(QWidget *parent);-
77-
78 QSize sizeHint() const Q_DECL_OVERRIDE;-
79 void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;-
80};-
81-
82QMenuBarExtension::QMenuBarExtension(QWidget *parent)-
83 : QToolButton(parent)-
84{-
85 setObjectName(QLatin1String("qt_menubar_ext_button"));-
86 setAutoRaise(true);-
87#ifndef QT_NO_MENU-
88 setPopupMode(QToolButton::InstantPopup);-
89#endif-
90 setIcon(style()->standardIcon(QStyle::SP_ToolBarHorizontalExtensionButton, 0, parentWidget()));-
91}
never executed: end of block
0
92-
93void QMenuBarExtension::paintEvent(QPaintEvent *)-
94{-
95 QStylePainter p(this);-
96 QStyleOptionToolButton opt;-
97 initStyleOption(&opt);-
98 // We do not need to draw both extension arrows-
99 opt.features &= ~QStyleOptionToolButton::HasMenu;-
100 p.drawComplexControl(QStyle::CC_ToolButton, opt);-
101}
never executed: end of block
0
102-
103-
104QSize QMenuBarExtension::sizeHint() const-
105{-
106 int ext = style()->pixelMetric(QStyle::PM_ToolBarExtensionExtent, 0, parentWidget());-
107 return QSize(ext, ext);
never executed: return QSize(ext, ext);
0
108}-
109-
110-
111/*!-
112 \internal-
113*/-
114QAction *QMenuBarPrivate::actionAt(QPoint p) const-
115{-
116 for(int i = 0; i < actions.size(); ++i) {
i < actions.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
117 if(actionRect(actions.at(i)).contains(p))
actionRect(act...)).contains(p)Description
TRUEnever evaluated
FALSEnever evaluated
0
118 return actions.at(i);
never executed: return actions.at(i);
0
119 }
never executed: end of block
0
120 return 0;
never executed: return 0;
0
121}-
122-
123QRect QMenuBarPrivate::menuRect(bool extVisible) const-
124{-
125 Q_Q(const QMenuBar);-
126-
127 int hmargin = q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q);-
128 QRect result = q->rect();-
129 result.adjust(hmargin, 0, -hmargin, 0);-
130-
131 if (extVisible) {
extVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
132 if (q->isRightToLeft())
q->isRightToLeft()Description
TRUEnever evaluated
FALSEnever evaluated
0
133 result.setLeft(result.left() + extension->sizeHint().width());
never executed: result.setLeft(result.left() + extension->sizeHint().width());
0
134 else-
135 result.setWidth(result.width() - extension->sizeHint().width());
never executed: result.setWidth(result.width() - extension->sizeHint().width());
0
136 }-
137-
138 if (leftWidget && leftWidget->isVisible()) {
leftWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
leftWidget->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
139 QSize sz = leftWidget->sizeHint();-
140 if (q->isRightToLeft())
q->isRightToLeft()Description
TRUEnever evaluated
FALSEnever evaluated
0
141 result.setRight(result.right() - sz.width());
never executed: result.setRight(result.right() - sz.width());
0
142 else-
143 result.setLeft(result.left() + sz.width());
never executed: result.setLeft(result.left() + sz.width());
0
144 }-
145-
146 if (rightWidget && rightWidget->isVisible()) {
rightWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
rightWidget->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
147 QSize sz = rightWidget->sizeHint();-
148 if (q->isRightToLeft())
q->isRightToLeft()Description
TRUEnever evaluated
FALSEnever evaluated
0
149 result.setLeft(result.left() + sz.width());
never executed: result.setLeft(result.left() + sz.width());
0
150 else-
151 result.setRight(result.right() - sz.width());
never executed: result.setRight(result.right() - sz.width());
0
152 }-
153-
154 return result;
never executed: return result;
0
155}-
156-
157bool QMenuBarPrivate::isVisible(QAction *action)-
158{-
159 return !hiddenActions.contains(action);
never executed: return !hiddenActions.contains(action);
0
160}-
161-
162void QMenuBarPrivate::updateGeometries()-
163{-
164 Q_Q(QMenuBar);-
165 if(!itemsDirty)
!itemsDirtyDescription
TRUEnever evaluated
FALSEnever evaluated
0
166 return;
never executed: return;
0
167 int q_width = q->width()-(q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q)*2);-
168 int q_start = -1;-
169 if(leftWidget || rightWidget) {
leftWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
rightWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
170 int vmargin = q->style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q)-
171 + q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q);-
172 int hmargin = q->style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, q)-
173 + q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q);-
174 if (leftWidget && leftWidget->isVisible()) {
leftWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
leftWidget->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
175 QSize sz = leftWidget->sizeHint();-
176 q_width -= sz.width();-
177 q_start = sz.width();-
178 QPoint pos(hmargin, (q->height() - leftWidget->height()) / 2);-
179 QRect vRect = QStyle::visualRect(q->layoutDirection(), q->rect(), QRect(pos, sz));-
180 leftWidget->setGeometry(vRect);-
181 }
never executed: end of block
0
182 if (rightWidget && rightWidget->isVisible()) {
rightWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
rightWidget->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
183 QSize sz = rightWidget->sizeHint();-
184 q_width -= sz.width();-
185 QPoint pos(q->width() - sz.width() - hmargin, vmargin);-
186 QRect vRect = QStyle::visualRect(q->layoutDirection(), q->rect(), QRect(pos, sz));-
187 rightWidget->setGeometry(vRect);-
188 }
never executed: end of block
0
189 }
never executed: end of block
0
190-
191#ifdef Q_OS_MAC-
192 if(q->isNativeMenuBar()) {//nothing to see here folks, move along..-
193 itemsDirty = false;-
194 return;-
195 }-
196#endif-
197 calcActionRects(q_width, q_start);-
198 currentAction = 0;-
199#ifndef QT_NO_SHORTCUT-
200 if(itemsDirty) {
itemsDirtyDescription
TRUEnever evaluated
FALSEnever evaluated
0
201 for(int j = 0; j < shortcutIndexMap.size(); ++j)
j < shortcutIndexMap.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
202 q->releaseShortcut(shortcutIndexMap.value(j));
never executed: q->releaseShortcut(shortcutIndexMap.value(j));
0
203 shortcutIndexMap.clear();-
204 const int actionsCount = actions.count();-
205 shortcutIndexMap.reserve(actionsCount);-
206 for (int i = 0; i < actionsCount; i++)
i < actionsCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
207 shortcutIndexMap.append(q->grabShortcut(QKeySequence::mnemonic(actions.at(i)->text())));
never executed: shortcutIndexMap.append(q->grabShortcut(QKeySequence::mnemonic(actions.at(i)->text())));
0
208 }
never executed: end of block
0
209#endif-
210 itemsDirty = false;-
211-
212 hiddenActions.clear();-
213 //this is the menu rectangle without any extension-
214 QRect menuRect = this->menuRect(false);-
215-
216 //we try to see if the actions will fit there-
217 bool hasHiddenActions = false;-
218 for (int i = 0; i < actions.count(); ++i) {
i < actions.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
219 const QRect &rect = actionRects.at(i);-
220 if (rect.isValid() && !menuRect.contains(rect)) {
rect.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
!menuRect.contains(rect)Description
TRUEnever evaluated
FALSEnever evaluated
0
221 hasHiddenActions = true;-
222 break;
never executed: break;
0
223 }-
224 }
never executed: end of block
0
225-
226 //...and if not, determine the ones that fit on the menu with the extension visible-
227 if (hasHiddenActions) {
hasHiddenActionsDescription
TRUEnever evaluated
FALSEnever evaluated
0
228 menuRect = this->menuRect(true);-
229 for (int i = 0; i < actions.count(); ++i) {
i < actions.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
230 const QRect &rect = actionRects.at(i);-
231 if (rect.isValid() && !menuRect.contains(rect)) {
rect.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
!menuRect.contains(rect)Description
TRUEnever evaluated
FALSEnever evaluated
0
232 hiddenActions.append(actions.at(i));-
233 }
never executed: end of block
0
234 }
never executed: end of block
0
235 }
never executed: end of block
0
236-
237 if (hiddenActions.count() > 0) {
hiddenActions.count() > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
238 QMenu *pop = extension->menu();-
239 if (!pop) {
!popDescription
TRUEnever evaluated
FALSEnever evaluated
0
240 pop = new QMenu(q);-
241 extension->setMenu(pop);-
242 }
never executed: end of block
0
243 pop->clear();-
244 pop->addActions(hiddenActions);-
245-
246 int vmargin = q->style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q);-
247 int x = q->isRightToLeft()
q->isRightToLeft()Description
TRUEnever evaluated
FALSEnever evaluated
0
248 ? menuRect.left() - extension->sizeHint().width() + 1-
249 : menuRect.right();-
250 extension->setGeometry(x, vmargin, extension->sizeHint().width(), menuRect.height() - vmargin*2);-
251 extension->show();-
252 } else {
never executed: end of block
0
253 extension->hide();-
254 }
never executed: end of block
0
255 q->updateGeometry();-
256}
never executed: end of block
0
257-
258QRect QMenuBarPrivate::actionRect(QAction *act) const-
259{-
260 const int index = actions.indexOf(act);-
261-
262 //makes sure the geometries are up-to-date-
263 const_cast<QMenuBarPrivate*>(this)->updateGeometries();-
264-
265 if (index < 0 || index >= actionRects.count())
index < 0Description
TRUEnever evaluated
FALSEnever evaluated
index >= actionRects.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
266 return QRect(); // that can happen in case of native menubar
never executed: return QRect();
0
267-
268 return actionRects.at(index);
never executed: return actionRects.at(index);
0
269}-
270-
271void QMenuBarPrivate::focusFirstAction()-
272{-
273 if(!currentAction) {
!currentActionDescription
TRUEnever evaluated
FALSEnever evaluated
0
274 updateGeometries();-
275 int index = 0;-
276 while (index < actions.count() && actionRects.at(index).isNull()) ++index;
never executed: ++index;
index < actions.count()Description
TRUEnever evaluated
FALSEnever evaluated
actionRects.at(index).isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
277 if (index < actions.count())
index < actions.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
278 setCurrentAction(actions.at(index));
never executed: setCurrentAction(actions.at(index));
0
279 }
never executed: end of block
0
280}
never executed: end of block
0
281-
282void QMenuBarPrivate::setKeyboardMode(bool b)-
283{-
284 Q_Q(QMenuBar);-
285 if (b && !q->style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, q)) {
bDescription
TRUEnever evaluated
FALSEnever evaluated
!q->style()->s...igation, 0, q)Description
TRUEnever evaluated
FALSEnever evaluated
0
286 setCurrentAction(0);-
287 return;
never executed: return;
0
288 }-
289 keyboardState = b;-
290 if(b) {
bDescription
TRUEnever evaluated
FALSEnever evaluated
0
291 QWidget *fw = QApplication::focusWidget();-
292 if (fw != q)
fw != qDescription
TRUEnever evaluated
FALSEnever evaluated
0
293 keyboardFocusWidget = fw;
never executed: keyboardFocusWidget = fw;
0
294 focusFirstAction();-
295 q->setFocus(Qt::MenuBarFocusReason);-
296 } else {
never executed: end of block
0
297 if(!popupState)
!popupStateDescription
TRUEnever evaluated
FALSEnever evaluated
0
298 setCurrentAction(0);
never executed: setCurrentAction(0);
0
299 if(keyboardFocusWidget) {
keyboardFocusWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
300 if (QApplication::focusWidget() == q)
QApplication::...sWidget() == qDescription
TRUEnever evaluated
FALSEnever evaluated
0
301 keyboardFocusWidget->setFocus(Qt::MenuBarFocusReason);
never executed: keyboardFocusWidget->setFocus(Qt::MenuBarFocusReason);
0
302 keyboardFocusWidget = 0;-
303 }
never executed: end of block
0
304 }
never executed: end of block
0
305 q->update();-
306}
never executed: end of block
0
307-
308void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst)-
309{-
310 Q_Q(QMenuBar);-
311 if(!action || !action->menu() || closePopupMode)
!actionDescription
TRUEnever evaluated
FALSEnever evaluated
!action->menu()Description
TRUEnever evaluated
FALSEnever evaluated
closePopupModeDescription
TRUEnever evaluated
FALSEnever evaluated
0
312 return;
never executed: return;
0
313 popupState = true;-
314 if (action->isEnabled() && action->menu()->isEnabled()) {
action->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
action->menu()->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
315 closePopupMode = 0;-
316 activeMenu = action->menu();-
317 activeMenu->d_func()->causedPopup.widget = q;-
318 activeMenu->d_func()->causedPopup.action = action;-
319-
320 QRect adjustedActionRect = actionRect(action);-
321 QPoint pos(q->mapToGlobal(QPoint(adjustedActionRect.left(), adjustedActionRect.bottom() + 1)));-
322 QSize popup_size = activeMenu->sizeHint();-
323-
324 //we put the popup menu on the screen containing the bottom-center of the action rect-
325 QRect screenRect = QApplication::desktop()->screenGeometry(pos + QPoint(adjustedActionRect.width() / 2, 0));-
326 pos = QPoint(qMax(pos.x(), screenRect.x()), qMax(pos.y(), screenRect.y()));-
327-
328 const bool fitUp = (q->mapToGlobal(adjustedActionRect.topLeft()).y() >= popup_size.height());-
329 const bool fitDown = (pos.y() + popup_size.height() <= screenRect.bottom());-
330 const bool rtl = q->isRightToLeft();-
331 const int actionWidth = adjustedActionRect.width();-
332-
333 if (!fitUp && !fitDown) { //we should shift the menu
!fitUpDescription
TRUEnever evaluated
FALSEnever evaluated
!fitDownDescription
TRUEnever evaluated
FALSEnever evaluated
0
334 bool shouldShiftToRight = !rtl;-
335 if (rtl && popup_size.width() > pos.x())
rtlDescription
TRUEnever evaluated
FALSEnever evaluated
popup_size.width() > pos.x()Description
TRUEnever evaluated
FALSEnever evaluated
0
336 shouldShiftToRight = true;
never executed: shouldShiftToRight = true;
0
337 else if (actionWidth + popup_size.width() + pos.x() > screenRect.right())
actionWidth + ...enRect.right()Description
TRUEnever evaluated
FALSEnever evaluated
0
338 shouldShiftToRight = false;
never executed: shouldShiftToRight = false;
0
339-
340 if (shouldShiftToRight) {
shouldShiftToRightDescription
TRUEnever evaluated
FALSEnever evaluated
0
341 pos.rx() += actionWidth + (rtl ? popup_size.width() : 0);
rtlDescription
TRUEnever evaluated
FALSEnever evaluated
0
342 } else {
never executed: end of block
0
343 //shift to left-
344 if (!rtl)
!rtlDescription
TRUEnever evaluated
FALSEnever evaluated
0
345 pos.rx() -= popup_size.width();
never executed: pos.rx() -= popup_size.width();
0
346 }
never executed: end of block
0
347 } else if (rtl) {
rtlDescription
TRUEnever evaluated
FALSEnever evaluated
0
348 pos.rx() += actionWidth;-
349 }
never executed: end of block
0
350-
351 if(!defaultPopDown || (fitUp && !fitDown))
!defaultPopDownDescription
TRUEnever evaluated
FALSEnever evaluated
fitUpDescription
TRUEnever evaluated
FALSEnever evaluated
!fitDownDescription
TRUEnever evaluated
FALSEnever evaluated
0
352 pos.setY(qMax(screenRect.y(), q->mapToGlobal(QPoint(0, adjustedActionRect.top()-popup_size.height())).y()));
never executed: pos.setY(qMax(screenRect.y(), q->mapToGlobal(QPoint(0, adjustedActionRect.top()-popup_size.height())).y()));
0
353 activeMenu->popup(pos);-
354 if(activateFirst)
activateFirstDescription
TRUEnever evaluated
FALSEnever evaluated
0
355 activeMenu->d_func()->setFirstActionActive();
never executed: activeMenu->d_func()->setFirstActionActive();
0
356 }
never executed: end of block
0
357 q->update(actionRect(action));-
358}
never executed: end of block
0
359-
360void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activateFirst)-
361{-
362 if(currentAction == action && popup == popupState)
currentAction == actionDescription
TRUEnever evaluated
FALSEnever evaluated
popup == popupStateDescription
TRUEnever evaluated
FALSEnever evaluated
0
363 return;
never executed: return;
0
364-
365 autoReleaseTimer.stop();-
366-
367 doChildEffects = (popup && !activeMenu);
popupDescription
TRUEnever evaluated
FALSEnever evaluated
!activeMenuDescription
TRUEnever evaluated
FALSEnever evaluated
0
368 Q_Q(QMenuBar);-
369 QWidget *fw = 0;-
370 if(QMenu *menu = activeMenu) {
QMenu *menu = activeMenuDescription
TRUEnever evaluated
FALSEnever evaluated
0
371 activeMenu = 0;-
372 if (popup) {
popupDescription
TRUEnever evaluated
FALSEnever evaluated
0
373 fw = q->window()->focusWidget();-
374 q->setFocus(Qt::NoFocusReason);-
375 }
never executed: end of block
0
376 menu->hide();-
377 }
never executed: end of block
0
378-
379 if(currentAction)
currentActionDescription
TRUEnever evaluated
FALSEnever evaluated
0
380 q->update(actionRect(currentAction));
never executed: q->update(actionRect(currentAction));
0
381-
382 popupState = popup;-
383#ifndef QT_NO_STATUSTIP-
384 QAction *previousAction = currentAction;-
385#endif-
386 currentAction = action;-
387 if (action && action->isEnabled()) {
actionDescription
TRUEnever evaluated
FALSEnever evaluated
action->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
388 activateAction(action, QAction::Hover);-
389 if(popup)
popupDescription
TRUEnever evaluated
FALSEnever evaluated
0
390 popupAction(action, activateFirst);
never executed: popupAction(action, activateFirst);
0
391 q->update(actionRect(action));-
392#ifndef QT_NO_STATUSTIP-
393 } else if (previousAction) {
never executed: end of block
previousActionDescription
TRUEnever evaluated
FALSEnever evaluated
0
394 QString empty;-
395 QStatusTipEvent tip(empty);-
396 QApplication::sendEvent(q, &tip);-
397#endif-
398 }
never executed: end of block
0
399 if (fw)
fwDescription
TRUEnever evaluated
FALSEnever evaluated
0
400 fw->setFocus(Qt::NoFocusReason);
never executed: fw->setFocus(Qt::NoFocusReason);
0
401}
never executed: end of block
0
402-
403void QMenuBarPrivate::calcActionRects(int max_width, int start) const-
404{-
405 Q_Q(const QMenuBar);-
406-
407 if(!itemsDirty)
!itemsDirtyDescription
TRUEnever evaluated
FALSEnever evaluated
0
408 return;
never executed: return;
0
409-
410 //let's reinitialize the buffer-
411 actionRects.resize(actions.count());-
412 actionRects.fill(QRect());-
413-
414 const QStyle *style = q->style();-
415-
416 const int itemSpacing = style->pixelMetric(QStyle::PM_MenuBarItemSpacing, 0, q);-
417 int max_item_height = 0, separator = -1, separator_start = 0, separator_len = 0;-
418-
419 //calculate size-
420 const QFontMetrics fm = q->fontMetrics();-
421 const int hmargin = style->pixelMetric(QStyle::PM_MenuBarHMargin, 0, q),-
422 vmargin = style->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q),-
423 icone = style->pixelMetric(QStyle::PM_SmallIconSize, 0, q);-
424 for(int i = 0; i < actions.count(); i++) {
i < actions.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
425 QAction *action = actions.at(i);-
426 if(!action->isVisible())
!action->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
427 continue;
never executed: continue;
0
428-
429 QSize sz;-
430-
431 //calc what I think the size is..-
432 if(action->isSeparator()) {
action->isSeparator()Description
TRUEnever evaluated
FALSEnever evaluated
0
433 if (style->styleHint(QStyle::SH_DrawMenuBarSeparator, 0, q))
style->styleHi...parator, 0, q)Description
TRUEnever evaluated
FALSEnever evaluated
0
434 separator = i;
never executed: separator = i;
0
435 continue; //we don't really position these!
never executed: continue;
0
436 } else {-
437 const QString s = action->text();-
438 QIcon is = action->icon();-
439 // If an icon is set, only the icon is visible-
440 if (!is.isNull())
!is.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
441 sz = sz.expandedTo(QSize(icone, icone));
never executed: sz = sz.expandedTo(QSize(icone, icone));
0
442 else if (!s.isEmpty())
!s.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
443 sz = fm.size(Qt::TextShowMnemonic, s);
never executed: sz = fm.size(Qt::TextShowMnemonic, s);
0
444 }
never executed: end of block
0
445-
446 //let the style modify the above size..-
447 QStyleOptionMenuItem opt;-
448 q->initStyleOption(&opt, action);-
449 sz = q->style()->sizeFromContents(QStyle::CT_MenuBarItem, &opt, sz, q);-
450-
451 if(!sz.isEmpty()) {
!sz.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
452 { //update the separator state-
453 int iWidth = sz.width() + itemSpacing;-
454 if(separator == -1)
separator == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
455 separator_start += iWidth;
never executed: separator_start += iWidth;
0
456 else-
457 separator_len += iWidth;
never executed: separator_len += iWidth;
0
458 }-
459 //maximum height-
460 max_item_height = qMax(max_item_height, sz.height());-
461 //append-
462 actionRects[i] = QRect(0, 0, sz.width(), sz.height());-
463 }
never executed: end of block
0
464 }
never executed: end of block
0
465-
466 //calculate position-
467 const int fw = q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q);-
468 int x = fw + ((start == -1) ? hmargin : start) + itemSpacing;
(start == -1)Description
TRUEnever evaluated
FALSEnever evaluated
0
469 int y = fw + vmargin;-
470 for(int i = 0; i < actions.count(); i++) {
i < actions.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
471 QRect &rect = actionRects[i];-
472 if (rect.isNull())
rect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
473 continue;
never executed: continue;
0
474-
475 //resize-
476 rect.setHeight(max_item_height);-
477-
478 //move-
479 if(separator != -1 && i >= separator) { //after the separator
separator != -1Description
TRUEnever evaluated
FALSEnever evaluated
i >= separatorDescription
TRUEnever evaluated
FALSEnever evaluated
0
480 int left = (max_width - separator_len - hmargin - itemSpacing) + (x - separator_start - hmargin);-
481 if(left < separator_start) { //wrap
left < separator_startDescription
TRUEnever evaluated
FALSEnever evaluated
0
482 separator_start = x = hmargin;-
483 y += max_item_height;-
484 }
never executed: end of block
0
485 rect.moveLeft(left);-
486 } else {
never executed: end of block
0
487 rect.moveLeft(x);-
488 }
never executed: end of block
0
489 rect.moveTop(y);-
490-
491 //keep moving along..-
492 x += rect.width() + itemSpacing;-
493-
494 //make sure we follow the layout direction-
495 rect = QStyle::visualRect(q->layoutDirection(), q->rect(), rect);-
496 }
never executed: end of block
0
497}
never executed: end of block
0
498-
499void QMenuBarPrivate::activateAction(QAction *action, QAction::ActionEvent action_e)-
500{-
501 Q_Q(QMenuBar);-
502 if (!action || !action->isEnabled())
!actionDescription
TRUEnever evaluated
FALSEnever evaluated
!action->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
503 return;
never executed: return;
0
504 action->activate(action_e);-
505 if (action_e == QAction::Hover)
action_e == QAction::HoverDescription
TRUEnever evaluated
FALSEnever evaluated
0
506 action->showStatusText(q);
never executed: action->showStatusText(q);
0
507-
508// if(action_e == QAction::Trigger)-
509// emit q->activated(action);-
510// else if(action_e == QAction::Hover)-
511// emit q->highlighted(action);-
512}
never executed: end of block
0
513-
514-
515void QMenuBarPrivate::_q_actionTriggered()-
516{-
517 Q_Q(QMenuBar);-
518 if (QAction *action = qobject_cast<QAction *>(q->sender())) {
QAction *actio...>(q->sender())Description
TRUEnever evaluated
FALSEnever evaluated
0
519 emit q->triggered(action);-
520 }
never executed: end of block
0
521}
never executed: end of block
0
522-
523void QMenuBarPrivate::_q_actionHovered()-
524{-
525 Q_Q(QMenuBar);-
526 if (QAction *action = qobject_cast<QAction *>(q->sender())) {
QAction *actio...>(q->sender())Description
TRUEnever evaluated
FALSEnever evaluated
0
527 emit q->hovered(action);-
528#ifndef QT_NO_ACCESSIBILITY-
529 if (QAccessible::isActive()) {
QAccessible::isActive()Description
TRUEnever evaluated
FALSEnever evaluated
0
530 int actionIndex = actions.indexOf(action);-
531 QAccessibleEvent focusEvent(q, QAccessible::Focus);-
532 focusEvent.setChild(actionIndex);-
533 QAccessible::updateAccessibility(&focusEvent);-
534 }
never executed: end of block
0
535#endif //QT_NO_ACCESSIBILITY-
536 }
never executed: end of block
0
537}
never executed: end of block
0
538-
539/*!-
540 Initialize \a option with the values from the menu bar and information from \a action. This method-
541 is useful for subclasses when they need a QStyleOptionMenuItem, but don't want-
542 to fill in all the information themselves.-
543-
544 \sa QStyleOption::initFrom(), QMenu::initStyleOption()-
545*/-
546void QMenuBar::initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const-
547{-
548 if (!option || !action)
!optionDescription
TRUEnever evaluated
FALSEnever evaluated
!actionDescription
TRUEnever evaluated
FALSEnever evaluated
0
549 return;
never executed: return;
0
550 Q_D(const QMenuBar);-
551 option->palette = palette();-
552 option->state = QStyle::State_None;-
553 if (isEnabled() && action->isEnabled())
isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
action->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
554 option->state |= QStyle::State_Enabled;
never executed: option->state |= QStyle::State_Enabled;
0
555 else-
556 option->palette.setCurrentColorGroup(QPalette::Disabled);
never executed: option->palette.setCurrentColorGroup(QPalette::Disabled);
0
557 option->fontMetrics = fontMetrics();-
558 if (d->currentAction && d->currentAction == action) {
d->currentActionDescription
TRUEnever evaluated
FALSEnever evaluated
d->currentAction == actionDescription
TRUEnever evaluated
FALSEnever evaluated
0
559 option->state |= QStyle::State_Selected;-
560 if (d->popupState && !d->closePopupMode)
d->popupStateDescription
TRUEnever evaluated
FALSEnever evaluated
!d->closePopupModeDescription
TRUEnever evaluated
FALSEnever evaluated
0
561 option->state |= QStyle::State_Sunken;
never executed: option->state |= QStyle::State_Sunken;
0
562 }
never executed: end of block
0
563 if (hasFocus() || d->currentAction)
hasFocus()Description
TRUEnever evaluated
FALSEnever evaluated
d->currentActionDescription
TRUEnever evaluated
FALSEnever evaluated
0
564 option->state |= QStyle::State_HasFocus;
never executed: option->state |= QStyle::State_HasFocus;
0
565 option->menuRect = rect();-
566 option->menuItemType = QStyleOptionMenuItem::Normal;-
567 option->checkType = QStyleOptionMenuItem::NotCheckable;-
568 option->text = action->text();-
569 option->icon = action->icon();-
570}
never executed: end of block
0
571-
572/*!-
573 \class QMenuBar-
574 \brief The QMenuBar class provides a horizontal menu bar.-
575-
576 \ingroup mainwindow-classes-
577 \inmodule QtWidgets-
578-
579 A menu bar consists of a list of pull-down menu items. You add-
580 menu items with addMenu(). For example, asuming that \c menubar-
581 is a pointer to a QMenuBar and \c fileMenu is a pointer to a-
582 QMenu, the following statement inserts the menu into the menu bar:-
583 \snippet code/src_gui_widgets_qmenubar.cpp 0-
584-
585 The ampersand in the menu item's text sets Alt+F as a shortcut for-
586 this menu. (You can use "\&\&" to get a real ampersand in the menu-
587 bar.)-
588-
589 There is no need to lay out a menu bar. It automatically sets its-
590 own geometry to the top of the parent widget and changes it-
591 appropriately whenever the parent is resized.-
592-
593 \section1 Usage-
594-
595 In most main window style applications you would use the-
596 \l{QMainWindow::}{menuBar()} function provided in QMainWindow,-
597 adding \l{QMenu}s to the menu bar and adding \l{QAction}s to the-
598 pop-up menus.-
599-
600 Example (from the \l{mainwindows/menus}{Menus} example):-
601-
602 \snippet mainwindows/menus/mainwindow.cpp 9-
603-
604 Menu items may be removed with removeAction().-
605-
606 Widgets can be added to menus by using instances of the QWidgetAction-
607 class to hold them. These actions can then be inserted into menus-
608 in the usual way; see the QMenu documentation for more details.-
609-
610 \section1 Platform Dependent Look and Feel-
611-
612 Different platforms have different requirements for the appearance-
613 of menu bars and their behavior when the user interacts with them.-
614 For example, Windows systems are often configured so that the-
615 underlined character mnemonics that indicate keyboard shortcuts-
616 for items in the menu bar are only shown when the \uicontrol{Alt} key is-
617 pressed.-
618-
619 \section1 QMenuBar as a Global Menu Bar-
620-
621 On \macos and on certain Linux desktop environments such as-
622 Ubuntu Unity, QMenuBar is a wrapper for using the system-wide menu bar.-
623 If you have multiple menu bars in one dialog the outermost menu bar-
624 (normally inside a widget with widget flag Qt::Window) will-
625 be used for the system-wide menu bar.-
626-
627 Qt for \macos also provides a menu bar merging feature to make-
628 QMenuBar conform more closely to accepted \macos menu bar layout.-
629 The merging functionality is based on string matching the title of-
630 a QMenu entry. These strings are translated (using QObject::tr())-
631 in the "QMenuBar" context. If an entry is moved its slots will still-
632 fire as if it was in the original place. The table below outlines-
633 the strings looked for and where the entry is placed if matched:-
634-
635 \table-
636 \header \li String matches \li Placement \li Notes-
637 \row \li about.*-
638 \li Application Menu | About <application name>-
639 \li The application name is fetched from the \c {Info.plist} file-
640 (see note below). If this entry is not found no About item-
641 will appear in the Application Menu.-
642 \row \li config, options, setup, settings or preferences-
643 \li Application Menu | Preferences-
644 \li If this entry is not found the Settings item will be disabled-
645 \row \li quit or exit-
646 \li Application Menu | Quit <application name>-
647 \li If this entry is not found a default Quit item will be-
648 created to call QCoreApplication::quit()-
649 \endtable-
650-
651 You can override this behavior by using the QAction::menuRole()-
652 property.-
653-
654 If you want all windows in a Mac application to share one menu-
655 bar, you must create a menu bar that does not have a parent.-
656 Create a parent-less menu bar this way:-
657-
658 \snippet code/src_gui_widgets_qmenubar.cpp 1-
659-
660 \b{Note:} Do \e{not} call QMainWindow::menuBar() to create the-
661 shared menu bar, because that menu bar will have the QMainWindow-
662 as its parent. That menu bar would only be displayed for the-
663 parent QMainWindow.-
664-
665 \b{Note:} The text used for the application name in the \macos menu-
666 bar is obtained from the value set in the \c{Info.plist} file in-
667 the application's bundle. See \l{Qt for macOS - Deployment}-
668 for more information.-
669-
670 \b{Note:} On Linux, if the com.canonical.AppMenu.Registrar-
671 service is available on the D-Bus session bus, then Qt will-
672 communicate with it to install the application's menus into the-
673 global menu bar, as described.-
674-
675 \section1 Examples-
676-
677 The \l{mainwindows/menus}{Menus} example shows how to use QMenuBar-
678 and QMenu. The other \l{Main Window Examples}{main window-
679 application examples} also provide menus using these classes.-
680-
681 \sa QMenu, QShortcut, QAction,-
682 {http://developer.apple.com/documentation/UserExperience/Conceptual/AppleHIGuidelines/XHIGIntro/XHIGIntro.html}{Introduction to Apple Human Interface Guidelines},-
683 {fowler}{GUI Design Handbook: Menu Bar}, {Menus Example}-
684*/-
685-
686-
687void QMenuBarPrivate::init()-
688{-
689 Q_Q(QMenuBar);-
690 q->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);-
691 q->setAttribute(Qt::WA_CustomWhatsThis);-
692-
693 if (!QApplication::instance()->testAttribute(Qt::AA_DontUseNativeMenuBar))
!QApplication:...NativeMenuBar)Description
TRUEnever evaluated
FALSEnever evaluated
0
694 platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar();
never executed: platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar();
0
695-
696 if (platformMenuBar)
platformMenuBarDescription
TRUEnever evaluated
FALSEnever evaluated
0
697 q->hide();
never executed: q->hide();
0
698#ifdef Q_OS_WINCE-
699 if (qt_wince_is_mobile()) {-
700 wceCreateMenuBar(q->parentWidget());-
701 if(wce_menubar)-
702 q->hide();-
703 }-
704 else {-
705 QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);-
706 }-
707#endif-
708 q->setBackgroundRole(QPalette::Button);-
709 handleReparent();-
710 q->setMouseTracking(q->style()->styleHint(QStyle::SH_MenuBar_MouseTracking, 0, q));-
711-
712 extension = new QMenuBarExtension(q);-
713 extension->setFocusPolicy(Qt::NoFocus);-
714 extension->hide();-
715}
never executed: end of block
0
716-
717//Gets the next action for keyboard navigation-
718QAction *QMenuBarPrivate::getNextAction(const int _start, const int increment) const-
719{-
720 Q_Q(const QMenuBar);-
721 const_cast<QMenuBarPrivate*>(this)->updateGeometries();-
722 bool allowActiveAndDisabled = q->style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, q);-
723 const int start = (_start == -1 && increment == -1) ? actions.count() : _start;
_start == -1Description
TRUEnever evaluated
FALSEnever evaluated
increment == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
724 const int end = increment == -1 ? 0 : actions.count() - 1;
increment == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
725-
726 for (int i = start; i != end;) {
i != endDescription
TRUEnever evaluated
FALSEnever evaluated
0
727 i += increment;-
728 QAction *current = actions.at(i);-
729 if (!actionRects.at(i).isNull() && (allowActiveAndDisabled || current->isEnabled()))
!actionRects.at(i).isNull()Description
TRUEnever evaluated
FALSEnever evaluated
allowActiveAndDisabledDescription
TRUEnever evaluated
FALSEnever evaluated
current->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
730 return current;
never executed: return current;
0
731 }
never executed: end of block
0
732-
733 if (_start != -1) //let's try from the beginning or the end
_start != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
734 return getNextAction(-1, increment);
never executed: return getNextAction(-1, increment);
0
735-
736 return 0;
never executed: return 0;
0
737}-
738-
739/*!-
740 Constructs a menu bar with parent \a parent.-
741*/-
742QMenuBar::QMenuBar(QWidget *parent) : QWidget(*new QMenuBarPrivate, parent, 0)-
743{-
744 Q_D(QMenuBar);-
745 d->init();-
746}
never executed: end of block
0
747-
748-
749/*!-
750 Destroys the menu bar.-
751*/-
752QMenuBar::~QMenuBar()-
753{-
754 Q_D(QMenuBar);-
755 delete d->platformMenuBar;-
756 d->platformMenuBar = 0;-
757-
758#ifdef Q_OS_WINCE-
759 if (qt_wince_is_mobile())-
760 d->wceDestroyMenuBar();-
761#endif-
762}
never executed: end of block
0
763-
764/*!-
765 \overload-
766-
767 This convenience function creates a new action with \a text.-
768 The function adds the newly created action to the menu's-
769 list of actions, and returns it.-
770-
771 \sa QWidget::addAction(), QWidget::actions()-
772*/-
773QAction *QMenuBar::addAction(const QString &text)-
774{-
775 QAction *ret = new QAction(text, this);-
776 addAction(ret);-
777 return ret;
never executed: return ret;
0
778}-
779-
780/*!-
781 \overload-
782-
783 This convenience function creates a new action with the given \a-
784 text. The action's triggered() signal is connected to the \a-
785 receiver's \a member slot. The function adds the newly created-
786 action to the menu's list of actions and returns it.-
787-
788 \sa QWidget::addAction(), QWidget::actions()-
789*/-
790QAction *QMenuBar::addAction(const QString &text, const QObject *receiver, const char* member)-
791{-
792 QAction *ret = new QAction(text, this);-
793 QObject::connect(ret, SIGNAL(triggered(bool)), receiver, member);-
794 addAction(ret);-
795 return ret;
never executed: return ret;
0
796}-
797-
798/*!-
799 Appends a new QMenu with \a title to the menu bar. The menu bar-
800 takes ownership of the menu. Returns the new menu.-
801-
802 \sa QWidget::addAction(), QMenu::menuAction()-
803*/-
804QMenu *QMenuBar::addMenu(const QString &title)-
805{-
806 QMenu *menu = new QMenu(title, this);-
807 addAction(menu->menuAction());-
808 return menu;
never executed: return menu;
0
809}-
810-
811/*!-
812 Appends a new QMenu with \a icon and \a title to the menu bar. The menu bar-
813 takes ownership of the menu. Returns the new menu.-
814-
815 \sa QWidget::addAction(), QMenu::menuAction()-
816*/-
817QMenu *QMenuBar::addMenu(const QIcon &icon, const QString &title)-
818{-
819 QMenu *menu = new QMenu(title, this);-
820 menu->setIcon(icon);-
821 addAction(menu->menuAction());-
822 return menu;
never executed: return menu;
0
823}-
824-
825/*!-
826 Appends \a menu to the menu bar. Returns the menu's menuAction().-
827-
828 \note The returned QAction object can be used to hide the corresponding-
829 menu.-
830-
831 \sa QWidget::addAction(), QMenu::menuAction()-
832*/-
833QAction *QMenuBar::addMenu(QMenu *menu)-
834{-
835 QAction *action = menu->menuAction();-
836 addAction(action);-
837 return action;
never executed: return action;
0
838}-
839-
840/*!-
841 Appends a separator to the menu.-
842*/-
843QAction *QMenuBar::addSeparator()-
844{-
845 QAction *ret = new QAction(this);-
846 ret->setSeparator(true);-
847 addAction(ret);-
848 return ret;
never executed: return ret;
0
849}-
850-
851/*!-
852 This convenience function creates a new separator action, i.e. an-
853 action with QAction::isSeparator() returning true. The function inserts-
854 the newly created action into this menu bar's list of actions before-
855 action \a before and returns it.-
856-
857 \sa QWidget::insertAction(), addSeparator()-
858*/-
859QAction *QMenuBar::insertSeparator(QAction *before)-
860{-
861 QAction *action = new QAction(this);-
862 action->setSeparator(true);-
863 insertAction(before, action);-
864 return action;
never executed: return action;
0
865}-
866-
867/*!-
868 This convenience function inserts \a menu before action \a before-
869 and returns the menus menuAction().-
870-
871 \sa QWidget::insertAction(), addMenu()-
872*/-
873QAction *QMenuBar::insertMenu(QAction *before, QMenu *menu)-
874{-
875 QAction *action = menu->menuAction();-
876 insertAction(before, action);-
877 return action;
never executed: return action;
0
878}-
879-
880/*!-
881 Returns the QAction that is currently highlighted. A null pointer-
882 will be returned if no action is currently selected.-
883*/-
884QAction *QMenuBar::activeAction() const-
885{-
886 Q_D(const QMenuBar);-
887 return d->currentAction;
never executed: return d->currentAction;
0
888}-
889-
890/*!-
891 \since 4.1-
892-
893 Sets the currently highlighted action to \a act.-
894*/-
895void QMenuBar::setActiveAction(QAction *act)-
896{-
897 Q_D(QMenuBar);-
898 d->setCurrentAction(act, true, false);-
899}
never executed: end of block
0
900-
901-
902/*!-
903 Removes all the actions from the menu bar.-
904-
905 \note On \macos, menu items that have been merged to the system-
906 menu bar are not removed by this function. One way to handle this-
907 would be to remove the extra actions yourself. You can set the-
908 \l{QAction::MenuRole}{menu role} on the different menus, so that-
909 you know ahead of time which menu items get merged and which do-
910 not. Then decide what to recreate or remove yourself.-
911-
912 \sa removeAction()-
913*/-
914void QMenuBar::clear()-
915{-
916 QList<QAction*> acts = actions();-
917 for(int i = 0; i < acts.size(); i++)
i < acts.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
918 removeAction(acts[i]);
never executed: removeAction(acts[i]);
0
919}
never executed: end of block
0
920-
921/*!-
922 \property QMenuBar::defaultUp-
923 \brief the popup orientation-
924-
925 The default popup orientation. By default, menus pop "down" the-
926 screen. By setting the property to true, the menu will pop "up".-
927 You might call this for menus that are \e below the document to-
928 which they refer.-
929-
930 If the menu would not fit on the screen, the other direction is-
931 used automatically.-
932*/-
933void QMenuBar::setDefaultUp(bool b)-
934{-
935 Q_D(QMenuBar);-
936 d->defaultPopDown = !b;-
937}
never executed: end of block
0
938-
939bool QMenuBar::isDefaultUp() const-
940{-
941 Q_D(const QMenuBar);-
942 return !d->defaultPopDown;
never executed: return !d->defaultPopDown;
0
943}-
944-
945/*!-
946 \reimp-
947*/-
948void QMenuBar::resizeEvent(QResizeEvent *)-
949{-
950 Q_D(QMenuBar);-
951 d->itemsDirty = true;-
952 d->updateGeometries();-
953}
never executed: end of block
0
954-
955/*!-
956 \reimp-
957*/-
958void QMenuBar::paintEvent(QPaintEvent *e)-
959{-
960 Q_D(QMenuBar);-
961 QPainter p(this);-
962 QRegion emptyArea(rect());-
963-
964 //draw the items-
965 for (int i = 0; i < d->actions.count(); ++i) {
i < d->actions.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
966 QAction *action = d->actions.at(i);-
967 QRect adjustedActionRect = d->actionRect(action);-
968 if (adjustedActionRect.isEmpty() || !d->isVisible(action))
adjustedActionRect.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
!d->isVisible(action)Description
TRUEnever evaluated
FALSEnever evaluated
0
969 continue;
never executed: continue;
0
970 if(!e->rect().intersects(adjustedActionRect))
!e->rect().int...tedActionRect)Description
TRUEnever evaluated
FALSEnever evaluated
0
971 continue;
never executed: continue;
0
972-
973 emptyArea -= adjustedActionRect;-
974 QStyleOptionMenuItem opt;-
975 initStyleOption(&opt, action);-
976 opt.rect = adjustedActionRect;-
977 p.setClipRect(adjustedActionRect);-
978 style()->drawControl(QStyle::CE_MenuBarItem, &opt, &p, this);-
979 }
never executed: end of block
0
980 //draw border-
981 if(int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this)) {
int fw = style...idth, 0, this)Description
TRUEnever evaluated
FALSEnever evaluated
0
982 QRegion borderReg;-
983 borderReg += QRect(0, 0, fw, height()); //left-
984 borderReg += QRect(width()-fw, 0, fw, height()); //right-
985 borderReg += QRect(0, 0, width(), fw); //top-
986 borderReg += QRect(0, height()-fw, width(), fw); //bottom-
987 p.setClipRegion(borderReg);-
988 emptyArea -= borderReg;-
989 QStyleOptionFrame frame;-
990 frame.rect = rect();-
991 frame.palette = palette();-
992 frame.state = QStyle::State_None;-
993 frame.lineWidth = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth);-
994 frame.midLineWidth = 0;-
995 style()->drawPrimitive(QStyle::PE_PanelMenuBar, &frame, &p, this);-
996 }
never executed: end of block
0
997 p.setClipRegion(emptyArea);-
998 QStyleOptionMenuItem menuOpt;-
999 menuOpt.palette = palette();-
1000 menuOpt.state = QStyle::State_None;-
1001 menuOpt.menuItemType = QStyleOptionMenuItem::EmptyArea;-
1002 menuOpt.checkType = QStyleOptionMenuItem::NotCheckable;-
1003 menuOpt.rect = rect();-
1004 menuOpt.menuRect = rect();-
1005 style()->drawControl(QStyle::CE_MenuBarEmptyArea, &menuOpt, &p, this);-
1006}
never executed: end of block
0
1007-
1008/*!-
1009 \reimp-
1010*/-
1011void QMenuBar::setVisible(bool visible)-
1012{-
1013 if (isNativeMenuBar()) {
isNativeMenuBar()Description
TRUEnever evaluated
FALSEnever evaluated
0
1014 if (!visible)
!visibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1015 QWidget::setVisible(false);
never executed: QWidget::setVisible(false);
0
1016 return;
never executed: return;
0
1017 }-
1018 QWidget::setVisible(visible);-
1019}
never executed: end of block
0
1020-
1021/*!-
1022 \reimp-
1023*/-
1024void QMenuBar::mousePressEvent(QMouseEvent *e)-
1025{-
1026 Q_D(QMenuBar);-
1027 if(e->button() != Qt::LeftButton)
e->button() != Qt::LeftButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
1028 return;
never executed: return;
0
1029-
1030 d->mouseDown = true;-
1031-
1032 QAction *action = d->actionAt(e->pos());-
1033 if (!action || !d->isVisible(action) || !action->isEnabled()) {
!actionDescription
TRUEnever evaluated
FALSEnever evaluated
!d->isVisible(action)Description
TRUEnever evaluated
FALSEnever evaluated
!action->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
1034 d->setCurrentAction(0);-
1035#ifndef QT_NO_WHATSTHIS-
1036 if (QWhatsThis::inWhatsThisMode())
QWhatsThis::inWhatsThisMode()Description
TRUEnever evaluated
FALSEnever evaluated
0
1037 QWhatsThis::showText(e->globalPos(), d->whatsThis, this);
never executed: QWhatsThis::showText(e->globalPos(), d->whatsThis, this);
0
1038#endif-
1039 return;
never executed: return;
0
1040 }-
1041-
1042 if(d->currentAction == action && d->popupState) {
d->currentAction == actionDescription
TRUEnever evaluated
FALSEnever evaluated
d->popupStateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1043 if(QMenu *menu = d->activeMenu) {
QMenu *menu = d->activeMenuDescription
TRUEnever evaluated
FALSEnever evaluated
0
1044 d->activeMenu = 0;-
1045 menu->setAttribute(Qt::WA_NoMouseReplay);-
1046 menu->hide();-
1047 }
never executed: end of block
0
1048 } else {
never executed: end of block
0
1049 d->setCurrentAction(action, true);-
1050 }
never executed: end of block
0
1051}-
1052-
1053/*!-
1054 \reimp-
1055*/-
1056void QMenuBar::mouseReleaseEvent(QMouseEvent *e)-
1057{-
1058 Q_D(QMenuBar);-
1059 if(e->button() != Qt::LeftButton || !d->mouseDown)
e->button() != Qt::LeftButtonDescription
TRUEnever evaluated
FALSEnever evaluated
!d->mouseDownDescription
TRUEnever evaluated
FALSEnever evaluated
0
1060 return;
never executed: return;
0
1061-
1062 d->mouseDown = false;-
1063 QAction *action = d->actionAt(e->pos());-
1064 if((d->closePopupMode && action == d->currentAction) || !action || !action->menu()) {
d->closePopupModeDescription
TRUEnever evaluated
FALSEnever evaluated
action == d->currentActionDescription
TRUEnever evaluated
FALSEnever evaluated
!actionDescription
TRUEnever evaluated
FALSEnever evaluated
!action->menu()Description
TRUEnever evaluated
FALSEnever evaluated
0
1065 //we set the current action before activating-
1066 //so that we let the leave event set the current back to 0-
1067 d->setCurrentAction(action, false);-
1068 if(action)
actionDescription
TRUEnever evaluated
FALSEnever evaluated
0
1069 d->activateAction(action, QAction::Trigger);
never executed: d->activateAction(action, QAction::Trigger);
0
1070 }
never executed: end of block
0
1071 d->closePopupMode = 0;-
1072}
never executed: end of block
0
1073-
1074/*!-
1075 \reimp-
1076*/-
1077void QMenuBar::keyPressEvent(QKeyEvent *e)-
1078{-
1079 Q_D(QMenuBar);-
1080 d->updateGeometries();-
1081 int key = e->key();-
1082 if(isRightToLeft()) { // in reverse mode open/close key for submenues are reversed
isRightToLeft()Description
TRUEnever evaluated
FALSEnever evaluated
0
1083 if(key == Qt::Key_Left)
key == Qt::Key_LeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
1084 key = Qt::Key_Right;
never executed: key = Qt::Key_Right;
0
1085 else if(key == Qt::Key_Right)
key == Qt::Key_RightDescription
TRUEnever evaluated
FALSEnever evaluated
0
1086 key = Qt::Key_Left;
never executed: key = Qt::Key_Left;
0
1087 }
never executed: end of block
0
1088 if(key == Qt::Key_Tab) //means right
key == Qt::Key_TabDescription
TRUEnever evaluated
FALSEnever evaluated
0
1089 key = Qt::Key_Right;
never executed: key = Qt::Key_Right;
0
1090 else if(key == Qt::Key_Backtab) //means left
key == Qt::Key_BacktabDescription
TRUEnever evaluated
FALSEnever evaluated
0
1091 key = Qt::Key_Left;
never executed: key = Qt::Key_Left;
0
1092-
1093 bool key_consumed = false;-
1094 switch(key) {-
1095 case Qt::Key_Up:
never executed: case Qt::Key_Up:
0
1096 case Qt::Key_Down:
never executed: case Qt::Key_Down:
0
1097 case Qt::Key_Enter:
never executed: case Qt::Key_Enter:
0
1098 case Qt::Key_Space:
never executed: case Qt::Key_Space:
0
1099 case Qt::Key_Return: {
never executed: case Qt::Key_Return:
0
1100 if(!style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, this) || !d->currentAction)
!style()->styl...tion, 0, this)Description
TRUEnever evaluated
FALSEnever evaluated
!d->currentActionDescription
TRUEnever evaluated
FALSEnever evaluated
0
1101 break;
never executed: break;
0
1102 if(d->currentAction->menu()) {
d->currentAction->menu()Description
TRUEnever evaluated
FALSEnever evaluated
0
1103 d->popupAction(d->currentAction, true);-
1104 } else if(key == Qt::Key_Enter || key == Qt::Key_Return || key == Qt::Key_Space) {
never executed: end of block
key == Qt::Key_EnterDescription
TRUEnever evaluated
FALSEnever evaluated
key == Qt::Key_ReturnDescription
TRUEnever evaluated
FALSEnever evaluated
key == Qt::Key_SpaceDescription
TRUEnever evaluated
FALSEnever evaluated
0
1105 d->activateAction(d->currentAction, QAction::Trigger);-
1106 d->setCurrentAction(d->currentAction, false);-
1107 d->setKeyboardMode(false);-
1108 }
never executed: end of block
0
1109 key_consumed = true;-
1110 break; }
never executed: break;
0
1111-
1112 case Qt::Key_Right:
never executed: case Qt::Key_Right:
0
1113 case Qt::Key_Left: {
never executed: case Qt::Key_Left:
0
1114 if(d->currentAction) {
d->currentActionDescription
TRUEnever evaluated
FALSEnever evaluated
0
1115 int index = d->actions.indexOf(d->currentAction);-
1116 if (QAction *nextAction = d->getNextAction(index, key == Qt::Key_Left ? -1 : +1)) {
QAction *nextA...eft ? -1 : +1)Description
TRUEnever evaluated
FALSEnever evaluated
0
1117 d->setCurrentAction(nextAction, d->popupState, true);-
1118 key_consumed = true;-
1119 }
never executed: end of block
0
1120 }
never executed: end of block
0
1121 break; }
never executed: break;
0
1122-
1123 default:
never executed: default:
0
1124 key_consumed = false;-
1125 }
never executed: end of block
0
1126-
1127 if (!key_consumed && e->matches(QKeySequence::Cancel)) {
!key_consumedDescription
TRUEnever evaluated
FALSEnever evaluated
e->matches(QKe...uence::Cancel)Description
TRUEnever evaluated
FALSEnever evaluated
0
1128 d->setCurrentAction(0);-
1129 d->setKeyboardMode(false);-
1130 key_consumed = true;-
1131 }
never executed: end of block
0
1132-
1133 if(!key_consumed &&
!key_consumedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1134 (!e->modifiers() ||
!e->modifiers()Description
TRUEnever evaluated
FALSEnever evaluated
0
1135 (e->modifiers()&(Qt::MetaModifier|Qt::AltModifier))) && e->text().length()==1 && !d->popupState) {
(e->modifiers(...:AltModifier))Description
TRUEnever evaluated
FALSEnever evaluated
e->text().length()==1Description
TRUEnever evaluated
FALSEnever evaluated
!d->popupStateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1136 int clashCount = 0;-
1137 QAction *first = 0, *currentSelected = 0, *firstAfterCurrent = 0;-
1138 {-
1139 QChar c = e->text()[0].toUpper();-
1140 for(int i = 0; i < d->actions.size(); ++i) {
i < d->actions.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
1141 if (d->actionRects.at(i).isNull())
d->actionRects.at(i).isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1142 continue;
never executed: continue;
0
1143 QAction *act = d->actions.at(i);-
1144 QString s = act->text();-
1145 if(!s.isEmpty()) {
!s.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1146 int ampersand = s.indexOf(QLatin1Char('&'));-
1147 if(ampersand >= 0) {
ampersand >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1148 if(s[ampersand+1].toUpper() == c) {
s[ampersand+1].toUpper() == cDescription
TRUEnever evaluated
FALSEnever evaluated
0
1149 clashCount++;-
1150 if(!first)
!firstDescription
TRUEnever evaluated
FALSEnever evaluated
0
1151 first = act;
never executed: first = act;
0
1152 if(act == d->currentAction)
act == d->currentActionDescription
TRUEnever evaluated
FALSEnever evaluated
0
1153 currentSelected = act;
never executed: currentSelected = act;
0
1154 else if (!firstAfterCurrent && currentSelected)
!firstAfterCurrentDescription
TRUEnever evaluated
FALSEnever evaluated
currentSelectedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1155 firstAfterCurrent = act;
never executed: firstAfterCurrent = act;
0
1156 }
never executed: end of block
0
1157 }
never executed: end of block
0
1158 }
never executed: end of block
0
1159 }
never executed: end of block
0
1160 }-
1161 QAction *next_action = 0;-
1162 if(clashCount >= 1) {
clashCount >= 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1163 if(clashCount == 1 || !d->currentAction || (currentSelected && !firstAfterCurrent))
clashCount == 1Description
TRUEnever evaluated
FALSEnever evaluated
!d->currentActionDescription
TRUEnever evaluated
FALSEnever evaluated
currentSelectedDescription
TRUEnever evaluated
FALSEnever evaluated
!firstAfterCurrentDescription
TRUEnever evaluated
FALSEnever evaluated
0
1164 next_action = first;
never executed: next_action = first;
0
1165 else-
1166 next_action = firstAfterCurrent;
never executed: next_action = firstAfterCurrent;
0
1167 }-
1168 if(next_action) {
next_actionDescription
TRUEnever evaluated
FALSEnever evaluated
0
1169 key_consumed = true;-
1170 d->setCurrentAction(next_action, true, true);-
1171 }
never executed: end of block
0
1172 }
never executed: end of block
0
1173 if(key_consumed)
key_consumedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1174 e->accept();
never executed: e->accept();
0
1175 else-
1176 e->ignore();
never executed: e->ignore();
0
1177}-
1178-
1179/*!-
1180 \reimp-
1181*/-
1182void QMenuBar::mouseMoveEvent(QMouseEvent *e)-
1183{-
1184 Q_D(QMenuBar);-
1185 if (!(e->buttons() & Qt::LeftButton))
!(e->buttons()...t::LeftButton)Description
TRUEnever evaluated
FALSEnever evaluated
0
1186 d->mouseDown = false;
never executed: d->mouseDown = false;
0
1187 bool popupState = d->popupState || d->mouseDown;
d->popupStateDescription
TRUEnever evaluated
FALSEnever evaluated
d->mouseDownDescription
TRUEnever evaluated
FALSEnever evaluated
0
1188 QAction *action = d->actionAt(e->pos());-
1189 if ((action && d->isVisible(action)) || !popupState)
actionDescription
TRUEnever evaluated
FALSEnever evaluated
d->isVisible(action)Description
TRUEnever evaluated
FALSEnever evaluated
!popupStateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1190 d->setCurrentAction(action, popupState);
never executed: d->setCurrentAction(action, popupState);
0
1191}
never executed: end of block
0
1192-
1193/*!-
1194 \reimp-
1195*/-
1196void QMenuBar::leaveEvent(QEvent *)-
1197{-
1198 Q_D(QMenuBar);-
1199 if((!hasFocus() && !d->popupState) ||
!hasFocus()Description
TRUEnever evaluated
FALSEnever evaluated
!d->popupStateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1200 (d->currentAction && d->currentAction->menu() == 0))
d->currentActionDescription
TRUEnever evaluated
FALSEnever evaluated
d->currentAction->menu() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1201 d->setCurrentAction(0);
never executed: d->setCurrentAction(0);
0
1202}
never executed: end of block
0
1203-
1204QPlatformMenu *QMenuBarPrivate::getPlatformMenu(QAction *action)-
1205{-
1206 if (!action || !action->menu())
!actionDescription
TRUEnever evaluated
FALSEnever evaluated
!action->menu()Description
TRUEnever evaluated
FALSEnever evaluated
0
1207 return 0;
never executed: return 0;
0
1208-
1209 QPlatformMenu *platformMenu = action->menu()->platformMenu();-
1210 if (!platformMenu && platformMenuBar) {
!platformMenuDescription
TRUEnever evaluated
FALSEnever evaluated
platformMenuBarDescription
TRUEnever evaluated
FALSEnever evaluated
0
1211 platformMenu = platformMenuBar->createMenu();-
1212 if (platformMenu)
platformMenuDescription
TRUEnever evaluated
FALSEnever evaluated
0
1213 action->menu()->setPlatformMenu(platformMenu);
never executed: action->menu()->setPlatformMenu(platformMenu);
0
1214 }
never executed: end of block
0
1215-
1216 return platformMenu;
never executed: return platformMenu;
0
1217}-
1218-
1219/*!-
1220 \reimp-
1221*/-
1222void QMenuBar::actionEvent(QActionEvent *e)-
1223{-
1224 Q_D(QMenuBar);-
1225 d->itemsDirty = true;-
1226-
1227 if (d->platformMenuBar) {
d->platformMenuBarDescription
TRUEnever evaluated
FALSEnever evaluated
0
1228#if !defined(Q_OS_WINCE)-
1229 QPlatformMenuBar *nativeMenuBar = d->platformMenuBar;-
1230#else-
1231 QMenuBarPrivate::QWceMenuBarPrivate *nativeMenuBar = d->wce_menubar;-
1232#endif-
1233 if (!nativeMenuBar)
!nativeMenuBarDescription
TRUEnever evaluated
FALSEnever evaluated
0
1234 return;
never executed: return;
0
1235-
1236 if (e->type() == QEvent::ActionAdded) {
e->type() == Q...t::ActionAddedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1237 QPlatformMenu *menu = d->getPlatformMenu(e->action());-
1238 if (menu) {
menuDescription
TRUEnever evaluated
FALSEnever evaluated
0
1239 QPlatformMenu* beforeMenu = NULL;-
1240 for (int beforeIndex = d->indexOf(e->action()) + 1;-
1241 !beforeMenu && (beforeIndex < actions().size());
!beforeMenuDescription
TRUEnever evaluated
FALSEnever evaluated
(beforeIndex <...ions().size())Description
TRUEnever evaluated
FALSEnever evaluated
0
1242 ++beforeIndex)-
1243 {-
1244 beforeMenu = d->getPlatformMenu(actions().at(beforeIndex));-
1245 }
never executed: end of block
0
1246-
1247 menu->setTag(reinterpret_cast<quintptr>(e->action()));-
1248 menu->setText(e->action()->text());-
1249 d->platformMenuBar->insertMenu(menu, beforeMenu);-
1250 }
never executed: end of block
0
1251 } else if (e->type() == QEvent::ActionRemoved) {
never executed: end of block
e->type() == Q...:ActionRemovedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1252 QPlatformMenu *menu = d->getPlatformMenu(e->action());-
1253 if (menu)
menuDescription
TRUEnever evaluated
FALSEnever evaluated
0
1254 d->platformMenuBar->removeMenu(menu);
never executed: d->platformMenuBar->removeMenu(menu);
0
1255 } else if (e->type() == QEvent::ActionChanged) {
never executed: end of block
e->type() == Q...:ActionChangedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1256 QPlatformMenu* cur = d->platformMenuBar->menuForTag(reinterpret_cast<quintptr>(e->action()));-
1257 QPlatformMenu *menu = d->getPlatformMenu(e->action());-
1258-
1259 // the menu associated with the action can change, need to-
1260 // remove and/or insert the new platform menu-
1261 if (menu != cur) {
menu != curDescription
TRUEnever evaluated
FALSEnever evaluated
0
1262 if (cur)
curDescription
TRUEnever evaluated
FALSEnever evaluated
0
1263 d->platformMenuBar->removeMenu(cur);
never executed: d->platformMenuBar->removeMenu(cur);
0
1264 if (menu) {
menuDescription
TRUEnever evaluated
FALSEnever evaluated
0
1265 menu->setTag(reinterpret_cast<quintptr>(e->action()));-
1266-
1267 QPlatformMenu* beforeMenu = NULL;-
1268 for (int beforeIndex = d->indexOf(e->action()) + 1;-
1269 !beforeMenu && (beforeIndex < actions().size());
!beforeMenuDescription
TRUEnever evaluated
FALSEnever evaluated
(beforeIndex <...ions().size())Description
TRUEnever evaluated
FALSEnever evaluated
0
1270 ++beforeIndex)-
1271 {-
1272 beforeMenu = d->getPlatformMenu(actions().at(beforeIndex));-
1273 }
never executed: end of block
0
1274 d->platformMenuBar->insertMenu(menu, beforeMenu);-
1275 }
never executed: end of block
0
1276 } else if (menu) {
never executed: end of block
menuDescription
TRUEnever evaluated
FALSEnever evaluated
0
1277 menu->setText(e->action()->text());-
1278 menu->setVisible(e->action()->isVisible());-
1279 menu->setEnabled(e->action()->isEnabled());-
1280 d->platformMenuBar->syncMenu(menu);-
1281 }
never executed: end of block
0
1282 }
never executed: end of block
0
1283 }
never executed: end of block
0
1284-
1285 if(e->type() == QEvent::ActionAdded) {
e->type() == Q...t::ActionAddedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1286 connect(e->action(), SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));-
1287 connect(e->action(), SIGNAL(hovered()), this, SLOT(_q_actionHovered()));-
1288 } else if(e->type() == QEvent::ActionRemoved) {
never executed: end of block
e->type() == Q...:ActionRemovedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1289 e->action()->disconnect(this);-
1290 }
never executed: end of block
0
1291 if (isVisible()) {
isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
1292 d->updateGeometries();-
1293 update();-
1294 }
never executed: end of block
0
1295}
never executed: end of block
0
1296-
1297/*!-
1298 \reimp-
1299*/-
1300void QMenuBar::focusInEvent(QFocusEvent *)-
1301{-
1302 Q_D(QMenuBar);-
1303 if(d->keyboardState)
d->keyboardStateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1304 d->focusFirstAction();
never executed: d->focusFirstAction();
0
1305}
never executed: end of block
0
1306-
1307/*!-
1308 \reimp-
1309*/-
1310void QMenuBar::focusOutEvent(QFocusEvent *)-
1311{-
1312 Q_D(QMenuBar);-
1313 if(!d->popupState) {
!d->popupStateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1314 d->setCurrentAction(0);-
1315 d->setKeyboardMode(false);-
1316 }
never executed: end of block
0
1317}
never executed: end of block
0
1318-
1319/*!-
1320 \reimp-
1321 */-
1322void QMenuBar::timerEvent (QTimerEvent *e)-
1323{-
1324 Q_D(QMenuBar);-
1325 if (e->timerId() == d->autoReleaseTimer.timerId()) {
e->timerId() =...imer.timerId()Description
TRUEnever evaluated
FALSEnever evaluated
0
1326 d->autoReleaseTimer.stop();-
1327 d->setCurrentAction(0);-
1328 }
never executed: end of block
0
1329 QWidget::timerEvent(e);-
1330}
never executed: end of block
0
1331-
1332-
1333void QMenuBarPrivate::handleReparent()-
1334{-
1335 Q_Q(QMenuBar);-
1336 QWidget *newParent = q->parentWidget();-
1337-
1338 //Note: if parent is reparented, then window may change even if parent doesn't.-
1339 // We need to install an avent filter on each parent up to the parent that is-
1340 // also a window (for shortcuts)-
1341 QWidget *newWindow = newParent ? newParent->window() : Q_NULLPTR;
newParentDescription
TRUEnever evaluated
FALSEnever evaluated
0
1342-
1343 QVector<QPointer<QWidget> > newParents;-
1344 // Remove event filters on ex-parents, keep them on still-parents-
1345 // The parents are always ordered in the vector-
1346 foreach (const QPointer<QWidget> &w, oldParents) {-
1347 if (w) {
wDescription
TRUEnever evaluated
FALSEnever evaluated
0
1348 if (newParent == w) {
newParent == wDescription
TRUEnever evaluated
FALSEnever evaluated
0
1349 newParents.append(w);-
1350 if (newParent != newWindow) //stop at the window
newParent != newWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1351 newParent = newParent->parentWidget();
never executed: newParent = newParent->parentWidget();
0
1352 } else {
never executed: end of block
0
1353 w->removeEventFilter(q);-
1354 }
never executed: end of block
0
1355 }-
1356 }
never executed: end of block
0
1357-
1358 // At this point, newParent is the next one to be added to newParents-
1359 while (newParent && newParent != newWindow) {
newParentDescription
TRUEnever evaluated
FALSEnever evaluated
newParent != newWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1360 //install event filters all the way up to (excluding) the window-
1361 newParents.append(newParent);-
1362 newParent->installEventFilter(q);-
1363 newParent = newParent->parentWidget();-
1364 }
never executed: end of block
0
1365-
1366 if (newParent && newWindow) {
newParentDescription
TRUEnever evaluated
FALSEnever evaluated
newWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1367 // Install the event filter on the window-
1368 newParents.append(newParent);-
1369 newParent->installEventFilter(q);-
1370 }
never executed: end of block
0
1371 oldParents = newParents;-
1372-
1373 if (platformMenuBar) {
platformMenuBarDescription
TRUEnever evaluated
FALSEnever evaluated
0
1374 if (newWindow) {
newWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1375 // force the underlying platform window to be created, since-
1376 // the platform menubar needs it (and we have no other way to-
1377 // discover when the platform window is created)-
1378 newWindow->createWinId();-
1379 platformMenuBar->handleReparent(newWindow->windowHandle());-
1380 } else {
never executed: end of block
0
1381 platformMenuBar->handleReparent(0);-
1382 }
never executed: end of block
0
1383 }-
1384-
1385#ifdef Q_OS_WINCE-
1386 if (qt_wince_is_mobile() && wce_menubar)-
1387 wce_menubar->rebuild();-
1388#endif-
1389}
never executed: end of block
0
1390-
1391/*!-
1392 \reimp-
1393*/-
1394void QMenuBar::changeEvent(QEvent *e)-
1395{-
1396 Q_D(QMenuBar);-
1397 if(e->type() == QEvent::StyleChange) {
e->type() == Q...t::StyleChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1398 d->itemsDirty = true;-
1399 setMouseTracking(style()->styleHint(QStyle::SH_MenuBar_MouseTracking, 0, this));-
1400 if(parentWidget())
parentWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
1401 resize(parentWidget()->width(), heightForWidth(parentWidget()->width()));
never executed: resize(parentWidget()->width(), heightForWidth(parentWidget()->width()));
0
1402 d->updateGeometries();-
1403 } else if (e->type() == QEvent::ParentChange) {
never executed: end of block
e->type() == Q...::ParentChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1404 d->handleReparent();-
1405 } else if (e->type() == QEvent::FontChange
never executed: end of block
e->type() == Q...nt::FontChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1406 || e->type() == QEvent::ApplicationFontChange) {
e->type() == Q...tionFontChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1407 d->itemsDirty = true;-
1408 d->updateGeometries();-
1409 }
never executed: end of block
0
1410-
1411 QWidget::changeEvent(e);-
1412}
never executed: end of block
0
1413-
1414/*!-
1415 \reimp-
1416*/-
1417bool QMenuBar::event(QEvent *e)-
1418{-
1419 Q_D(QMenuBar);-
1420 switch (e->type()) {-
1421 case QEvent::KeyPress: {
never executed: case QEvent::KeyPress:
0
1422 QKeyEvent *ke = (QKeyEvent*)e;-
1423#if 0-
1424 if(!d->keyboardState) { //all keypresses..-
1425 d->setCurrentAction(0);-
1426 return ;-
1427 }-
1428#endif-
1429 if(ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) {
ke->key() == Qt::Key_TabDescription
TRUEnever evaluated
FALSEnever evaluated
ke->key() == Qt::Key_BacktabDescription
TRUEnever evaluated
FALSEnever evaluated
0
1430 keyPressEvent(ke);-
1431 return true;
never executed: return true;
0
1432 }-
1433-
1434 } break;
never executed: break;
0
1435#ifndef QT_NO_SHORTCUT-
1436 case QEvent::Shortcut: {
never executed: case QEvent::Shortcut:
0
1437 QShortcutEvent *se = static_cast<QShortcutEvent *>(e);-
1438 int shortcutId = se->shortcutId();-
1439 for(int j = 0; j < d->shortcutIndexMap.size(); ++j) {
j < d->shortcutIndexMap.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
1440 if (shortcutId == d->shortcutIndexMap.value(j))
shortcutId == ...exMap.value(j)Description
TRUEnever evaluated
FALSEnever evaluated
0
1441 d->_q_internalShortcutActivated(j);
never executed: d->_q_internalShortcutActivated(j);
0
1442 }
never executed: end of block
0
1443 } break;
never executed: break;
0
1444#endif-
1445 case QEvent::Show:
never executed: case QEvent::Show:
0
1446 d->_q_updateLayout();-
1447 break;
never executed: break;
0
1448 case QEvent::ShortcutOverride: {
never executed: case QEvent::ShortcutOverride:
0
1449 QKeyEvent *kev = static_cast<QKeyEvent*>(e);-
1450 //we only filter out escape if there is a current action-
1451 if (kev->matches(QKeySequence::Cancel) && d->currentAction) {
kev->matches(Q...uence::Cancel)Description
TRUEnever evaluated
FALSEnever evaluated
d->currentActionDescription
TRUEnever evaluated
FALSEnever evaluated
0
1452 e->accept();-
1453 return true;
never executed: return true;
0
1454 }-
1455 }-
1456 break;
never executed: break;
0
1457-
1458-
1459#ifndef QT_NO_WHATSTHIS-
1460 case QEvent::QueryWhatsThis:
never executed: case QEvent::QueryWhatsThis:
0
1461 e->setAccepted(d->whatsThis.size());-
1462 if (QAction *action = d->actionAt(static_cast<QHelpEvent*>(e)->pos())) {
QAction *actio...t*>(e)->pos())Description
TRUEnever evaluated
FALSEnever evaluated
0
1463 if (action->whatsThis().size() || action->menu())
action->whatsThis().size()Description
TRUEnever evaluated
FALSEnever evaluated
action->menu()Description
TRUEnever evaluated
FALSEnever evaluated
0
1464 e->accept();
never executed: e->accept();
0
1465 }
never executed: end of block
0
1466 return true;
never executed: return true;
0
1467#endif-
1468 case QEvent::LayoutDirectionChange:
never executed: case QEvent::LayoutDirectionChange:
0
1469 d->_q_updateLayout();-
1470 break;
never executed: break;
0
1471 default:
never executed: default:
0
1472 break;
never executed: break;
0
1473 }-
1474 return QWidget::event(e);
never executed: return QWidget::event(e);
0
1475}-
1476-
1477/*!-
1478 \reimp-
1479*/-
1480bool QMenuBar::eventFilter(QObject *object, QEvent *event)-
1481{-
1482 Q_D(QMenuBar);-
1483 if (object && (event->type() == QEvent::ParentChange)) //GrandparentChange
objectDescription
TRUEnever evaluated
FALSEnever evaluated
(event->type()...:ParentChange)Description
TRUEnever evaluated
FALSEnever evaluated
0
1484 d->handleReparent();
never executed: d->handleReparent();
0
1485-
1486 if (object == d->leftWidget || object == d->rightWidget) {
object == d->leftWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
object == d->rightWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1487 switch (event->type()) {-
1488 case QEvent::ShowToParent:
never executed: case QEvent::ShowToParent:
0
1489 case QEvent::HideToParent:
never executed: case QEvent::HideToParent:
0
1490 d->_q_updateLayout();-
1491 break;
never executed: break;
0
1492 default:
never executed: default:
0
1493 break;
never executed: break;
0
1494 }-
1495 }-
1496-
1497 if (style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, this)) {
style()->style...tion, 0, this)Description
TRUEnever evaluated
FALSEnever evaluated
0
1498 if (d->altPressed) {
d->altPressedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1499 switch (event->type()) {-
1500 case QEvent::KeyPress:
never executed: case QEvent::KeyPress:
0
1501 case QEvent::KeyRelease:
never executed: case QEvent::KeyRelease:
0
1502 {-
1503 QKeyEvent *kev = static_cast<QKeyEvent*>(event);-
1504 if (kev->key() == Qt::Key_Alt || kev->key() == Qt::Key_Meta) {
kev->key() == Qt::Key_AltDescription
TRUEnever evaluated
FALSEnever evaluated
kev->key() == Qt::Key_MetaDescription
TRUEnever evaluated
FALSEnever evaluated
0
1505 if (event->type() == QEvent::KeyPress) // Alt-press does not interest us, we have the shortcut-override event
event->type() ...vent::KeyPressDescription
TRUEnever evaluated
FALSEnever evaluated
0
1506 break;
never executed: break;
0
1507 d->setKeyboardMode(!d->keyboardState);-
1508 }
never executed: end of block
0
1509 }-
1510 // fall through-
1511 case QEvent::MouseButtonPress:
code before this statement never executed: case QEvent::MouseButtonPress:
never executed: case QEvent::MouseButtonPress:
0
1512 case QEvent::MouseButtonRelease:
never executed: case QEvent::MouseButtonRelease:
0
1513 case QEvent::MouseMove:
never executed: case QEvent::MouseMove:
0
1514 case QEvent::FocusIn:
never executed: case QEvent::FocusIn:
0
1515 case QEvent::FocusOut:
never executed: case QEvent::FocusOut:
0
1516 case QEvent::ActivationChange:
never executed: case QEvent::ActivationChange:
0
1517 d->altPressed = false;-
1518 qApp->removeEventFilter(this);-
1519 break;
never executed: break;
0
1520 default:
never executed: default:
0
1521 break;
never executed: break;
0
1522 }-
1523 } else if (isVisible()) {
isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
1524 if (event->type() == QEvent::ShortcutOverride) {
event->type() ...ortcutOverrideDescription
TRUEnever evaluated
FALSEnever evaluated
0
1525 QKeyEvent *kev = static_cast<QKeyEvent*>(event);-
1526 if ((kev->key() == Qt::Key_Alt || kev->key() == Qt::Key_Meta)
kev->key() == Qt::Key_AltDescription
TRUEnever evaluated
FALSEnever evaluated
kev->key() == Qt::Key_MetaDescription
TRUEnever evaluated
FALSEnever evaluated
0
1527 && kev->modifiers() == Qt::AltModifier) {
kev->modifiers...t::AltModifierDescription
TRUEnever evaluated
FALSEnever evaluated
0
1528 d->altPressed = true;-
1529 qApp->installEventFilter(this);-
1530 }
never executed: end of block
0
1531 }
never executed: end of block
0
1532 }
never executed: end of block
0
1533 }
never executed: end of block
0
1534-
1535 return false;
never executed: return false;
0
1536}-
1537-
1538/*!-
1539 Returns the QAction at \a pt. Returns 0 if there is no action at \a pt or if-
1540the location has a separator.-
1541-
1542 \sa addAction(), addSeparator()-
1543*/-
1544QAction *QMenuBar::actionAt(const QPoint &pt) const-
1545{-
1546 Q_D(const QMenuBar);-
1547 return d->actionAt(pt);
never executed: return d->actionAt(pt);
0
1548}-
1549-
1550/*!-
1551 Returns the geometry of action \a act as a QRect.-
1552-
1553 \sa actionAt()-
1554*/-
1555QRect QMenuBar::actionGeometry(QAction *act) const-
1556{-
1557 Q_D(const QMenuBar);-
1558 return d->actionRect(act);
never executed: return d->actionRect(act);
0
1559}-
1560-
1561/*!-
1562 \reimp-
1563*/-
1564QSize QMenuBar::minimumSizeHint() const-
1565{-
1566 Q_D(const QMenuBar);-
1567 const bool as_gui_menubar = !isNativeMenuBar();-
1568-
1569 ensurePolished();-
1570 QSize ret(0, 0);-
1571 const_cast<QMenuBarPrivate*>(d)->updateGeometries();-
1572 const int hmargin = style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, this);-
1573 const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this);-
1574 int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);-
1575 int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this);-
1576 if(as_gui_menubar) {
as_gui_menubarDescription
TRUEnever evaluated
FALSEnever evaluated
0
1577 int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width();
parentWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
1578 d->calcActionRects(w - (2 * fw), 0);-
1579 for (int i = 0; ret.isNull() && i < d->actions.count(); ++i)
ret.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
i < d->actions.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1580 ret = d->actionRects.at(i).size();
never executed: ret = d->actionRects.at(i).size();
0
1581 if (!d->extension->isHidden())
!d->extension->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
0
1582 ret += QSize(d->extension->sizeHint().width(), 0);
never executed: ret += QSize(d->extension->sizeHint().width(), 0);
0
1583 ret += QSize(2*fw + hmargin, 2*fw + vmargin);-
1584 }
never executed: end of block
0
1585 int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;-
1586 if(d->leftWidget) {
d->leftWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1587 QSize sz = d->leftWidget->minimumSizeHint();-
1588 ret.setWidth(ret.width() + sz.width());-
1589 if(sz.height() + margin > ret.height())
sz.height() + ...> ret.height()Description
TRUEnever evaluated
FALSEnever evaluated
0
1590 ret.setHeight(sz.height() + margin);
never executed: ret.setHeight(sz.height() + margin);
0
1591 }
never executed: end of block
0
1592 if(d->rightWidget) {
d->rightWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1593 QSize sz = d->rightWidget->minimumSizeHint();-
1594 ret.setWidth(ret.width() + sz.width());-
1595 if(sz.height() + margin > ret.height())
sz.height() + ...> ret.height()Description
TRUEnever evaluated
FALSEnever evaluated
0
1596 ret.setHeight(sz.height() + margin);
never executed: ret.setHeight(sz.height() + margin);
0
1597 }
never executed: end of block
0
1598 if(as_gui_menubar) {
as_gui_menubarDescription
TRUEnever evaluated
FALSEnever evaluated
0
1599 QStyleOptionMenuItem opt;-
1600 opt.rect = rect();-
1601 opt.menuRect = rect();-
1602 opt.state = QStyle::State_None;-
1603 opt.menuItemType = QStyleOptionMenuItem::Normal;-
1604 opt.checkType = QStyleOptionMenuItem::NotCheckable;-
1605 opt.palette = palette();-
1606 return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt,
never executed: return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt, ret.expandedTo(QApplication::globalStrut()), this));
0
1607 ret.expandedTo(QApplication::globalStrut()),
never executed: return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt, ret.expandedTo(QApplication::globalStrut()), this));
0
1608 this));
never executed: return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt, ret.expandedTo(QApplication::globalStrut()), this));
0
1609 }-
1610 return ret;
never executed: return ret;
0
1611}-
1612-
1613/*!-
1614 \reimp-
1615*/-
1616QSize QMenuBar::sizeHint() const-
1617{-
1618 Q_D(const QMenuBar);-
1619 const bool as_gui_menubar = !isNativeMenuBar();-
1620-
1621 ensurePolished();-
1622 QSize ret(0, 0);-
1623 const_cast<QMenuBarPrivate*>(d)->updateGeometries();-
1624 const int hmargin = style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, this);-
1625 const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this);-
1626 int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);-
1627 int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this);-
1628 if(as_gui_menubar) {
as_gui_menubarDescription
TRUEnever evaluated
FALSEnever evaluated
0
1629 const int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width();
parentWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
1630 d->calcActionRects(w - (2 * fw), 0);-
1631 for (int i = 0; i < d->actionRects.count(); ++i) {
i < d->actionRects.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1632 const QRect &actionRect = d->actionRects.at(i);-
1633 ret = ret.expandedTo(QSize(actionRect.x() + actionRect.width(), actionRect.y() + actionRect.height()));-
1634 }
never executed: end of block
0
1635 //the action geometries already contain the top and left-
1636 //margins. So we only need to add those from right and bottom.-
1637 ret += QSize(fw + hmargin, fw + vmargin);-
1638 }
never executed: end of block
0
1639 int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;-
1640 if(d->leftWidget) {
d->leftWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1641 QSize sz = d->leftWidget->sizeHint();-
1642 sz.rheight() += margin;-
1643 ret = ret.expandedTo(sz);-
1644 }
never executed: end of block
0
1645 if(d->rightWidget) {
d->rightWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1646 QSize sz = d->rightWidget->sizeHint();-
1647 ret.setWidth(ret.width() + sz.width());-
1648 if(sz.height() + margin > ret.height())
sz.height() + ...> ret.height()Description
TRUEnever evaluated
FALSEnever evaluated
0
1649 ret.setHeight(sz.height() + margin);
never executed: ret.setHeight(sz.height() + margin);
0
1650 }
never executed: end of block
0
1651 if(as_gui_menubar) {
as_gui_menubarDescription
TRUEnever evaluated
FALSEnever evaluated
0
1652 QStyleOptionMenuItem opt;-
1653 opt.rect = rect();-
1654 opt.menuRect = rect();-
1655 opt.state = QStyle::State_None;-
1656 opt.menuItemType = QStyleOptionMenuItem::Normal;-
1657 opt.checkType = QStyleOptionMenuItem::NotCheckable;-
1658 opt.palette = palette();-
1659 return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt,
never executed: return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt, ret.expandedTo(QApplication::globalStrut()), this));
0
1660 ret.expandedTo(QApplication::globalStrut()),
never executed: return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt, ret.expandedTo(QApplication::globalStrut()), this));
0
1661 this));
never executed: return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt, ret.expandedTo(QApplication::globalStrut()), this));
0
1662 }-
1663 return ret;
never executed: return ret;
0
1664}-
1665-
1666/*!-
1667 \reimp-
1668*/-
1669int QMenuBar::heightForWidth(int) const-
1670{-
1671 Q_D(const QMenuBar);-
1672 const bool as_gui_menubar = !isNativeMenuBar();-
1673-
1674 const_cast<QMenuBarPrivate*>(d)->updateGeometries();-
1675 int height = 0;-
1676 const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this);-
1677 int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);-
1678 int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this);-
1679 if(as_gui_menubar) {
as_gui_menubarDescription
TRUEnever evaluated
FALSEnever evaluated
0
1680 for (int i = 0; i < d->actionRects.count(); ++i)
i < d->actionRects.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1681 height = qMax(height, d->actionRects.at(i).height());
never executed: height = qMax(height, d->actionRects.at(i).height());
0
1682 if (height) //there is at least one non-null item
heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
1683 height += spaceBelowMenuBar;
never executed: height += spaceBelowMenuBar;
0
1684 height += 2*fw;-
1685 height += 2*vmargin;-
1686 }
never executed: end of block
0
1687 int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;-
1688 if(d->leftWidget)
d->leftWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1689 height = qMax(d->leftWidget->sizeHint().height() + margin, height);
never executed: height = qMax(d->leftWidget->sizeHint().height() + margin, height);
0
1690 if(d->rightWidget)
d->rightWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1691 height = qMax(d->rightWidget->sizeHint().height() + margin, height);
never executed: height = qMax(d->rightWidget->sizeHint().height() + margin, height);
0
1692 if(as_gui_menubar) {
as_gui_menubarDescription
TRUEnever evaluated
FALSEnever evaluated
0
1693 QStyleOptionMenuItem opt;-
1694 opt.init(this);-
1695 opt.menuRect = rect();-
1696 opt.state = QStyle::State_None;-
1697 opt.menuItemType = QStyleOptionMenuItem::Normal;-
1698 opt.checkType = QStyleOptionMenuItem::NotCheckable;-
1699 return style()->sizeFromContents(QStyle::CT_MenuBar, &opt, QSize(0, height), this).height(); //not pretty..
never executed: return style()->sizeFromContents(QStyle::CT_MenuBar, &opt, QSize(0, height), this).height();
0
1700 }-
1701 return height;
never executed: return height;
0
1702}-
1703-
1704/*!-
1705 \internal-
1706*/-
1707void QMenuBarPrivate::_q_internalShortcutActivated(int id)-
1708{-
1709 Q_Q(QMenuBar);-
1710 QAction *act = actions.at(id);-
1711 setCurrentAction(act, true, true);-
1712 if (act && !act->menu()) {
actDescription
TRUEnever evaluated
FALSEnever evaluated
!act->menu()Description
TRUEnever evaluated
FALSEnever evaluated
0
1713 activateAction(act, QAction::Trigger);-
1714 //100 is the same as the default value in QPushButton::animateClick-
1715 autoReleaseTimer.start(100, q);-
1716 } else if (act && q->style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, q)) {
never executed: end of block
actDescription
TRUEnever evaluated
FALSEnever evaluated
q->style()->st...igation, 0, q)Description
TRUEnever evaluated
FALSEnever evaluated
0
1717 // When we open a menu using a shortcut, we should end up in keyboard state-
1718 setKeyboardMode(true);-
1719 }
never executed: end of block
0
1720}
never executed: end of block
0
1721-
1722void QMenuBarPrivate::_q_updateLayout()-
1723{-
1724 Q_Q(QMenuBar);-
1725 itemsDirty = true;-
1726 if (q->isVisible()) {
q->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
1727 updateGeometries();-
1728 q->update();-
1729 }
never executed: end of block
0
1730}
never executed: end of block
0
1731-
1732/*!-
1733 \fn void QMenuBar::setCornerWidget(QWidget *widget, Qt::Corner corner)-
1734-
1735 This sets the given \a widget to be shown directly on the left of the first-
1736 menu item, or on the right of the last menu item, depending on \a corner.-
1737-
1738 The menu bar takes ownership of \a widget, reparenting it into the menu bar.-
1739 However, if the \a corner already contains a widget, this previous widget-
1740 will no longer be managed and will still be a visible child of the menu bar.-
1741-
1742 \note Using a corner other than Qt::TopRightCorner or Qt::TopLeftCorner-
1743 will result in a warning.-
1744*/-
1745void QMenuBar::setCornerWidget(QWidget *w, Qt::Corner corner)-
1746{-
1747 Q_D(QMenuBar);-
1748 switch (corner) {-
1749 case Qt::TopLeftCorner:
never executed: case Qt::TopLeftCorner:
0
1750 if (d->leftWidget)
d->leftWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1751 d->leftWidget->removeEventFilter(this);
never executed: d->leftWidget->removeEventFilter(this);
0
1752 d->leftWidget = w;-
1753 break;
never executed: break;
0
1754 case Qt::TopRightCorner:
never executed: case Qt::TopRightCorner:
0
1755 if (d->rightWidget)
d->rightWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1756 d->rightWidget->removeEventFilter(this);
never executed: d->rightWidget->removeEventFilter(this);
0
1757 d->rightWidget = w;-
1758 break;
never executed: break;
0
1759 default:
never executed: default:
0
1760 qWarning("QMenuBar::setCornerWidget: Only TopLeftCorner and TopRightCorner are supported");-
1761 return;
never executed: return;
0
1762 }-
1763-
1764 if (w) {
wDescription
TRUEnever evaluated
FALSEnever evaluated
0
1765 w->setParent(this);-
1766 w->installEventFilter(this);-
1767 }
never executed: end of block
0
1768-
1769 d->_q_updateLayout();-
1770}
never executed: end of block
0
1771-
1772/*!-
1773 Returns the widget on the left of the first or on the right of the last menu-
1774 item, depending on \a corner.-
1775-
1776 \note Using a corner other than Qt::TopRightCorner or Qt::TopLeftCorner-
1777 will result in a warning.-
1778*/-
1779QWidget *QMenuBar::cornerWidget(Qt::Corner corner) const-
1780{-
1781 Q_D(const QMenuBar);-
1782 QWidget *w = 0;-
1783 switch(corner) {-
1784 case Qt::TopLeftCorner:
never executed: case Qt::TopLeftCorner:
0
1785 w = d->leftWidget;-
1786 break;
never executed: break;
0
1787 case Qt::TopRightCorner:
never executed: case Qt::TopRightCorner:
0
1788 w = d->rightWidget;-
1789 break;
never executed: break;
0
1790 default:
never executed: default:
0
1791 qWarning("QMenuBar::cornerWidget: Only TopLeftCorner and TopRightCorner are supported");-
1792 break;
never executed: break;
0
1793 }-
1794-
1795 return w;
never executed: return w;
0
1796}-
1797-
1798/*!-
1799 \property QMenuBar::nativeMenuBar-
1800 \brief Whether or not a menubar will be used as a native menubar on platforms that support it-
1801 \since 4.6-
1802-
1803 This property specifies whether or not the menubar should be used as a native menubar on-
1804 platforms that support it. The currently supported platforms are \macos, and-
1805 Linux desktops which use the com.canonical.dbusmenu D-Bus interface (such as Ubuntu Unity).-
1806 If this property is \c true, the menubar is used in the native menubar and is not in the window of-
1807 its parent; if \c false the menubar remains in the window. On other platforms,-
1808 setting this attribute has no effect, and reading this attribute will always return \c false.-
1809-
1810 The default is to follow whether the Qt::AA_DontUseNativeMenuBar attribute-
1811 is set for the application. Explicitly setting this property overrides-
1812 the presence (or absence) of the attribute.-
1813*/-
1814-
1815void QMenuBar::setNativeMenuBar(bool nativeMenuBar)-
1816{-
1817 Q_D(QMenuBar);-
1818 if (nativeMenuBar != bool(d->platformMenuBar)) {
nativeMenuBar ...atformMenuBar)Description
TRUEnever evaluated
FALSEnever evaluated
0
1819 if (!nativeMenuBar) {
!nativeMenuBarDescription
TRUEnever evaluated
FALSEnever evaluated
0
1820 delete d->platformMenuBar;-
1821 d->platformMenuBar = 0;-
1822 } else {
never executed: end of block
0
1823 if (!d->platformMenuBar)
!d->platformMenuBarDescription
TRUEnever evaluated
FALSEnever evaluated
0
1824 d->platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar();
never executed: d->platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar();
0
1825 }
never executed: end of block
0
1826-
1827 updateGeometry();-
1828 if (!nativeMenuBar && parentWidget())
!nativeMenuBarDescription
TRUEnever evaluated
FALSEnever evaluated
parentWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
1829 setVisible(true);
never executed: setVisible(true);
0
1830 }
never executed: end of block
0
1831}
never executed: end of block
0
1832-
1833bool QMenuBar::isNativeMenuBar() const-
1834{-
1835 Q_D(const QMenuBar);-
1836 return bool(d->platformMenuBar);
never executed: return bool(d->platformMenuBar);
0
1837}-
1838-
1839/*!-
1840 \internal-
1841*/-
1842QPlatformMenuBar *QMenuBar::platformMenuBar()-
1843{-
1844 Q_D(const QMenuBar);-
1845 return d->platformMenuBar;
never executed: return d->platformMenuBar;
0
1846}-
1847-
1848/*!-
1849 \since 4.4-
1850-
1851 Sets the default action to \a act.-
1852-
1853 The default action is assigned to the left soft key. The menu is assigned-
1854 to the right soft key.-
1855-
1856 Currently there is only support for the default action on Windows-
1857 Mobile. On all other platforms this method is not available.-
1858-
1859 \sa defaultAction()-
1860*/-
1861-
1862#ifdef Q_OS_WINCE-
1863void QMenuBar::setDefaultAction(QAction *act)-
1864{-
1865 Q_D(QMenuBar);-
1866 if (d->defaultAction == act)-
1867 return;-
1868 if (qt_wince_is_mobile())-
1869 if (d->defaultAction) {-
1870 disconnect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction()));-
1871 disconnect(d->defaultAction, SIGNAL(destroyed()), this, SLOT(_q_updateDefaultAction()));-
1872 }-
1873 d->defaultAction = act;-
1874 if (qt_wince_is_mobile())-
1875 if (d->defaultAction) {-
1876 connect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction()));-
1877 connect(d->defaultAction, SIGNAL(destroyed()), this, SLOT(_q_updateDefaultAction()));-
1878 }-
1879 if (d->wce_menubar) {-
1880 d->wce_menubar->rebuild();-
1881 }-
1882}-
1883-
1884/*!-
1885 \since 4.4-
1886-
1887 Returns the current default action.-
1888-
1889 \sa setDefaultAction()-
1890*/-
1891QAction *QMenuBar::defaultAction() const-
1892{-
1893 return d_func()->defaultAction;-
1894}-
1895#endif-
1896-
1897/*!-
1898 \fn void QMenuBar::triggered(QAction *action)-
1899-
1900 This signal is emitted when an action in a menu belonging to this menubar-
1901 is triggered as a result of a mouse click; \a action is the action that-
1902 caused the signal to be emitted.-
1903-
1904 \note QMenuBar has to have ownership of the QMenu in order this signal to work.-
1905-
1906 Normally, you connect each menu action to a single slot using-
1907 QAction::triggered(), but sometimes you will want to connect-
1908 several items to a single slot (most often if the user selects-
1909 from an array). This signal is useful in such cases.-
1910-
1911 \sa hovered(), QAction::triggered()-
1912*/-
1913-
1914/*!-
1915 \fn void QMenuBar::hovered(QAction *action)-
1916-
1917 This signal is emitted when a menu action is highlighted; \a action-
1918 is the action that caused the event to be sent.-
1919-
1920 Often this is used to update status information.-
1921-
1922 \sa triggered(), QAction::hovered()-
1923*/-
1924-
1925// for private slots-
1926-
1927-
1928QT_END_NAMESPACE-
1929-
1930#include <moc_qmenubar.cpp>-
1931-
1932#endif // QT_NO_MENUBAR-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9