on xenial help sign in
s/FloatingFlickableHelper/MouseEventGenerator
commitb80c4c781838e18e0eb6466bdf916122229932e5 authorDaniel d'Andrada <> dateMon 11 Jan 2016, 17:57 (11 years ago) parent74200b3
6 files changed+90−77
plugins/Ubuntu/Gestures/CMakeLists.txt+1−1 plugins/Ubuntu/Gestures/FloatingFlickableHelper.cpp−59 plugins/Ubuntu/Gestures/MouseEventGenerator.cpp+64 plugins/Ubuntu/Gestures/FloatingFlickableHelper.h → plugins/Ubuntu/Gestures/MouseEventGenerator.h+15−9 plugins/Ubuntu/Gestures/plugin.cpp+3−3 qml/Components/FloatingFlickable.qml+7−5
plugins/Ubuntu/Gestures/CMakeLists.txt+1−1
@@ -5,7 +5,7 @@ set(UbuntuGesturesQml_SOURCES
55 plugin.cpp
66 AxisVelocityCalculator.cpp
77 Direction.cpp
8− FloatingFlickableHelper.cpp
8+ MouseEventGenerator.cpp
99 PressedOutsideNotifier.cpp
1010 TouchDispatcher.cpp
1111 TouchGate.cpp
plugins/Ubuntu/Gestures/FloatingFlickableHelper.cppdeleted−59
@@ -1,59 +0,0 @@
1−/*
2− * Copyright (C) 2015 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−
17−#include "FloatingFlickableHelper.h"
18−
19−#include <QCoreApplication>
20−#include <QMouseEvent>
21−#include <QQuickItem>
22−
23−FloatingFlickableHelper::FloatingFlickableHelper(QObject *parent)
24− : QObject(parent)
25− , m_mousePressed(false)
26−{
27−}
28−
29−void FloatingFlickableHelper::onDragAreaTouchPosChanged(QQuickItem *flickable, const QPointF touchPosition)
30−{
31− if (m_mousePressed) {
32− QMouseEvent mouseEvent(QEvent::MouseMove,
33− QPointF(touchPosition.x(), touchPosition.y()),
34− Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
35−
36− QCoreApplication::sendEvent(flickable, &mouseEvent);
37−
38− }
39−}
40−
41−void FloatingFlickableHelper::onDragAreaDraggingChanged(QQuickItem *flickable, bool dragging, const QPointF touchPosition)
42−{
43− if (dragging && !m_mousePressed) {
44− QMouseEvent mouseEvent(QEvent::MouseButtonPress,
45− QPointF(touchPosition.x(), touchPosition.y()),
46− Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
47−
48− QCoreApplication::sendEvent(flickable, &mouseEvent);
49− m_mousePressed = true;
50−
51− } else if (!dragging && m_mousePressed) {
52− QMouseEvent mouseEvent(QEvent::MouseButtonRelease,
53− QPointF(touchPosition.x(), touchPosition.y()),
54− Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
55−
56− QCoreApplication::sendEvent(flickable, &mouseEvent);
57− m_mousePressed = false;
58− }
59−}
plugins/Ubuntu/Gestures/MouseEventGenerator.cppnew file+64
@@ -0,0 +1,64 @@
1+/*
2+ * Copyright (C) 2015-2016 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+
17+#include "MouseEventGenerator.h"
18+
19+#include <QCoreApplication>
20+#include <QMouseEvent>
21+#include <QQuickItem>
22+
23+MouseEventGenerator::MouseEventGenerator(QObject *parent)
24+ : QObject(parent)
25+{
26+}
27+
28+void MouseEventGenerator::move(const QPointF position)
29+{
30+ if (!m_mousePressed || !m_targetItem) {
31+ return;
32+ }
33+
34+ QMouseEvent mouseEvent(QEvent::MouseMove,
35+ QPointF(position.x(), position.y()), Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
36+
37+ QCoreApplication::sendEvent(m_targetItem, &mouseEvent);
38+}
39+
40+void MouseEventGenerator::press(const QPointF position)
41+{
42+ if (m_mousePressed || !m_targetItem) {
43+ return;
44+ }
45+
46+ QMouseEvent mouseEvent(QEvent::MouseButtonPress,
47+ QPointF(position.x(), position.y()), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
48+
49+ QCoreApplication::sendEvent(m_targetItem, &mouseEvent);
50+ m_mousePressed = true;
51+}
52+
53+void MouseEventGenerator::release(const QPointF position)
54+{
55+ if (!m_mousePressed || !m_targetItem) {
56+ return;
57+ }
58+
59+ QMouseEvent mouseEvent(QEvent::MouseButtonRelease,
60+ QPointF(position.x(), position.y()), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
61+
62+ QCoreApplication::sendEvent(m_targetItem, &mouseEvent);
63+ m_mousePressed = false;
64+}
plugins/Ubuntu/Gestures/FloatingFlickableHelper.h → plugins/Ubuntu/Gestures/MouseEventGenerator.hrenamed+15−9
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -14,8 +14,8 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#ifndef FLOATING_FLICKABLE_HELPER_H
18−#define FLOATING_FLICKABLE_HELPER_H
17+#ifndef MOUSEEVENTGENERATOR_H
18+#define MOUSEEVENTGENERATOR_H
1919
2020#include <QObject>
2121#include <QPointF>
@@ -24,19 +24,25 @@
2424
2525class QQuickItem;
2626
27−class UBUNTUGESTURESQML_EXPORT FloatingFlickableHelper : public QObject {
27+class UBUNTUGESTURESQML_EXPORT MouseEventGenerator : public QObject {
2828 Q_OBJECT
29+ Q_PROPERTY(QQuickItem* targetItem MEMBER m_targetItem NOTIFY targetItemChanged)
2930
3031public:
31− FloatingFlickableHelper(QObject *parent = nullptr);
32+ MouseEventGenerator(QObject *parent = nullptr);
3233
33− Q_INVOKABLE void onDragAreaTouchPosChanged(QQuickItem *flickable, const QPointF touchPosition);
34− Q_INVOKABLE void onDragAreaDraggingChanged(QQuickItem *flickable, bool dragging, const QPointF touchPosition);
34+ Q_INVOKABLE void move(const QPointF position);
35+ Q_INVOKABLE void press(const QPointF position);
36+ Q_INVOKABLE void release(const QPointF position);
37+
38+Q_SIGNALS:
39+ void targetItemChanged(QQuickItem *);
3540
3641private:
37− bool m_mousePressed;
42+ bool m_mousePressed {false};
43+ QQuickItem *m_targetItem {nullptr};
3844
3945 friend class tst_FloatingFlickable;
4046};
4147
42−#endif
48+#endif // MOUSEEVENTGENERATOR_H
plugins/Ubuntu/Gestures/plugin.cpp+3−3
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013,2015 Canonical, Ltd.
2+ * Copyright (C) 2013,2015,2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
1717#include "plugin.h"
1818#include "AxisVelocityCalculator.h"
1919#include "Direction.h"
20−#include "FloatingFlickableHelper.h"
20+#include "MouseEventGenerator.h"
2121#include "PressedOutsideNotifier.h"
2222#include "TouchGate.h"
2323
@@ -33,7 +33,7 @@ void UbuntuGesturesQmlPlugin::registerTypes(const char *uri)
3333{
3434 qmlRegisterSingletonType<Direction>(uri, 0, 1, "Direction", directionSingleton);
3535 qmlRegisterType<AxisVelocityCalculator>(uri, 0, 1, "AxisVelocityCalculator");
36− qmlRegisterType<FloatingFlickableHelper>(uri, 0, 1, "FloatingFlickableHelper");
36+ qmlRegisterType<MouseEventGenerator>(uri, 0, 1, "MouseEventGenerator");
3737 qmlRegisterType<PressedOutsideNotifier>(uri, 0, 1, "PressedOutsideNotifier");
3838 qmlRegisterType<TouchGate>(uri, 0, 1, "TouchGate");
3939}
qml/Components/FloatingFlickable.qml+7−5
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -35,8 +35,9 @@ Item {
3535 property alias contentY: flickable.contentY
3636 property alias direction: swipeArea.direction
3737
38− FloatingFlickableHelper {
39− id: ffh
38+ MouseEventGenerator {
39+ id: mouseEventGenerator
40+ targetItem: flickable
4041 }
4142
4243 Flickable {
@@ -51,7 +52,8 @@ Item {
5152 anchors.fill: parent
5253 direction: Direction.Horizontal
5354
54− onTouchPositionChanged: ffh.onDragAreaTouchPosChanged(flickable, touchPosition);
55− onDraggingChanged: ffh.onDragAreaDraggingChanged(flickable, dragging, touchPosition);
55+ onTouchPositionChanged: mouseEventGenerator.move(touchPosition);
56+ onDraggingChanged: dragging ? mouseEventGenerator.press(touchPosition)
57+ : mouseEventGenerator.release(touchPosition)
5658 }
5759}