9#if QT_CONFIG(accessibility)
15#if QT_CONFIG(mainwindow)
21#if QT_CONFIG(toolbutton)
24#if QT_CONFIG(whatsthis)
27#include <qpa/qplatformtheme.h>
28#include "private/qguiapplication_p.h"
29#include "qpa/qplatformintegration.h"
33#include <private/qscreen_p.h>
99 if (
q->isRightToLeft())
107 if (
q->isRightToLeft())
115 if (
q->isRightToLeft())
143 q_width -= sz.
width();
144 q_start = sz.
width();
151 q_width -= sz.
width();
159 if (
q->isNativeMenuBar()) {
166#ifndef QT_NO_SHORTCUT
173 for (
int i = 0;
i < actionsCount;
i++)
184 bool hasHiddenActions =
false;
188 hasHiddenActions =
true;
194 if (hasHiddenActions) {
214 int x =
q->isRightToLeft()
285 activeMenu->d_func()->causedPopup.action = action;
291 QScreen *menubarScreen =
q->window()->windowHandle()->screen();
294 popupScreen = menubarScreen;
297 const bool fitUp = (
pos.y() - popup_size.
height() >= screenRect.
top());
298 const bool fitDown = (
pos.y() + popup_size.
height() <= screenRect.
bottom());
299 const bool rtl =
q->isRightToLeft();
300 const int actionWidth = adjustedActionRect.
width();
302 if (!fitUp && !fitDown) {
303 bool shouldShiftToRight = !rtl;
304 if (rtl && popup_size.
width() >
pos.x())
305 shouldShiftToRight =
true;
306 else if (actionWidth + popup_size.
width() +
pos.x() > screenRect.
right())
307 shouldShiftToRight =
false;
309 if (shouldShiftToRight) {
310 pos.rx() += actionWidth + (rtl ? popup_size.
width() : 0);
317 pos.rx() += actionWidth;
353#if QT_CONFIG(statustip)
362#if QT_CONFIG(statustip)
363 }
else if (previousAction) {
384 const QStyle *style =
q->style();
387 int max_item_height = 0, separator = -1, separator_start = 0, separator_len = 0;
412 else if (!
s.isEmpty())
418 q->initStyleOption(&
opt, action);
423 int iWidth = sz.
width() + itemSpacing;
425 separator_start += iWidth;
427 separator_len += iWidth;
430 max_item_height =
qMax(max_item_height, sz.
height());
438 int x = fw + ((
start == -1) ? hmargin :
start) + itemSpacing;
439 int y = fw + vmargin;
446 rect.setHeight(max_item_height);
449 if (separator != -1 &&
i >= separator) {
450 int left = (max_width - separator_len - hmargin - itemSpacing) + (
x - separator_start - hmargin);
451 if (
left < separator_start) {
452 separator_start =
x = hmargin;
453 y += max_item_height;
462 x +=
rect.width() + itemSpacing;
488 if (
QAction *action = qobject_cast<QAction *>(
q->sender())) {
489 emit q->triggered(action);
496 if (
QAction *action = qobject_cast<QAction *>(
q->sender())) {
497 emit q->hovered(action);
498#if QT_CONFIG(accessibility)
499 if (QAccessible::isActive()) {
501 QAccessibleEvent focusEvent(
q, QAccessible::Focus);
502 focusEvent.setChild(actionIndex);
503 QAccessible::updateAccessibility(&focusEvent);
528 if (
d->currentAction &&
d->currentAction == action) {
530 if (
d->popupState && !
d->closePopupMode)
717 delete d->platformMenuBar;
718 d->platformMenuBar =
nullptr;
770 ret->setSeparator(
true);
811 return d->currentAction;
822 d->setCurrentAction(act,
true,
false);
841 for(
int i = 0;
i < acts.
size();
i++)
860 d->defaultPopDown = !
b;
866 return !
d->defaultPopDown;
875 d->itemsDirty =
true;
876 d->updateGeometries();
889 for (
int i = 0;
i <
d->actions.size(); ++
i) {
891 QRect adjustedActionRect =
d->actionRect(action);
892 if (adjustedActionRect.
isEmpty() || !
d->isVisible(action))
894 if (!
e->rect().intersects(adjustedActionRect))
897 emptyArea -= adjustedActionRect;
901 p.setClipRect(adjustedActionRect);
911 p.setClipRegion(borderReg);
912 emptyArea -= borderReg;
921 p.setClipRegion(emptyArea);
956 QAction *action =
d->actionAt(
e->position().toPoint());
957 if (!action || !
d->isVisible(action) || !action->
isEnabled()) {
958 d->setCurrentAction(
nullptr);
959#if QT_CONFIG(whatsthis)
966 if (
d->currentAction == action &&
d->popupState) {
968 d->activeMenu =
nullptr;
973 d->setCurrentAction(action,
true);
986 d->mouseDown =
false;
987 QAction *action =
d->actionAt(
e->position().toPoint());
990 if (!
d->isVisible(action))
992 if ((
d->closePopupMode && action ==
d->currentAction) || !action || !action->
menu()) {
995 d->setCurrentAction(action,
false);
999 d->closePopupMode = 0;
1008 d->updateGeometries();
1021 bool key_consumed =
false;
1030 if (
d->currentAction->menu()) {
1031 d->popupAction(
d->currentAction,
true);
1034 d->setCurrentAction(
d->currentAction,
false);
1035 d->setKeyboardMode(
false);
1037 key_consumed =
true;
1042 if (
d->currentAction) {
1043 int index =
d->actions.indexOf(
d->currentAction);
1045 d->setCurrentAction(nextAction,
d->popupState,
true);
1046 key_consumed =
true;
1052 key_consumed =
false;
1055#ifndef QT_NO_SHORTCUT
1057 d->setCurrentAction(
nullptr);
1058 d->setKeyboardMode(
false);
1059 key_consumed =
true;
1063 if (!key_consumed &&
1067 QAction *
first =
nullptr, *currentSelected =
nullptr, *firstAfterCurrent =
nullptr;
1069 const QChar c =
e->text().at(0).toUpper();
1070 for(
int i = 0;
i <
d->actions.size(); ++
i) {
1071 if (
d->actionRects.at(
i).isNull())
1077 if (ampersand >= 0) {
1078 if (
s[ampersand+1].toUpper() ==
c) {
1082 if (act ==
d->currentAction)
1083 currentSelected = act;
1084 else if (!firstAfterCurrent && currentSelected)
1085 firstAfterCurrent = act;
1091 QAction *next_action =
nullptr;
1092 if (clashCount >= 1) {
1093 if (clashCount == 1 || !
d->currentAction || (currentSelected && !firstAfterCurrent))
1094 next_action =
first;
1096 next_action = firstAfterCurrent;
1099 key_consumed =
true;
1100 d->setCurrentAction(next_action,
true,
true);
1116 d->mouseDown =
false;
1124 bool popupState =
d->popupState ||
d->mouseDown;
1125 QAction *action =
d->actionAt(
e->position().toPoint());
1126 if ((action &&
d->isVisible(action)) || !popupState)
1127 d->setCurrentAction(action, popupState);
1137 (
d->currentAction &&
d->currentAction->menu() ==
nullptr))
1138 d->setCurrentAction(
nullptr);
1143 if (!action || !action->
menu())
1160 for (
int beforeIndex =
indexOf(
const_cast<QAction *
>(action)) + 1;
1161 !beforeMenu && (beforeIndex <
q->actions().
size());
1171 const auto tag =
reinterpret_cast<quintptr>(action);
1185 d->itemsDirty =
true;
1187 if (
d->platformMenuBar) {
1192 auto action =
static_cast<QAction *
>(
e->action());
1196 d->copyActionToPlatformMenu(action,
menu);
1198 QPlatformMenu *beforeMenu =
d->findInsertionPlatformMenu(action);
1199 d->platformMenuBar->insertMenu(
menu, beforeMenu);
1204 d->platformMenuBar->removeMenu(
menu);
1213 d->platformMenuBar->removeMenu(cur);
1215 d->copyActionToPlatformMenu(action,
menu);
1217 QPlatformMenu *beforeMenu =
d->findInsertionPlatformMenu(action);
1218 d->platformMenuBar->insertMenu(
menu, beforeMenu);
1221 d->copyActionToPlatformMenu(action,
menu);
1222 d->platformMenuBar->syncMenu(
menu);
1231 e->action()->disconnect(
this);
1236 d->updateGeometries();
1247 if (
d->keyboardState)
1248 d->focusFirstAction();
1257 if (!
d->popupState) {
1258 d->setCurrentAction(
nullptr);
1259 d->setKeyboardMode(
false);
1269 if (
e->timerId() ==
d->autoReleaseTimer.timerId()) {
1270 d->autoReleaseTimer.stop();
1271 d->setCurrentAction(
nullptr);
1285 QWidget *newWindow = newParent ? newParent->
window() :
nullptr;
1292 if (newParent ==
w) {
1294 if (newParent != newWindow)
1303 while (newParent && newParent != newWindow) {
1305 newParents.
append(newParent);
1310 if (newParent && newWindow) {
1312 newParents.
append(newParent);
1337 d->itemsDirty =
true;
1341 d->updateGeometries();
1343 d->handleReparent();
1346 d->itemsDirty =
true;
1347 d->updateGeometries();
1359 switch (
e->type()) {
1363 if (!
d->keyboardState) {
1364 d->setCurrentAction(0);
1374#ifndef QT_NO_SHORTCUT
1377 int shortcutId = se->shortcutId();
1378 for(
int j = 0;
j <
d->shortcutIndexMap.size(); ++
j) {
1379 if (shortcutId ==
d->shortcutIndexMap.value(
j))
1380 d->_q_internalShortcutActivated(
j);
1385 d->_q_updateLayout();
1387#ifndef QT_NO_SHORTCUT
1398#if QT_CONFIG(whatsthis)
1400 e->setAccepted(
d->whatsThis.size());
1402 if (action->whatsThis().size() || action->menu())
1408 d->_q_updateLayout();
1423 d->handleReparent();
1425 if (
object ==
d->leftWidget ||
object ==
d->rightWidget) {
1426 switch (
event->type()) {
1429 d->_q_updateLayout();
1444 d->platformMenuBar->handleReparent(
handle);
1448 if (
d->altPressed) {
1449 switch (
event->type()) {
1457 d->setKeyboardMode(!
d->keyboardState);
1468 d->altPressed =
false;
1469 qApp->removeEventFilter(
this);
1479 d->altPressed =
true;
1480 qApp->installEventFilter(
this);
1498 return d->actionAt(pt);
1509 return d->actionRect(act);
1527 if (as_gui_menubar) {
1529 d->calcActionRects(
w - (2 * fw), 0);
1531 ret =
d->actionRects.at(
i).size();
1532 if (!
d->extension->isHidden())
1533 ret +=
QSize(
d->extension->sizeHint().width(), 0);
1534 ret +=
QSize(2*fw + hmargin, 2*fw + vmargin);
1536 int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;
1537 if (
d->leftWidget) {
1538 QSize sz =
d->leftWidget->minimumSizeHint();
1540 if (sz.
height() + margin >
ret.height())
1543 if (
d->rightWidget) {
1544 QSize sz =
d->rightWidget->minimumSizeHint();
1546 if (sz.
height() + margin >
ret.height())
1549 if (as_gui_menubar) {
1577 if (as_gui_menubar) {
1579 d->calcActionRects(
w - (2 * fw), 0);
1580 for (
int i = 0;
i <
d->actionRects.size(); ++
i) {
1581 const QRect &actionRect =
d->actionRects.at(
i);
1586 ret +=
QSize(fw + hmargin, fw + vmargin);
1588 int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;
1589 if (
d->leftWidget) {
1590 QSize sz =
d->leftWidget->sizeHint();
1592 ret =
ret.expandedTo(sz);
1594 if (
d->rightWidget) {
1595 QSize sz =
d->rightWidget->sizeHint();
1597 if (sz.
height() + margin >
ret.height())
1600 if (as_gui_menubar) {
1626 if (as_gui_menubar) {
1627 for (
int i = 0;
i <
d->actionRects.size(); ++
i)
1630 height += spaceBelowMenuBar;
1634 int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;
1639 if (as_gui_menubar) {
1658 if (act && act->
menu()) {
1667 if (act && !act->
menu()) {
1681 if (
q->isVisible()) {
1706 d->leftWidget->removeEventFilter(
this);
1711 d->rightWidget->removeEventFilter(
this);
1715 qWarning(
"QMenuBar::setCornerWidget: Only TopLeftCorner and TopRightCorner are supported");
1721 w->installEventFilter(
this);
1724 d->_q_updateLayout();
1746 qWarning(
"QMenuBar::cornerWidget: Only TopLeftCorner and TopRightCorner are supported");
1775 delete d->platformMenuBar;
1776 d->platformMenuBar =
nullptr;
1777 d->itemsDirty =
true;
1779 if (!
d->platformMenuBar)
1792 return bool(
d->platformMenuBar);
1801 return d->platformMenuBar;
1836#include <moc_qmenubar.cpp>
The QActionEvent class provides an event that is generated when a QAction is added,...
The QAction class provides an abstraction for user commands that can be added to different user inter...
ActionEvent
This enum type is used when calling QAction::activate()
T menu() const
Returns the menu contained by this action.
bool isSeparator() const
Returns true if this action is a separator action; otherwise it returns false.
void setSeparator(bool b)
If b is true then this action will be considered a separator.
bool showStatusText(QObject *object=nullptr)
Updates the relevant status bar for the UI represented by object by sending a QStatusTipEvent.
void activate(ActionEvent event)
Sends the relevant signals for ActionEvent event.
QString text
the action's descriptive text
QIcon icon
the action's icon
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or \nullptr if no widget in this ap...
static QWidget * activePopupWidget()
Returns the active popup widget.
void start(int msec, QObject *obj)
\obsolete Use chrono overload instead.
void stop()
Stops the timer.
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
The QFocusEvent class contains event parameters for widget focus events.
\reentrant \inmodule QtGui
QSize size(int flags, const QString &str, int tabstops=0, int *tabarray=nullptr) const
Returns the size in pixels of text.
int midLineWidth
the width of the mid-line
int lineWidth
the line width
static QPlatformTheme * platformTheme()
QScreen * primaryScreen
the primary (or default) screen of the application.
The QHelpEvent class provides an event that is used to request helpful information about a particular...
const QPoint & pos() const
Returns the mouse cursor position when the event was generated, relative to the widget to which the e...
The QIcon class provides scalable icons in different modes and states.
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
The QKeyEvent class describes a key event.
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
int key() const
Returns the code of the key that was pressed or released.
static QKeySequence mnemonic(const QString &text)
Returns the shortcut key sequence for the mnemonic in text, or an empty key sequence if no mnemonics ...
qsizetype size() const noexcept
QList< T > & fill(parameter_type t, qsizetype size=-1)
const_reference at(qsizetype i) const noexcept
T value(qsizetype i) const
void reserve(qsizetype size)
void resize(qsizetype size)
void append(parameter_type t)
void installEventFilter(QObject *filterObj)
Installs an event filter filterObj on this object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
void removeEventFilter(QObject *obj)
Removes an event filter object obj from this object.
virtual void timerEvent(QTimerEvent *event)
This event handler can be reimplemented in a subclass to receive timer events for the object.
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
The QPaintEvent class contains event parameters for paint events.
The QPainter class performs low-level painting on widgets and other paint devices.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr bool isEmpty() const noexcept
Returns true if the rectangle is empty, otherwise returns false.
constexpr void adjust(int x1, int y1, int x2, int y2) noexcept
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
bool contains(const QRect &r, bool proper=false) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr int width() const noexcept
Returns the width of the rectangle.
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
The QRegion class specifies a clip region for a painter.
The QResizeEvent class contains event parameters for resize events.
The QScreen class is used to query screen properties. \inmodule QtGui.
QRect geometry
the screen's geometry in pixels
QRect virtualGeometry
the pixel geometry of the virtual desktop to which this screen belongs
QScreen * virtualSiblingAt(QPoint point)
Returns the screen at point within the set of \l QScreen::virtualSiblings(), or nullptr if outside of...
The QShortcutEvent class provides an event which is generated when the user presses a key combination...
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
constexpr int & rheight() noexcept
Returns a reference to the height.
constexpr QSize expandedTo(const QSize &) const noexcept
Returns a size holding the maximum width and height of this size and the given otherSize.
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
The QStatusTipEvent class provides an event that is used to show messages in a status bar.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
\variable QStyleOptionFocusRect::backgroundColor
void initFrom(const QWidget *w)
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=nullptr) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
@ SH_MainWindow_SpaceBelowMenuBar
@ SH_MenuBar_AltKeyNavigation
@ SH_Menu_AllowActiveAndDisabled
@ SH_MenuBar_MouseTracking
@ SH_DrawMenuBarSeparator
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
@ SP_ToolBarHorizontalExtensionButton
static QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRect, const QRect &logicalRect)
Returns the given logicalRectangle converted to screen coordinates based on the specified direction.
@ PM_ToolBarExtensionExtent
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const =0
Draws the given element with the provided painter with the style options specified by option.
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
Returns the value of the given pixel metric.
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
static void showText(const QPoint &pos, const QString &text, QWidget *w=nullptr)
Shows text as a "What's This?" window, at global position pos.
static bool inWhatsThisMode()
Returns true if the user interface is in "What's This?" mode; otherwise returns false.
Combined button and popup list for selecting options.
@ MouseEventNotSynthesized
@ AA_DontUseNativeMenuBar
AudioChannelLayoutTag tag
constexpr const T & qMax(const T &a, const T &b)
GLboolean GLboolean GLboolean b
GLuint64 GLenum void * handle
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble GLdouble GLdouble q
QtConcurrent::task([]{ qDebug("Hello, world!");}).spawn(FutureResult void increment(QPromise< int > &promise, int i)
[10]
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
bool contains(const AT &t) const noexcept
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent