aboutsummaryrefslogtreecommitdiffstats
path: root/src/virtualkeyboard
diff options
context:
space:
mode:
authorJarkko Koivikko <jarkko.koivikko@code-q.fi>2017-09-21 23:28:23 +0300
committerMitch Curtis <mitch.curtis@qt.io>2018-01-19 09:40:22 +0000
commit46f6b84e7e8d5cff6e038d47026baf657ecb1460 (patch)
treeb5a0fd8a5a8f149244011026956b274f914ddac5 /src/virtualkeyboard
parentd297dfd0641e6608386205d99a0518726c315867 (diff)
Add support for external language switch
Added new signal InputPanel::externalLanguageSwitch and a property InputPanel::externalLanguageSwitchEnabled for enabling external language switch. If the externalLanguageSwitchEnabled is true, the signal is triggered instead of built-in language popup. The new language can be selected by setting the VirtualKeyboardSettings::locale property. [ChangeLog] Add option to use external language dialog instead of built-in language popup. Change-Id: I44f88e6b3e52db4cfbee02bd3b6d7f4be38a9521 Reviewed-by: Jarkko Koivikko <jarkko.koivikko@code-q.fi> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/virtualkeyboard')
-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
4 files changed, 193 insertions, 4 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: