Changeset View
Changeset View
Standalone View
Standalone View
kcms/input/kcm/libinput/main.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2018 Roman Gilg <subdiff@gmail.com> | ||||
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; either version 2 of the License, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License | ||||
15 | * along with this program; if not, write to the Free Software | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | | ||||
19 | import QtQuick 2.7 | ||||
20 | import QtQuick.Controls 1.4 as Controls | ||||
21 | import QtQuick.Layouts 1.3 as Layouts | ||||
22 | import QtQuick.Controls.Styles 1.4 as Styles | ||||
23 | | ||||
24 | import org.kde.plasma.core 2.0 as PlasmaCore | ||||
25 | | ||||
26 | import "components" | ||||
27 | | ||||
28 | Item { | ||||
29 | id: root | ||||
30 | | ||||
31 | property size sizeHint: Qt.size(maincol.width, maincol.height) | ||||
32 | property size minimumSizeHint: Qt.size(maincol.width/2, deviceSelector.height) | ||||
33 | property alias deviceIndex: deviceSelector.currentIndex | ||||
34 | signal changeSignal() | ||||
35 | | ||||
36 | property QtObject device | ||||
37 | property int deviceCount: backend.deviceCount | ||||
38 | | ||||
39 | property bool loading: false | ||||
40 | | ||||
41 | function resetModel(index) { | ||||
42 | deviceCount = backend.deviceCount | ||||
43 | maincol.enabled = deviceCount | ||||
44 | deviceSelector.enabled = deviceCount > 1 | ||||
45 | | ||||
46 | loading = true | ||||
47 | if (deviceCount) { | ||||
48 | device = deviceModel[index] | ||||
49 | deviceSelector.model = deviceModel | ||||
50 | deviceSelector.currentIndex = index | ||||
51 | console.log("Configuration of device '" + | ||||
52 | (index + 1) + " : " + device.name + "' opened") | ||||
53 | } else { | ||||
54 | deviceSelector.model = [""] | ||||
55 | console.log("No device found") | ||||
56 | } | ||||
57 | loading = false | ||||
58 | } | ||||
59 | | ||||
60 | function syncValuesFromBackend() { | ||||
61 | loading = true | ||||
62 | | ||||
63 | deviceEnabled.load() | ||||
64 | leftHanded.load() | ||||
65 | accelSpeed.load() | ||||
66 | accelProfile.load() | ||||
67 | | ||||
68 | naturalScroll.load() | ||||
69 | | ||||
70 | loading = false | ||||
71 | } | ||||
72 | | ||||
73 | Controls.ScrollView { | ||||
74 | anchors.fill: parent | ||||
75 | | ||||
76 | Layouts.ColumnLayout { | ||||
77 | id: maincol | ||||
78 | enabled: deviceCount | ||||
79 | spacing: units.largeSpacing | ||||
80 | | ||||
81 | Layouts.RowLayout { | ||||
82 | spacing: units.largeSpacing | ||||
83 | | ||||
84 | Controls.Label { | ||||
85 | text: i18n("Device:") | ||||
86 | } | ||||
87 | | ||||
88 | Controls.ComboBox { | ||||
89 | id: deviceSelector | ||||
90 | enabled: deviceCount > 1 | ||||
91 | Layouts.Layout.fillWidth: true | ||||
92 | model: deviceModel | ||||
93 | textRole: "name" | ||||
94 | | ||||
95 | onCurrentIndexChanged: { | ||||
96 | if (deviceCount) { | ||||
97 | device = deviceModel[currentIndex] | ||||
98 | if (!loading) { | ||||
99 | changeSignal() | ||||
100 | } | ||||
101 | console.log("Configuration of device '" + | ||||
102 | (currentIndex+1) + " : " + device.name + "' opened") | ||||
103 | } | ||||
104 | root.syncValuesFromBackend() | ||||
105 | } | ||||
106 | } | ||||
107 | } | ||||
108 | | ||||
109 | Column { | ||||
110 | spacing: units.smallSpacing * 2 | ||||
111 | | ||||
112 | Column { | ||||
113 | leftPadding: units.smallSpacing | ||||
114 | Column { | ||||
115 | spacing: units.smallSpacing | ||||
116 | Controls.Label { | ||||
117 | text: i18n("General settings:") | ||||
118 | } | ||||
119 | | ||||
120 | Column { | ||||
121 | leftPadding: units.smallSpacing | ||||
122 | Column { | ||||
123 | spacing: units.smallSpacing | ||||
124 | Controls.CheckBox { | ||||
125 | id: deviceEnabled | ||||
126 | text: i18n("Device enabled") | ||||
127 | | ||||
128 | function load() { | ||||
129 | if (!maincol.enabled) { | ||||
130 | checked = false | ||||
131 | return | ||||
132 | } | ||||
133 | enabled = device.supportsDisableEvents | ||||
134 | checked = enabled && device.enabled | ||||
135 | } | ||||
136 | | ||||
137 | onCheckedChanged: { | ||||
138 | if (enabled && !root.loading) { | ||||
139 | device.enabled = checked | ||||
140 | root.changeSignal() | ||||
141 | } | ||||
142 | } | ||||
143 | | ||||
144 | ToolTip { | ||||
145 | text: i18n("Accept input through this device.") | ||||
146 | } | ||||
147 | } | ||||
148 | | ||||
149 | Controls.CheckBox { | ||||
150 | id: leftHanded | ||||
151 | text: i18n("Left handed mode") | ||||
152 | | ||||
153 | function load() { | ||||
154 | if (!maincol.enabled) { | ||||
155 | checked = false | ||||
156 | return | ||||
157 | } | ||||
158 | enabled = device.supportsLeftHanded | ||||
159 | checked = enabled && device.leftHanded | ||||
160 | } | ||||
161 | | ||||
162 | onCheckedChanged: { | ||||
163 | if (enabled && !root.loading) { | ||||
164 | device.leftHanded = checked | ||||
165 | root.changeSignal() | ||||
166 | } | ||||
167 | } | ||||
168 | | ||||
169 | ToolTip { | ||||
170 | text: i18n("Swap left and right buttons.") | ||||
171 | } | ||||
172 | } | ||||
173 | | ||||
174 | Controls.CheckBox { | ||||
175 | id: middleEmulation | ||||
176 | text: i18n("Emulate middle button") | ||||
177 | | ||||
178 | function load() { | ||||
179 | if (!maincol.enabled) { | ||||
180 | checked = false | ||||
181 | return | ||||
182 | } | ||||
183 | enabled = device.supportsMiddleEmulation | ||||
184 | checked = enabled && device.middleEmulation | ||||
185 | } | ||||
186 | | ||||
187 | onCheckedChanged: { | ||||
188 | if (enabled && !root.loading) { | ||||
189 | device.middleEmulation = checked | ||||
190 | root.changeSignal() | ||||
191 | } | ||||
192 | } | ||||
193 | | ||||
194 | ToolTip { | ||||
195 | text: i18n("Clicking left and right button simultaneously sends middle button click.") | ||||
196 | } | ||||
197 | } | ||||
198 | } | ||||
199 | } | ||||
200 | } | ||||
201 | } | ||||
202 | | ||||
203 | Column { | ||||
204 | leftPadding: units.smallSpacing | ||||
205 | Column { | ||||
206 | spacing: units.smallSpacing | ||||
207 | Controls.Label { | ||||
208 | text: i18n("Acceleration:") | ||||
209 | } | ||||
210 | | ||||
211 | Column { | ||||
212 | leftPadding: units.smallSpacing | ||||
213 | Column { | ||||
214 | spacing: units.smallSpacing * 2 | ||||
215 | | ||||
216 | Row { | ||||
217 | Controls.Slider { | ||||
218 | id: accelSpeed | ||||
219 | anchors.verticalCenter: parent.verticalCenter | ||||
220 | | ||||
221 | tickmarksEnabled: true | ||||
222 | | ||||
223 | minimumValue: 1 | ||||
224 | maximumValue: 10 | ||||
225 | stepSize: 1 | ||||
226 | | ||||
227 | implicitWidth: units.gridUnit * 9 | ||||
228 | | ||||
229 | function load() { | ||||
230 | enabled = device.supportsPointerAcceleration | ||||
231 | if (!enabled) { | ||||
232 | value = 0.1 | ||||
233 | return | ||||
234 | } | ||||
235 | // transform libinput's pointer acceleration range [-1, 1] to slider range [1, 10] | ||||
236 | value = 4.5 * device.pointerAcceleration + 5.5 | ||||
237 | } | ||||
238 | | ||||
239 | onValueChanged: { | ||||
240 | if (device != undefined && enabled && !root.loading) { | ||||
241 | // transform slider range [1, 10] to libinput's pointer acceleration range [-1, 1] | ||||
242 | device.pointerAcceleration = Math.round( (value - 5.5) / 4.5 * 100 ) / 100 | ||||
243 | root.changeSignal() | ||||
244 | } | ||||
245 | } | ||||
246 | } | ||||
247 | } | ||||
248 | | ||||
249 | ExclGroupBox { | ||||
250 | id: accelProfile | ||||
251 | label: i18n("Acceleration Profile:") | ||||
252 | model: [i18n("Flat"), i18n("Adaptive")] | ||||
253 | | ||||
254 | function load() { | ||||
255 | enabled = device.supportsPointerAccelerationProfileAdaptive | ||||
256 | | ||||
257 | if (!enabled) { | ||||
258 | itemAt(0).checked = false | ||||
259 | itemAt(1).checked = false | ||||
260 | return | ||||
261 | } | ||||
262 | | ||||
263 | itemAt(0).tooltiptext = i18n("Cursor moves the same distance as finger.") | ||||
264 | itemAt(1).tooltiptext = i18n("Cursor travel distance depends on movement speed of finger.") | ||||
265 | | ||||
266 | var toCheck = device.pointerAccelerationProfileAdaptive ? 1 : 0 | ||||
267 | itemAt(toCheck).checked = true | ||||
268 | } | ||||
269 | | ||||
270 | onCurrentChanged: { | ||||
271 | if (enabled && !root.loading) { | ||||
272 | device.pointerAccelerationProfileFlat = itemAt(0).checked | ||||
273 | device.pointerAccelerationProfileAdaptive = itemAt(1).checked | ||||
274 | root.changeSignal() | ||||
275 | } | ||||
276 | } | ||||
277 | } | ||||
278 | } | ||||
279 | } | ||||
280 | } | ||||
281 | } | ||||
282 | | ||||
283 | Column { | ||||
284 | leftPadding: units.smallSpacing | ||||
285 | Column { | ||||
286 | spacing: units.smallSpacing | ||||
287 | Controls.Label { | ||||
288 | text: i18n("Scrolling:") | ||||
289 | } | ||||
290 | | ||||
291 | Column { | ||||
292 | leftPadding: units.smallSpacing | ||||
293 | Column { | ||||
294 | spacing: units.smallSpacing | ||||
295 | | ||||
296 | Controls.CheckBox { | ||||
297 | id: naturalScroll | ||||
298 | text: i18n("Invert scroll direction") | ||||
299 | | ||||
300 | function load() { | ||||
301 | enabled = device.supportsNaturalScroll | ||||
302 | checked = enabled && device.naturalScroll | ||||
303 | } | ||||
304 | | ||||
305 | onCheckedChanged: { | ||||
306 | if (enabled && !root.loading) { | ||||
307 | device.naturalScroll = checked | ||||
308 | root.changeSignal() | ||||
309 | } | ||||
310 | } | ||||
311 | | ||||
312 | ToolTip { | ||||
313 | text: i18n("Touchscreen like scrolling.") | ||||
314 | } | ||||
315 | } | ||||
316 | } | ||||
317 | } | ||||
318 | } | ||||
319 | } | ||||
320 | } | ||||
321 | } | ||||
322 | } | ||||
323 | } |