on xenial help sign in
uinput singleton
commitb2c4c3abd000770a3161b18a5e11067b681a1092 authorNick Dedekind <nick.dedekind@canonical.com> dateThu 12 Jan 2017, 12:14 (10 years ago) parent8ec082f
4 files changed+28−18
plugins/UInput/plugin.cpp+7−1 qml/Components/VirtualTouchPad.qml+13−14 tests/mocks/UInput/plugin.cpp+6−1 tests/qmltests/Components/tst_VirtualTouchPad.qml+2−2
plugins/UInput/plugin.cpp+7−1
@@ -19,8 +19,14 @@
1919
2020#include <QtQml/qqml.h>
2121
22+
23+QObject* uinputSingleton(QQmlEngine*, QJSEngine*)
24+{
25+ return new UInput;
26+}
27+
2228void UInputPlugin::registerTypes(const char *uri)
2329{
2430 Q_ASSERT(uri == QLatin1String("UInput"));
25− qmlRegisterType<UInput>(uri, 0, 1, "UInput");
31+ qmlRegisterSingletonType<UInput>(uri, 0, 1, "UInput", uinputSingleton);
2632}
qml/Components/VirtualTouchPad.qml+13−14
@@ -24,10 +24,9 @@ import "../Components"
2424
2525Item {
2626 id: root
27− property var uinput: UInput {
28− Component.onCompleted: createMouse();
29− Component.onDestruction: removeMouse();
30− }
27+
28+ Component.onCompleted: UInput.createMouse()
29+ Component.onDestruction: UInput.removeMouse()
3130
3231 Component.onCompleted: {
3332 if (!settings.touchpadTutorialHasRun) {
@@ -85,7 +84,7 @@ Item {
8584 if (((point1.pressed && !point2.pressed) || (!point1.pressed && point2.pressed))
8685 && clickTimer.running) {
8786 clickTimer.stop();
88− uinput.pressMouse(UInput.ButtonLeft)
87+ UInput.pressMouse(UInput.ButtonLeft)
8988 isDoubleClick = true;
9089 }
9190 isClick = true;
@@ -104,7 +103,7 @@ Item {
104103
105104 onReleased: {
106105 if (isDoubleClick || isDrag) {
107− uinput.releaseMouse(UInput.ButtonLeft)
106+ UInput.releaseMouse(UInput.ButtonLeft)
108107 isDoubleClick = false;
109108 }
110109 if (isClick) {
@@ -120,8 +119,8 @@ Item {
120119 interval: 200
121120 property int button: UInput.ButtonLeft
122121 onTriggered: {
123− uinput.pressMouse(button);
124− uinput.releaseMouse(button);
122+ UInput.pressMouse(button);
123+ UInput.releaseMouse(button);
125124 }
126125 function scheduleClick(button) {
127126 clickTimer.button = button;
@@ -138,7 +137,7 @@ Item {
138137 isDrag = true;
139138 }
140139
141− uinput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
140+ UInput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
142141 }
143142
144143 function scroll(touchPoints) {
@@ -166,7 +165,7 @@ Item {
166165 dh /= 2;
167166 dv /= 2;
168167
169− uinput.scrollMouse(dh, dv);
168+ UInput.scrollMouse(dh, dv);
170169 }
171170
172171 touchPoints: [
@@ -189,8 +188,8 @@ Item {
189188 objectName: "leftButton"
190189 Layout.fillWidth: true
191190 Layout.fillHeight: true
192− onPressed: uinput.pressMouse(UInput.ButtonLeft);
193− onReleased: uinput.releaseMouse(UInput.ButtonLeft);
191+ onPressed: UInput.pressMouse(UInput.ButtonLeft);
192+ onReleased: UInput.releaseMouse(UInput.ButtonLeft);
194193 property bool highlight: false
195194 UbuntuShape {
196195 anchors.fill: parent
@@ -204,8 +203,8 @@ Item {
204203 objectName: "rightButton"
205204 Layout.fillWidth: true
206205 Layout.fillHeight: true
207− onPressed: uinput.pressMouse(UInput.ButtonRight);
208− onReleased: uinput.releaseMouse(UInput.ButtonRight);
206+ onPressed: UInput.pressMouse(UInput.ButtonRight);
207+ onReleased: UInput.releaseMouse(UInput.ButtonRight);
209208 property bool highlight: false
210209 UbuntuShape {
211210 anchors.fill: parent
tests/mocks/UInput/plugin.cpp+6−1
@@ -19,8 +19,13 @@
1919
2020#include <QtQml/qqml.h>
2121
22+QObject* uinputSingleton(QQmlEngine*, QJSEngine*)
23+{
24+ return new MockUInput;
25+}
26+
2227void MockUInputPlugin::registerTypes(const char *uri)
2328{
2429 Q_ASSERT(uri == QLatin1String("UInput"));
25− qmlRegisterType<MockUInput>(uri, 0, 1, "UInput");
30+ qmlRegisterSingletonType<MockUInput>(uri, 0, 1, "UInput", uinputSingleton);
2631}
tests/qmltests/Components/tst_VirtualTouchPad.qml+2−2
@@ -39,11 +39,11 @@ Rectangle {
3939
4040 SignalSpy {
4141 id: mouseEventSpy1
42− target: touchScreenPad.uinput
42+ target: UInput
4343 }
4444 SignalSpy {
4545 id: mouseEventSpy2
46− target: touchScreenPad.uinput
46+ target: UInput
4747 }
4848
4949 UnityTestCase {