From 0ef4080e4f99499b9d8495e24e110727cfc8b803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCgler?= Date: Tue, 26 Mar 2013 22:17:25 +0100 Subject: [PATCH] positioning for context menu --- src/declarativeimports/plasmacomponents/qmenu.cpp | 10 ++++++++-- .../plasmacomponents/qmenuitem.cpp | 13 ++++++++----- src/declarativeimports/plasmacomponents/qmenuitem.h | 7 ++++--- .../contents/ui/PlasmoidPage.qml | 5 +++-- .../testcomponentsapplet/contents/ui/TestMenu.qml | 7 ++++++- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/declarativeimports/plasmacomponents/qmenu.cpp b/src/declarativeimports/plasmacomponents/qmenu.cpp index 046053a63..64c584f9c 100644 --- a/src/declarativeimports/plasmacomponents/qmenu.cpp +++ b/src/declarativeimports/plasmacomponents/qmenu.cpp @@ -22,8 +22,7 @@ #include #include #include -// #include -// #include +#include #include #include "plasmacomponentsplugin.h" @@ -174,6 +173,12 @@ void QMenuProxy::open(int x, int y) } else { parentItem = qobject_cast(parent()); } + QPointF pos = parentItem->mapToScene(QPointF(x, y)); + //qDebug() << "I've an Item at " << pos; + if (parentItem->window() && parentItem->window()->screen()) { + pos = parentItem->window()->mapToGlobal(pos.toPoint()); + } + screenPos = pos.toPoint(); /* if (!parentItem || !parentItem->scene()) { m_menu->popup(QPoint(0, 0)); @@ -235,6 +240,7 @@ void QMenuProxy::open() } else { parentItem = qobject_cast(parent()); } + /* if (!parentItem || !parentItem->scene()) { m_menu->popup(QPoint(0, 0)); diff --git a/src/declarativeimports/plasmacomponents/qmenuitem.cpp b/src/declarativeimports/plasmacomponents/qmenuitem.cpp index 5d3cdd63e..791ce4b53 100644 --- a/src/declarativeimports/plasmacomponents/qmenuitem.cpp +++ b/src/declarativeimports/plasmacomponents/qmenuitem.cpp @@ -19,6 +19,7 @@ #include "qmenuitem.h" + QMenuItem::QMenuItem(QQuickItem *parent) : QQuickItem(parent), m_action(0) @@ -43,15 +44,17 @@ void QMenuItem::setAction(QAction* a) } } -QIcon QMenuItem::icon() const +QString QMenuItem::icon() const { - return m_action->icon(); + return m_icon; } -void QMenuItem::setIcon(const QIcon& i) +void QMenuItem::setIcon(const QString& i) { - m_action->setIcon(i); - emit iconChanged(); + if (i != m_icon) { + m_action->setIcon(QIcon::fromTheme(i)); + emit iconChanged(); + } } bool QMenuItem::separator() const diff --git a/src/declarativeimports/plasmacomponents/qmenuitem.h b/src/declarativeimports/plasmacomponents/qmenuitem.h index 20ab11279..c011669d6 100644 --- a/src/declarativeimports/plasmacomponents/qmenuitem.h +++ b/src/declarativeimports/plasmacomponents/qmenuitem.h @@ -38,7 +38,7 @@ class QMenuItem : public QQuickItem */ Q_PROPERTY(bool separator READ separator WRITE setSeparator NOTIFY separatorChanged) Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) - Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY iconChanged) + Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged) Q_PROPERTY(QAction* action READ action WRITE setAction NOTIFY actionChanged) public: @@ -46,8 +46,8 @@ public: QAction* action() const; void setAction(QAction* a); - QIcon icon() const; - void setIcon(const QIcon& i); + QString icon() const; + void setIcon(const QString& i); bool separator() const; void setSeparator(bool s); QString text() const; @@ -63,6 +63,7 @@ Q_SIGNALS: private: QAction* m_action; + QString m_icon; }; #endif // QMENUITEM_H diff --git a/src/shell/applets/testcomponentsapplet/contents/ui/PlasmoidPage.qml b/src/shell/applets/testcomponentsapplet/contents/ui/PlasmoidPage.qml index a6fcd518d..5b621309a 100644 --- a/src/shell/applets/testcomponentsapplet/contents/ui/PlasmoidPage.qml +++ b/src/shell/applets/testcomponentsapplet/contents/ui/PlasmoidPage.qml @@ -58,7 +58,6 @@ PlasmaComponents.Page { if (checked) plasmoid.backgroundHints = 2; } } - } PlasmaComponents.Button { @@ -71,6 +70,7 @@ PlasmaComponents.Page { } PlasmaComponents.Button { + id: ctxButton height: theme.iconSizes.desktop text: "Context Menu" Loader { @@ -80,8 +80,9 @@ PlasmaComponents.Page { if (menuLoader.source == "") { menuLoader.source = "TestMenu.qml" } else { - menuLoader.source = "" + //menuLoader.source = "" } + menuLoader.item.open(0, height); } } diff --git a/src/shell/applets/testcomponentsapplet/contents/ui/TestMenu.qml b/src/shell/applets/testcomponentsapplet/contents/ui/TestMenu.qml index f52e4dfd0..b84197b49 100644 --- a/src/shell/applets/testcomponentsapplet/contents/ui/TestMenu.qml +++ b/src/shell/applets/testcomponentsapplet/contents/ui/TestMenu.qml @@ -39,9 +39,14 @@ PlasmaComponents.Menu { onClicked: print(" Clicked on : " + text) } + PlasmaComponents.MenuItem { + text: "White Tip Reef Shark" + icon: "kmag" + onClicked: print(" Clicked on : " + text) + } + Component.onCompleted:{ print("TestMenu.qml served .. opening"); - testMenu.open(); } }