summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@digia.com>2015-05-19 12:36:55 +0200
committerShawn Rutledge <shawn.rutledge@digia.com>2015-05-21 05:17:08 +0000
commitd8bfd812c3383e24196588f5d3e1de4719fcac02 (patch)
treea852f31638a8ec0e9289db7fdb0ea610995c64d3 /src/widgets
parent2858a3c91b745357c1fa99b49b24705a155c6609 (diff)
D-Bus system tray icon: submenus can be created after context menu
QMenuPrivate::init() calls QPlatformTheme::createPlatformMenu() to create a platform menu, but on Linux, that returns null for now. QSystemTrayIcon::setContextMenu() results in recursive calls to QSystemTrayIconPrivate::addPlatformMenu() which then calls QDBusTrayIcon::createMenu() for the context menu and each submenu. However if a submenu is added afterwards, a corresponding platform menu is not immediately created. Now copyActionToPlatformItem() will detect and create the missing platform submenu, by calling a new method: DBusPlatformMenu::createSubMenu(). This is because there is no way of knowing that it's a tray-specific context menu (which is so far the only case in which we use DBusPlatformMenu). So, QPlatformMenu::createSubMenu() needs to exist as a new QPA interface for this use case. Task-number: QTBUG-45803 Change-Id: Ib319e873082196515ea0580d70d069099cf2c175 Reviewed-by: Jørgen Lind <jorgen.lind@theqtcompany.com>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/widgets/qmenu.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp
index 1749f9d8c7..2f0dcc49d1 100644
--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -183,7 +183,7 @@ void QMenuPrivate::setPlatformMenu(QPlatformMenu *menu)
}
// forward declare function
-static void copyActionToPlatformItem(const QAction *action, QPlatformMenuItem* item);
+static void copyActionToPlatformItem(const QAction *action, QPlatformMenuItem *item, QPlatformMenu *itemsMenu);
void QMenuPrivate::syncPlatformMenu()
{
@@ -200,7 +200,7 @@ void QMenuPrivate::syncPlatformMenu()
menuItem->setTag(reinterpret_cast<quintptr>(action));
QObject::connect(menuItem, SIGNAL(activated()), action, SLOT(trigger()), Qt::QueuedConnection);
QObject::connect(menuItem, SIGNAL(hovered()), action, SIGNAL(hovered()), Qt::QueuedConnection);
- copyActionToPlatformItem(action, menuItem);
+ copyActionToPlatformItem(action, menuItem, platformMenu.data());
platformMenu->insertMenuItem(menuItem, beforeItem);
beforeItem = menuItem;
}
@@ -3105,7 +3105,7 @@ QMenu::timerEvent(QTimerEvent *e)
}
}
-static void copyActionToPlatformItem(const QAction *action, QPlatformMenuItem* item)
+static void copyActionToPlatformItem(const QAction *action, QPlatformMenuItem *item, QPlatformMenu *itemsMenu)
{
item->setText(action->text());
item->setIsSeparator(action->isSeparator());
@@ -3131,6 +3131,8 @@ static void copyActionToPlatformItem(const QAction *action, QPlatformMenuItem* i
item->setEnabled(action->isEnabled());
if (action->menu()) {
+ if (!action->menu()->platformMenu())
+ action->menu()->setPlatformMenu(itemsMenu->createSubMenu());
item->setMenu(action->menu()->platformMenu());
} else {
item->setMenu(0);
@@ -3185,7 +3187,7 @@ void QMenu::actionEvent(QActionEvent *e)
menuItem->setTag(reinterpret_cast<quintptr>(e->action()));
QObject::connect(menuItem, SIGNAL(activated()), e->action(), SLOT(trigger()));
QObject::connect(menuItem, SIGNAL(hovered()), e->action(), SIGNAL(hovered()));
- copyActionToPlatformItem(e->action(), menuItem);
+ copyActionToPlatformItem(e->action(), menuItem, d->platformMenu);
QPlatformMenuItem* beforeItem = d->platformMenu->menuItemForTag(reinterpret_cast<quintptr>(e->before()));
d->platformMenu->insertMenuItem(menuItem, beforeItem);
} else if (e->type() == QEvent::ActionRemoved) {
@@ -3195,7 +3197,7 @@ void QMenu::actionEvent(QActionEvent *e)
} else if (e->type() == QEvent::ActionChanged) {
QPlatformMenuItem *menuItem = d->platformMenu->menuItemForTag(reinterpret_cast<quintptr>(e->action()));
if (menuItem) {
- copyActionToPlatformItem(e->action(), menuItem);
+ copyActionToPlatformItem(e->action(), menuItem, d->platformMenu);
d->platformMenu->syncMenuItem(menuItem);
}
}