summaryrefslogtreecommitdiff
path: root/src/controls/qquickmenu.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@digia.com>2014-09-26 10:56:26 +0200
committerJ-P Nurmi <jpnurmi@digia.com>2014-09-30 15:27:06 +0200
commite1ba563285270fd20e0aa8b9692b1bf1686b0128 (patch)
tree642863bfafe1287b45a10a14d3839a8951a16a41 /src/controls/qquickmenu.cpp
parent00665083ce5ccccab00b852164f03fe1efa9c504 (diff)
downloadqtquickcontrols-e1ba563285270fd20e0aa8b9692b1bf1686b0128.tar.gz
qquickmenu: add support for providing a target rect to __popup()
Using a target rect as menu location instead of a position has been supported in QPlatformMenu for a while. The reason for specifying a rect instead of a position is that then the OS can decide if the popup should be placed above or below the target rect so that it fits inside the screen. A typical example is when showing an edit menu around a text selection. If the selection (target rectangle) is far up on the screen, the popup (with arrow) will be placed below the selection instead of above, which is the normal. Change-Id: Ie6cd6a92f1d9ef480c1e455960021c7f18f86569 Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src/controls/qquickmenu.cpp')
-rw-r--r--src/controls/qquickmenu.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/controls/qquickmenu.cpp b/src/controls/qquickmenu.cpp
index f96a326e..69328349 100644
--- a/src/controls/qquickmenu.cpp
+++ b/src/controls/qquickmenu.cpp
@@ -377,10 +377,10 @@ void QQuickMenu::popup()
if (QQuickWindow *parentWindow = findParentWindow())
mousePos = parentWindow->mapFromGlobal(mousePos);
- __popup(mousePos.x(), mousePos.y());
+ __popup(QRectF(mousePos.x(), mousePos.y(), 0, 0));
}
-void QQuickMenu::__popup(qreal x, qreal y, int atItemIndex, MenuType menuType)
+void QQuickMenu::__popup(const QRectF &targetRect, int atItemIndex, MenuType menuType)
{
if (popupVisible()) {
__closeMenu();
@@ -401,14 +401,16 @@ void QQuickMenu::__popup(qreal x, qreal y, int atItemIndex, MenuType menuType)
parentWindow = renderWindow; // may not be a QQuickWindow anymore (happens when using QQuickWidget)
if (m_platformMenu) {
- QPointF screenPosition(x + m_xOffset, y + m_yOffset);
+ QRectF globalTargetRect = targetRect.translated(m_xOffset, m_yOffset);
if (visualItem()) {
- if (qGuiApp->isRightToLeft())
- screenPosition.rx() -= qMax(static_cast<qreal>(m_minimumWidth), m_menuContentItem->width());
- screenPosition = visualItem()->mapToScene(screenPosition);
+ if (qGuiApp->isRightToLeft()) {
+ qreal w = qMax(static_cast<qreal>(m_minimumWidth), m_menuContentItem->width());
+ globalTargetRect.moveLeft(w - targetRect.x() - targetRect.width());
+ }
+ globalTargetRect = visualItem()->mapRectToScene(globalTargetRect);
}
m_platformMenu->setMenuType(QPlatformMenu::MenuType(menuType));
- m_platformMenu->showPopup(parentWindow, screenPosition.toPoint(), atItem ? atItem->platformItem() : 0);
+ m_platformMenu->showPopup(parentWindow, globalTargetRect.toRect(), atItem ? atItem->platformItem() : 0);
} else {
m_popupWindow = new QQuickMenuPopupWindow();
if (visualItem())
@@ -421,7 +423,7 @@ void QQuickMenu::__popup(qreal x, qreal y, int atItemIndex, MenuType menuType)
connect(m_popupWindow, SIGNAL(visibleChanged(bool)), this, SLOT(windowVisibleChanged(bool)));
connect(m_popupWindow, SIGNAL(geometryChanged()), this, SIGNAL(__popupGeometryChanged()));
- m_popupWindow->setPosition(x + m_xOffset, y + m_yOffset);
+ m_popupWindow->setPosition(targetRect.x() + m_xOffset, targetRect.y() + targetRect.height() + m_yOffset);
m_popupWindow->show();
}
}