1/**************************************************************************** 2** 3** Copyright (C) 2018 The Qt Company Ltd. 4** Contact: https://www.qt.io/licensing/ 5** 6** This file is part of the documentation of the Qt Toolkit. 7** 8** $QT_BEGIN_LICENSE:FDL$ 9** Commercial License Usage 10** Licensees holding valid commercial Qt licenses may use this file in 11** accordance with the commercial license agreement provided with the 12** Software or, alternatively, in accordance with the terms contained in 13** a written agreement between you and The Qt Company. For licensing terms 14** and conditions see https://www.qt.io/terms-conditions. For further 15** information use the contact form at https://www.qt.io/contact-us. 16** 17** GNU Free Documentation License Usage 18** Alternatively, this file may be used under the terms of the GNU Free 19** Documentation License version 1.3 as published by the Free Software 20** Foundation and appearing in the file included in the packaging of 21** this file. Please review the following information to ensure 22** the GNU Free Documentation License version 1.3 requirements 23** will be met: https://www.gnu.org/licenses/fdl-1.3.html. 24** $QT_END_LICENSE$ 25** 26****************************************************************************/ 27 28// ![popup] 29Dialog { 30 id: languageDialog 31 title: "Select Input Language" 32 modality: Qt.ApplicationModal 33 34 function show(localeList, currentIndex) { 35 languageListModel.clear() 36 for (var i = 0; i < localeList.length; i++) { 37 languageListModel.append({localeName: localeList[i], displayName: Qt.locale(localeList[i]).nativeLanguageName}) 38 } 39 languageListView.currentIndex = currentIndex 40 languageListView.positionViewAtIndex(currentIndex, ListView.Center) 41 languageDialog.visible = true 42 } 43 44 contentItem: ListView { 45 id: languageListView 46 model: ListModel { 47 id: languageListModel 48 function selectItem(index) { 49 VirtualKeyboardSettings.locale = languageListModel.get(index).localeName 50 languageDialog.visible = false 51 } 52 } 53 delegate: Item { 54 id: languageListItem 55 width: languageNameTextMetrics.width * 17 56 height: languageNameTextMetrics.height + languageListLabel.anchors.topMargin + languageListLabel.anchors.bottomMargin 57 Text { 58 id: languageListLabel 59 anchors.left: parent.left 60 anchors.top: parent.top 61 anchors.leftMargin: languageNameTextMetrics.height / 2 62 anchors.rightMargin: anchors.leftMargin 63 anchors.topMargin: languageNameTextMetrics.height / 3 64 anchors.bottomMargin: anchors.topMargin 65 text: languageNameFormatter.elidedText 66 color: "#5CAA15" 67 font { 68 weight: Font.Normal 69 pixelSize: 28 70 } 71 } 72 TextMetrics { 73 id: languageNameTextMetrics 74 font { 75 weight: Font.Normal 76 pixelSize: 28 77 } 78 text: "X" 79 } 80 TextMetrics { 81 id: languageNameFormatter 82 font { 83 weight: Font.Normal 84 pixelSize: 28 85 } 86 elide: Text.ElideRight 87 elideWidth: languageListItem.width - languageListLabel.anchors.leftMargin - languageListLabel.anchors.rightMargin 88 text: displayName 89 } 90 MouseArea { 91 anchors.fill: parent 92 hoverEnabled: true 93 onClicked: { 94 if (index === -1) 95 return 96 parent.ListView.view.currentIndex = index 97 parent.ListView.view.model.selectItem(index) 98 } 99 } 100 states: State { 101 name: "current" 102 when: languageListItem.ListView.isCurrentItem 103 PropertyChanges { 104 target: languageListLabel 105 color: "black" 106 } 107 } 108 } 109 } 110} 111// ![popup] 112 113// ![declaring] 114LanguageDialog { 115 id: languageDialog 116 width: 400 117 height: 400 118} 119// ![declaring] 120 121// ![using] 122InputPanel { 123 id: inputPanel 124 externalLanguageSwitchEnabled: true 125 onExternalLanguageSwitch: languageDialog.show(localeList, currentIndex) 126 // ... 127} 128// ![using] 129