Merge lp:~dandrader/unity/phablet_mouseTouchAdaptor into lp:unity/phablet

Proposed by Daniel d'Andrada
Status: Merged
Approved by: Michał Sawicz
Approved revision: no longer in the source branch.
Merged at revision: 685
Proposed branch: lp:~dandrader/unity/phablet_mouseTouchAdaptor
Merge into: lp:unity/phablet
Diff against target: 295 lines (+175/-13)
7 files modified
CMakeLists.txt (+3/-5)
MouseTouchAdaptor.cpp (+97/-0)
MouseTouchAdaptor.h (+50/-0)
main.cpp (+9/-0)
run (+11/-3)
run_on_device (+1/-1)
tests/autopilot/qml_phone_shell/tests/__init__.py (+4/-4)
To merge this branch: bzr merge lp:~dandrader/unity/phablet_mouseTouchAdaptor
Reviewer Review Type Date Requested Status
Michał Sawicz Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+164870@code.launchpad.net

Commit message

New build option to convert QMouseEvents into QTouchEvents

You will need this if you want to interact with touch-only components (such as
the upcoming Launcher) using a mouse.

Needed only when manually testing on a desktop.

Description of the change

New build option to convert QMouseEvents into QTouchEvents

You will need this if you want to interact with touch-only components (such as the upcoming Launcher) using a mouse.

Needed only when manually testing on a desktop.

To post a comment you must log in.
Revision history for this message
Michał Sawicz (saviq) wrote :

Hey, do you think it would make sense to make this both a build-time and run-time option? I.e. so that we can easily switch between "emulated touch" and "real pointer" interaction without rebuilding?

review: Needs Information
Revision history for this message
Daniel d'Andrada (dandrader) wrote :

> Hey, do you think it would make sense to make this both a build-time and run-
> time option? I.e. so that we can easily switch between "emulated touch" and
> "real pointer" interaction without rebuilding?

I would rather not do it until we need it, i.e., until we have a real use case for it. Otherwise the needed extra code would just be cruft.

Revision history for this message
Michał Sawicz (saviq) wrote :

W dniu 21.05.2013 14:36, Daniel d'Andrada pisze:
> I would rather not do it until we need it, i.e., until we have a real use case for it. Otherwise the needed extra code would just be cruft.

Even though we're focused on touch now, we should not forget about
pointer interaction, so IMO this would be useful already to be able to «
./run -- --no-mousetouch » or similar to be able to check out how it
behaves with pointer. And also it'd be like 10 lines maybe?

--
Michał Sawicz <email address hidden>
Canonical Services Ltd.

Revision history for this message
Daniel d'Andrada (dandrader) wrote :

> W dniu 21.05.2013 14:36, Daniel d'Andrada pisze:
> > I would rather not do it until we need it, i.e., until we have a real use
> case for it. Otherwise the needed extra code would just be cruft.
>
> Even though we're focused on touch now, we should not forget about
> pointer interaction, so IMO this would be useful already to be able to «
> ./run -- --no-mousetouch » or similar to be able to check out how it
> behaves with pointer. And also it'd be like 10 lines maybe?

Actually, 2 more lines are needed to implement that. :)

Done.

Revision history for this message
Michał Sawicz (saviq) wrote :

214 + #ifdef CONVERT_MOUSE_TO_TOUCH
215 + MouseTouchAdaptor mouseTouchAdaptor;
216 + mouseTouchAdaptor.setTargetWindow(view);
217 + if (!args.contains(QLatin1String("-nomousetouch"))) {
218 + application.installEventFilter(&mouseTouchAdaptor);
219 + }
220 + #endif // CONVERT_MOUSE_TO_TOUCH

Let's not instantiate the MouseTouchAdaptor at all?

review: Needs Fixing
Revision history for this message
Daniel d'Andrada (dandrader) wrote :

> 214 + #ifdef CONVERT_MOUSE_TO_TOUCH
> 215 + MouseTouchAdaptor mouseTouchAdaptor;
> 216 + mouseTouchAdaptor.setTargetWindow(view);
> 217 + if (!args.contains(QLatin1String("-nomousetouch"))) {
> 218 + application.installEventFilter(&mouseTouchAdaptor);
> 219 + }
> 220 + #endif // CONVERT_MOUSE_TO_TOUCH
>
> Let's not instantiate the MouseTouchAdaptor at all?

