aboutsummaryrefslogtreecommitdiffstats
path: root/src/virtualkeyboard/content
diff options
context:
space:
mode:
authorJarkko Koivikko <jarkko.koivikko@code-q.fi>2015-03-20 10:28:18 +0200
committerJarkko Koivikko <jarkko.koivikko@code-q.fi>2015-06-17 12:33:30 +0300
commitd0ded0ea4a0f322fe1fd54348ad0e0b4ae74a1af (patch)
treeb590e713cfd4e3721f7c72783164abe4342c3424 /src/virtualkeyboard/content
parent85b64c67f4b948c3d3aefee237b7606a41ccccba (diff)
Add new property sharedLayouts to KeyboardLayout
This property allows to define which keyboard layouts share the custom input method created by KeyboardLayout.createInputMethod(). Note that changing the locale still causes an explicit destruction of a custom input method. This change gives more control to custom input method creation and destruction. Change-Id: I478ec38de67146bec12a6abfc25f54691a9ba614 Reviewed-by: Gatis Paeglis <gatis.paeglis@theqtcompany.com>
Diffstat (limited to 'src/virtualkeyboard/content')
-rw-r--r--src/virtualkeyboard/content/components/Keyboard.qml26
-rw-r--r--src/virtualkeyboard/content/components/KeyboardLayout.qml17
-rw-r--r--src/virtualkeyboard/content/components/KeyboardLayoutLoader.qml17
-rw-r--r--src/virtualkeyboard/content/layouts/ja_JP/main.qml1
-rw-r--r--src/virtualkeyboard/content/layouts/ja_JP/symbols.qml1
-rw-r--r--src/virtualkeyboard/content/layouts/ko_KR/main.qml1
-rw-r--r--src/virtualkeyboard/content/layouts/ko_KR/symbols.qml1
-rw-r--r--src/virtualkeyboard/content/layouts/zh_CN/main.qml1
-rw-r--r--src/virtualkeyboard/content/layouts/zh_CN/symbols.qml1
9 files changed, 59 insertions, 7 deletions
diff --git a/src/virtualkeyboard/content/components/Keyboard.qml b/src/virtualkeyboard/content/components/Keyboard.qml
index a24fee30..e9271b7e 100644
--- a/src/virtualkeyboard/content/components/Keyboard.qml
+++ b/src/virtualkeyboard/content/components/Keyboard.qml
@@ -52,6 +52,7 @@ Item {
property var defaultInputMethod: initDefaultInputMethod()
property var plainInputMethod: PlainInputMethod {}
property var customInputMethod: null
+ property var customInputMethodSharedLayouts: []
property int defaultInputMode: InputEngine.Latin
property bool inputMethodNeedsReset: true
property bool inputModeNeedsReset: true
@@ -829,11 +830,16 @@ Item {
if (!InputContext.focus)
return
+ // Reset the custom input method if it is not included in the list of shared layouts
+ if (customInputMethod && !inputMethodNeedsReset && customInputMethodSharedLayouts.indexOf(layoutType) === -1)
+ inputMethodNeedsReset = true
+
if (inputMethodNeedsReset) {
if (customInputMethod) {
customInputMethod.destroy()
customInputMethod = null
}
+ customInputMethodSharedLayouts = []
inputMethodNeedsReset = false
}
@@ -841,10 +847,24 @@ Item {
var inputMode = InputContext.inputEngine.inputMode
// Use input method from keyboard layout
- if (keyboardLayoutLoader.item.inputMethod)
+ if (keyboardLayoutLoader.item.inputMethod) {
inputMethod = keyboardLayoutLoader.item.inputMethod
- else if (!customInputMethod)
- customInputMethod = keyboardLayoutLoader.item.createInputMethod()
+ } else if (!customInputMethod) {
+ try {
+ customInputMethod = keyboardLayoutLoader.item.createInputMethod()
+ if (customInputMethod) {
+ // Pull the list of shared layouts from the keyboard layout
+ if (keyboardLayoutLoader.item.sharedLayouts)
+ customInputMethodSharedLayouts = customInputMethodSharedLayouts.concat(keyboardLayoutLoader.item.sharedLayouts)
+
+ // Make sure the current layout is included in the list
+ if (customInputMethodSharedLayouts.indexOf(layoutType) === -1)
+ customInputMethodSharedLayouts.push(layoutType)
+ }
+ } catch (e) {
+ console.error(e.message)
+ }
+ }
if (!inputMethod)
inputMethod = customInputMethod ? customInputMethod : defaultInputMethod
diff --git a/src/virtualkeyboard/content/components/KeyboardLayout.qml b/src/virtualkeyboard/content/components/KeyboardLayout.qml
index 4e0497f3..8610b7e5 100644
--- a/src/virtualkeyboard/content/components/KeyboardLayout.qml
+++ b/src/virtualkeyboard/content/components/KeyboardLayout.qml
@@ -85,13 +85,26 @@ ColumnLayout {
The input method object created by this function can outlive
keyboard layout transitions in certain cases. In particular,
- this applies to the transitions between the symbol and the
- main view.
+ this applies to the transitions between the layouts listed in
+ the sharedLayouts property.
*/
function createInputMethod() {
return null
}
+ /*! List of layout names which share the input method created
+ by the createInputMethod() function.
+
+ If the list is empty (the default) the input method is not
+ shared with any other layout and will be destroyed when the
+ layout changes.
+
+ The list should contain only the name of the layout type,
+ e.g., ['symbols']. The current layout does not have to be
+ included in the list.
+ */
+ property var sharedLayouts
+
/*! Sets the input mode to be used in this layout.
By default, the virtual keyboard attempts to preserve
diff --git a/src/virtualkeyboard/content/components/KeyboardLayoutLoader.qml b/src/virtualkeyboard/content/components/KeyboardLayoutLoader.qml
index cc721c7b..f2fff916 100644
--- a/src/virtualkeyboard/content/components/KeyboardLayoutLoader.qml
+++ b/src/virtualkeyboard/content/components/KeyboardLayoutLoader.qml
@@ -79,13 +79,26 @@ Loader {
The input method object created by this function can outlive
keyboard layout transitions in certain cases. In particular,
- this applies to the transitions between the symbol and the
- main view.
+ this applies to the transitions between the layouts listed in
+ the sharedLayouts property.
*/
function createInputMethod() {
return item ? item.createInputMethod() : null
}
+ /*! List of layout names which share the input method created
+ by the createInputMethod() function.
+
+ If the list is empty (the default) the input method is not
+ shared with any other layout and will be destroyed when the
+ layout changes.
+
+ The list should contain only the name of the layout type,
+ e.g., ['symbols']. The current layout does not have to be
+ included in the list.
+ */
+ property var sharedLayouts: item ? item.sharedLayouts : null
+
/*! Sets the input mode for all the keyboard layouts loaded
in this context.
diff --git a/src/virtualkeyboard/content/layouts/ja_JP/main.qml b/src/virtualkeyboard/content/layouts/ja_JP/main.qml
index bbdbf2a2..11f8a519 100644
--- a/src/virtualkeyboard/content/layouts/ja_JP/main.qml
+++ b/src/virtualkeyboard/content/layouts/ja_JP/main.qml
@@ -23,6 +23,7 @@ KeyboardLayoutLoader {
function createInputMethod() {
return Qt.createQmlObject('import QtQuick 2.0; import QtQuick.Enterprise.VirtualKeyboard 1.3; JapaneseInputMethod {}', parent, "japaneseInputMethod")
}
+ sharedLayouts: ['symbols']
sourceComponent: InputContext.inputEngine.inputMode === InputEngine.FullwidthLatin ? page2 : page1
Component {
id: page1
diff --git a/src/virtualkeyboard/content/layouts/ja_JP/symbols.qml b/src/virtualkeyboard/content/layouts/ja_JP/symbols.qml
index 5b811196..d547a8c3 100644
--- a/src/virtualkeyboard/content/layouts/ja_JP/symbols.qml
+++ b/src/virtualkeyboard/content/layouts/ja_JP/symbols.qml
@@ -24,6 +24,7 @@ KeyboardLayoutLoader {
function createInputMethod() {
return Qt.createQmlObject('import QtQuick 2.0; import QtQuick.Enterprise.VirtualKeyboard 1.3; JapaneseInputMethod {}', parent, "japaneseInputMethod")
}
+ sharedLayouts: ['main']
property int page
readonly property int numPages: 3
property var keysPage1: [
diff --git a/src/virtualkeyboard/content/layouts/ko_KR/main.qml b/src/virtualkeyboard/content/layouts/ko_KR/main.qml
index 1b6c9ab4..a58e6aa4 100644
--- a/src/virtualkeyboard/content/layouts/ko_KR/main.qml
+++ b/src/virtualkeyboard/content/layouts/ko_KR/main.qml
@@ -24,6 +24,7 @@ KeyboardLayoutLoader {
return Qt.createQmlObject('import QtQuick 2.0; import QtQuick.Enterprise.VirtualKeyboard 1.3; HangulInputMethod {}', parent, "hangulInputMethod")
}
sourceComponent: InputContext.shift ? page2 : page1
+ sharedLayouts: ['symbols']
Component {
id: page1
KeyboardLayout {
diff --git a/src/virtualkeyboard/content/layouts/ko_KR/symbols.qml b/src/virtualkeyboard/content/layouts/ko_KR/symbols.qml
index 392bbdf8..f9596a1c 100644
--- a/src/virtualkeyboard/content/layouts/ko_KR/symbols.qml
+++ b/src/virtualkeyboard/content/layouts/ko_KR/symbols.qml
@@ -24,6 +24,7 @@ KeyboardLayoutLoader {
function createInputMethod() {
return Qt.createQmlObject('import QtQuick 2.0; import QtQuick.Enterprise.VirtualKeyboard 1.3; HangulInputMethod {}', parent, "hangulInputMethod")
}
+ sharedLayouts: ['main']
property bool secondPage
onVisibleChanged: if (!visible) secondPage = false
sourceComponent: secondPage ? page2 : page1
diff --git a/src/virtualkeyboard/content/layouts/zh_CN/main.qml b/src/virtualkeyboard/content/layouts/zh_CN/main.qml
index eef1b4b1..2e65f479 100644
--- a/src/virtualkeyboard/content/layouts/zh_CN/main.qml
+++ b/src/virtualkeyboard/content/layouts/zh_CN/main.qml
@@ -24,6 +24,7 @@ KeyboardLayout {
function createInputMethod() {
return Qt.createQmlObject('import QtQuick 2.0; import QtQuick.Enterprise.VirtualKeyboard 1.3; PinyinInputMethod {}', parent, "pinyinInputMethod")
}
+ sharedLayouts: ['symbols']
keyWeight: 160
KeyboardRow {
Key {
diff --git a/src/virtualkeyboard/content/layouts/zh_CN/symbols.qml b/src/virtualkeyboard/content/layouts/zh_CN/symbols.qml
index 3944b164..58e65fd2 100644
--- a/src/virtualkeyboard/content/layouts/zh_CN/symbols.qml
+++ b/src/virtualkeyboard/content/layouts/zh_CN/symbols.qml
@@ -24,6 +24,7 @@ KeyboardLayoutLoader {
function createInputMethod() {
return Qt.createQmlObject('import QtQuick 2.0; import QtQuick.Enterprise.VirtualKeyboard 1.3; PinyinInputMethod {}', parent, "pinyinInputMethod")
}
+ sharedLayouts: ['main']
property int page
readonly property int numPages: 3
property var keysPage1: [