diff options
author | Liang Qi <liang.qi@qt.io> | 2017-11-09 11:05:03 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-11-09 11:47:57 +0100 |
commit | 88cf04458002d863750e9121af7dcd9bcbfaa169 (patch) | |
tree | caccae211eef1a27fa5caae3a8403830b615bd5e /src/widgets/widgets/qmenubar.cpp | |
parent | 19b0ce5daa31e2ffebfcf2701143742302f1deb4 (diff) | |
parent | 579d0cb2bed193ccb1901b121a360f85d1c57a54 (diff) |
Merge remote-tracking branch 'origin/5.9' into 5.10
Conflicts:
src/gui/kernel/qwindow.cpp
src/plugins/platforms/cocoa/qcocoawindow.mm
src/plugins/platforms/windows/qwindowssystemtrayicon.cpp
src/plugins/platforms/xcb/qxcbconnection_xi2.cpp
tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp
tests/auto/widgets/kernel/qaction/tst_qaction.cpp
Change-Id: Ifa515dc0ece7eb1471b00c1214149629a7e6a233
Diffstat (limited to 'src/widgets/widgets/qmenubar.cpp')
-rw-r--r-- | src/widgets/widgets/qmenubar.cpp | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp index cc6f39c439..ece2a0a9c9 100644 --- a/src/widgets/widgets/qmenubar.cpp +++ b/src/widgets/widgets/qmenubar.cpp @@ -1188,7 +1188,7 @@ void QMenuBar::leaveEvent(QEvent *) d->setCurrentAction(0); } -QPlatformMenu *QMenuBarPrivate::getPlatformMenu(QAction *action) +QPlatformMenu *QMenuBarPrivate::getPlatformMenu(const QAction *action) { if (!action || !action->menu()) return 0; @@ -1203,6 +1203,29 @@ QPlatformMenu *QMenuBarPrivate::getPlatformMenu(QAction *action) return platformMenu; } +QPlatformMenu *QMenuBarPrivate::findInsertionPlatformMenu(const QAction *action) +{ + Q_Q(QMenuBar); + QPlatformMenu *beforeMenu = nullptr; + for (int beforeIndex = indexOf(const_cast<QAction *>(action)) + 1; + !beforeMenu && (beforeIndex < q->actions().size()); + ++beforeIndex) { + beforeMenu = getPlatformMenu(q->actions().at(beforeIndex)); + } + + return beforeMenu; +} + +void QMenuBarPrivate::copyActionToPlatformMenu(const QAction *action, QPlatformMenu *menu) +{ + const auto tag = reinterpret_cast<quintptr>(action); + if (menu->tag() != tag) + menu->setTag(tag); + menu->setText(action->text()); + menu->setVisible(action->isVisible()); + menu->setEnabled(action->isEnabled()); +} + /*! \reimp */ @@ -1219,16 +1242,9 @@ void QMenuBar::actionEvent(QActionEvent *e) if (e->type() == QEvent::ActionAdded) { QPlatformMenu *menu = d->getPlatformMenu(e->action()); if (menu) { - QPlatformMenu* beforeMenu = NULL; - for (int beforeIndex = d->indexOf(e->action()) + 1; - !beforeMenu && (beforeIndex < actions().size()); - ++beforeIndex) - { - beforeMenu = d->getPlatformMenu(actions().at(beforeIndex)); - } + d->copyActionToPlatformMenu(e->action(), menu); - menu->setTag(reinterpret_cast<quintptr>(e->action())); - menu->setText(e->action()->text()); + QPlatformMenu *beforeMenu = d->findInsertionPlatformMenu(e->action()); d->platformMenuBar->insertMenu(menu, beforeMenu); } } else if (e->type() == QEvent::ActionRemoved) { @@ -1236,7 +1252,7 @@ void QMenuBar::actionEvent(QActionEvent *e) if (menu) d->platformMenuBar->removeMenu(menu); } else if (e->type() == QEvent::ActionChanged) { - QPlatformMenu* cur = d->platformMenuBar->menuForTag(reinterpret_cast<quintptr>(e->action())); + QPlatformMenu *cur = d->platformMenuBar->menuForTag(reinterpret_cast<quintptr>(e->action())); QPlatformMenu *menu = d->getPlatformMenu(e->action()); // the menu associated with the action can change, need to @@ -1245,21 +1261,13 @@ void QMenuBar::actionEvent(QActionEvent *e) if (cur) d->platformMenuBar->removeMenu(cur); if (menu) { - menu->setTag(reinterpret_cast<quintptr>(e->action())); - - QPlatformMenu* beforeMenu = NULL; - for (int beforeIndex = d->indexOf(e->action()) + 1; - !beforeMenu && (beforeIndex < actions().size()); - ++beforeIndex) - { - beforeMenu = d->getPlatformMenu(actions().at(beforeIndex)); - } + d->copyActionToPlatformMenu(e->action(), menu); + + QPlatformMenu *beforeMenu = d->findInsertionPlatformMenu(e->action()); d->platformMenuBar->insertMenu(menu, beforeMenu); } } else if (menu) { - menu->setText(e->action()->text()); - menu->setVisible(e->action()->isVisible()); - menu->setEnabled(e->action()->isEnabled()); + d->copyActionToPlatformMenu(e->action(), menu); d->platformMenuBar->syncMenu(menu); } } |