From 9976c47ad98cfa274b18fefd40f3c478008e646a Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 24 Feb 2014 14:01:05 +0100 Subject: [PATCH] add a transientParent property if this contextmenu is done from a Dialog, add this as transientParent --- src/declarativeimports/plasmacomponents/qmenu.cpp | 15 +++++++++++++++ src/declarativeimports/plasmacomponents/qmenu.h | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/src/declarativeimports/plasmacomponents/qmenu.cpp b/src/declarativeimports/plasmacomponents/qmenu.cpp index 1610ff600..a9b41a9a4 100644 --- a/src/declarativeimports/plasmacomponents/qmenu.cpp +++ b/src/declarativeimports/plasmacomponents/qmenu.cpp @@ -91,6 +91,21 @@ void QMenuProxy::setVisualParent(QObject *parent) emit visualParentChanged(); } +QWindow *QMenuProxy::transientParent() +{ + return m_menu->windowHandle()->transientParent(); +} + +void QMenuProxy::setTransientParent(QWindow *parent) +{ + if (parent == m_menu->windowHandle()->transientParent()) { + return; + } + + m_menu->windowHandle()->setTransientParent(parent); + emit transientParentChanged(); +} + bool QMenuProxy::event(QEvent *event) { switch (event->type()) { diff --git a/src/declarativeimports/plasmacomponents/qmenu.h b/src/declarativeimports/plasmacomponents/qmenu.h index 78aadeca8..d1a5b7390 100644 --- a/src/declarativeimports/plasmacomponents/qmenu.h +++ b/src/declarativeimports/plasmacomponents/qmenu.h @@ -35,6 +35,11 @@ class QMenuProxy : public QObject Q_PROPERTY(QQmlListProperty content READ content CONSTANT) Q_CLASSINFO("DefaultProperty", "content") + /** + * This is a hint to the window manager that this window is a dialog or pop-up on behalf of the given window. + */ + Q_PROPERTY(QWindow *transientParent READ transientParent WRITE setTransientParent NOTIFY transientParentChanged) + /** * the visualParent is used to position the menu. it can be an item on the scene, like a button (that will open the menu on clicked) or another menuitem (in this case this will be a submenu) */ @@ -53,6 +58,9 @@ public: QObject *visualParent() const; void setVisualParent(QObject *parent); + QWindow *transientParent(); + void setTransientParent(QWindow *parent); + Q_INVOKABLE void open(int x = 0, int y = 0); //Q_INVOKABLE void open(); Q_INVOKABLE void close(); @@ -66,6 +74,7 @@ protected: Q_SIGNALS: void statusChanged(); void visualParentChanged(); + void transientParentChanged(); void triggered(QMenuItem *item); void triggeredIndex(int index);