on xenial help sign in
uinput singleton
b2c4c3aNick Dedekind
plugins/UInput/plugin.cpp+7−1
@@ -19,8 +19,14 @@
19
19
20#include <QtQml/qqml.h>
20#include <QtQml/qqml.h>
21
21
22+
23+QObject* uinputSingleton(QQmlEngine*, QJSEngine*)
24+{
25+ return new UInput;
26+}
27+
22void UInputPlugin::registerTypes(const char *uri)
28void UInputPlugin::registerTypes(const char *uri)
23{
29{
24 Q_ASSERT(uri == QLatin1String("UInput"));
30 Q_ASSERT(uri == QLatin1String("UInput"));
25− qmlRegisterType<UInput>(uri, 0, 1, "UInput");
31+ qmlRegisterSingletonType<UInput>(uri, 0, 1, "UInput", uinputSingleton);
26}
32}
qml/Components/VirtualTouchPad.qml+13−14
@@ -24,10 +24,9 @@ import "../Components"
24
24
25Item {
25Item {
26 id: root
26 id: root
27− property var uinput: UInput {
27+
28− Component.onCompleted: createMouse();
28+ Component.onCompleted: UInput.createMouse()
29− Component.onDestruction: removeMouse();
29+ Component.onDestruction: UInput.removeMouse()
30− }
31
30
32 Component.onCompleted: {
31 Component.onCompleted: {
33 if (!settings.touchpadTutorialHasRun) {
32 if (!settings.touchpadTutorialHasRun) {
@@ -85,7 +84,7 @@ Item {
85 if (((point1.pressed && !point2.pressed) || (!point1.pressed && point2.pressed))
84 if (((point1.pressed && !point2.pressed) || (!point1.pressed && point2.pressed))
86 && clickTimer.running) {
85 && clickTimer.running) {
87 clickTimer.stop();
86 clickTimer.stop();
88− uinput.pressMouse(UInput.ButtonLeft)
87+ UInput.pressMouse(UInput.ButtonLeft)
89 isDoubleClick = true;
88 isDoubleClick = true;
90 }
89 }
91 isClick = true;
90 isClick = true;
@@ -104,7 +103,7 @@ Item {
104
103
105 onReleased: {
104 onReleased: {
106 if (isDoubleClick || isDrag) {
105 if (isDoubleClick || isDrag) {
107− uinput.releaseMouse(UInput.ButtonLeft)
106+ UInput.releaseMouse(UInput.ButtonLeft)
108 isDoubleClick = false;
107 isDoubleClick = false;
109 }
108 }
110 if (isClick) {
109 if (isClick) {
@@ -120,8 +119,8 @@ Item {
120 interval: 200
119 interval: 200
121 property int button: UInput.ButtonLeft
120 property int button: UInput.ButtonLeft
122 onTriggered: {
121 onTriggered: {
123− uinput.pressMouse(button);
122+ UInput.pressMouse(button);
124− uinput.releaseMouse(button);
123+ UInput.releaseMouse(button);
125 }
124 }
126 function scheduleClick(button) {
125 function scheduleClick(button) {
127 clickTimer.button = button;
126 clickTimer.button = button;
@@ -138,7 +137,7 @@ Item {
138 isDrag = true;
137 isDrag = true;
139 }
138 }
140
139
141− uinput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
140+ UInput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
142 }
141 }
143
142
144 function scroll(touchPoints) {
143 function scroll(touchPoints) {
@@ -166,7 +165,7 @@ Item {
166 dh /= 2;
165 dh /= 2;
167 dv /= 2;
166 dv /= 2;
168
167
169− uinput.scrollMouse(dh, dv);
168+ UInput.scrollMouse(dh, dv);
170 }
169 }
171
170
172 touchPoints: [
171 touchPoints: [
@@ -189,8 +188,8 @@ Item {
189 objectName: "leftButton"
188 objectName: "leftButton"
190 Layout.fillWidth: true
189 Layout.fillWidth: true
191 Layout.fillHeight: true
190 Layout.fillHeight: true
192− onPressed: uinput.pressMouse(UInput.ButtonLeft);
191+ onPressed: UInput.pressMouse(UInput.ButtonLeft);
193− onReleased: uinput.releaseMouse(UInput.ButtonLeft);
192+ onReleased: UInput.releaseMouse(UInput.ButtonLeft);
194 property bool highlight: false
193 property bool highlight: false
195 UbuntuShape {
194 UbuntuShape {
196 anchors.fill: parent
195 anchors.fill: parent
@@ -204,8 +203,8 @@ Item {
204 objectName: "rightButton"
203 objectName: "rightButton"
205 Layout.fillWidth: true
204 Layout.fillWidth: true
206 Layout.fillHeight: true
205 Layout.fillHeight: true
207− onPressed: uinput.pressMouse(UInput.ButtonRight);
206+ onPressed: UInput.pressMouse(UInput.ButtonRight);
208− onReleased: uinput.releaseMouse(UInput.ButtonRight);
207+ onReleased: UInput.releaseMouse(UInput.ButtonRight);
209 property bool highlight: false
208 property bool highlight: false
210 UbuntuShape {
209 UbuntuShape {
211 anchors.fill: parent
210 anchors.fill: parent
tests/mocks/UInput/plugin.cpp+6−1
@@ -19,8 +19,13 @@
19
19
20#include <QtQml/qqml.h>
20#include <QtQml/qqml.h>
21
21
22+QObject* uinputSingleton(QQmlEngine*, QJSEngine*)
23+{
24+ return new MockUInput;
25+}
26+
22void MockUInputPlugin::registerTypes(const char *uri)
27void MockUInputPlugin::registerTypes(const char *uri)
23{
28{
24 Q_ASSERT(uri == QLatin1String("UInput"));
29 Q_ASSERT(uri == QLatin1String("UInput"));
25− qmlRegisterType<MockUInput>(uri, 0, 1, "UInput");
30+ qmlRegisterSingletonType<MockUInput>(uri, 0, 1, "UInput", uinputSingleton);
26}
31}
tests/qmltests/Components/tst_VirtualTouchPad.qml+2−2
@@ -39,11 +39,11 @@ Rectangle {
39
39
40 SignalSpy {
40 SignalSpy {
41 id: mouseEventSpy1
41 id: mouseEventSpy1
42− target: touchScreenPad.uinput
42+ target: UInput
43 }
43 }
44 SignalSpy {
44 SignalSpy {
45 id: mouseEventSpy2
45 id: mouseEventSpy2
46− target: touchScreenPad.uinput
46+ target: UInput
47 }
47 }
48
48
49 UnityTestCase {
49 UnityTestCase {