summaryrefslogtreecommitdiff
path: root/src/controls/Private
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@digia.com>2014-08-19 13:16:45 +0200
committerJ-P Nurmi <jpnurmi@digia.com>2014-09-11 17:29:09 +0200
commit080d028c99df0f313f7dddf25da4843dabd57ef5 (patch)
treeb991fc2bfe94e2af2005b7adaf4bda4735f592b1 /src/controls/Private
parent16216d2484492031542e85ae8d73f94f487aba8f (diff)
downloadqtquickcontrols-080d028c99df0f313f7dddf25da4843dabd57ef5.tar.gz
TextSingleton: implement API for getting current item with selection
On some platforms (iOS) you can select text without giving focus to the input. To be able to clear selection from other parts of the code (iOS will only let one input have selection at a time), we need to track this. Later patches will make use of it. Change-Id: I4689253b439e0a86349e53c2edf2554fc96225f8 Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src/controls/Private')
-rw-r--r--src/controls/Private/TextInputWithHandles.qml2
-rw-r--r--src/controls/Private/TextSingleton.qml24
2 files changed, 25 insertions, 1 deletions
diff --git a/src/controls/Private/TextInputWithHandles.qml b/src/controls/Private/TextInputWithHandles.qml
index cace83f6..59ba971e 100644
--- a/src/controls/Private/TextInputWithHandles.qml
+++ b/src/controls/Private/TextInputWithHandles.qml
@@ -38,6 +38,7 @@
**
****************************************************************************/
import QtQuick 2.2
+import QtQuick.Controls.Private 1.0
TextInput {
id: input
@@ -71,6 +72,7 @@ TextInput {
selectionHandle.position = (selectionStart !== cursorPosition) ? selectionStart : selectionEnd
blockRecursion = false
}
+ TextSingleton.updateSelectionItem(input)
}
function activate() {
diff --git a/src/controls/Private/TextSingleton.qml b/src/controls/Private/TextSingleton.qml
index 7bccdd55..3ff89af0 100644
--- a/src/controls/Private/TextSingleton.qml
+++ b/src/controls/Private/TextSingleton.qml
@@ -33,4 +33,26 @@
pragma Singleton
import QtQuick 2.2
-Text {}
+Text {
+ /**
+ selectionItem is the item that currently has a text selection. On some platforms
+ (iOS) you can select text without activating the input field. This means that
+ selectionItem can be different from item with active focus on those platforms.
+ */
+ property Item selectionItem: null
+
+ function updateSelectionItem(item)
+ {
+ // Convenience function to check if we should transfer or
+ // remove selectionItem status from item.
+ var selection = item.selectionStart !== item.selectionEnd
+ if (item === selectionItem) {
+ if (!selection)
+ selectionItem = null
+ } else if (selection) {
+ if (selectionItem)
+ selectionItem.select(selectionItem.cursorPosition, selectionItem.cursorPosition)
+ selectionItem = item
+ }
+ }
+}