Ok. Done.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) wrote :

Restarted the CI job - Jenkins fail.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:686
http://jenkins.qa.ubuntu.com/job/unity-phablet-ci/999/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins:8080/job/unity-phablet-ci/999/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2013-05-16 12:02:23 +0000
3+++ CMakeLists.txt 2013-05-22 16:22:25 +0000
4@@ -139,15 +139,13 @@
5 set(shell_app_HDRS
6 )
7
8-set(shell_app_SRCS
9- main.cpp)
10-
11 add_executable(${SHELL_APP}
12 ${shellapplication_MOC_SRCS}
13- ${shell_app_SRCS}
14+ main.cpp
15+ MouseTouchAdaptor.cpp
16 )
17
18-qt5_use_modules(${SHELL_APP} Qml Quick)
19+qt5_use_modules(${SHELL_APP} Qml Quick Test)
20
21 target_link_libraries(${SHELL_APP}
22 ${Qt5Qml_LIBRARIES}
23
24=== added file 'MouseTouchAdaptor.cpp'
25--- MouseTouchAdaptor.cpp 1970-01-01 00:00:00 +0000
26+++ MouseTouchAdaptor.cpp 2013-05-22 16:22:25 +0000
27@@ -0,0 +1,97 @@
28+/*
29+ * Copyright (C) 2013 Canonical, Ltd.
30+ *
31+ * This program is free software; you can redistribute it and/or modify
32+ * it under the terms of the GNU General Public License as published by
33+ * the Free Software Foundation; version 3.
34+ *
35+ * This program is distributed in the hope that it will be useful,
36+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
37+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38+ * GNU General Public License for more details.
39+ *
40+ * You should have received a copy of the GNU General Public License
41+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
42+ *
43+ * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
44+ */
45+
46+#include "MouseTouchAdaptor.h"
47+
48+#include <qpa/qwindowsysteminterface.h>
49+
50+#include <QtGui/QMouseEvent>
51+#include <QtTest/QTest>
52+
53+using QTest::QTouchEventSequence;
54+
55+MouseTouchAdaptor::MouseTouchAdaptor(QObject *parent)
56+ : QObject(parent)
57+ , m_targetWindow(0)
58+{
59+ m_touchDevice = new QTouchDevice;
60+ m_touchDevice->setType(QTouchDevice::TouchScreen);
61+ QWindowSystemInterface::registerTouchDevice(m_touchDevice);
62+}
63+
64+void MouseTouchAdaptor::setTargetWindow(QWindow *window)
65+{
66+ m_targetWindow = window;
67+}
68+
69+bool MouseTouchAdaptor::eventFilter(QObject *, QEvent *event)
70+{
71+ Q_ASSERT(m_targetWindow);
72+
73+ if (event->type() == QEvent::MouseButtonPress) {
74+ return handleMousePress(static_cast<QMouseEvent*>(event));
75+ } else if (event->type() == QEvent::MouseMove) {
76+ return handleMouseMove(static_cast<QMouseEvent*>(event));
77+ } else if (event->type() == QEvent::MouseButtonRelease) {
78+ return handleMouseRelease(static_cast<QMouseEvent*>(event));
79+ } else {
80+ return false;
81+ }
82+}
83+
84+bool MouseTouchAdaptor::handleMousePress(QMouseEvent *mouseEvent)
85+{
86+ // Just eat the event if it wasn't a left mouse press
87+ if (mouseEvent->button() != Qt::LeftButton)
88+ return true;
89+
90+ QTouchEventSequence touchEvent = QTest::touchEvent(m_targetWindow, m_touchDevice,
91+ false /* autoCommit */);
92+ touchEvent.press(0 /* touchId */, mouseEvent->windowPos().toPoint());
93+ touchEvent.commit(false /* processEvents */);
94+
95+ return true;
96+}
97+
98+bool MouseTouchAdaptor::handleMouseMove(QMouseEvent *mouseEvent)
99+{
100+ // Just eat the event if left button isn't pressed
101+ if (!(mouseEvent->buttons() & Qt::LeftButton))
102+ return true;
103+
104+ QTouchEventSequence touchEvent = QTest::touchEvent(m_targetWindow, m_touchDevice,
105+ false /* autoCommit */);
106+ touchEvent.move(0 /* touchId */, mouseEvent->windowPos().toPoint());
107+ touchEvent.commit(false /* processEvents */);
108+
109+ return true;
110+}
111+
112+bool MouseTouchAdaptor::handleMouseRelease(QMouseEvent *mouseEvent)
113+{
114+ // Just eat the event if it wasn't a left button release
115+ if (mouseEvent->button() != Qt::LeftButton)
116+ return true;
117+
118+ QTouchEventSequence touchEvent = QTest::touchEvent(m_targetWindow, m_touchDevice,
119+ false /* autoCommit */);
120+ touchEvent.release(0 /* touchId */, mouseEvent->windowPos().toPoint());
121+ touchEvent.commit(false /* processEvents */);
122+
123+ return true;
124+}
125
126=== added file 'MouseTouchAdaptor.h'
127--- MouseTouchAdaptor.h 1970-01-01 00:00:00 +0000
128+++ MouseTouchAdaptor.h 2013-05-22 16:22:25 +0000
129@@ -0,0 +1,50 @@
130+/*
131+ * Copyright (C) 2013 Canonical, Ltd.
132+ *
133+ * This program is free software; you can redistribute it and/or modify
134+ * it under the terms of the GNU General Public License as published by
135+ * the Free Software Foundation; version 3.
136+ *
137+ * This program is distributed in the hope that it will be useful,
138+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
139+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
140+ * GNU General Public License for more details.
141+ *
142+ * You should have received a copy of the GNU General Public License
143+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
144+ *
145+ * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
146+ */
147+
148+#ifndef MOUSE_TOUCH_ADAPTOR_H
149+#define MOUSE_TOUCH_ADAPTOR_H
150+
151+#include <QtCore/QObject>
152+
153+class QMouseEvent;
154+class QTouchDevice;
155+class QWindow;
156+
157+// Transforms QMouseEvents into single-finger QTouchEvents.
158+class MouseTouchAdaptor : public QObject {
159+ Q_OBJECT
160+
161+public:
162+ MouseTouchAdaptor(QObject *parent = 0);
163+
164+ // The window that will receive the generated QTouchEvents
165+ void setTargetWindow(QWindow *window);
166+
167+ // Filters QMouseEvents and posts the equivalent QTouchEvents.
168+ virtual bool eventFilter(QObject *watched, QEvent *event);
169+
170+private:
171+ bool handleMousePress(QMouseEvent *mouseEvent);
172+ bool handleMouseMove(QMouseEvent *mouseEvent);
173+ bool handleMouseRelease(QMouseEvent *mouseEvent);
174+
175+ QWindow *m_targetWindow;
176+ QTouchDevice *m_touchDevice;
177+};
178+
179+#endif // MOUSE_TOUCH_ADAPTOR_H
180
181=== modified file 'main.cpp'
182--- main.cpp 2013-04-30 23:55:56 +0000
183+++ main.cpp 2013-05-22 16:22:25 +0000
184@@ -27,6 +27,7 @@
185
186 // local
187 #include "paths.h"
188+#include "MouseTouchAdaptor.h"
189
190 namespace {
191 /* When you append and import path to the list of import paths it will be the *last*
192@@ -89,6 +90,14 @@
193 view->setFlags(Qt::FramelessWindowHint);
194 }
195
196+ // You will need this if you want to interact with touch-only components using a mouse
197+ // Needed only when manually testing on a desktop.
198+ if (args.contains(QLatin1String("-mousetouch"))) {
199+ MouseTouchAdaptor *mouseTouchAdaptor = new MouseTouchAdaptor(&application);
200+ mouseTouchAdaptor->setTargetWindow(view);
201+ application.installEventFilter(mouseTouchAdaptor);
202+ }
203+
204 QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface();
205 /* Shell is declared as a system session so that it always receives all
206 input events.
207
208=== modified file 'run'
209--- run 2013-05-02 17:06:48 +0000
210+++ run 2013-05-22 16:22:25 +0000
211@@ -4,6 +4,7 @@
212 export LD_LIBRARY_PATH=$PWD/../unity_build/build/lib
213 GDB=false
214 FAKE=false
215+MOUSE_TOUCH=true
216
217 usage() {
218 echo "usage: "$0" [OPTIONS]\n" >&2
219@@ -12,11 +13,12 @@
220 echo " -f, --fake Force use of fake Qml modules." >&2
221 echo " -g, --gdb Run through gdb." >&2
222 echo " -h, --help Show this help." >&2
223+ echo " -m, --nomousetouch Run without -mousetouch argument." >&2
224 echo >&2
225 exit 1
226 }
227
228-ARGS=`getopt -n$0 -u -a --longoptions="fake,gdb,help" -o "fgh" -- "$@"`
229+ARGS=`getopt -n$0 -u -a --longoptions="fake,gdb,help,nomousetouch" -o "fghm" -- "$@"`
230 [ $? -ne 0 ] && usage
231 eval set -- "$ARGS"
232
233@@ -26,6 +28,7 @@
234 -f|--fake) FAKE=true;;
235 -g|--gdb) GDB=true;;
236 -h|--help) usage;;
237+ -m|--nomousetouch) MOUSE_TOUCH=false;;
238 --) shift;break;;
239 esac
240 shift
241@@ -41,8 +44,13 @@
242 export UBUNTU_ICON_THEME=ubuntu-mobile
243 fi
244
245+QML_PHONE_SHELL_ARGS=""
246+if $MOUSE_TOUCH; then
247+ QML_PHONE_SHELL_ARGS="$QML_PHONE_SHELL_ARGS -mousetouch"
248+fi
249+
250 if $GDB; then
251- gdb -ex run --args $QML_PHONE_SHELL_PATH $@
252+ gdb -ex run --args $QML_PHONE_SHELL_PATH $QML_PHONE_SHELL_ARGS $@
253 else
254- $QML_PHONE_SHELL_PATH $@
255+ $QML_PHONE_SHELL_PATH $QML_PHONE_SHELL_ARGS $@
256 fi
257
258=== modified file 'run_on_device'
259--- run_on_device 2013-04-30 21:07:27 +0000
260+++ run_on_device 2013-05-22 16:22:25 +0000
261@@ -129,6 +129,6 @@
262 echo "Building.."
263 build
264 echo "Running.."
265- run
266+ run --nomousetouch
267 fi
268
269
270=== modified file 'tests/autopilot/qml_phone_shell/tests/__init__.py'
271--- tests/autopilot/qml_phone_shell/tests/__init__.py 2013-05-14 12:16:08 +0000
272+++ tests/autopilot/qml_phone_shell/tests/__init__.py 2013-05-22 16:22:25 +0000
273@@ -41,18 +41,18 @@
274 os.environ['QML2_IMPORT_PATH'] = "../../builddir/plugins:../../builddir/tests/mocks"
275 if geometry != "0x0":
276 self.app = self.launch_test_application(
277- "../../builddir/qml-phone-shell", "-geometry", geometry, "-frameless")
278+ "../../builddir/qml-phone-shell", "-geometry", geometry, "-frameless", "-mousetouch")
279 else:
280 self.app = self.launch_test_application(
281- "../../builddir/qml-phone-shell", "-fullscreen")
282+ "../../builddir/qml-phone-shell", "-fullscreen", "-mousetouch")
283
284 def launch_test_installed(self, geometry):
285 if model() == 'Desktop' and geometry != "0x0":
286 self.app = self.launch_test_application(
287- "qml-phone-shell", "-geometry", geometry, "-frameless")
288+ "qml-phone-shell", "-geometry", geometry, "-frameless", "-mousetouch")
289 else:
290 self.app = self.launch_test_application(
291- "qml-phone-shell", "-fullscreen")
292+ "qml-phone-shell", "-fullscreen", "-mousetouch")
293
294 def skipWrapper(*args, **kwargs):
295 pass

Subscribers

People subscribed via source and target branches