on xenial help sign in
drop the buttons, make the pad full screen as suggested by design
commit03ff1bd55411d68c301a7caae533ca394f08a56c authorMichael Zanetti <michael.zanetti@canonical.com> dateTue 17 Nov 2015, 13:51 (11 years ago) parentf0e724f
4 files changed+110−161
qml/Components/VirtualTouchPad.qml+84−125 qml/DisabledScreenNotice.qml+25−10 tests/qmltests/Components/tst_VirtualTouchPad.qml−25 tests/qmltests/tst_DisabledScreenNotice.qml+1−1
qml/Components/VirtualTouchPad.qml+84−125
@@ -18,7 +18,6 @@ import QtQuick 2.4
1818import QtQuick.Layouts 1.1
1919import Ubuntu.Components 1.3
2020import UInput 0.1
21−import Cursor 1.0
2221
2322ColumnLayout {
2423 spacing: units.gu(2)
@@ -28,148 +27,108 @@ ColumnLayout {
2827 Component.onDestruction: removeMouse();
2928 }
3029
31− UbuntuShape {
32− Layout.fillWidth: true
33− Layout.fillHeight: true
34− backgroundColor: "black"
35− opacity: 0.4
36−
37− Image {
38− anchors.centerIn: parent
39− height: units.gu(2)
40− width: units.gu(2)
41− source: "image://cursor/default/left_ptr"
30+
31+ MultiPointTouchArea {
32+ objectName: "touchPadArea"
33+ anchors.fill: parent
34+
35+ property int clickThreshold: units.gu(1.5)
36+ property bool isClick: false
37+ property bool pressed: false
38+
39+ onPressed: {
40+ print("pressed", point1.pressed, point2.pressed)
41+ // If double-tapping *really* fast, it could happen that we end up having only point2 pressed
42+ // Make sure we check for both combos, only point1 or only point2
43+ if (((point1.pressed && !point2.pressed) || (!point1.pressed && point2.pressed))
44+ && clickTimer.running) {
45+ clickTimer.stop();
46+ uinput.pressMouse(UInput.ButtonLeft)
47+ pressed = true;
48+ }
49+ isClick = true;
4250 }
4351
44− MultiPointTouchArea {
45− objectName: "touchPadArea"
46− anchors.fill: parent
47−
48− property int clickThreshold: units.gu(1.5)
49− property bool isClick: false
50− property bool pressed: false
51−
52− onPressed: {
53− print("pressed", point1.pressed, point2.pressed)
54− // If double-tapping *really* fast, it could happen that we end up having only point2 pressed
55− // Make sure we check for both combos, only point1 or only point2
56− if (((point1.pressed && !point2.pressed) || (!point1.pressed && point2.pressed))
57− && clickTimer.running) {
58− clickTimer.stop();
59− uinput.pressMouse(UInput.ButtonLeft)
60− pressed = true;
61− }
62− isClick = true;
52+ onUpdated: {
53+ switch (touchPoints.length) {
54+ case 1:
55+ moveMouse(touchPoints);
56+ return;
57+ case 2:
58+ scroll(touchPoints);
59+ return;
6360 }
61+ }
6462
65− onUpdated: {
66− switch (touchPoints.length) {
67− case 1:
68− moveMouse(touchPoints);
69− return;
70− case 2:
71− scroll(touchPoints);
72− return;
63+ onReleased: {
64+ var tp = touchPoints[0]
65+ if (isClick) {
66+ if (pressed) {
67+ uinput.releaseMouse(UInput.ButtonLeft)
68+ pressed = false;
7369 }
70+ clickTimer.scheduleClick(point1.pressed ? UInput.ButtonRight : UInput.ButtonLeft)
7471 }
72+ isClick = false;
73+ }
7574
76− onReleased: {
77− var tp = touchPoints[0]
78− if (isClick) {
79− if (pressed) {
80− uinput.releaseMouse(UInput.ButtonLeft)
81− pressed = false;
82− }
83− clickTimer.scheduleClick(point1.pressed ? UInput.ButtonRight : UInput.ButtonLeft)
84− }
85− isClick = false;
75+ Timer {
76+ id: clickTimer
77+ repeat: false
78+ interval: 100
79+ property int button: UInput.ButtonLeft
80+ onTriggered: {
81+ uinput.pressMouse(button);
82+ uinput.releaseMouse(button);
8683 }
84+ function scheduleClick(button) {
85+ clickTimer.button = button;
86+ clickTimer.start();
87+ }
88+ }
8789
88− Timer {
89− id: clickTimer
90− repeat: false
91− interval: 100
92− property int button: UInput.ButtonLeft
93− onTriggered: {
94− uinput.pressMouse(button);
95− uinput.releaseMouse(button);
96− }
97− function scheduleClick(button) {
98− clickTimer.button = button;
99− clickTimer.start();
100− }
90+ function moveMouse(touchPoints) {
91+ var tp = touchPoints[0];
92+ if (isClick &&
93+ (Math.abs(tp.x - tp.startX) > clickThreshold ||
94+ Math.abs(tp.y - tp.startY) > clickThreshold)) {
95+ isClick = false;
10196 }
10297
103− function moveMouse(touchPoints) {
104− var tp = touchPoints[0];
105− if (isClick &&
106− (Math.abs(tp.x - tp.startX) > clickThreshold ||
107− Math.abs(tp.y - tp.startY) > clickThreshold)) {
108− isClick = false;
109− }
98+ uinput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
99+ }
110100
111− uinput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
101+ function scroll(touchPoints) {
102+ var dh = 0;
103+ var dv = 0;
104+ var tp = touchPoints[0];
105+ if (isClick &&
106+ (Math.abs(tp.x - tp.startX) > clickThreshold ||
107+ Math.abs(tp.y - tp.startY) > clickThreshold)) {
108+ isClick = false;
112109 }
110+ dh += tp.x - tp.previousX;
111+ dv += tp.y - tp.previousY;
113112
114− function scroll(touchPoints) {
115− var dh = 0;
116− var dv = 0;
117− var tp = touchPoints[0];
118− if (isClick &&
119− (Math.abs(tp.x - tp.startX) > clickThreshold ||
120− Math.abs(tp.y - tp.startY) > clickThreshold)) {
121− isClick = false;
122− }
123− dh += tp.x - tp.previousX;
124− dv += tp.y - tp.previousY;
125−
126− tp = touchPoints[1];
127− if (isClick &&
128− (Math.abs(tp.x - tp.startX) > clickThreshold ||
129− Math.abs(tp.y - tp.startY) > clickThreshold)) {
130− isClick = false;
131− }
132− dh += tp.x - tp.previousX;
133− dv += tp.y - tp.previousY;
134−
135− uinput.scrollMouse(dh, dv);
113+ tp = touchPoints[1];
114+ if (isClick &&
115+ (Math.abs(tp.x - tp.startX) > clickThreshold ||
116+ Math.abs(tp.y - tp.startY) > clickThreshold)) {
117+ isClick = false;
136118 }
119+ dh += tp.x - tp.previousX;
120+ dv += tp.y - tp.previousY;
137121
138− touchPoints: [
139− TouchPoint {
140− id: point1
141− },
142− TouchPoint {
143− id: point2
144− }
145− ]
122+ uinput.scrollMouse(dh, dv);
146123 }
147− }
148124
149− RowLayout {
150− Layout.fillWidth: true
151− spacing: units.gu(2)
152− Button {
153− objectName: "leftButton"
154− Layout.fillWidth: true
155− onPressedChanged: {
156− if (pressed) {
157− uinput.pressMouse(UInput.ButtonLeft)
158− } else {
159− uinput.releaseMouse(UInput.ButtonLeft)
160− }
161− }
162− }
163− Button {
164− objectName: "rightButton"
165− Layout.fillWidth: true
166− onPressedChanged: {
167− if (pressed) {
168− uinput.pressMouse(UInput.ButtonRight)
169− } else {
170− uinput.releaseMouse(UInput.ButtonRight)
171− }
125+ touchPoints: [
126+ TouchPoint {
127+ id: point1
128+ },
129+ TouchPoint {
130+ id: point2
172131 }
173− }
132+ ]
174133 }
175134}
qml/DisabledScreenNotice.qml+25−10
@@ -22,6 +22,8 @@ import "Components"
2222Image {
2323 id: root
2424
25+ property bool infoNoteDisplayed: true
26+
2527 WallpaperResolver {
2628 width: root.width
2729 id: wallpaperResolver
@@ -29,25 +31,38 @@ Image {
2931
3032 source: wallpaperResolver.background
3133
32− ColumnLayout {
34+
35+ VirtualTouchPad {
36+ anchors.fill: parent
37+ }
38+
39+
40+ MouseArea {
3341 anchors.fill: parent
34− anchors.margins: units.gu(2)
35− spacing: units.gu(2)
42+ opacity: infoNoteDisplayed ? 1 : 0
43+ visible: opactiy > 0
44+ Behavior on opacity {
45+ UbuntuNumberAnimation { }
46+ }
47+
48+ onClicked: root.infoNoteDisplayed = false;
49+
50+ Rectangle {
51+ anchors.fill: parent
52+ color: "black"
53+ opacity: 0.4
54+ }
3655
3756 Label {
3857 id: text
39− Layout.fillWidth: true
40− text: i18n.tr("Your device is now connected to an external display.")
58+ anchors.centerIn: parent
59+ width: parent.width - units.gu(8)
60+ text: i18n.tr("Your device is now connected to an external display. Use this screen as a touch pad to interact with the mouse.")
4161 color: "white"
4262 horizontalAlignment: Text.AlignHCenter
4363 verticalAlignment: Text.AlignVCenter
4464 fontSize: "x-large"
4565 wrapMode: Text.Wrap
4666 }
47−
48− VirtualTouchPad {
49− Layout.fillWidth: true
50− Layout.fillHeight: true
51− }
5267 }
5368}
tests/qmltests/Components/tst_VirtualTouchPad.qml−25
@@ -108,30 +108,5 @@ Item {
108108 tryCompare(mouseEventSpy2, "count", 0)
109109 mouseRelease(touchPadArea)
110110 }
111−
112− function test_buttons_data() {
113− return [
114− { tag: "left", button: UInput.ButtonLeft },
115− { tag: "left", button: UInput.ButtonRight }
116− ]
117− }
118−
119− function test_buttons(data) {
120− mouseEventSpy1.signalName = "mousePressed"
121− mouseEventSpy2.signalName = "mouseReleased"
122−
123− var button = findChild(touchScreenPad, data.button === UInput.ButtonLeft ? "leftButton" : "rightButton");
124−
125− mousePress(button);
126− tryCompare(mouseEventSpy1, "count", 1)
127− tryCompare(mouseEventSpy2, "count", 0)
128− compare(mouseEventSpy1.signalArguments[0][0], data.button)
129−
130− mouseRelease(button);
131− tryCompare(mouseEventSpy1, "count", 1)
132− tryCompare(mouseEventSpy2, "count", 1)
133− compare(mouseEventSpy2.signalArguments[0][0], data.button)
134−
135− }
136111 }
137112}
tests/qmltests/tst_DisabledScreenNotice.qml+1−1
@@ -21,7 +21,7 @@ import "../../qml"
2121
2222Item {
2323 id: root
24− width: units.gu(70)
24+ width: units.gu(40)
2525 height: units.gu(70)
2626
2727 DisabledScreenNotice {