summaryrefslogtreecommitdiffstats
path: root/src/platformsupport
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/platformsupport
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/platformsupport')
-rw-r--r--src/platformsupport/dbusmenu/qdbusplatformmenu.cpp9
-rw-r--r--src/platformsupport/dbusmenu/qdbusplatformmenu_p.h4
2 files changed, 11 insertions, 2 deletions
diff --git a/src/platformsupport/dbusmenu/qdbusplatformmenu.cpp b/src/platformsupport/dbusmenu/qdbusplatformmenu.cpp
index 93c822cefb..a64e107e71 100644
--- a/src/platformsupport/dbusmenu/qdbusplatformmenu.cpp
+++ b/src/platformsupport/dbusmenu/qdbusplatformmenu.cpp
@@ -75,6 +75,9 @@ void QDBusPlatformMenuItem::setIcon(const QIcon &icon)
m_icon = icon;
}
+/*!
+ Set a submenu under this menu item.
+*/
void QDBusPlatformMenuItem::setMenu(QPlatformMenu *menu)
{
m_subMenu = static_cast<QDBusPlatformMenu *>(menu);
@@ -242,8 +245,12 @@ const QList<QDBusPlatformMenuItem *> QDBusPlatformMenu::items() const
QPlatformMenuItem *QDBusPlatformMenu::createMenuItem() const
{
QDBusPlatformMenuItem *ret = new QDBusPlatformMenuItem();
- ret->setMenu(const_cast<QDBusPlatformMenu *>(this));
return ret;
}
+QPlatformMenu *QDBusPlatformMenu::createSubMenu() const
+{
+ return new QDBusPlatformMenu;
+}
+
QT_END_NAMESPACE
diff --git a/src/platformsupport/dbusmenu/qdbusplatformmenu_p.h b/src/platformsupport/dbusmenu/qdbusplatformmenu_p.h
index 2519533e32..16bb4f195c 100644
--- a/src/platformsupport/dbusmenu/qdbusplatformmenu_p.h
+++ b/src/platformsupport/dbusmenu/qdbusplatformmenu_p.h
@@ -124,7 +124,7 @@ public:
quintptr tag()const Q_DECL_OVERRIDE { return m_tag; }
void setTag(quintptr tag) Q_DECL_OVERRIDE;
- const QString text() { return m_text; }
+ const QString text() const { return m_text; }
void setText(const QString &text) Q_DECL_OVERRIDE;
void setIcon(const QIcon &icon) Q_DECL_OVERRIDE;
void setEnabled(bool enabled) Q_DECL_OVERRIDE;
@@ -150,6 +150,7 @@ public:
const QList<QDBusPlatformMenuItem *> items() const;
QPlatformMenuItem *createMenuItem() const Q_DECL_OVERRIDE;
+ QPlatformMenu *createSubMenu() const Q_DECL_OVERRIDE;
bool operator==(const QDBusPlatformMenu& other) { return m_tag == other.m_tag; }
@@ -175,6 +176,7 @@ private:
uint m_revision;
QHash<quintptr, QDBusPlatformMenuItem *> m_itemsByTag;
QList<QDBusPlatformMenuItem *> m_items;
+ QDBusPlatformMenuItem *m_containingMenuItem;
static QList<QDBusPlatformMenu *> m_topLevelMenus;
};