2 * Copyright (C) 2015 Canonical Ltd.
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.
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.
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/>.
18import QtQuick.Layouts 1.1
19import Lomiri.Components 1.3
20import Qt.labs.settings 1.0
27 property bool oskEnabled: false
29 Component.onCompleted: {
31 if (!settings.touchpadTutorialHasRun) {
35 Component.onDestruction: UInput.removeMouse()
37 function runTutorial() {
38 // If the tutorial animation is started too early, e.g. in Component.onCompleted,
39 // root width & height might be reported as 0x0 still. As animations read their
40 // values at startup and won't update them, lets make sure to only start once
41 // we have some actual size.
42 if (root.width > 0 && root.height > 0) {
45 tutorialTimer.start();
54 onTriggered: root.runTutorial();
57 readonly property bool pressed: point1.pressed || point2.pressed || leftButton.pressed || rightButton.pressed
59 property var settings: Settings {
60 objectName: "virtualTouchPadSettings"
61 property bool touchpadTutorialHasRun: false
62 property bool oskEnabled: true
66 objectName: "touchPadArea"
68 enabled: !tutorial.running || tutorial.paused
70 // FIXME: Once we have Qt DPR support, this should be Qt.styleHints.startDragDistance
71 readonly property int clickThreshold: internalGu * 1.5
72 property bool isClick: false
73 property bool isDoubleClick: false
74 property bool isDrag: false
77 if (tutorial.paused) {
82 // If double-tapping *really* fast, it could happen that we end up having only point2 pressed
83 // Make sure we check for both combos, only point1 or only point2
84 if (((point1.pressed && !point2.pressed) || (!point1.pressed && point2.pressed))
85 && clickTimer.running) {
87 UInput.pressMouse(UInput.ButtonLeft)
94 switch (touchPoints.length) {
96 moveMouse(touchPoints);
105 if (isDoubleClick || isDrag) {
106 UInput.releaseMouse(UInput.ButtonLeft)
107 isDoubleClick = false;
110 clickTimer.scheduleClick(point1.pressed ? UInput.ButtonRight : UInput.ButtonLeft)
120 property int button: UInput.ButtonLeft
122 UInput.pressMouse(button);
123 UInput.releaseMouse(button);
125 function scheduleClick(button) {
126 clickTimer.button = button;
131 function moveMouse(touchPoints) {
132 var tp = touchPoints[0];
134 (Math.abs(tp.x - tp.startX) > clickThreshold ||
135 Math.abs(tp.y - tp.startY) > clickThreshold)) {
140 UInput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
143 function scroll(touchPoints) {
146 var tp = touchPoints[0];
148 (Math.abs(tp.x - tp.startX) > clickThreshold ||
149 Math.abs(tp.y - tp.startY) > clickThreshold)) {
152 dh += tp.x - tp.previousX;
153 dv += tp.y - tp.previousY;
157 (Math.abs(tp.x - tp.startX) > clickThreshold ||
158 Math.abs(tp.y - tp.startY) > clickThreshold)) {
161 dh += tp.x - tp.previousX;
162 dv += tp.y - tp.previousY;
164 // As we added up the movement of the two fingers, let's divide it again by 2
168 UInput.scrollMouse(dh, dv);
182 anchors { left: parent.left; right: parent.right; bottom: parent.bottom; margins: -internalGu * 1 }
183 height: internalGu * 10
184 spacing: internalGu * 1
188 objectName: "leftButton"
189 Layout.fillWidth: true
190 Layout.fillHeight: true
191 onPressed: UInput.pressMouse(UInput.ButtonLeft);
192 onReleased: UInput.releaseMouse(UInput.ButtonLeft);
193 property bool highlight: false
196 backgroundColor: leftButton.highlight || leftButton.pressed ? LomiriColors.ash : LomiriColors.inkstone
197 Behavior on backgroundColor { ColorAnimation { duration: LomiriAnimation.FastDuration } }
203 objectName: "rightButton"
204 Layout.fillWidth: true
205 Layout.fillHeight: true
206 onPressed: UInput.pressMouse(UInput.ButtonRight);
207 onReleased: UInput.releaseMouse(UInput.ButtonRight);
208 property bool highlight: false
211 backgroundColor: rightButton.highlight || rightButton.pressed ? LomiriColors.ash : LomiriColors.inkstone
212 Behavior on backgroundColor { ColorAnimation { duration: LomiriAnimation.FastDuration } }
219 objectName: "oskButton"
220 anchors { right: parent.right; top: parent.top; margins: internalGu * 2 }
221 height: internalGu * 6
225 settings.oskEnabled = !settings.oskEnabled
231 color: LomiriColors.inkstone
236 anchors.margins: internalGu * 1.5
237 name: "input-keyboard-symbolic"
243 // Don't resize when there is only one screen to avoid resize clashing with the InputMethod in the Shell.
244 enabled: root.oskEnabled && settings.oskEnabled && !tutorial.running
245 objectName: "inputMethod"
251 objectName: "tutorialLabel"
252 anchors { left: parent.left; top: parent.top; right: parent.right; margins: internalGu * 4; topMargin: internalGu * 10 }
255 font.pixelSize: 2 * internalGu
257 wrapMode: Text.WordWrap
262 objectName: "tutorialImage"
263 height: internalGu * 8
265 name: "input-touchpad-symbolic"
269 anchors { top: tutorialLabel.bottom; horizontalCenter: parent.horizontalCenter; margins: internalGu * 2 }
274 objectName: "tutorialFinger1"
275 width: internalGu * 5
277 property real scale: 1
281 width: parent.width * parent.scale
283 anchors.centerIn: parent
285 color: LomiriColors.inkstone
291 objectName: "tutorialFinger2"
292 width: internalGu * 5
294 property real scale: 1
298 width: parent.width * parent.scale
300 anchors.centerIn: parent
302 color: LomiriColors.inkstone
306 SequentialAnimation {
308 objectName: "tutorialAnimation"
310 PropertyAction { targets: [leftButton, rightButton, oskButton]; property: "enabled"; value: false }
311 PropertyAction { targets: [leftButton, rightButton, oskButton]; property: "opacity"; value: 0 }
312 PropertyAction { target: tutorialLabel; property: "text"; value: i18n.tr("Your device is now connected to an external display. Use this screen as a touch pad to interact with the pointer.") }
313 LomiriNumberAnimation { targets: [tutorialLabel, tutorialImage]; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
314 PropertyAction { target: tutorial; property: "paused"; value: true }
315 PauseAnimation { duration: 500 } // it takes a bit until pausing actually takes effect
316 LomiriNumberAnimation { targets: [tutorialLabel, tutorialImage]; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
318 LomiriNumberAnimation { target: leftButton; property: "opacity"; to: 1 }
319 LomiriNumberAnimation { target: rightButton; property: "opacity"; to: 1 }
321 PauseAnimation { duration: LomiriAnimation.SleepyDuration }
322 PropertyAction { target: tutorialLabel; property: "text"; value: i18n.tr("Tap left button to click.") }
323 LomiriNumberAnimation { target: tutorialLabel; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
324 SequentialAnimation {
326 PropertyAction { target: leftButton; property: "highlight"; value: true }
327 PauseAnimation { duration: LomiriAnimation.FastDuration }
328 PropertyAction { target: leftButton; property: "highlight"; value: false }
329 PauseAnimation { duration: LomiriAnimation.SleepyDuration }
331 LomiriNumberAnimation { target: tutorialLabel; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
333 PauseAnimation { duration: LomiriAnimation.SleepyDuration }
334 PropertyAction { target: tutorialLabel; property: "text"; value: i18n.tr("Tap right button to right click.") }
335 LomiriNumberAnimation { target: tutorialLabel; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
336 SequentialAnimation {
338 PropertyAction { target: rightButton; property: "highlight"; value: true }
339 PauseAnimation { duration: LomiriAnimation.FastDuration }
340 PropertyAction { target: rightButton; property: "highlight"; value: false }
341 PauseAnimation { duration: LomiriAnimation.SleepyDuration }
343 LomiriNumberAnimation { target: tutorialLabel; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
345 PauseAnimation { duration: LomiriAnimation.SleepyDuration }
346 PropertyAction { target: tutorialLabel; property: "text"; value: i18n.tr("Swipe with two fingers to scroll.") }
347 LomiriNumberAnimation { target: tutorialLabel; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
348 PropertyAction { target: tutorialFinger1; property: "x"; value: root.width / 2 - tutorialFinger1.width - internalGu * 1 }
349 PropertyAction { target: tutorialFinger2; property: "x"; value: root.width / 2 + tutorialFinger1.width + internalGu * 1 - tutorialFinger2.width }
350 PropertyAction { target: tutorialFinger1; property: "y"; value: root.height / 2 - internalGu * 10 }
351 PropertyAction { target: tutorialFinger2; property: "y"; value: root.height / 2 - internalGu * 10 }
352 SequentialAnimation {
354 LomiriNumberAnimation { target: tutorialFinger1; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
355 LomiriNumberAnimation { target: tutorialFinger2; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
356 LomiriNumberAnimation { target: tutorialFinger1; property: "scale"; from: 0; to: 1; duration: LomiriAnimation.FastDuration }
357 LomiriNumberAnimation { target: tutorialFinger2; property: "scale"; from: 0; to: 1; duration: LomiriAnimation.FastDuration }
360 LomiriNumberAnimation { target: tutorialFinger1; property: "y"; to: root.height / 2 + internalGu * 10; duration: LomiriAnimation.SleepyDuration }
361 LomiriNumberAnimation { target: tutorialFinger2; property: "y"; to: root.height / 2 + internalGu * 10; duration: LomiriAnimation.SleepyDuration }
364 LomiriNumberAnimation { target: tutorialFinger1; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
365 LomiriNumberAnimation { target: tutorialFinger2; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
366 LomiriNumberAnimation { target: tutorialFinger1; property: "scale"; from: 1; to: 0; duration: LomiriAnimation.FastDuration }
367 LomiriNumberAnimation { target: tutorialFinger2; property: "scale"; from: 1; to: 0; duration: LomiriAnimation.FastDuration }
369 PauseAnimation { duration: LomiriAnimation.SlowDuration }
371 LomiriNumberAnimation { target: tutorialFinger1; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
372 LomiriNumberAnimation { target: tutorialFinger2; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
373 LomiriNumberAnimation { target: tutorialFinger1; property: "scale"; from: 0; to: 1; duration: LomiriAnimation.FastDuration }
374 LomiriNumberAnimation { target: tutorialFinger2; property: "scale"; from: 0; to: 1; duration: LomiriAnimation.FastDuration }
377 LomiriNumberAnimation { target: tutorialFinger1; property: "y"; to: root.height / 2 - internalGu * 10; duration: LomiriAnimation.SleepyDuration }
378 LomiriNumberAnimation { target: tutorialFinger2; property: "y"; to: root.height / 2 - internalGu * 10; duration: LomiriAnimation.SleepyDuration }
381 LomiriNumberAnimation { target: tutorialFinger1; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
382 LomiriNumberAnimation { target: tutorialFinger2; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
383 LomiriNumberAnimation { target: tutorialFinger1; property: "scale"; from: 1; to: 0; duration: LomiriAnimation.FastDuration }
384 LomiriNumberAnimation { target: tutorialFinger2; property: "scale"; from: 1; to: 0; duration: LomiriAnimation.FastDuration }
386 PauseAnimation { duration: LomiriAnimation.SlowDuration }
388 LomiriNumberAnimation { target: tutorialLabel; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
390 PauseAnimation { duration: LomiriAnimation.SleepyDuration }
391 PropertyAction { target: tutorialLabel; property: "text"; value: i18n.tr("Find more settings in the system settings.") }
392 LomiriNumberAnimation { target: tutorialLabel; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
393 PauseAnimation { duration: 2000 }
394 LomiriNumberAnimation { target: tutorialLabel; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
396 LomiriNumberAnimation { target: oskButton; property: "opacity"; to: 1 }
397 PropertyAction { targets: [leftButton, rightButton, oskButton]; property: "enabled"; value: true }
399 PropertyAction { target: settings; property: "touchpadTutorialHasRun"; value: true }