summaryrefslogtreecommitdiff
path: root/src/controls/Private
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/Private
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/Private')
-rw-r--r--src/controls/Private/EditMenu_base.qml2
-rw-r--r--src/controls/Private/EditMenu_ios.qml14
-rw-r--r--src/controls/Private/MenuContentItem.qml2
3 files changed, 8 insertions, 10 deletions
diff --git a/src/controls/Private/EditMenu_base.qml b/src/controls/Private/EditMenu_base.qml
index aed4e464..597541bc 100644
--- a/src/controls/Private/EditMenu_base.qml
+++ b/src/controls/Private/EditMenu_base.qml
@@ -106,7 +106,7 @@ Item {
if (control.menu) {
getMenuInstance().__dismissMenu();
var menuPos = mapToItem(null, mouse.x, mouse.y)
- getMenuInstance().__popup(menuPos.x, menuPos.y, -1, MenuPrivate.EditMenu);
+ getMenuInstance().__popup(Qt.rect(menuPos.x, menuPos.y, 0, 0), -1, MenuPrivate.EditMenu);
}
}
}
diff --git a/src/controls/Private/EditMenu_ios.qml b/src/controls/Private/EditMenu_ios.qml
index 1fe92e46..aeb21b03 100644
--- a/src/controls/Private/EditMenu_ios.qml
+++ b/src/controls/Private/EditMenu_ios.qml
@@ -173,15 +173,13 @@ Item {
&& (!cursorHandle.pressed && !selectionHandle.pressed)
&& (!flickable || !flickable.moving)
&& (cursorHandle.delegate)) {
- // center menu on top of selection:
- var r1 = input.positionToRectangle(input.selectionStart);
- var r2 = input.cursorRectangle;
- var xMin = Math.min(r1.x, r2.x);
- var xMax = Math.max(r1.x, r2.x);
- var centerX = xMin + ((xMax - xMin) / 2);
- var popupPos = input.mapToItem(null, centerX, r1.y);
+ var p1 = input.positionToRectangle(input.selectionStart);
+ var p2 = input.positionToRectangle(input.selectionEnd);
+ var topLeft = input.mapToItem(null, p1.x, p1.y);
+ var size = Qt.size(p2.x - p1.x + p1.width, p2.y - p1.y + p1.height)
+ var targetRect = Qt.rect(topLeft.x, topLeft.y, size.width, size.height);
getMenuInstance().__dismissMenu();
- getMenuInstance().__popup(popupPos.x, popupPos.y, -1, MenuPrivate.EditMenu);
+ getMenuInstance().__popup(targetRect, -1, MenuPrivate.EditMenu);
} else {
getMenuInstance().__dismissMenu();
}
diff --git a/src/controls/Private/MenuContentItem.qml b/src/controls/Private/MenuContentItem.qml
index 62e5d033..a503d1d4 100644
--- a/src/controls/Private/MenuContentItem.qml
+++ b/src/controls/Private/MenuContentItem.qml
@@ -207,7 +207,7 @@ Loader {
if (__menu.__currentIndex === __menuItemIndex) {
if (__menuItem.__usingDefaultStyle)
__menuItem.style = __menu.style
- __menuItem.__popup(menuFrameLoader.width - (d.style.submenuOverlap + d.style.padding.right), -d.style.padding.top, -1)
+ __menuItem.__popup(Qt.rect(menuFrameLoader.width - (d.style.submenuOverlap + d.style.padding.right), -d.style.padding.top, 0, 0), -1)
}
} else {
openMenuTimer.start()