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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2013-05-16 12:02:23 +0000
+++ CMakeLists.txt 2013-05-22 16:22:25 +0000
@@ -139,15 +139,13 @@
139set(shell_app_HDRS139set(shell_app_HDRS
140 )140 )
141141
142set(shell_app_SRCS
143 main.cpp)
144
145add_executable(${SHELL_APP}142add_executable(${SHELL_APP}
146 ${shellapplication_MOC_SRCS}143 ${shellapplication_MOC_SRCS}
147 ${shell_app_SRCS}144 main.cpp
145 MouseTouchAdaptor.cpp
148 )146 )
149147
150qt5_use_modules(${SHELL_APP} Qml Quick)148qt5_use_modules(${SHELL_APP} Qml Quick Test)
151149
152target_link_libraries(${SHELL_APP}150target_link_libraries(${SHELL_APP}
153 ${Qt5Qml_LIBRARIES}151 ${Qt5Qml_LIBRARIES}
154152
=== added file 'MouseTouchAdaptor.cpp'
--- MouseTouchAdaptor.cpp 1970-01-01 00:00:00 +0000
+++ MouseTouchAdaptor.cpp 2013-05-22 16:22:25 +0000
@@ -0,0 +1,97 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
17 */
18
19#include "MouseTouchAdaptor.h"
20
21#include <qpa/qwindowsysteminterface.h>
22
23#include <QtGui/QMouseEvent>
24#include <QtTest/QTest>
25
26using QTest::QTouchEventSequence;
27
28MouseTouchAdaptor::MouseTouchAdaptor(QObject *parent)
29 : QObject(parent)
30 , m_targetWindow(0)
31{
32 m_touchDevice = new QTouchDevice;
33 m_touchDevice->setType(QTouchDevice::TouchScreen);
34 QWindowSystemInterface::registerTouchDevice(m_touchDevice);
35}
36
37void MouseTouchAdaptor::setTargetWindow(QWindow *window)
38{
39 m_targetWindow = window;
40}
41
42bool MouseTouchAdaptor::eventFilter(QObject *, QEvent *event)
43{
44 Q_ASSERT(m_targetWindow);
45
46 if (event->type() == QEvent::MouseButtonPress) {
47 return handleMousePress(static_cast<QMouseEvent*>(event));
48 } else if (event->type() == QEvent::MouseMove) {
49 return handleMouseMove(static_cast<QMouseEvent*>(event));
50 } else if (event->type() == QEvent::MouseButtonRelease) {
51 return handleMouseRelease(static_cast<QMouseEvent*>(event));
52 } else {
53 return false;
54 }
55}
56
57bool MouseTouchAdaptor::handleMousePress(QMouseEvent *mouseEvent)
58{
59 // Just eat the event if it wasn't a left mouse press
60 if (mouseEvent->button() != Qt::LeftButton)
61 return true;
62
63 QTouchEventSequence touchEvent = QTest::touchEvent(m_targetWindow, m_touchDevice,
64 false /* autoCommit */);
65 touchEvent.press(0 /* touchId */, mouseEvent->windowPos().toPoint());
66 touchEvent.commit(false /* processEvents */);
67
68 return true;
69}
70
71bool MouseTouchAdaptor::handleMouseMove(QMouseEvent *mouseEvent)
72{
73 // Just eat the event if left button isn't pressed
74 if (!(mouseEvent->buttons() & Qt::LeftButton))
75 return true;
76
77 QTouchEventSequence touchEvent = QTest::touchEvent(m_targetWindow, m_touchDevice,
78 false /* autoCommit */);
79 touchEvent.move(0 /* touchId */, mouseEvent->windowPos().toPoint());
80 touchEvent.commit(false /* processEvents */);
81
82 return true;
83}
84
85bool MouseTouchAdaptor::handleMouseRelease(QMouseEvent *mouseEvent)
86{
87 // Just eat the event if it wasn't a left button release
88 if (mouseEvent->button() != Qt::LeftButton)
89 return true;
90
91 QTouchEventSequence touchEvent = QTest::touchEvent(m_targetWindow, m_touchDevice,
92 false /* autoCommit */);
93 touchEvent.release(0 /* touchId */, mouseEvent->windowPos().toPoint());
94 touchEvent.commit(false /* processEvents */);
95
96 return true;
97}
098
=== added file 'MouseTouchAdaptor.h'
--- MouseTouchAdaptor.h 1970-01-01 00:00:00 +0000
+++ MouseTouchAdaptor.h 2013-05-22 16:22:25 +0000
@@ -0,0 +1,50 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
17 */
18
19#ifndef MOUSE_TOUCH_ADAPTOR_H
20#define MOUSE_TOUCH_ADAPTOR_H
21
22#include <QtCore/QObject>
23
24class QMouseEvent;
25class QTouchDevice;
26class QWindow;
27
28// Transforms QMouseEvents into single-finger QTouchEvents.
29class MouseTouchAdaptor : public QObject {
30 Q_OBJECT
31
32public:
33 MouseTouchAdaptor(QObject *parent = 0);
34
35 // The window that will receive the generated QTouchEvents
36 void setTargetWindow(QWindow *window);
37
38 // Filters QMouseEvents and posts the equivalent QTouchEvents.
39 virtual bool eventFilter(QObject *watched, QEvent *event);
40
41private:
42 bool handleMousePress(QMouseEvent *mouseEvent);
43 bool handleMouseMove(QMouseEvent *mouseEvent);
44 bool handleMouseRelease(QMouseEvent *mouseEvent);
45
46 QWindow *m_targetWindow;
47 QTouchDevice *m_touchDevice;
48};
49
50#endif // MOUSE_TOUCH_ADAPTOR_H
051
=== modified file 'main.cpp'
--- main.cpp 2013-04-30 23:55:56 +0000
+++ main.cpp 2013-05-22 16:22:25 +0000
@@ -27,6 +27,7 @@
2727
28// local28// local
29#include "paths.h"29#include "paths.h"
30#include "MouseTouchAdaptor.h"
3031
31namespace {32namespace {
32/* When you append and import path to the list of import paths it will be the *last*33/* When you append and import path to the list of import paths it will be the *last*
@@ -89,6 +90,14 @@
89 view->setFlags(Qt::FramelessWindowHint);90 view->setFlags(Qt::FramelessWindowHint);
90 }91 }
9192
93 // You will need this if you want to interact with touch-only components using a mouse
94 // Needed only when manually testing on a desktop.
95 if (args.contains(QLatin1String("-mousetouch"))) {
96 MouseTouchAdaptor *mouseTouchAdaptor = new MouseTouchAdaptor(&application);
97 mouseTouchAdaptor->setTargetWindow(view);
98 application.installEventFilter(mouseTouchAdaptor);
99 }
100
92 QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface();101 QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface();
93 /* Shell is declared as a system session so that it always receives all102 /* Shell is declared as a system session so that it always receives all
94 input events.103 input events.
95104
=== modified file 'run'
--- run 2013-05-02 17:06:48 +0000
+++ run 2013-05-22 16:22:25 +0000
@@ -4,6 +4,7 @@
4export LD_LIBRARY_PATH=$PWD/../unity_build/build/lib4export LD_LIBRARY_PATH=$PWD/../unity_build/build/lib
5GDB=false5GDB=false
6FAKE=false6FAKE=false
7MOUSE_TOUCH=true
78
8usage() {9usage() {
9 echo "usage: "$0" [OPTIONS]\n" >&210 echo "usage: "$0" [OPTIONS]\n" >&2
@@ -12,11 +13,12 @@
12 echo " -f, --fake Force use of fake Qml modules." >&213 echo " -f, --fake Force use of fake Qml modules." >&2
13 echo " -g, --gdb Run through gdb." >&214 echo " -g, --gdb Run through gdb." >&2
14 echo " -h, --help Show this help." >&215 echo " -h, --help Show this help." >&2
16 echo " -m, --nomousetouch Run without -mousetouch argument." >&2
15 echo >&217 echo >&2
16 exit 118 exit 1
17}19}
1820
19ARGS=`getopt -n$0 -u -a --longoptions="fake,gdb,help" -o "fgh" -- "$@"`21ARGS=`getopt -n$0 -u -a --longoptions="fake,gdb,help,nomousetouch" -o "fghm" -- "$@"`
20[ $? -ne 0 ] && usage22[ $? -ne 0 ] && usage
21eval set -- "$ARGS"23eval set -- "$ARGS"
2224
@@ -26,6 +28,7 @@
26 -f|--fake) FAKE=true;;28 -f|--fake) FAKE=true;;
27 -g|--gdb) GDB=true;;29 -g|--gdb) GDB=true;;
28 -h|--help) usage;;30 -h|--help) usage;;
31 -m|--nomousetouch) MOUSE_TOUCH=false;;
29 --) shift;break;;32 --) shift;break;;
30 esac33 esac
31 shift34 shift
@@ -41,8 +44,13 @@
41 export UBUNTU_ICON_THEME=ubuntu-mobile44 export UBUNTU_ICON_THEME=ubuntu-mobile
42fi45fi
4346
47QML_PHONE_SHELL_ARGS=""
48if $MOUSE_TOUCH; then
49 QML_PHONE_SHELL_ARGS="$QML_PHONE_SHELL_ARGS -mousetouch"
50fi
51
44if $GDB; then52if $GDB; then
45 gdb -ex run --args $QML_PHONE_SHELL_PATH $@53 gdb -ex run --args $QML_PHONE_SHELL_PATH $QML_PHONE_SHELL_ARGS $@
46else54else
47 $QML_PHONE_SHELL_PATH $@55 $QML_PHONE_SHELL_PATH $QML_PHONE_SHELL_ARGS $@
48fi56fi
4957
=== modified file 'run_on_device'
--- run_on_device 2013-04-30 21:07:27 +0000
+++ run_on_device 2013-05-22 16:22:25 +0000
@@ -129,6 +129,6 @@
129 echo "Building.."129 echo "Building.."
130 build130 build
131 echo "Running.."131 echo "Running.."
132 run132 run --nomousetouch
133fi133fi
134134
135135
=== modified file 'tests/autopilot/qml_phone_shell/tests/__init__.py'
--- tests/autopilot/qml_phone_shell/tests/__init__.py 2013-05-14 12:16:08 +0000
+++ tests/autopilot/qml_phone_shell/tests/__init__.py 2013-05-22 16:22:25 +0000
@@ -41,18 +41,18 @@
41 os.environ['QML2_IMPORT_PATH'] = "../../builddir/plugins:../../builddir/tests/mocks"41 os.environ['QML2_IMPORT_PATH'] = "../../builddir/plugins:../../builddir/tests/mocks"
42 if geometry != "0x0":42 if geometry != "0x0":
43 self.app = self.launch_test_application(43 self.app = self.launch_test_application(
44 "../../builddir/qml-phone-shell", "-geometry", geometry, "-frameless")44 "../../builddir/qml-phone-shell", "-geometry", geometry, "-frameless", "-mousetouch")
45 else:45 else:
46 self.app = self.launch_test_application(46 self.app = self.launch_test_application(
47 "../../builddir/qml-phone-shell", "-fullscreen")47 "../../builddir/qml-phone-shell", "-fullscreen", "-mousetouch")
4848
49 def launch_test_installed(self, geometry):49 def launch_test_installed(self, geometry):
50 if model() == 'Desktop' and geometry != "0x0":50 if model() == 'Desktop' and geometry != "0x0":
51 self.app = self.launch_test_application(51 self.app = self.launch_test_application(
52 "qml-phone-shell", "-geometry", geometry, "-frameless")52 "qml-phone-shell", "-geometry", geometry, "-frameless", "-mousetouch")
53 else:53 else:
54 self.app = self.launch_test_application(54 self.app = self.launch_test_application(
55 "qml-phone-shell", "-fullscreen")55 "qml-phone-shell", "-fullscreen", "-mousetouch")
5656
57 def skipWrapper(*args, **kwargs):57 def skipWrapper(*args, **kwargs):
58 pass58 pass

Subscribers

People subscribed via source and target branches