summaryrefslogtreecommitdiffstats
path: root/src/controls/qtmenu.cpp
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@digia.com>2013-03-14 13:28:50 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-14 18:23:03 +0100
commit693cc7c041e1fb7f44628ee1e8a1a64bf999195d (patch)
treeb7849fcab0a03197aae97b0a0202f4f84df78e1b /src/controls/qtmenu.cpp
parentc29f0a978ac436cbc408d80059b541683e93ae85 (diff)
QtMenuPopupWindow: Refactor code away from QtMenu
Also prepares to expose the class in QML, since it is needed for the (in progress) drop-down list implementation. Change-Id: I978f26590594050f52bd2244fe2c264967b65b38 Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src/controls/qtmenu.cpp')
-rw-r--r--src/controls/qtmenu.cpp37
1 files changed, 7 insertions, 30 deletions
diff --git a/src/controls/qtmenu.cpp b/src/controls/qtmenu.cpp
index 0fe475724..150efcee1 100644
--- a/src/controls/qtmenu.cpp
+++ b/src/controls/qtmenu.cpp
@@ -235,40 +235,17 @@ void QtMenu::__popup(qreal x, qreal y, int atItemIndex)
m_platformMenu->showPopup(parentWindow, screenPosition.toPoint(), atItem ? atItem->platformItem() : 0);
} else {
m_popupWindow = new QtMenuPopupWindow();
- m_popupWindow->setParentWindow(parentWindow);
+ if (visualItem())
+ m_popupWindow->setParentItem(visualItem());
+ else
+ m_popupWindow->setParentWindow(parentWindow);
m_popupWindow->setMenuContentItem(m_menuContentItem);
- connect(m_popupWindow, SIGNAL(visibleChanged(bool)), this, SLOT(windowVisibleChanged(bool)));
+ m_popupWindow->setItemAt(atItem ? atItem->visualItem() : 0);
- if (parentWindow) {
- if (visualItem()) {
- QPointF pos = visualItem()->mapToItem(parentWindow->contentItem(), QPointF(x, y));
- x = pos.x();
- y = pos.y();
- }
-
- x += parentWindow->geometry().left();
- y += parentWindow->geometry().top();
- }
-
- QQuickItem *visualItem = atItem ? atItem->visualItem() : 0;
- if (visualItem) {
- QPointF pos = visualItem->position();
- x -= pos.x();
- y -= pos.y();
- m_popupWindow->setItemAt(visualItem);
- }
-
- qreal initialWidth = qMax(qreal(1), m_menuContentItem->width());
- qreal initialHeight = qMax(qreal(1), m_menuContentItem->height());
-
- if (!qobject_cast<QtMenuPopupWindow *>(parentWindow)) // No need for parent menu windows
- if (QQuickItem *mg = parentWindow->mouseGrabberItem())
- mg->ungrabMouse();
+ connect(m_popupWindow, SIGNAL(visibleChanged(bool)), this, SLOT(windowVisibleChanged(bool)));
- m_popupWindow->setGeometry(x, y, initialWidth, initialHeight);
+ m_popupWindow->setPosition(x, y);
m_popupWindow->show();
- m_popupWindow->setMouseGrabEnabled(true); // Needs to be done after calling show()
- m_popupWindow->setKeyboardGrabEnabled(true);
}
}