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/>.
18 import QtQuick.Layouts 1.1
19 import Ubuntu.Components 1.3
20 import Qt.labs.settings 1.0
21 import Unity.Screens 0.1
23 import "../Components"
27 property var uinput: UInput {
28 Component.onCompleted: createMouse();
29 Component.onDestruction: removeMouse();
32 Component.onCompleted: {
33 if (!settings.touchpadTutorialHasRun) {
38 function runTutorial() {
39 // If the tutorial animation is started too early, e.g. in Component.onCompleted,
40 // root width & height might be reported as 0x0 still. As animations read their
41 // values at startup and won't update them, lets make sure to only start once
42 // we have some actual size.
43 if (root.width > 0 && root.height > 0) {
46 tutorialTimer.start();
55 onTriggered: root.runTutorial();
58 readonly property bool pressed: point1.pressed || point2.pressed || leftButton.pressed || rightButton.pressed
60 property var settings: Settings {
61 objectName: "virtualTouchPadSettings"
62 property bool touchpadTutorialHasRun: false
63 property bool oskEnabled: true
67 objectName: "touchPadArea"
69 enabled: !tutorial.running || tutorial.paused
71 // FIXME: Once we have Qt DPR support, this should be Qt.styleHints.startDragDistance
72 readonly property int clickThreshold: internalGu * 1.5
73 property bool isClick: false
74 property bool isDoubleClick: false
75 property bool isDrag: false
78 if (tutorial.paused) {
83 // If double-tapping *really* fast, it could happen that we end up having only point2 pressed
84 // Make sure we check for both combos, only point1 or only point2
85 if (((point1.pressed && !point2.pressed) || (!point1.pressed && point2.pressed))
86 && clickTimer.running) {
88 uinput.pressMouse(UInput.ButtonLeft)
95 switch (touchPoints.length) {
97 moveMouse(touchPoints);
106 if (isDoubleClick || isDrag) {
107 uinput.releaseMouse(UInput.ButtonLeft)
108 isDoubleClick = false;
111 clickTimer.scheduleClick(point1.pressed ? UInput.ButtonRight : UInput.ButtonLeft)
121 property int button: UInput.ButtonLeft
123 uinput.pressMouse(button);
124 uinput.releaseMouse(button);
126 function scheduleClick(button) {
127 clickTimer.button = button;
132 function moveMouse(touchPoints) {
133 var tp = touchPoints[0];
135 (Math.abs(tp.x - tp.startX) > clickThreshold ||
136 Math.abs(tp.y - tp.startY) > clickThreshold)) {
141 uinput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
144 function scroll(touchPoints) {
147 var tp = touchPoints[0];
149 (Math.abs(tp.x - tp.startX) > clickThreshold ||
150 Math.abs(tp.y - tp.startY) > clickThreshold)) {
153 dh += tp.x - tp.previousX;
154 dv += tp.y - tp.previousY;
158 (Math.abs(tp.x - tp.startX) > clickThreshold ||
159 Math.abs(tp.y - tp.startY) > clickThreshold)) {
162 dh += tp.x - tp.previousX;
163 dv += tp.y - tp.previousY;
165 // As we added up the movement of the two fingers, let's divide it again by 2
169 uinput.scrollMouse(dh, dv);
183 anchors { left: parent.left; right: parent.right; bottom: parent.bottom; margins: -internalGu * 1 }
184 height: internalGu * 10
185 spacing: internalGu * 1
189 objectName: "leftButton"
190 Layout.fillWidth: true
191 Layout.fillHeight: true
192 onPressed: uinput.pressMouse(UInput.ButtonLeft);
193 onReleased: uinput.releaseMouse(UInput.ButtonLeft);
194 property bool highlight: false
197 backgroundColor: leftButton.highlight || leftButton.pressed ? UbuntuColors.ash : UbuntuColors.inkstone
198 Behavior on backgroundColor { ColorAnimation { duration: UbuntuAnimation.FastDuration } }
204 objectName: "rightButton"
205 Layout.fillWidth: true
206 Layout.fillHeight: true
207 onPressed: uinput.pressMouse(UInput.ButtonRight);
208 onReleased: uinput.releaseMouse(UInput.ButtonRight);
209 property bool highlight: false
212 backgroundColor: rightButton.highlight || rightButton.pressed ? UbuntuColors.ash : UbuntuColors.inkstone
213 Behavior on backgroundColor { ColorAnimation { duration: UbuntuAnimation.FastDuration } }
220 objectName: "oskButton"
221 anchors { right: parent.right; top: parent.top; margins: internalGu * 2 }
222 height: internalGu * 6
226 settings.oskEnabled = !settings.oskEnabled
232 color: UbuntuColors.inkstone
237 anchors.margins: internalGu * 1.5
238 name: "input-keyboard-symbolic"
248 // Don't resize when there is only one screen to avoid resize clashing with the InputMethod in the Shell.
249 enabled: screens.count > 1 && settings.oskEnabled && !tutorial.running
250 objectName: "inputMethod"
256 objectName: "tutorialLabel"
257 anchors { left: parent.left; top: parent.top; right: parent.right; margins: internalGu * 4; topMargin: internalGu * 10 }
260 font.pixelSize: 2 * internalGu
262 wrapMode: Text.WordWrap
267 objectName: "tutorialImage"
268 height: internalGu * 8
270 name: "input-touchpad-symbolic"
274 anchors { top: tutorialLabel.bottom; horizontalCenter: parent.horizontalCenter; margins: internalGu * 2 }
279 objectName: "tutorialFinger1"
280 width: internalGu * 5
282 property real scale: 1
286 width: parent.width * parent.scale
288 anchors.centerIn: parent
290 color: UbuntuColors.inkstone
296 objectName: "tutorialFinger2"
297 width: internalGu * 5
299 property real scale: 1
303 width: parent.width * parent.scale
305 anchors.centerIn: parent
307 color: UbuntuColors.inkstone
311 SequentialAnimation {
313 objectName: "tutorialAnimation"
315 PropertyAction { targets: [leftButton, rightButton, oskButton]; property: "enabled"; value: false }
316 PropertyAction { targets: [leftButton, rightButton, oskButton]; property: "opacity"; value: 0 }
317 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.") }
318 UbuntuNumberAnimation { targets: [tutorialLabel, tutorialImage]; property: "opacity"; to: 1; duration: UbuntuAnimation.FastDuration }
319 PropertyAction { target: tutorial; property: "paused"; value: true }
320 PauseAnimation { duration: 500 } // it takes a bit until pausing actually takes effect
321 UbuntuNumberAnimation { targets: [tutorialLabel, tutorialImage]; property: "opacity"; to: 0; duration: UbuntuAnimation.FastDuration }
323 UbuntuNumberAnimation { target: leftButton; property: "opacity"; to: 1 }
324 UbuntuNumberAnimation { target: rightButton; property: "opacity"; to: 1 }
326 PauseAnimation { duration: UbuntuAnimation.SleepyDuration }
327 PropertyAction { target: tutorialLabel; property: "text"; value: i18n.tr("Tap left button to click.") }
328 UbuntuNumberAnimation { target: tutorialLabel; property: "opacity"; to: 1; duration: UbuntuAnimation.FastDuration }
329 SequentialAnimation {
331 PropertyAction { target: leftButton; property: "highlight"; value: true }
332 PauseAnimation { duration: UbuntuAnimation.FastDuration }
333 PropertyAction { target: leftButton; property: "highlight"; value: false }
334 PauseAnimation { duration: UbuntuAnimation.SleepyDuration }
336 UbuntuNumberAnimation { target: tutorialLabel; property: "opacity"; to: 0; duration: UbuntuAnimation.FastDuration }
338 PauseAnimation { duration: UbuntuAnimation.SleepyDuration }
339 PropertyAction { target: tutorialLabel; property: "text"; value: i18n.tr("Tap right button to right click.") }
340 UbuntuNumberAnimation { target: tutorialLabel; property: "opacity"; to: 1; duration: UbuntuAnimation.FastDuration }
341 SequentialAnimation {
343 PropertyAction { target: rightButton; property: "highlight"; value: true }
344 PauseAnimation { duration: UbuntuAnimation.FastDuration }
345 PropertyAction { target: rightButton; property: "highlight"; value: false }
346 PauseAnimation { duration: UbuntuAnimation.SleepyDuration }
348 UbuntuNumberAnimation { target: tutorialLabel; property: "opacity"; to: 0; duration: UbuntuAnimation.FastDuration }
350 PauseAnimation { duration: UbuntuAnimation.SleepyDuration }
351 PropertyAction { target: tutorialLabel; property: "text"; value: i18n.tr("Swipe with two fingers to scroll.") }
352 UbuntuNumberAnimation { target: tutorialLabel; property: "opacity"; to: 1; duration: UbuntuAnimation.FastDuration }
353 PropertyAction { target: tutorialFinger1; property: "x"; value: root.width / 2 - tutorialFinger1.width - internalGu * 1 }
354 PropertyAction { target: tutorialFinger2; property: "x"; value: root.width / 2 + tutorialFinger1.width + internalGu * 1 - tutorialFinger2.width }
355 PropertyAction { target: tutorialFinger1; property: "y"; value: root.height / 2 - internalGu * 10 }
356 PropertyAction { target: tutorialFinger2; property: "y"; value: root.height / 2 - internalGu * 10 }
357 SequentialAnimation {
359 UbuntuNumberAnimation { target: tutorialFinger1; property: "opacity"; to: 1; duration: UbuntuAnimation.FastDuration }
360 UbuntuNumberAnimation { target: tutorialFinger2; property: "opacity"; to: 1; duration: UbuntuAnimation.FastDuration }
361 UbuntuNumberAnimation { target: tutorialFinger1; property: "scale"; from: 0; to: 1; duration: UbuntuAnimation.FastDuration }
362 UbuntuNumberAnimation { target: tutorialFinger2; property: "scale"; from: 0; to: 1; duration: UbuntuAnimation.FastDuration }
365 UbuntuNumberAnimation { target: tutorialFinger1; property: "y"; to: root.height / 2 + internalGu * 10; duration: UbuntuAnimation.SleepyDuration }
366 UbuntuNumberAnimation { target: tutorialFinger2; property: "y"; to: root.height / 2 + internalGu * 10; duration: UbuntuAnimation.SleepyDuration }
369 UbuntuNumberAnimation { target: tutorialFinger1; property: "opacity"; to: 0; duration: UbuntuAnimation.FastDuration }
370 UbuntuNumberAnimation { target: tutorialFinger2; property: "opacity"; to: 0; duration: UbuntuAnimation.FastDuration }
371 UbuntuNumberAnimation { target: tutorialFinger1; property: "scale"; from: 1; to: 0; duration: UbuntuAnimation.FastDuration }
372 UbuntuNumberAnimation { target: tutorialFinger2; property: "scale"; from: 1; to: 0; duration: UbuntuAnimation.FastDuration }
374 PauseAnimation { duration: UbuntuAnimation.SlowDuration }
376 UbuntuNumberAnimation { target: tutorialFinger1; property: "opacity"; to: 1; duration: UbuntuAnimation.FastDuration }
377 UbuntuNumberAnimation { target: tutorialFinger2; property: "opacity"; to: 1; duration: UbuntuAnimation.FastDuration }
378 UbuntuNumberAnimation { target: tutorialFinger1; property: "scale"; from: 0; to: 1; duration: UbuntuAnimation.FastDuration }
379 UbuntuNumberAnimation { target: tutorialFinger2; property: "scale"; from: 0; to: 1; duration: UbuntuAnimation.FastDuration }
382 UbuntuNumberAnimation { target: tutorialFinger1; property: "y"; to: root.height / 2 - internalGu * 10; duration: UbuntuAnimation.SleepyDuration }
383 UbuntuNumberAnimation { target: tutorialFinger2; property: "y"; to: root.height / 2 - internalGu * 10; duration: UbuntuAnimation.SleepyDuration }
386 UbuntuNumberAnimation { target: tutorialFinger1; property: "opacity"; to: 0; duration: UbuntuAnimation.FastDuration }
387 UbuntuNumberAnimation { target: tutorialFinger2; property: "opacity"; to: 0; duration: UbuntuAnimation.FastDuration }
388 UbuntuNumberAnimation { target: tutorialFinger1; property: "scale"; from: 1; to: 0; duration: UbuntuAnimation.FastDuration }
389 UbuntuNumberAnimation { target: tutorialFinger2; property: "scale"; from: 1; to: 0; duration: UbuntuAnimation.FastDuration }
391 PauseAnimation { duration: UbuntuAnimation.SlowDuration }
393 UbuntuNumberAnimation { target: tutorialLabel; property: "opacity"; to: 0; duration: UbuntuAnimation.FastDuration }
395 PauseAnimation { duration: UbuntuAnimation.SleepyDuration }
396 PropertyAction { target: tutorialLabel; property: "text"; value: i18n.tr("Find more settings in the system settings.") }
397 UbuntuNumberAnimation { target: tutorialLabel; property: "opacity"; to: 1; duration: UbuntuAnimation.FastDuration }
398 PauseAnimation { duration: 2000 }
399 UbuntuNumberAnimation { target: tutorialLabel; property: "opacity"; to: 0; duration: UbuntuAnimation.FastDuration }
401 UbuntuNumberAnimation { target: oskButton; property: "opacity"; to: 1 }
402 PropertyAction { targets: [leftButton, rightButton, oskButton]; property: "enabled"; value: true }
404 PropertyAction { target: settings; property: "touchpadTutorialHasRun"; value: true }