@@ -15,8 +15,10 @@
1515 */
1616
1717import QtQuick 2.4
18+import QtQuick.Layouts 1.1
1819import Ubuntu.Components 1.3
1920import UInput 0.1
21+import Cursor 1.0
2022import "Components"
2123
2224Image {
@@ -29,45 +31,158 @@ Image {
2931
3032 source: wallpaperResolver.background
3133
32− UbuntuShape {
33− anchors.fill: virtualTouchPad
34− backgroundColor: "black"
35− opacity: 0.4
36− }
37−
3834 UInput {
3935 id: uinput
4036 Component.onCompleted: createMouse();
4137 Component.onDestruction: removeMouse();
4238 }
4339
44− MouseArea {
45− id: virtualTouchPad
40+ ColumnLayout {
4641 anchors.fill: parent
4742 anchors.margins: units.gu(2)
43+ spacing: units.gu(2)
44+
45+ Label {
46+ id: text
47+ Layout.fillWidth: true
48+ text: i18n.tr("Your device is now connected to an external display.")
49+ color: "white"
50+ horizontalAlignment: Text.AlignHCenter
51+ verticalAlignment: Text.AlignVCenter
52+ fontSize: "x-large"
53+ wrapMode: Text.Wrap
54+ }
55+
56+ UbuntuShape {
57+ Layout.fillWidth: true
58+ Layout.fillHeight: true
59+ backgroundColor: "black"
60+ opacity: 0.4
61+
62+ Image {
63+ anchors.centerIn: parent
64+ height: units.gu(2)
65+ width: units.gu(2)
66+ source: "image://cursor/default/left_ptr"
67+ }
68+
69+ MultiPointTouchArea {
70+ anchors.fill: parent
71+
72+ property int clickThreshold: units.gu(1.5)
73+ property bool isClick: false
74+
75+ onPressed: {
76+ if (point1.pressed && !point2.pressed && clickTimer.running) {
77+ clickTimer.stop();
78+ uinput.pressMouse(UInput.ButtonLeft)
79+ }
80+ isClick = true;
81+ }
4882
49− property int oldX
50− property int oldY
83+ onUpdated: {
84+ switch (touchPoints.length) {
85+ case 1:
86+ moveMouse(touchPoints);
87+ return;
88+ case 2:
89+ scroll(touchPoints);
90+ return;
91+ }
92+ }
5193
52− onPressed: {
53− oldX = mouseX;
54− oldY = mouseY;
94+ onReleased: {
95+ var tp = touchPoints[0]
96+ if (isClick) {
97+ clickTimer.scheduleClick(point1.pressed ? UInput.ButtonRight : UInput.ButtonLeft)
98+ }
99+ isClick = false;
100+ }
101+
102+ Timer {
103+ id: clickTimer
104+ repeat: false
105+ interval: 100
106+ property int button: UInput.ButtonLeft
107+ onTriggered: {
108+ uinput.pressMouse(button);
109+ uinput.releaseMouse(button);
110+ }
111+ function scheduleClick(button) {
112+ clickTimer.button = button;
113+ clickTimer.start();
114+ }
115+ }
116+
117+ function moveMouse(touchPoints) {
118+ var tp = touchPoints[0];
119+ if (isClick &&
120+ (Math.abs(tp.x - tp.startX) > clickThreshold ||
121+ Math.abs(tp.y - tp.startY) > clickThreshold)) {
122+ isClick = false;
123+ }
124+
125+ uinput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
126+ }
127+
128+ function scroll(touchPoints) {
129+ var dh = 0;
130+ var dv = 0;
131+ var tp = touchPoints[0];
132+ if (isClick &&
133+ (Math.abs(tp.x - tp.startX) > clickThreshold ||
134+ Math.abs(tp.y - tp.startY) > clickThreshold)) {
135+ isClick = false;
136+ }
137+ dh += tp.x - tp.previousX;
138+ dv += tp.y - tp.previousY;
139+
140+ tp = touchPoints[1];
141+ if (isClick &&
142+ (Math.abs(tp.x - tp.startX) > clickThreshold ||
143+ Math.abs(tp.y - tp.startY) > clickThreshold)) {
144+ isClick = false;
145+ }
146+ dh += tp.x - tp.previousX;
147+ dv += tp.y - tp.previousY;
148+
149+ uinput.scrollMouse(dh, dv);
150+ }
151+
152+ touchPoints: [
153+ TouchPoint {
154+ id: point1
155+ },
156+ TouchPoint {
157+ id: point2
158+ }
159+ ]
160+ }
55161 }
56162
57− onPositionChanged: {
58− uinput.moveMouse(mouseX - oldX, mouseY - oldY)
163+ RowLayout {
164+ Layout.fillWidth: true
165+ spacing: units.gu(2)
166+ Button {
167+ Layout.fillWidth: true
168+ onPressedChanged: {
169+ if (pressed) {
170+ uinput.pressMouse(UInput.ButtonLeft)
171+ } else {
172+ uinput.releaseMouse(UInput.ButtonLeft)
173+ }
174+ }
175+ }
176+ Button {
177+ Layout.fillWidth: true
178+ onPressedChanged: {
179+ if (pressed) {
180+ uinput.pressMouse(UInput.ButtonRight)
181+ } else {
182+ uinput.releaseMouse(UInput.ButtonRight)
183+ }
184+ }
185+ }
59186 }
60187 }
61−
62−// Label {
63−// id: text
64−// anchors.centerIn: parent
65−// width: parent.width / 2
66−// text: i18n.tr("Your device is now connected to an external display.")
67−// color: "white"
68−// horizontalAlignment: Text.AlignHCenter
69−// verticalAlignment: Text.AlignVCenter
70−// fontSize: "x-large"
71−// wrapMode: Text.Wrap
72−// }
73188}