summaryrefslogtreecommitdiff
path: root/src/controls/qtmenupopupwindow.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/qtmenupopupwindow.cpp
parentc29f0a978ac436cbc408d80059b541683e93ae85 (diff)
downloadqtquickcontrols-693cc7c041e1fb7f44628ee1e8a1a64bf999195d.tar.gz
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/qtmenupopupwindow.cpp')
-rw-r--r--src/controls/qtmenupopupwindow.cpp52
1 files changed, 50 insertions, 2 deletions
diff --git a/src/controls/qtmenupopupwindow.cpp b/src/controls/qtmenupopupwindow.cpp
index 406dfff0..3a7ad737 100644
--- a/src/controls/qtmenupopupwindow.cpp
+++ b/src/controls/qtmenupopupwindow.cpp
@@ -49,12 +49,59 @@
QT_BEGIN_NAMESPACE
QtMenuPopupWindow::QtMenuPopupWindow(QWindow *parent) :
- QQuickWindow(parent), m_mouseMoved(false), m_itemAt(0)
+ QQuickWindow(parent), m_mouseMoved(false), m_itemAt(0),
+ m_parentItem(0), m_menuContentItem(0)
{
setFlags(Qt::Popup);
setModality(Qt::WindowModal);
}
+void QtMenuPopupWindow::show()
+{
+ qreal posx = x();
+ qreal posy = y();
+ if (QQuickWindow *parentWindow = qobject_cast<QQuickWindow *>(transientParent())) {
+ if (m_parentItem) {
+ QPointF pos = m_parentItem->mapToItem(parentWindow->contentItem(), QPointF(posx, posy));
+ posx = pos.x();
+ posy = pos.y();
+ }
+
+ posx += parentWindow->geometry().left();
+ posy += parentWindow->geometry().top();
+ }
+
+ if (m_itemAt) {
+ QPointF pos = m_itemAt->position();
+ posx -= pos.x();
+ posy -= pos.y();
+ }
+
+ if (m_menuContentItem) {
+ qreal initialWidth = qMax(qreal(1), m_menuContentItem->width());
+ qreal initialHeight = qMax(qreal(1), m_menuContentItem->height());
+ setGeometry(posx, posy, initialWidth, initialHeight);
+ } else {
+ setPosition(posx, posy);
+ }
+
+ if (!qobject_cast<QtMenuPopupWindow *>(transientParent())) // No need for parent menu windows
+ if (QQuickWindow *w = qobject_cast<QQuickWindow *>(transientParent()))
+ if (QQuickItem *mg = w->mouseGrabberItem())
+ mg->ungrabMouse();
+
+ QQuickWindow::show();
+ setMouseGrabEnabled(true); // Needs to be done after calling show()
+ setKeyboardGrabEnabled(true);
+}
+
+void QtMenuPopupWindow::setParentItem(QQuickItem *item)
+{
+ m_parentItem = item;
+ if (m_parentItem)
+ setParentWindow(m_parentItem->window());
+}
+
void QtMenuPopupWindow::setMenuContentItem(QQuickItem *contentItem)
{
if (!contentItem)
@@ -63,9 +110,10 @@ void QtMenuPopupWindow::setMenuContentItem(QQuickItem *contentItem)
contentItem->setParentItem(this->contentItem());
connect(contentItem, SIGNAL(widthChanged()), this, SLOT(updateSize()));
connect(contentItem, SIGNAL(heightChanged()), this, SLOT(updateSize()));
+ m_menuContentItem = contentItem;
}
-void QtMenuPopupWindow::setItemAt(const QQuickItem *menuItem)
+void QtMenuPopupWindow::setItemAt(QQuickItem *menuItem)
{
if (m_itemAt) {
disconnect(m_itemAt, SIGNAL(xChanged()), this, SLOT(updatePosition()));