1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QMENUBAR_P_H
5#define QMENUBAR_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtWidgets/private/qtwidgetsglobal_p.h>
19#include "QtWidgets/qstyleoption.h"
20#include <private/qmenu_p.h> // Mac needs what in this file!
21#include <qpa/qplatformmenu.h>
22
23QT_REQUIRE_CONFIG(menubar);
24
25QT_BEGIN_NAMESPACE
26
27class QMenuBarExtension;
28class QMenuBarPrivate : public QWidgetPrivate
29{
30 Q_DECLARE_PUBLIC(QMenuBar)
31public:
32 QMenuBarPrivate() : itemsDirty(0), currentAction(nullptr), mouseDown(0),
33 closePopupMode(0), defaultPopDown(1), popupState(0), keyboardState(0), altPressed(0),
34 doChildEffects(false), platformMenuBar(nullptr)
35 { }
36
37 ~QMenuBarPrivate()
38 {
39 delete platformMenuBar;
40 }
41
42 void init();
43 QAction *getNextAction(const int start, const int increment) const;
44
45 //item calculations
46 uint itemsDirty : 1;
47
48 QList<int> shortcutIndexMap;
49 mutable QList<QRect> actionRects;
50 void calcActionRects(int max_width, int start) const;
51 QRect actionRect(QAction *) const;
52 void updateGeometries();
53
54 //selection
55 QPointer<QAction>currentAction;
56 uint mouseDown : 1, closePopupMode : 1, defaultPopDown;
57 QAction *actionAt(QPoint p) const;
58 void setCurrentAction(QAction *, bool =false, bool =false);
59 void popupAction(QAction *, bool);
60
61 //active popup state
62 uint popupState : 1;
63 QPointer<QMenu> activeMenu;
64
65 //keyboard mode for keyboard navigation
66 void focusFirstAction();
67 void setKeyboardMode(bool);
68 uint keyboardState : 1, altPressed : 1;
69 QPointer<QWidget> keyboardFocusWidget;
70
71 //firing of events
72 void activateAction(QAction *, QAction::ActionEvent);
73
74 void _q_actionTriggered();
75 void _q_actionHovered();
76 void _q_internalShortcutActivated(int);
77 void _q_updateLayout();
78
79 //extra widgets in the menubar
80 QPointer<QWidget> leftWidget, rightWidget;
81 QMenuBarExtension *extension;
82 bool isVisible(QAction *action);
83
84 //menu fading/scrolling effects
85 bool doChildEffects;
86
87 QRect menuRect(bool) const;
88
89 // reparenting
90 void handleReparent();
91 QList<QPointer<QWidget>> oldParents;
92
93 QList<QAction*> hiddenActions;
94 //default action
95 QPointer<QAction> defaultAction;
96
97 QBasicTimer autoReleaseTimer;
98 QPlatformMenuBar *platformMenuBar;
99 QPlatformMenu *getPlatformMenu(const QAction *action);
100 QPlatformMenu *findInsertionPlatformMenu(const QAction *action);
101 void copyActionToPlatformMenu(const QAction *e, QPlatformMenu *menu);
102
103 inline int indexOf(QAction *act) const { return q_func()->actions().indexOf(t: act); }
104};
105
106QT_END_NAMESPACE
107
108#endif // QMENUBAR_P_H
109

source code of qtbase/src/widgets/widgets/qmenubar_p.h