aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/virtualkeyboard/content/InputPanel.qml46
-rw-r--r--src/virtualkeyboard/content/components/Keyboard.qml22
-rw-r--r--src/virtualkeyboard/doc/snippets/qtvirtualkeyboard-custom-language-popup.qml128
-rw-r--r--src/virtualkeyboard/doc/src/user-guide.qdoc1
-rw-r--r--tests/auto/inputpanel/data/inputpanel/inputpanel.qml11
-rw-r--r--tests/auto/inputpanel/data/tst_inputpanel.qml16
6 files changed, 217 insertions, 7 deletions
diff --git a/src/virtualkeyboard/content/InputPanel.qml b/src/virtualkeyboard/content/InputPanel.qml
index f9d25a02..3f88bb30 100644
--- a/src/virtualkeyboard/content/InputPanel.qml
+++ b/src/virtualkeyboard/content/InputPanel.qml
@@ -61,6 +61,52 @@ Item {
*/
property alias active: keyboard.active
+ /*!
+ \qmlproperty bool InputPanel::externalLanguageSwitchEnabled
+ \since QtQuick.VirtualKeyboard 2.4
+
+ This property enables the external language switch mechanism.
+ When this property is \c true, the virtual keyboard will not show
+ the built-in language popup, but will emit the \l externalLanguageSwitch
+ signal instead. The application can handle this signal and show a
+ custom language selection dialog instead.
+ */
+ property bool externalLanguageSwitchEnabled
+
+ /*!
+ \qmlsignal InputPanel::externalLanguageSwitch(var localeList, int currentIndex)
+ \since QtQuick.VirtualKeyboard 2.4
+
+ This signal is emitted when \l externalLanguageSwitchEnabled is \c true
+ and the \l {user-guide-language}{language switch key} is pressed by the user.
+
+ It serves as a hook to display a custom language dialog instead of
+ the built-in language popup in the virtual keyboard.
+
+ The \a localeList parameter contains a list of locale names to choose
+ from. To get more information about a particular language, use the \l Qt.locale()
+ function. The \a currentIndex is the index of current locale in the
+ \a localeList. This item should be highlighted as the current item in the UI.
+
+ To select a new language, use the \l {VirtualKeyboardSettings::locale}
+ {VirtualKeyboardSettings.locale} property.
+
+ Below is an example that demonstrates a custom language dialog implementation:
+
+ \snippet qtvirtualkeyboard-custom-language-popup.qml popup
+
+ The dialog would then be declared:
+
+ \snippet qtvirtualkeyboard-custom-language-popup.qml declaring
+
+ In the application's InputPanel, add the following code:
+
+ \snippet qtvirtualkeyboard-custom-language-popup.qml using
+
+ The custom dialog will now be shown when the language switch key is pressed.
+ */
+ signal externalLanguageSwitch(var localeList, int currentIndex)
+
/*! \internal */
property alias keyboard: keyboard
diff --git a/src/virtualkeyboard/content/components/Keyboard.qml b/src/virtualkeyboard/content/components/Keyboard.qml
index 22378b44..5a2e76eb 100644
--- a/src/virtualkeyboard/content/components/Keyboard.qml
+++ b/src/virtualkeyboard/content/components/Keyboard.qml
@@ -1069,9 +1069,20 @@ Item {
function showLanguagePopup(parentItem, customLayoutsOnly) {
if (!languagePopupList.enabled) {
- var locales = keyboard.listLocales(customLayoutsOnly)
+ var locales = keyboard.listLocales(customLayoutsOnly, parent.externalLanguageSwitchEnabled)
+ if (parent.externalLanguageSwitchEnabled) {
+ var currentIndex = 0
+ for (var i = 0; i < locales.length; i++) {
+ if (locales[i] === keyboard.locale) {
+ currentIndex = i
+ break
+ }
+ }
+ parent.externalLanguageSwitch(locales, currentIndex)
+ return
+ }
languageListModel.clear()
- for (var i = 0; i < locales.length; i++) {
+ for (i = 0; i < locales.length; i++) {
languageListModel.append({localeName: locales[i].name, displayName: locales[i].locale.nativeLanguageName, localeIndex: locales[i].index})
if (locales[i].index === keyboard.localeIndex)
languagePopupList.currentIndex = i
@@ -1269,12 +1280,15 @@ Item {
availableCustomLocaleIndices = newIndices
}
- function listLocales(customLayoutsOnly) {
+ function listLocales(customLayoutsOnly, localeNameOnly) {
var locales = []
var localeIndices = customLayoutsOnly ? availableCustomLocaleIndices : availableLocaleIndices
for (var i = 0; i < localeIndices.length; i++) {
var layoutFolder = layoutsModel.get(localeIndices[i], "fileName")
- locales.push({locale:Qt.locale(layoutFolder), index:localeIndices[i], name:layoutFolder})
+ if (localeNameOnly)
+ locales.push(layoutFolder)
+ else
+ locales.push({locale:Qt.locale(layoutFolder), index:localeIndices[i], name:layoutFolder})
}
return locales
}
diff --git a/src/virtualkeyboard/doc/snippets/qtvirtualkeyboard-custom-language-popup.qml b/src/virtualkeyboard/doc/snippets/qtvirtualkeyboard-custom-language-popup.qml
new file mode 100644
index 00000000..261ad9be
--- /dev/null
+++ b/src/virtualkeyboard/doc/snippets/qtvirtualkeyboard-custom-language-popup.qml
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// ![popup]
+Dialog {
+ id: languageDialog
+ title: "Select Input Language"
+ modality: Qt.ApplicationModal
+
+ function show(localeList, currentIndex) {
+ languageListModel.clear()
+ for (var i = 0; i < localeList.length; i++) {
+ languageListModel.append({localeName: localeList[i], displayName: Qt.locale(localeList[i]).nativeLanguageName})
+ }
+ languageListView.currentIndex = currentIndex
+ languageListView.positionViewAtIndex(currentIndex, ListView.Center)
+ languageDialog.visible = true
+ }
+
+ contentItem: ListView {
+ id: languageListView
+ model: ListModel {
+ id: languageListModel
+ function selectItem(index) {
+ VirtualKeyboardSettings.locale = languageListModel.get(index).localeName
+ languageDialog.visible = false
+ }
+ }
+ delegate: Item {
+ id: languageListItem
+ width: languageNameTextMetrics.width * 17
+ height: languageNameTextMetrics.height + languageListLabel.anchors.topMargin + languageListLabel.anchors.bottomMargin
+ Text {
+ id: languageListLabel
+ anchors.left: parent.left
+ anchors.top: parent.top
+ anchors.leftMargin: languageNameTextMetrics.height / 2
+ anchors.rightMargin: anchors.leftMargin
+ anchors.topMargin: languageNameTextMetrics.height / 3
+ anchors.bottomMargin: anchors.topMargin
+ text: languageNameFormatter.elidedText
+ color: "#5CAA15"
+ font {
+ weight: Font.Normal
+ pixelSize: 28
+ }
+ }
+ TextMetrics {
+ id: languageNameTextMetrics
+ font {
+ weight: Font.Normal
+ pixelSize: 28
+ }
+ text: "X"
+ }
+ TextMetrics {
+ id: languageNameFormatter
+ font {
+ weight: Font.Normal
+ pixelSize: 28
+ }
+ elide: Text.ElideRight
+ elideWidth: languageListItem.width - languageListLabel.anchors.leftMargin - languageListLabel.anchors.rightMargin
+ text: displayName
+ }
+ MouseArea {
+ anchors.fill: parent
+ hoverEnabled: true
+ onClicked: {
+ if (index === -1)
+ return
+ parent.ListView.view.currentIndex = index
+ parent.ListView.view.model.selectItem(index)
+ }
+ }
+ states: State {
+ name: "current"
+ when: languageListItem.ListView.isCurrentItem
+ PropertyChanges {
+ target: languageListLabel
+ color: "black"
+ }
+ }
+ }
+ }
+}
+// ![popup]
+
+// ![declaring]
+LanguageDialog {
+ id: languageDialog
+ width: 400
+ height: 400
+}
+// ![declaring]
+
+// ![using]
+InputPanel {
+ id: inputPanel
+ externalLanguageSwitchEnabled: true
+ onExternalLanguageSwitch: languageDialog.show(localeList, currentIndex)
+ // ...
+}
+// ![using]
diff --git a/src/virtualkeyboard/doc/src/user-guide.qdoc b/src/virtualkeyboard/doc/src/user-guide.qdoc
index c2d9d9f0..67ea6747 100644
--- a/src/virtualkeyboard/doc/src/user-guide.qdoc
+++ b/src/virtualkeyboard/doc/src/user-guide.qdoc
@@ -44,6 +44,7 @@ Once \l {Deployment Guide}{properly installed}, the virtual keyboard can be
opened by clicking on a text input field.
\section1 Language
+\target user-guide-language
The language can be changed by pressing the language key, which is illustrated
with a "globe" icon:
diff --git a/tests/auto/inputpanel/data/inputpanel/inputpanel.qml b/tests/auto/inputpanel/data/inputpanel/inputpanel.qml
index dfdb941b..ded8aee3 100644
--- a/tests/auto/inputpanel/data/inputpanel/inputpanel.qml
+++ b/tests/auto/inputpanel/data/inputpanel/inputpanel.qml
@@ -91,6 +91,7 @@ InputPanel {
property alias wordCandidateListVisibleSpy: wordCandidateListVisibleSpy
property alias shiftStateSpy: shiftStateSpy
property alias shadowInputControlVisibleSpy: shadowInputControlVisibleSpy
+ property alias externalLanguageSwitchSpy: externalLanguageSwitchSpy
signal inputMethodResult(var text)
@@ -188,6 +189,12 @@ InputPanel {
signalName: "onVisibleChanged"
}
+ SignalSpy {
+ id: externalLanguageSwitchSpy
+ target: inputPanel
+ signalName: "onExternalLanguageSwitch"
+ }
+
function findChildByProperty(parent, propertyName, propertyValue, compareCb) {
var obj = null
if (parent === null)
@@ -293,6 +300,10 @@ InputPanel {
return true
}
+ function setExternalLanguageSwitchEnabled(enabled) {
+ externalLanguageSwitchEnabled = enabled
+ }
+
function findVirtualKey(key) {
return Utils.findChild(keyboardLayoutLoader, key, function(obj, param) {
if (!obj.hasOwnProperty("key") || !obj.hasOwnProperty("text"))
diff --git a/tests/auto/inputpanel/data/tst_inputpanel.qml b/tests/auto/inputpanel/data/tst_inputpanel.qml
index 61d6f509..f9164f97 100644
--- a/tests/auto/inputpanel/data/tst_inputpanel.qml
+++ b/tests/auto/inputpanel/data/tst_inputpanel.qml
@@ -82,6 +82,7 @@ Rectangle {
inputPanel.setWclAlwaysVisible(data !== undefined && data.hasOwnProperty("wclAlwaysVisible") && data.wclAlwaysVisible)
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)
container.forceActiveFocus()
if (data !== undefined && data.hasOwnProperty("initText")) {
textInput.text = data.initText
@@ -1527,14 +1528,23 @@ Rectangle {
}
}
- function test_languagePopupListToggle() {
- prepareTest()
+ function test_languagePopupListToggle_data() {
+ return [
+ { externalLanguageSwitchEnabled: true },
+ { externalLanguageSwitchEnabled: false },
+ ]
+ }
+
+ function test_languagePopupListToggle(data) {
+ prepareTest(data)
if (inputPanel.availableLocales.length < 2)
skip("Input language can not be changed")
var changeLanguageKey = inputPanel.findObjectByName("changeLanguageKey")
var languagePopupList = inputPanel.findObjectByName("languagePopupList")
+ inputPanel.externalLanguageSwitchSpy.clear()
inputPanel.virtualKeyClick(changeLanguageKey)
- compare(languagePopupList.visible, true)
+ compare(languagePopupList.visible, !data.externalLanguageSwitchEnabled)
+ compare(inputPanel.externalLanguageSwitchSpy.count, data.externalLanguageSwitchEnabled ? 1 : 0)
inputPanel.virtualKeyClick(changeLanguageKey)
compare(languagePopupList.visible, false)
}