diff options
author | Richard Moe Gustavsen <richard.gustavsen@digia.com> | 2014-09-23 15:53:49 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@digia.com> | 2014-09-24 13:53:29 +0200 |
commit | 1a1a19f74e7f55388da043ae1e2e34e334d5f740 (patch) | |
tree | 6705740218c6ba15c61cf8ebd45a2ec4bf569c3c /src/controls/Private | |
parent | 094528f9206d3f03220d0bc67951c7034e02dca6 (diff) | |
download | qtquickcontrols-1a1a19f74e7f55388da043ae1e2e34e334d5f740.tar.gz |
EditMenu: let menu property be a component to lazy load it
Since all input fields have a menu assigned to it by
default (which in most cases never will be shown), it should
be an optimization to await creating it until needed.
Change-Id: I5777bbdae42103981e9b2f5ddfdfd763acea07ae
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src/controls/Private')
-rw-r--r-- | src/controls/Private/EditMenu.qml | 22 | ||||
-rw-r--r-- | src/controls/Private/EditMenu_base.qml | 63 | ||||
-rw-r--r-- | src/controls/Private/EditMenu_ios.qml | 10 |
3 files changed, 61 insertions, 34 deletions
diff --git a/src/controls/Private/EditMenu.qml b/src/controls/Private/EditMenu.qml index c0faf9ff..f4d80bd5 100644 --- a/src/controls/Private/EditMenu.qml +++ b/src/controls/Private/EditMenu.qml @@ -47,7 +47,27 @@ Loader { property Item cursorHandle property Item selectionHandle property Flickable flickable - property Menu defaultMenu: item && item.defaultMenu ? item.defaultMenu : null + property Component defaultMenu: item && item.defaultMenu ? item.defaultMenu : null + property Menu menuInstance: null + + Connections { + target: control + onMenuChanged: { + if (menuInstance !== null) { + menuInstance.destroy() + menuInstance = null + } + } + } + + function getMenuInstance() + { + // Lazy load menu when first requested + if (!menuInstance && control.menu) { + menuInstance = control.menu.createObject(input); + } + return menuInstance; + } source: Qt.resolvedUrl("EditMenu_" + (Qt.platform.os === "ios" ? "ios" : "base") + ".qml") } diff --git a/src/controls/Private/EditMenu_base.qml b/src/controls/Private/EditMenu_base.qml index 88cef62a..aed4e464 100644 --- a/src/controls/Private/EditMenu_base.qml +++ b/src/controls/Private/EditMenu_base.qml @@ -42,45 +42,52 @@ import QtQuick.Controls 1.2 import QtQuick.Controls.Private 1.0 Item { + id: editMenuBase anchors.fill: parent - Action { + Component { id: cutAction - text: "Cu&t" - shortcut: StandardKey.Cut - iconName: "edit-cut" - enabled: !input.readOnly && selectionStart !== selectionEnd - onTriggered: { - input.cut(); - input.select(input.cursorPosition, input.cursorPosition); + Action { + text: "Cu&t" + shortcut: StandardKey.Cut + iconName: "edit-cut" + enabled: !input.readOnly && selectionStart !== selectionEnd + onTriggered: { + input.cut(); + input.select(input.cursorPosition, input.cursorPosition); + } } } - Action { + Component { id: copyAction - text: "&Copy" - shortcut: StandardKey.Copy - iconName: "edit-copy" - enabled: input.selectionStart !== input.selectionEnd - onTriggered: { - input.copy(); - input.select(input.cursorPosition, input.cursorPosition); + Action { + text: "&Copy" + shortcut: StandardKey.Copy + iconName: "edit-copy" + enabled: input.selectionStart !== input.selectionEnd + onTriggered: { + input.copy(); + input.select(input.cursorPosition, input.cursorPosition); + } } } - Action { + Component { id: pasteAction - text: "&Paste" - shortcut: StandardKey.Paste - iconName: "edit-paste" - enabled: input.canPaste - onTriggered: input.paste() + Action { + text: "&Paste" + shortcut: StandardKey.Paste + iconName: "edit-paste" + enabled: input.canPaste + onTriggered: input.paste() + } } - property Menu defaultMenu: Menu { - MenuItem { action: cutAction } - MenuItem { action: copyAction } - MenuItem { action: pasteAction } + property Component defaultMenu: Menu { + MenuItem { action: cutAction.createObject(editMenuBase) } + MenuItem { action: copyAction.createObject(editMenuBase) } + MenuItem { action: pasteAction.createObject(editMenuBase) } } MouseArea { @@ -97,9 +104,9 @@ Item { input.activate() if (control.menu) { - control.menu.__dismissMenu(); + getMenuInstance().__dismissMenu(); var menuPos = mapToItem(null, mouse.x, mouse.y) - control.menu.__popup(menuPos.x, menuPos.y, -1, MenuPrivate.EditMenu); + getMenuInstance().__popup(menuPos.x, menuPos.y, -1, MenuPrivate.EditMenu); } } } diff --git a/src/controls/Private/EditMenu_ios.qml b/src/controls/Private/EditMenu_ios.qml index e41e0cb6..1fe92e46 100644 --- a/src/controls/Private/EditMenu_ios.qml +++ b/src/controls/Private/EditMenu_ios.qml @@ -46,7 +46,7 @@ Item { anchors.fill: parent property bool __showMenuFromTouchAndHold: false - property Menu defaultMenu: Menu { + property Component defaultMenu: Menu { MenuItem { text: "cut" visible: !input.readOnly && selectionStart !== selectionEnd @@ -99,7 +99,7 @@ Item { } onClicked: { - if (control.menu && control.menu.__popupVisible) { + if (control.menu && getMenuInstance().__popupVisible) { select(input.cursorPosition, input.cursorPosition); } else { input.activate(); @@ -180,10 +180,10 @@ Item { var xMax = Math.max(r1.x, r2.x); var centerX = xMin + ((xMax - xMin) / 2); var popupPos = input.mapToItem(null, centerX, r1.y); - control.menu.__dismissMenu(); - control.menu.__popup(popupPos.x, popupPos.y, -1, MenuPrivate.EditMenu); + getMenuInstance().__dismissMenu(); + getMenuInstance().__popup(popupPos.x, popupPos.y, -1, MenuPrivate.EditMenu); } else { - control.menu.__dismissMenu(); + getMenuInstance().__dismissMenu(); } } } |