From 708be449c3fcb284ccea89d1c32e974106968f20 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 20 Sep 2012 16:28:49 +0200 Subject: [PATCH] fix absolute screen position for menu position --- declarativeimports/plasmacomponents/qmenu.cpp | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/declarativeimports/plasmacomponents/qmenu.cpp b/declarativeimports/plasmacomponents/qmenu.cpp index 7f4673e1b..e2c90293d 100644 --- a/declarativeimports/plasmacomponents/qmenu.cpp +++ b/declarativeimports/plasmacomponents/qmenu.cpp @@ -165,7 +165,52 @@ void QMenuProxy::open(int x, int y) m_menu->addAction (item); } - QPoint screenPos = QApplication::activeWindow()->mapToGlobal(QPoint(x, y)); + QPoint screenPos; + + QGraphicsObject *parentItem; + if (m_visualParent) { + parentItem = qobject_cast(m_visualParent.data()); + } else { + parentItem = qobject_cast(parent()); + } + + if (!parentItem || !parentItem->scene()) { + open(0, 0); + return; + } + + QList views = parentItem->scene()->views(); + + if (views.size() < 1) { + open(0, 0); + return; + } + + QGraphicsView *view = 0; + if (views.size() == 1) { + view = views[0]; + } else { + QGraphicsView *found = 0; + QGraphicsView *possibleFind = 0; + foreach (QGraphicsView *v, views) { + if (v->sceneRect().intersects(parentItem->sceneBoundingRect()) || + v->sceneRect().contains(parentItem->scenePos())) { + if (v->isActiveWindow()) { + found = v; + } else { + possibleFind = v; + } + } + } + view = found ? found : possibleFind; + } + + if (view) { + screenPos = view->mapToGlobal(view->mapFromScene(parentItem->scenePos()+ QPoint(x, y))); + } else { + screenPos = QApplication::activeWindow()->mapToGlobal(QPoint(x, y)); + } + m_menu->popup(screenPos); m_status = DialogStatus::Open; emit statusChanged();