diff options
author | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2018-08-28 11:51:06 +0300 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2018-09-07 08:21:47 +0000 |
commit | 3adc25c8b2105418f86d0c6390832e887d483cc0 (patch) | |
tree | 29f2baca228aa8488df088a9a6a00354c3bcadbf | |
parent | ea088ff4c53e625be194f4c915fed912f9518bcf (diff) |
Enable layout mirroring for word candidate list
Change 4a92afe75bfb7886ecb1b3282b05b2985c39fe3c disabled layout
mirroring for virtual keyboard. This change enables layout mirroring
for word candidate list.
Changes to navigation cursor logic are necessary, so that navigation
cursor follows text direction.
Task-number: QTBUG-70041
Change-Id: I59ec8968294c1c342e10f718dbd2360f25378956
Reviewed-by: Jarkko Koivikko <jarkko.koivikko@code-q.fi>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
5 files changed, 90 insertions, 25 deletions
diff --git a/src/virtualkeyboard/content/InputPanel.qml b/src/virtualkeyboard/content/InputPanel.qml index 9310238d..b32ac340 100644 --- a/src/virtualkeyboard/content/InputPanel.qml +++ b/src/virtualkeyboard/content/InputPanel.qml @@ -114,9 +114,6 @@ Item { /*! \internal */ readonly property bool __isRootItem: inputPanel.parent != null && inputPanel.parent.parent == null - LayoutMirroring.enabled: false - LayoutMirroring.childrenInherit: true - SelectionControl { objectName: "selectionControl" x: -parent.x diff --git a/src/virtualkeyboard/content/components/AlternativeKeys.qml b/src/virtualkeyboard/content/components/AlternativeKeys.qml index a1fcfe14..7879f006 100644 --- a/src/virtualkeyboard/content/components/AlternativeKeys.qml +++ b/src/virtualkeyboard/content/components/AlternativeKeys.qml @@ -37,6 +37,8 @@ Item { property int keyCode property point origin signal clicked + LayoutMirroring.enabled: false + LayoutMirroring.childrenInherit: true z: 1 visible: active diff --git a/src/virtualkeyboard/content/components/Keyboard.qml b/src/virtualkeyboard/content/components/Keyboard.qml index 84717450..6f13c61d 100644 --- a/src/virtualkeyboard/content/components/Keyboard.qml +++ b/src/virtualkeyboard/content/components/Keyboard.qml @@ -169,6 +169,7 @@ Item { } onNavigationKeyPressed: { var initialKey + var direction = wordCandidateView.effectiveLayoutDirection == Qt.LeftToRight ? 1 : -1 switch (key) { case Qt.Key_Left: if (keyboard.navigationModeActive && !keyboardInputArea.initialKey) { @@ -193,17 +194,21 @@ Item { break } if (wordCandidateView.count) { - if (wordCandidateView.currentIndex > 0) { + if (wordCandidateView.effectiveLayoutDirection == Qt.LeftToRight && + wordCandidateView.currentIndex > 0) { wordCandidateView.decrementCurrentIndex() + } else if (wordCandidateView.effectiveLayoutDirection == Qt.RightToLeft && + wordCandidateView.currentIndex + 1 < wordCandidateView.count) { + wordCandidateView.incrementCurrentIndex() } else { keyboardInputArea.navigateToNextKey(0, 0, false) initialKey = keyboardInputArea.initialKey - if (!keyboardInputArea.navigateToNextKey(-1, -1, false)) { - keyboardInputArea.initialKey = initialKey - keyboardInputArea.navigateToNextKey(-1, -1, true) - } else { - keyboardInputArea.navigateToNextKey(1, 1, false) - } + while (keyboardInputArea.navigateToNextKey(0, 1 * direction, false)) + initialKey = keyboardInputArea.initialKey + while (keyboardInputArea.navigateToNextKey(1, 0, false)) + initialKey = keyboardInputArea.initialKey + keyboardInputArea.initialKey = initialKey + keyboardInputArea.navigateToNextKey(0, 0, false) } break } @@ -211,14 +216,18 @@ Item { initialKey = keyboardInputArea.initialKey if (!keyboardInputArea.navigateToNextKey(-1, 0, false)) { keyboardInputArea.initialKey = initialKey - if (!keyboardInputArea.navigateToNextKey(0, -1, false)) { + if (!keyboardInputArea.navigateToNextKey(0, -1 * direction, false)) { if (wordCandidateView.count) { - if (wordCandidateView.currentIndex === -1) - wordCandidateView.incrementCurrentIndex() + if (wordCandidateView.count) { + wordCandidateView.currentIndex = + wordCandidateView.effectiveLayoutDirection == Qt.LeftToRight ? + (wordCandidateView.count - 1) : 0 + break + } break } keyboardInputArea.initialKey = initialKey - keyboardInputArea.navigateToNextKey(0, -1, true) + keyboardInputArea.navigateToNextKey(0, -1 * direction, true) } keyboardInputArea.navigateToNextKey(-1, 0, true) } @@ -283,17 +292,21 @@ Item { break } if (wordCandidateView.count) { - if (wordCandidateView.currentIndex + 1 < wordCandidateView.count) { + if (wordCandidateView.effectiveLayoutDirection == Qt.LeftToRight && + wordCandidateView.currentIndex + 1 < wordCandidateView.count) { wordCandidateView.incrementCurrentIndex() + } else if (wordCandidateView.effectiveLayoutDirection == Qt.RightToLeft && + wordCandidateView.currentIndex > 0) { + wordCandidateView.decrementCurrentIndex() } else { keyboardInputArea.navigateToNextKey(0, 0, false) initialKey = keyboardInputArea.initialKey - if (!keyboardInputArea.navigateToNextKey(1, 1, false)) { - keyboardInputArea.initialKey = initialKey - keyboardInputArea.navigateToNextKey(1, 1, true) - } else { - keyboardInputArea.navigateToNextKey(-1, -1, false) - } + while (keyboardInputArea.navigateToNextKey(0, -1 * direction, false)) + initialKey = keyboardInputArea.initialKey; + while (keyboardInputArea.navigateToNextKey(-1, 0, false)) + initialKey = keyboardInputArea.initialKey; + keyboardInputArea.initialKey = initialKey + keyboardInputArea.navigateToNextKey(0, 0, false) } break } @@ -301,14 +314,15 @@ Item { initialKey = keyboardInputArea.initialKey if (!keyboardInputArea.navigateToNextKey(1, 0, false)) { keyboardInputArea.initialKey = initialKey - if (!keyboardInputArea.navigateToNextKey(0, 1, false)) { + if (!keyboardInputArea.navigateToNextKey(0, 1 * direction, false)) { if (wordCandidateView.count) { - if (wordCandidateView.currentIndex === -1) - wordCandidateView.incrementCurrentIndex() + wordCandidateView.currentIndex = + wordCandidateView.effectiveLayoutDirection == Qt.LeftToRight ? + 0 : (wordCandidateView.count - 1) break } keyboardInputArea.initialKey = initialKey - keyboardInputArea.navigateToNextKey(0, 1, true) + keyboardInputArea.navigateToNextKey(0, 1 * direction, true) } keyboardInputArea.navigateToNextKey(1, 0, true) } @@ -786,6 +800,8 @@ Item { width: Math.round(keyboardBackground.width) height: Math.round(style.keyboardDesignHeight * width / style.keyboardDesignWidth) anchors.horizontalCenter: parent.horizontalCenter + LayoutMirroring.enabled: false + LayoutMirroring.childrenInherit: true Loader { id: keyboardLayoutLoader @@ -1075,6 +1091,8 @@ Item { id: languagePopup z: 1 anchors.fill: parent + LayoutMirroring.enabled: false + LayoutMirroring.childrenInherit: true MouseArea { onPressed: keyboard.hideLanguagePopup() @@ -1185,6 +1203,8 @@ Item { objectName: "wordCandidateContextMenu" z: 1 anchors.fill: parent + LayoutMirroring.enabled: false + LayoutMirroring.childrenInherit: true property int previousWordCandidateIndex: -1 readonly property bool active: wordCandidateContextMenuList.visible property bool openedByNavigationKeyLongPress diff --git a/tests/auto/inputpanel/data/inputpanel/inputpanel.qml b/tests/auto/inputpanel/data/inputpanel/inputpanel.qml index 358c49ea..99fde40e 100644 --- a/tests/auto/inputpanel/data/inputpanel/inputpanel.qml +++ b/tests/auto/inputpanel/data/inputpanel/inputpanel.qml @@ -97,6 +97,8 @@ InputPanel { signal inputMethodResult(var text) + LayoutMirroring.childrenInherit: true + Connections { target: InputContext onPreeditTextChanged: if (InputContext.preeditText.length > 0) inputMethodResult(InputContext.preeditText) @@ -387,6 +389,10 @@ InputPanel { externalLanguageSwitchEnabled = enabled } + function setLayoutMirroring(enabled) { + LayoutMirroring.enabled = enabled + } + function findVirtualKey(key) { return Utils.findChild(keyboardLayoutLoader, key, function(obj, param) { if (!obj.hasOwnProperty("key") || !obj.hasOwnProperty("text")) @@ -600,6 +606,8 @@ InputPanel { function activateNavigationKeyMode() { if (!inputPanel.naviationHighlight.visible) { + inputPanel.naviationHighlight.moveDuration = 0 + inputPanel.naviationHighlight.resizeDuration = 0 emulateNavigationKeyClick(Qt.Key_Right) if (inputPanel.naviationHighlight.visible) { while (inputPanel.naviationHighlightAnimating) diff --git a/tests/auto/inputpanel/data/tst_inputpanel.qml b/tests/auto/inputpanel/data/tst_inputpanel.qml index eea2f97e..7cea7058 100644 --- a/tests/auto/inputpanel/data/tst_inputpanel.qml +++ b/tests/auto/inputpanel/data/tst_inputpanel.qml @@ -84,6 +84,7 @@ Rectangle { inputPanel.setWclAutoCommitWord(data !== undefined && data.hasOwnProperty("wclAutoCommitWord") && data.wclAutoCommitWord) inputPanel.setFullScreenMode(data !== undefined && data.hasOwnProperty("fullScreenMode") && data.fullScreenMode) inputPanel.setExternalLanguageSwitchEnabled(data !== undefined && data.hasOwnProperty("externalLanguageSwitchEnabled") && data.externalLanguageSwitchEnabled) + inputPanel.setLayoutMirroring(data !== undefined && data.hasOwnProperty("layoutMirroring") && data.layoutMirroring) var window = container.Window.window verify(window) @@ -780,6 +781,43 @@ Rectangle { verify(textInput.text.length > 0) } + function test_navigationKeyLayoutMirroring_data() { + return [ + { layoutMirroring: false }, + { layoutMirroring: true }, + ] + } + + function test_navigationKeyLayoutMirroring(data) { + prepareTest(data) + + if (!inputPanel.activateNavigationKeyMode()) + skip("Arrow key navigation not enabled") + verify(inputPanel.naviationHighlight.visible) + + verify(inputPanel.navigateToKey("q")) + var initialKey = inputPanel.keyboardInputArea.initialKey + + var keysTraversed = [] + do { + verify(keysTraversed.indexOf(inputPanel.keyboardInputArea.initialKey) === -1) + var currentKey = inputPanel.keyboardInputArea.initialKey + keysTraversed.push(currentKey) + inputPanel.emulateNavigationKeyClick(Qt.Key_Right) + } while (initialKey !== inputPanel.keyboardInputArea.initialKey) + + inputPanel.setLayoutMirroring(!data.layoutMirroring) + + do { + var indexOfKey = keysTraversed.indexOf(inputPanel.keyboardInputArea.initialKey) + verify(indexOfKey !== -1) + keysTraversed.splice(indexOfKey, 1) + inputPanel.emulateNavigationKeyClick(Qt.Key_Left) + } while (initialKey !== inputPanel.keyboardInputArea.initialKey) + + compare(keysTraversed.length, 0) + } + function test_spellCorrectionSuggestions_data() { return [ { initInputMethodHints: Qt.ImhNoPredictiveText, inputSequence: "hwllo", unexpectedSuggestion: "Hello", outputText: "Hwllo" }, |