diff options
author | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2017-08-02 10:10:09 +0300 |
---|---|---|
committer | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2017-08-04 15:50:44 +0000 |
commit | a0b84f2f3f6f5fdfef5efcdf80d3c3fe7a887233 (patch) | |
tree | aa20ab00cd1ee55ddd45de101be31ef907335b44 | |
parent | d3543cadc85b47b1fa5fb0f5de2fb597a2cbb23f (diff) |
Prefer current input mode when switching between handwriting mode
If a keyboard layout provides multiple choices for input modes
(e.g. latin and cyrillic), prefer the current choice when switching
to handwriting layout and back.
Also, use the same mechanism to avoid binding loop when switching
input mode with InputModeKey contained in a KeyboardLayoutLoader
where the layout depends on the input mode.
Change-Id: If7adae92db39f3b1e49ec362679e6b6ae7f32fa4
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
4 files changed, 45 insertions, 49 deletions
diff --git a/src/virtualkeyboard/content/components/HandwritingModeKey.qml b/src/virtualkeyboard/content/components/HandwritingModeKey.qml index b07cdcd6..815d89db 100644 --- a/src/virtualkeyboard/content/components/HandwritingModeKey.qml +++ b/src/virtualkeyboard/content/components/HandwritingModeKey.qml @@ -49,6 +49,6 @@ Key { displayText: "HWR" functionKey: true visible: keyboard.isHandwritingAvailable() - onClicked: keyboard.handwritingMode = !keyboard.handwritingMode + onClicked: keyboard.setHandwritingMode(!keyboard.handwritingMode) keyPanelDelegate: keyboard.style ? keyboard.style.handwritingKeyPanel : undefined } diff --git a/src/virtualkeyboard/content/components/Keyboard.qml b/src/virtualkeyboard/content/components/Keyboard.qml index 8dfd7f7d..47df1afa 100644 --- a/src/virtualkeyboard/content/components/Keyboard.qml +++ b/src/virtualkeyboard/content/components/Keyboard.qml @@ -48,14 +48,17 @@ Item { property string locale: localeIndex >= 0 && localeIndex < layoutsModel.count ? layoutsModel.get(localeIndex, "fileName") : "" property string inputLocale property int defaultLocaleIndex: -1 - property bool latinOnly: InputContext.inputMethodHints & Qt.ImhLatinOnly - property bool preferNumbers: InputContext.inputMethodHints & Qt.ImhPreferNumbers + readonly property bool latinOnly: InputContext.inputMethodHints & (Qt.ImhLatinOnly | Qt.ImhEmailCharactersOnly | Qt.ImhUrlCharactersOnly) + readonly property bool preferNumbers: InputContext.inputMethodHints & Qt.ImhPreferNumbers + readonly property bool dialableCharactersOnly: InputContext.inputMethodHints & Qt.ImhDialableCharactersOnly + readonly property bool formattedNumbersOnly: InputContext.inputMethodHints & Qt.ImhFormattedNumbersOnly + readonly property bool digitsOnly: InputContext.inputMethodHints & Qt.ImhDigitsOnly property string layout property string layoutType: { if (keyboard.handwritingMode) return "handwriting" - if (InputContext.inputMethodHints & Qt.ImhDialableCharactersOnly) return "dialpad" - if (InputContext.inputMethodHints & Qt.ImhFormattedNumbersOnly) return "numbers" - if (InputContext.inputMethodHints & Qt.ImhDigitsOnly) return "digits" + if (keyboard.dialableCharactersOnly) return "dialpad" + if (keyboard.formattedNumbersOnly) return "numbers" + if (keyboard.digitsOnly) return "digits" if (keyboard.symbolMode) return "symbols" return "main" } @@ -128,17 +131,14 @@ Item { updateAvailableLocaleIndices() updateLayout() } - onLatinOnlyChanged: { - if (!latinOnly) - inputModeNeedsReset = true - updateInputMethod() - } + onLatinOnlyChanged: inputModeNeedsReset = true onPreferNumbersChanged: { keyboard.symbolMode = !keyboard.handwritingMode && preferNumbers - if (!preferNumbers) - inputModeNeedsReset = true - updateInputMethod() + inputModeNeedsReset = true } + onDialableCharactersOnlyChanged: inputModeNeedsReset = true + onFormattedNumbersOnlyChanged: inputModeNeedsReset = true + onDigitsOnlyChanged: inputModeNeedsReset = true onHandwritingModeChanged: if (!keyboard.handwritingMode) keyboard.fullScreenHandwritingMode = false onFullScreenHandwritingModeChanged: if (keyboard.fullScreenHandwritingMode) keyboard.handwritingMode = true onLanguagePopupListActiveChanged: { @@ -751,6 +751,12 @@ Item { when: keyboard.layout.length > 0 } + onItemChanged: { + // Reset input mode if the new layout wants to override it + if (item && item.inputMode !== -1) + inputModeNeedsReset = true + } + MultiPointTouchArea { id: keyboardInputArea objectName: "keyboardInputArea" @@ -1139,29 +1145,30 @@ Item { var inputModes = InputContext.inputEngine.inputModes if (inputModes.length > 0) { // Reset to default input mode if the input locale has changed - if (inputModeNeedsReset) + if (inputModeNeedsReset) { inputMode = inputModes[0] - // Check the current layout for input mode override - if (keyboardLayoutLoader.item.inputMode !== -1) - inputMode = keyboardLayoutLoader.item.inputMode + // Check the current layout for input mode override + if (keyboardLayoutLoader.item.inputMode !== -1) + inputMode = keyboardLayoutLoader.item.inputMode + + // Update input mode automatically in handwriting mode + if (keyboard.handwritingMode) { + if (keyboard.dialableCharactersOnly && inputModes.indexOf(InputEngine.Dialable) !== -1) + inputMode = InputEngine.Dialable + else if ((keyboard.formattedNumbersOnly || keyboard.digitsOnly) && inputModes.indexOf(InputEngine.Numeric) !== -1) + inputMode = InputEngine.Numeric + else if (keyboardLayoutLoader.item.inputMode === -1) + inputMode = inputModes[0] + } - // Update input mode automatically in handwriting mode - if (keyboard.handwritingMode) { - if ((InputContext.inputMethodHints & Qt.ImhDialableCharactersOnly) && inputModes.indexOf(InputEngine.Dialable) !== -1) - inputMode = InputEngine.Dialable - else if ((InputContext.inputMethodHints & (Qt.ImhFormattedNumbersOnly | Qt.ImhDigitsOnly)) && inputModes.indexOf(InputEngine.Numeric) !== -1) + // Check the input method hints for input mode overrides + if (latinOnly) + inputMode = InputEngine.Latin + if (preferNumbers) inputMode = InputEngine.Numeric - else if (keyboardLayoutLoader.item.inputMode === -1) - inputMode = inputModes[0] } - // Check the input method hints for input mode overrides - if (latinOnly) - inputMode = InputEngine.Latin - if (preferNumbers) - inputMode = InputEngine.Numeric - // Make sure the input mode is supported by the current input method if (inputModes.indexOf(inputMode) === -1) inputMode = inputModes[0] @@ -1349,4 +1356,10 @@ Item { function isHandwritingAvailable() { return VirtualKeyboardInputMethods.indexOf("HandwritingInputMethod") !== -1 && layoutExists(locale, "handwriting") } + + function setHandwritingMode(enabled, resetInputMode) { + if (enabled && resetInputMode) + inputModeNeedsReset = true + handwritingMode = enabled + } } diff --git a/src/virtualkeyboard/content/layouts/ja_JP/handwriting.qml b/src/virtualkeyboard/content/layouts/ja_JP/handwriting.qml index 0820cbbc..9fe3b191 100644 --- a/src/virtualkeyboard/content/layouts/ja_JP/handwriting.qml +++ b/src/virtualkeyboard/content/layouts/ja_JP/handwriting.qml @@ -36,23 +36,6 @@ KeyboardLayout { return Qt.createQmlObject('import QtQuick 2.0; import QtQuick.VirtualKeyboard 2.3; HandwritingInputMethod {}', parent) } sharedLayouts: ['symbols'] - inputMode: preferredInputMode() - - Connections { - target: InputContext - onInputMethodHintsChanged: { - var newInputMode = preferredInputMode() - if (InputContext.inputEngine.inputModes.indexOf(newInputMode) !== -1) - InputContext.inputEngine.inputMode = newInputMode - } - } - - function preferredInputMode() { - return InputContext.inputMethodHints & - (Qt.ImhPreferLatin | Qt.ImhEmailCharactersOnly | Qt.ImhUrlCharactersOnly | - Qt.ImhLatinOnly) ? InputEngine.Latin : InputEngine.JapaneseHandwriting - } - KeyboardRow { Layout.preferredHeight: 3 KeyboardColumn { diff --git a/tests/auto/inputpanel/data/inputpanel/inputpanel.qml b/tests/auto/inputpanel/data/inputpanel/inputpanel.qml index 4fc167e4..1113a268 100644 --- a/tests/auto/inputpanel/data/inputpanel/inputpanel.qml +++ b/tests/auto/inputpanel/data/inputpanel/inputpanel.qml @@ -555,7 +555,7 @@ InputPanel { function setHandwritingMode(enabled) { if (inputPanel.keyboard.handwritingMode !== enabled) { if (!enabled || inputPanel.keyboard.isHandwritingAvailable()) - inputPanel.keyboard.handwritingMode = enabled + inputPanel.keyboard.setHandwritingMode(enabled, true) } return inputPanel.keyboard.handwritingMode === enabled } |