Lomiri
Loading...
Searching...
No Matches
20-keyboard.qml
1/*
2 * Copyright (C) 2016 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17import QtQuick 2.12
18import Lomiri.Components 1.3
19import Lomiri.Components.ListItems 1.3
20import Lomiri.SystemSettings.LanguagePlugin 1.0
21import Wizard 0.1
22import AccountsService 0.1
23import Lomiri.InputInfo 0.1
24import QtMir.Application 0.1
25import ".." as LocalComponents
26import "../../Components"
27
28LocalComponents.Page {
29 objectName: "keyboardPage"
30
31 title: i18n.tr("Select Keyboard")
32 forwardButtonSourceComponent: forwardButton
33
34 skip: keyboardsModel.count == 0
35 skipValid: false
36
37 LomiriLanguagePlugin {
38 id: langPlugin
39 }
40
41 KeyboardLayoutsModel {
42 id: layoutsModel
43 language: selectedLanguage
44 }
45
46 InputDeviceModel {
47 id: keyboardsModel
48 deviceFilter: InputInfo.Keyboard
49 Component.onCompleted: skipValid = true;
50 }
51
52 readonly property string selectedLanguage: langPlugin.languageCodes[langSelector.selectedIndex].split(".")[0] // chop off the codeset (.UTF-8)
53
54 property string selectedKeymap: ""
55
56 Column {
57 id: column
58 spacing: units.gu(2)
59
60 anchors {
61 fill: content
62 leftMargin: wideMode ? parent.leftMargin : staticMargin
63 rightMargin: wideMode ? parent.rightMargin : staticMargin
64 topMargin: staticMargin
65 }
66
67 Label {
68 id: label1
69 anchors.left: parent.left
70 anchors.right: parent.right
71 text: i18n.tr("Keyboard language")
72 font.weight: Font.Normal
73 color: textColor
74 }
75
76 LocalComponents.WizardItemSelector {
77 id: langSelector
78 objectName: "langSelector"
79 anchors.left: parent.left
80 anchors.right: parent.right
81 model: langPlugin.languageNames
82 selectedIndex: langPlugin.languageCodes.indexOf(i18n.language)
83 onSelectedIndexChanged: {
84 keyboardListView.currentIndex = -1;
85 selectedKeymap = "";
86 }
87 }
88
89 Label {
90 id: label2
91 anchors.left: parent.left
92 anchors.right: parent.right
93 text: i18n.tr("Keyboard layout")
94 font.weight: Font.Normal
95 color: textColor
96 }
97
98 ListView {
99 id: keyboardListView
100 clip: true
101 anchors.left: parent.left
102 anchors.right: parent.right
103 snapMode: ListView.SnapToItem
104 model: layoutsModel
105 currentIndex: -1
106 opacity: langSelector.expanded ? 0.5 : 1
107 height: column.height - label1.height - langSelector.height - label2.height - column.spacing * 3
108 enabled: !langSelector.expanded
109 Behavior on opacity {
110 LomiriNumberAnimation {}
111 }
112
113 delegate: ListItem {
114 id: itemDelegate
115 objectName: "kbdDelegate" + index
116 height: layout.height + (divider.visible ? divider.height : 0)
117 readonly property bool isCurrent: index === ListView.view.currentIndex
118 highlightColor: backgroundColor
119 divider.colorFrom: dividerColor
120 divider.colorTo: backgroundColor
121
122 ListItemLayout {
123 id: layout
124 title.text: displayName
125 title.color: textColor
126 subtitle.text: layoutId
127 subtitle.color: textColor
128 padding.leading: -units.gu(1)
129 padding.trailing: -units.gu(1)
130 Image {
131 SlotsLayout.position: SlotsLayout.Trailing
132 SlotsLayout.overrideVerticalPositioning: true
133 fillMode: Image.PreserveAspectFit
134 anchors.verticalCenter: parent.verticalCenter
135 height: units.gu(1.5)
136 source: "data/Tick@30.png"
137 visible: itemDelegate.isCurrent
138 }
139 }
140
141 onClicked: {
142 keyboardListView.currentIndex = index;
143 selectedKeymap = layoutId;
144 }
145 }
146 }
147 }
148
149 Component {
150 id: forwardButton
151 LocalComponents.StackButton {
152 text: keyboardListView.currentIndex != -1 ? i18n.tr("Next") : i18n.tr("Skip")
153 onClicked: {
154 if (keyboardListView.currentIndex != -1) {
155 AccountsService.keymaps = selectedKeymap;
156 }
157 pageStack.next();
158 }
159 }
160 }
161}