diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-03-09 16:38:39 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-04-16 06:56:52 +0000 |
commit | 19159469400ed6daa8bba1020eaaf149a16f1f18 (patch) | |
tree | f31f193a27499994ce3545b612f84ef37d6ae91a | |
parent | c439f4635a17101ceb410b3c2416bf15c6d00d80 (diff) | |
download | qtquickcontrols-19159469400ed6daa8bba1020eaaf149a16f1f18.tar.gz |
Fix text selection handles to float on top
Task-number: QTBUG-42538
Change-Id: Ia6d38819c994dcd9713958faf0c17de2023c9f25
Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
-rw-r--r-- | src/controls/Private/TextInputWithHandles.qml | 21 | ||||
-rw-r--r-- | src/controls/TextArea.qml | 31 | ||||
-rw-r--r-- | tests/manual/texthandles/main.qml | 3 |
3 files changed, 36 insertions, 19 deletions
diff --git a/src/controls/Private/TextInputWithHandles.qml b/src/controls/Private/TextInputWithHandles.qml index f931986f..1c40f588 100644 --- a/src/controls/Private/TextInputWithHandles.qml +++ b/src/controls/Private/TextInputWithHandles.qml @@ -35,6 +35,7 @@ ****************************************************************************/ import QtQuick 2.2 +import QtQuick.Window 2.2 import QtQuick.Controls.Private 1.0 TextInput { @@ -128,16 +129,25 @@ TextInput { anchors.fill: parent } + ScenePosListener { + id: listener + item: input + enabled: input.activeFocus && Qt.platform.os !== "ios" && Settings.isMobile + } + TextHandle { id: selectionHandle editor: input - parent: control + z: 1000001 // DefaultWindowDecoration+1 + parent: !input.activeFocus || Qt.platform.os === "ios" ? control : Window.contentItem // float (QTBUG-42538) control: input.control active: control.selectByMouse && Settings.isMobile maximum: cursorHandle.position - 1 - property var mappedPos: parent.mapFromItem(editor, editor.selectionRectangle.x, editor.selectionRectangle.y) + // Mention scenePos in the mappedPos binding to force re-evaluation if it changes + property var mappedPos: listener.scenePos.x !== listener.scenePos.y !== Number.MAX_VALUE ? + editor.mapToItem(parent, editor.selectionRectangle.x, editor.selectionRectangle.y) : -1 x: mappedPos.x y: mappedPos.y @@ -158,12 +168,15 @@ TextInput { id: cursorHandle editor: input - parent: control + z: 1000001 // DefaultWindowDecoration+1 + parent: !input.activeFocus || Qt.platform.os === "ios" ? control : Window.contentItem // float (QTBUG-42538) control: input.control active: control.selectByMouse && Settings.isMobile minimum: input.hasSelection ? selectionHandle.position + 1 : -1 - property var mappedPos: parent.mapFromItem(editor, editor.cursorRectangle.x, editor.cursorRectangle.y) + // Mention scenePos in the mappedPos binding to force re-evaluation if it changes + property var mappedPos: listener.scenePos.x !== listener.scenePos.y !== Number.MAX_VALUE ? + editor.mapToItem(parent, editor.cursorRectangle.x, editor.cursorRectangle.y) : -1 x: mappedPos.x y: mappedPos.y diff --git a/src/controls/TextArea.qml b/src/controls/TextArea.qml index 299b1813..3a90a2cc 100644 --- a/src/controls/TextArea.qml +++ b/src/controls/TextArea.qml @@ -35,6 +35,7 @@ ****************************************************************************/ import QtQuick 2.2 +import QtQuick.Window 2.2 import QtQuick.Controls 1.2 import QtQuick.Controls.Private 1.0 /*! @@ -874,25 +875,31 @@ ScrollView { anchors.fill: parent } + ScenePosListener { + id: listener + item: edit + enabled: edit.activeFocus && Qt.platform.os !== "ios" && Settings.isMobile + } + TextHandle { id: selectionHandle editor: edit control: area - z: 1 // above scrollbars - parent: Qt.platform.os === "ios" ? editor : __scroller // no clip + z: 1000001 // DefaultWindowDecoration+1 + parent: !edit.activeFocus || Qt.platform.os === "ios" ? editor : Window.contentItem // float (QTBUG-42538) active: area.selectByMouse && Settings.isMobile delegate: __style.__selectionHandle maximum: cursorHandle.position - 1 - // Mention contentX and contentY in the mappedPos binding to force re-evaluation if they change - property var mappedPos: flickableItem.contentX !== flickableItem.contentY !== Number.MAX_VALUE ? - parent.mapFromItem(editor, editor.selectionRectangle.x, editor.selectionRectangle.y) : -1 + // Mention scenePos, contentX and contentY in the mappedPos binding to force re-evaluation if they change + property var mappedPos: listener.scenePos.x !== listener.scenePos.y !== flickableItem.contentX !== flickableItem.contentY !== Number.MAX_VALUE ? + editor.mapToItem(parent, editor.selectionRectangle.x, editor.selectionRectangle.y) : -1 x: mappedPos.x y: mappedPos.y property var posInViewport: flickableItem.contentX !== flickableItem.contentY !== Number.MAX_VALUE ? - parent.mapToItem(viewport, handleX, handleY) : -1 + viewport.mapFromItem(parent, handleX, handleY) : -1 visible: pressed || (edit.hasSelection && posInViewport.y + handleHeight >= -1 && posInViewport.y <= viewport.height + 1 @@ -915,20 +922,20 @@ ScrollView { editor: edit control: area - z: 1 // above scrollbars - parent: Qt.platform.os === "ios" ? editor : __scroller // no clip + z: 1000001 // DefaultWindowDecoration+1 + parent: !edit.activeFocus || Qt.platform.os === "ios" ? editor : Window.contentItem // float (QTBUG-42538) active: area.selectByMouse && Settings.isMobile delegate: __style.__cursorHandle minimum: edit.hasSelection ? selectionHandle.position + 1 : -1 - // Mention contentX and contentY in the mappedPos binding to force re-evaluation if they change - property var mappedPos: flickableItem.contentX !== flickableItem.contentY !== Number.MAX_VALUE ? - parent.mapFromItem(editor, editor.cursorRectangle.x, editor.cursorRectangle.y) : -1 + // Mention scenePos, contentX and contentY in the mappedPos binding to force re-evaluation if they change + property var mappedPos: listener.scenePos.x !== listener.scenePos.y !== flickableItem.contentX !== flickableItem.contentY !== Number.MAX_VALUE ? + editor.mapToItem(parent, editor.cursorRectangle.x, editor.cursorRectangle.y) : -1 x: mappedPos.x y: mappedPos.y property var posInViewport: flickableItem.contentX !== flickableItem.contentY !== Number.MAX_VALUE ? - parent.mapToItem(viewport, handleX, handleY) : -1 + viewport.mapFromItem(parent, handleX, handleY) : -1 visible: pressed || ((edit.cursorVisible || edit.hasSelection) && posInViewport.y + handleHeight >= -1 && posInViewport.y <= viewport.height + 1 diff --git a/tests/manual/texthandles/main.qml b/tests/manual/texthandles/main.qml index 4a6ed8b1..46b77dc7 100644 --- a/tests/manual/texthandles/main.qml +++ b/tests/manual/texthandles/main.qml @@ -100,7 +100,6 @@ ApplicationWindow { TextField { id: field - z: 1 text: loremIpsum Layout.fillWidth: true selectByMouse: selectBox.checked @@ -113,7 +112,6 @@ ApplicationWindow { SpinBox { id: spinbox - z: 1 decimals: 2 value: 500000 maximumValue: 1000000 @@ -129,7 +127,6 @@ ApplicationWindow { ComboBox { id: combobox - z: 1 editable: true currentIndex: 1 Layout.fillWidth: true |