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
28 property bool oskEnabled: false
29 property bool showRotateButton: false
34 id: aethercastDisplays
37 Component.onCompleted: {
39 if (!settings.touchpadTutorialHasRun) {
43 Component.onDestruction: UInput.removeMouse()
45 function runTutorial() {
46 // If the tutorial animation is started too early, e.g. in Component.onCompleted,
47 // root width & height might be reported as 0x0 still. As animations read their
48 // values at startup and won't update them, lets make sure to only start once
49 // we have some actual size.
50 if (root.width > 0 && root.height > 0) {
53 tutorialTimer.start();
62 onTriggered: root.runTutorial();
65 readonly property bool pressed: point1.pressed || point2.pressed || leftButton.pressed || rightButton.pressed
67 property var settings: Settings {
68 objectName: "virtualTouchPadSettings"
69 property bool touchpadTutorialHasRun: false
70 property bool oskEnabled: true
74 objectName: "touchPadArea"
76 enabled: !tutorial.running || tutorial.paused
78 // FIXME: Once we have Qt DPR support, this should be Qt.styleHints.startDragDistance
79 readonly property int clickThreshold: internalGu * 0.5
80 property bool isClick: false
81 property bool isDoubleClick: false
82 property bool isDrag: false
85 if (tutorial.paused) {
90 // If double-tapping *really* fast, it could happen that we end up having only point2 pressed
91 // Make sure we check for both combos, only point1 or only point2
92 if (((point1.pressed && !point2.pressed) || (!point1.pressed && point2.pressed))
93 && clickTimer.running) {
95 UInput.pressMouse(UInput.ButtonLeft)
102 switch (touchPoints.length) {
104 moveMouse(touchPoints);
113 if (isDoubleClick || isDrag) {
114 UInput.releaseMouse(UInput.ButtonLeft)
115 isDoubleClick = false;
118 clickTimer.scheduleClick(point1.pressed ? UInput.ButtonRight : UInput.ButtonLeft)
128 property int button: UInput.ButtonLeft
130 UInput.pressMouse(button);
131 UInput.releaseMouse(button);
133 function scheduleClick(button) {
134 clickTimer.button = button;
139 function moveMouse(touchPoints) {
140 var tp = touchPoints[0];
142 (Math.abs(tp.x - tp.startX) > clickThreshold ||
143 Math.abs(tp.y - tp.startY) > clickThreshold)) {
148 UInput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
151 function scroll(touchPoints) {
154 var tp = touchPoints[0];
156 (Math.abs(tp.x - tp.startX) > clickThreshold ||
157 Math.abs(tp.y - tp.startY) > clickThreshold)) {
160 dh += tp.x - tp.previousX;
161 dv += tp.y - tp.previousY;
165 (Math.abs(tp.x - tp.startX) > clickThreshold ||
166 Math.abs(tp.y - tp.startY) > clickThreshold)) {
169 dh += tp.x - tp.previousX;
170 dv += tp.y - tp.previousY;
172 // As we added up the movement of the two fingers, let's divide it again by 2
176 UInput.scrollMouse(dh, dv);
190 anchors { left: parent.left; right: parent.right; bottom: parent.bottom; margins: -internalGu * 1 }
191 height: internalGu * 10
192 spacing: internalGu * 1
196 objectName: "leftButton"
197 Layout.fillWidth: true
198 Layout.fillHeight: true
199 onPressed: UInput.pressMouse(UInput.ButtonLeft);
200 onReleased: UInput.releaseMouse(UInput.ButtonLeft);
201 property bool highlight: false
204 backgroundColor: leftButton.highlight || leftButton.pressed ? LomiriColors.ash : LomiriColors.inkstone
205 Behavior on backgroundColor { ColorAnimation { duration: LomiriAnimation.FastDuration } }
211 objectName: "rightButton"
212 Layout.fillWidth: true
213 Layout.fillHeight: true
214 onPressed: UInput.pressMouse(UInput.ButtonRight);
215 onReleased: UInput.releaseMouse(UInput.ButtonRight);
216 property bool highlight: false
219 backgroundColor: rightButton.highlight || rightButton.pressed ? LomiriColors.ash : LomiriColors.inkstone
220 Behavior on backgroundColor { ColorAnimation { duration: LomiriAnimation.FastDuration } }
227 objectName: "disconnectButton"
228 anchors { right: parent.right; top: parent.top; margins: internalGu * 2 }
229 height: internalGu * 6
230 width: visible ? height : 0
231 visible: aethercastDisplays.state === "connected"
234 aethercastDisplays.enabled = false
240 color: LomiriColors.inkstone
245 anchors.margins: internalGu * 1.5
253 objectName: "oskButton"
254 anchors { right: disconnectButton.left; top: parent.top; margins: internalGu * 2 }
255 height: internalGu * 6
259 settings.oskEnabled = !settings.oskEnabled
265 color: LomiriColors.inkstone
270 anchors.margins: internalGu * 1.5
271 name: "input-keyboard-symbolic"
272 color: settings.oskEnabled ? LomiriColors.porcelain : LomiriColors.red
278 objectName: "rotateButton"
279 anchors { right: oskButton.left; top: parent.top; margins: internalGu * 2 }
280 height: internalGu * 6
282 visible: root.showRotateButton
284 onClicked: root.rotate();
289 color: LomiriColors.inkstone
294 anchors.margins: internalGu * 1.5
296 color: LomiriColors.porcelain
302 // Don't resize when there is only one screen to avoid resize clashing with the InputMethod in the Shell.
303 enabled: root.oskEnabled && settings.oskEnabled && !tutorial.running
304 objectName: "inputMethod"
310 objectName: "tutorialLabel"
311 anchors { left: parent.left; top: parent.top; right: parent.right; margins: internalGu * 4; topMargin: internalGu * 10 }
314 font.pixelSize: 2 * internalGu
316 wrapMode: Text.WordWrap
321 objectName: "tutorialImage"
322 height: internalGu * 8
324 name: "input-touchpad-symbolic"
328 anchors { top: tutorialLabel.bottom; horizontalCenter: parent.horizontalCenter; margins: internalGu * 2 }
333 objectName: "tutorialFinger1"
334 width: internalGu * 5
336 property real scale: 1
340 width: parent.width * parent.scale
342 anchors.centerIn: parent
344 color: LomiriColors.inkstone
350 objectName: "tutorialFinger2"
351 width: internalGu * 5
353 property real scale: 1
357 width: parent.width * parent.scale
359 anchors.centerIn: parent
361 color: LomiriColors.inkstone
365 SequentialAnimation {
367 objectName: "tutorialAnimation"
369 PropertyAction { targets: [leftButton, rightButton, oskButton]; property: "enabled"; value: false }
370 PropertyAction { targets: [leftButton, rightButton, oskButton]; property: "opacity"; value: 0 }
371 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.") }
372 LomiriNumberAnimation { targets: [tutorialLabel, tutorialImage]; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
373 PropertyAction { target: tutorial; property: "paused"; value: true }
374 PauseAnimation { duration: 500 } // it takes a bit until pausing actually takes effect
375 LomiriNumberAnimation { targets: [tutorialLabel, tutorialImage]; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
377 LomiriNumberAnimation { target: leftButton; property: "opacity"; to: 1 }
378 LomiriNumberAnimation { target: rightButton; property: "opacity"; to: 1 }
380 PauseAnimation { duration: LomiriAnimation.SleepyDuration }
381 PropertyAction { target: tutorialLabel; property: "text"; value: i18n.tr("Tap left button to click.") }
382 LomiriNumberAnimation { target: tutorialLabel; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
383 SequentialAnimation {
385 PropertyAction { target: leftButton; property: "highlight"; value: true }
386 PauseAnimation { duration: LomiriAnimation.FastDuration }
387 PropertyAction { target: leftButton; property: "highlight"; value: false }
388 PauseAnimation { duration: LomiriAnimation.SleepyDuration }
390 LomiriNumberAnimation { target: tutorialLabel; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
392 PauseAnimation { duration: LomiriAnimation.SleepyDuration }
393 PropertyAction { target: tutorialLabel; property: "text"; value: i18n.tr("Tap right button to right click.") }
394 LomiriNumberAnimation { target: tutorialLabel; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
395 SequentialAnimation {
397 PropertyAction { target: rightButton; property: "highlight"; value: true }
398 PauseAnimation { duration: LomiriAnimation.FastDuration }
399 PropertyAction { target: rightButton; property: "highlight"; value: false }
400 PauseAnimation { duration: LomiriAnimation.SleepyDuration }
402 LomiriNumberAnimation { target: tutorialLabel; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
404 PauseAnimation { duration: LomiriAnimation.SleepyDuration }
405 PropertyAction { target: tutorialLabel; property: "text"; value: i18n.tr("Swipe with two fingers to scroll.") }
406 LomiriNumberAnimation { target: tutorialLabel; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
407 PropertyAction { target: tutorialFinger1; property: "x"; value: root.width / 2 - tutorialFinger1.width - internalGu * 1 }
408 PropertyAction { target: tutorialFinger2; property: "x"; value: root.width / 2 + tutorialFinger1.width + internalGu * 1 - tutorialFinger2.width }
409 PropertyAction { target: tutorialFinger1; property: "y"; value: root.height / 2 - internalGu * 10 }
410 PropertyAction { target: tutorialFinger2; property: "y"; value: root.height / 2 - internalGu * 10 }
411 SequentialAnimation {
413 LomiriNumberAnimation { target: tutorialFinger1; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
414 LomiriNumberAnimation { target: tutorialFinger2; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
415 LomiriNumberAnimation { target: tutorialFinger1; property: "scale"; from: 0; to: 1; duration: LomiriAnimation.FastDuration }
416 LomiriNumberAnimation { target: tutorialFinger2; property: "scale"; from: 0; to: 1; duration: LomiriAnimation.FastDuration }
419 LomiriNumberAnimation { target: tutorialFinger1; property: "y"; to: root.height / 2 + internalGu * 10; duration: LomiriAnimation.SleepyDuration }
420 LomiriNumberAnimation { target: tutorialFinger2; property: "y"; to: root.height / 2 + internalGu * 10; duration: LomiriAnimation.SleepyDuration }
423 LomiriNumberAnimation { target: tutorialFinger1; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
424 LomiriNumberAnimation { target: tutorialFinger2; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
425 LomiriNumberAnimation { target: tutorialFinger1; property: "scale"; from: 1; to: 0; duration: LomiriAnimation.FastDuration }
426 LomiriNumberAnimation { target: tutorialFinger2; property: "scale"; from: 1; to: 0; duration: LomiriAnimation.FastDuration }
428 PauseAnimation { duration: LomiriAnimation.SlowDuration }
430 LomiriNumberAnimation { target: tutorialFinger1; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
431 LomiriNumberAnimation { target: tutorialFinger2; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
432 LomiriNumberAnimation { target: tutorialFinger1; property: "scale"; from: 0; to: 1; duration: LomiriAnimation.FastDuration }
433 LomiriNumberAnimation { target: tutorialFinger2; property: "scale"; from: 0; to: 1; duration: LomiriAnimation.FastDuration }
436 LomiriNumberAnimation { target: tutorialFinger1; property: "y"; to: root.height / 2 - internalGu * 10; duration: LomiriAnimation.SleepyDuration }
437 LomiriNumberAnimation { target: tutorialFinger2; property: "y"; to: root.height / 2 - internalGu * 10; duration: LomiriAnimation.SleepyDuration }
440 LomiriNumberAnimation { target: tutorialFinger1; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
441 LomiriNumberAnimation { target: tutorialFinger2; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
442 LomiriNumberAnimation { target: tutorialFinger1; property: "scale"; from: 1; to: 0; duration: LomiriAnimation.FastDuration }
443 LomiriNumberAnimation { target: tutorialFinger2; property: "scale"; from: 1; to: 0; duration: LomiriAnimation.FastDuration }
445 PauseAnimation { duration: LomiriAnimation.SlowDuration }
447 LomiriNumberAnimation { target: tutorialLabel; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
449 PauseAnimation { duration: LomiriAnimation.SleepyDuration }
450 PropertyAction { target: tutorialLabel; property: "text"; value: i18n.tr("Find more settings in the system settings.") }
451 LomiriNumberAnimation { target: tutorialLabel; property: "opacity"; to: 1; duration: LomiriAnimation.FastDuration }
452 PauseAnimation { duration: 2000 }
453 LomiriNumberAnimation { target: tutorialLabel; property: "opacity"; to: 0; duration: LomiriAnimation.FastDuration }
455 LomiriNumberAnimation { target: oskButton; property: "opacity"; to: 1 }
456 PropertyAction { targets: [leftButton, rightButton, oskButton]; property: "enabled"; value: true }
458 PropertyAction { target: settings; property: "touchpadTutorialHasRun"; value: true }