on xenial help sign in
Implement the FloatingFlickable without needeing the .h of SwipeArea

And other small fixlets

commit21dc999a7da4292907c91d46d16a71964d2fdb4f authorAlbert Astals Cid <albert.astals@canonical.com> dateThu 10 Dec 2015, 11:22 (11 years ago) parent257b6f0
14 files changed+204−281
plugins/Ubuntu/Gestures/CMakeLists.txt+1−1 plugins/Ubuntu/Gestures/Direction.h+1 plugins/Ubuntu/Gestures/FloatingFlickable.cpp−150 plugins/Ubuntu/Gestures/FloatingFlickable.h−86 plugins/Ubuntu/Gestures/FloatingFlickableHelper.cpp+59 plugins/Ubuntu/Gestures/FloatingFlickableHelper.h+42 plugins/Ubuntu/Gestures/plugin.cpp+2−2 qml/Components/FloatingFlickable.qml+57 qml/Stages/DesktopSpread.qml+1 tests/plugins/Ubuntu/Gestures/CMakeLists.txt+1−1 tests/plugins/Ubuntu/Gestures/tst_FloatingFlickable.cpp+14−17 tests/plugins/Ubuntu/Gestures/tst_FloatingFlickable.qml+1 tests/qmltests/Components/CMakeLists.txt+5−6 tests/qmltests/Components/tst_DragHandle.cpp+20−18
plugins/Ubuntu/Gestures/CMakeLists.txt+1−1
@@ -5,7 +5,7 @@ set(UbuntuGesturesQml_SOURCES
55 plugin.cpp
66 AxisVelocityCalculator.cpp
77 Direction.cpp
8−# FloatingFlickable.cpp TODO
8+ FloatingFlickableHelper.cpp
99 PressedOutsideNotifier.cpp
1010 TouchDispatcher.cpp
1111 TouchGate.cpp
plugins/Ubuntu/Gestures/Direction.h+1
@@ -29,6 +29,7 @@ class UBUNTUGESTURESQML_EXPORT Direction : public QObject {
2929 Q_ENUMS(Type)
3030
3131public:
32+ // Make sure it is kept synchronized with SDK UCSwipeArea::Direction
3233 enum Type {
3334 Rightwards, // Along the positive direction of the X axis
3435 Leftwards, // Along the negative direction of the X axis
plugins/Ubuntu/Gestures/FloatingFlickable.cppdeleted−150
@@ -1,150 +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 "FloatingFlickable.h"
18−
19−#include <private/qquickflickable_p.h>
20−#include "DirectionalDragArea.h"
21−
22−#include <QDebug>
23−
24−FloatingFlickable::FloatingFlickable(QQuickItem *parent)
25− : QQuickItem(parent)
26− , m_mousePressed(false)
27−{
28− m_dragArea = new DirectionalDragArea(this);
29− m_dragArea->setWidth(width());
30− m_dragArea->setHeight(height());
31− m_dragArea->setDirection(Direction::Horizontal);
32− connect(m_dragArea, &DirectionalDragArea::touchXChanged,
33− this, &FloatingFlickable::onDragAreaTouchPosChanged);
34− connect(m_dragArea, &DirectionalDragArea::touchYChanged,
35− this, &FloatingFlickable::onDragAreaTouchPosChanged);
36− connect(m_dragArea, &DirectionalDragArea::draggingChanged,
37− this, &FloatingFlickable::onDragAreaDraggingChanged);
38− connect(m_dragArea, &DirectionalDragArea::directionChanged, this, &FloatingFlickable::directionChanged);
39−
40− m_flickable = new QQuickFlickable(this);
41− m_flickable->setEnabled(false);
42− m_flickable->setWidth(width());
43− m_flickable->setHeight(height());
44− connect(m_flickable, &QQuickFlickable::contentWidthChanged, this, &FloatingFlickable::contentWidthChanged);
45− connect(m_flickable, &QQuickFlickable::contentHeightChanged, this, &FloatingFlickable::contentHeightChanged);
46− connect(m_flickable, &QQuickFlickable::contentXChanged, this, &FloatingFlickable::contentXChanged);
47− connect(m_flickable, &QQuickFlickable::contentYChanged, this, &FloatingFlickable::contentYChanged);
48−
49− connect(this, &QQuickItem::widthChanged, this, &FloatingFlickable::updateChildrenWidth);
50− connect(this, &QQuickItem::heightChanged, this, &FloatingFlickable::updateChildrenHeight);
51−}
52−
53−qreal FloatingFlickable::contentWidth() const
54−{
55− return m_flickable->contentWidth();
56−}
57−
58−void FloatingFlickable::setContentWidth(qreal contentWidth)
59−{
60− m_flickable->setContentWidth(contentWidth);
61−}
62−
63−qreal FloatingFlickable::contentHeight() const
64−{
65− return m_flickable->contentHeight();
66−}
67−
68−void FloatingFlickable::setContentHeight(qreal contentHeight)
69−{
70− m_flickable->setContentHeight(contentHeight);
71−}
72−
73−qreal FloatingFlickable::contentX() const
74−{
75− return m_flickable->contentX();
76−}
77−
78−void FloatingFlickable::setContentX(qreal contentX)
79−{
80− m_flickable->setContentX(contentX);
81−}
82−
83−qreal FloatingFlickable::contentY() const
84−{
85− return m_flickable->contentY();
86−}
87−
88−void FloatingFlickable::setContentY(qreal contentY)
89−{
90− m_flickable->setContentY(contentY);
91−}
92−
93−Direction::Type FloatingFlickable::direction() const
94−{
95− return m_dragArea->direction();
96−}
97−
98−void FloatingFlickable::setDirection(Direction::Type direction)
99−{
100− m_dragArea->setDirection(direction);
101− if (Direction::isHorizontal(direction)) {
102− m_flickable->setFlickableDirection(QQuickFlickable::HorizontalFlick);
103− } else {
104− m_flickable->setFlickableDirection(QQuickFlickable::VerticalFlick);
105− }
106−}
107−
108−void FloatingFlickable::updateChildrenWidth()
109−{
110− m_dragArea->setWidth(width());
111− m_flickable->setWidth(width());
112−}
113−
114−void FloatingFlickable::updateChildrenHeight()
115−{
116− m_dragArea->setHeight(height());
117− m_flickable->setHeight(height());
118−}
119−
120−void FloatingFlickable::onDragAreaTouchPosChanged(qreal)
121−{
122− if (m_mousePressed) {
123− QMouseEvent mouseEvent(QEvent::MouseMove,
124− QPointF(m_dragArea->touchX(),m_dragArea->touchY()),
125− Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
126−
127− QCoreApplication::sendEvent(m_flickable, &mouseEvent);
128−
129− }
130−}
131−
132−void FloatingFlickable::onDragAreaDraggingChanged(bool dragging)
133−{
134− if (dragging && !m_mousePressed) {
135− QMouseEvent mouseEvent(QEvent::MouseButtonPress,
136− QPointF(m_dragArea->touchX(),m_dragArea->touchY()),
137− Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
138−
139− QCoreApplication::sendEvent(m_flickable, &mouseEvent);
140− m_mousePressed = true;
141−
142− } else if (!dragging && m_mousePressed) {
143− QMouseEvent mouseEvent(QEvent::MouseButtonRelease,
144− QPointF(m_dragArea->touchX(),m_dragArea->touchY()),
145− Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
146−
147− QCoreApplication::sendEvent(m_flickable, &mouseEvent);
148− m_mousePressed = false;
149− }
150−}
plugins/Ubuntu/Gestures/FloatingFlickable.hdeleted−86
@@ -1,86 +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−#ifndef FLOATING_FLICKABLE_H
18−#define FLOATING_FLICKABLE_H
19−
20−#include <QQuickItem>
21−#include "UbuntuGesturesQmlGlobal.h"
22−#include "Direction.h"
23−
24−class DirectionalDragArea;
25−class QQuickFlickable;
26−
27−/*
28− A Flickable that can be put in front of the item to be flicked and
29− still have the item-to-be-flicked receive input events that are not flicks.
30−
31− Ie, it's a Flickable that, input-wise, is transparent to non-flick gestures.
32−
33− With a regular Flickable you would have to make the item-to-be-flicked a child
34− of Flicakble to achieve the same result. FloatingFlickable has no such requirement
35− or limitation.
36− */
37−class UBUNTUGESTURESQML_EXPORT FloatingFlickable : public QQuickItem {
38− Q_OBJECT
39−
40− Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged)
41− Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged)
42− Q_PROPERTY(qreal contentX READ contentX WRITE setContentX NOTIFY contentXChanged)
43− Q_PROPERTY(qreal contentY READ contentY WRITE setContentY NOTIFY contentYChanged)
44−
45− Q_PROPERTY(Direction::Type direction READ direction WRITE setDirection NOTIFY directionChanged)
46−
47−Q_SIGNALS:
48− void contentWidthChanged();
49− void contentHeightChanged();
50− void contentXChanged();
51− void contentYChanged();
52− void directionChanged();
53−
54−public:
55− FloatingFlickable(QQuickItem *parent = nullptr);
56−
57− qreal contentWidth() const;
58− void setContentWidth(qreal contentWidth);
59−
60− qreal contentHeight() const;
61− void setContentHeight(qreal contentHeight);
62−
63− qreal contentX() const;
64− void setContentX(qreal contentX);
65−
66− qreal contentY() const;
67− void setContentY(qreal contentY);
68−
69− Direction::Type direction() const;
70− void setDirection(Direction::Type);
71−
72−private Q_SLOTS:
73− void updateChildrenWidth();
74− void updateChildrenHeight();
75− void onDragAreaTouchPosChanged(qreal);
76− void onDragAreaDraggingChanged(bool value);
77−
78−private:
79− DirectionalDragArea *m_dragArea;
80− QQuickFlickable *m_flickable;
81− bool m_mousePressed;
82−
83− friend class tst_FloatingFlickable;
84−};
85−
86−#endif // FLOATING_FLICKABLE_H
plugins/Ubuntu/Gestures/FloatingFlickableHelper.cppnew file+59
@@ -0,0 +1,59 @@
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/FloatingFlickableHelper.hnew file+42
@@ -0,0 +1,42 @@
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+#ifndef FLOATING_FLICKABLE_HELPER_H
18+#define FLOATING_FLICKABLE_HELPER_H
19+
20+#include <QObject>
21+#include <QPointF>
22+
23+#include "UbuntuGesturesQmlGlobal.h"
24+
25+class QQuickItem;
26+
27+class UBUNTUGESTURESQML_EXPORT FloatingFlickableHelper : public QObject {
28+ Q_OBJECT
29+
30+public:
31+ FloatingFlickableHelper(QObject *parent = nullptr);
32+
33+ Q_INVOKABLE void onDragAreaTouchPosChanged(QQuickItem *flickable, const QPointF touchPosition);
34+ Q_INVOKABLE void onDragAreaDraggingChanged(QQuickItem *flickable, bool dragging, const QPointF touchPosition);
35+
36+private:
37+ bool m_mousePressed;
38+
39+ friend class tst_FloatingFlickable;
40+};
41+
42+#endif
plugins/Ubuntu/Gestures/plugin.cpp+2−2
@@ -17,7 +17,7 @@
1717#include "plugin.h"
1818#include "AxisVelocityCalculator.h"
1919#include "Direction.h"
20−#include "FloatingFlickable.h"
20+#include "FloatingFlickableHelper.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<FloatingFlickable>(uri, 0, 1, "FloatingFlickable"); TODO
36+ qmlRegisterType<FloatingFlickableHelper>(uri, 0, 1, "FloatingFlickableHelper");
3737 qmlRegisterType<PressedOutsideNotifier>(uri, 0, 1, "PressedOutsideNotifier");
3838 qmlRegisterType<TouchGate>(uri, 0, 1, "TouchGate");
3939}
qml/Components/FloatingFlickable.qmlnew file+57
@@ -0,0 +1,57 @@
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+
17+import QtQuick 2.4
18+import Ubuntu.Components 1.3
19+import Ubuntu.Gestures 0.1
20+
21+/*
22+ A Flickable that can be put in front of the item to be flicked and
23+ still have the item-to-be-flicked receive input events that are not flicks.
24+
25+ Ie, it's a Flickable that, input-wise, is transparent to non-flick gestures.
26+
27+ With a regular Flickable you would have to make the item-to-be-flicked a child
28+ of Flicakble to achieve the same result. FloatingFlickable has no such requirement
29+ or limitation.
30+ */
31+Item {
32+ property alias contentWidth: flickable.contentWidth
33+ property alias contentHeight: flickable.contentHeight
34+ property alias contentX: flickable.contentX
35+ property alias contentY: flickable.contentY
36+ property alias direction: swipeArea.direction
37+
38+ FloatingFlickableHelper {
39+ id: ffh
40+ }
41+
42+ Flickable {
43+ id: flickable
44+ enabled: false
45+ anchors.fill: parent
46+ flickableDirection: Direction.isHorizontal(swipeArea.direction) ? Flickable.HorizontalFlick : Flickable.VerticalFlick
47+ }
48+
49+ SwipeArea {
50+ id: swipeArea
51+ anchors.fill: parent
52+ direction: Direction.Horizontal
53+
54+ onTouchPositionChanged: ffh.onDragAreaTouchPosChanged(flickable, touchPosition);
55+ onDraggingChanged: ffh.onDragAreaDraggingChanged(flickable, dragging, touchPosition);
56+ }
57+}
qml/Stages/DesktopSpread.qml+1
@@ -19,6 +19,7 @@ import QtQuick.Layouts 1.1
1919import Ubuntu.Components 1.3
2020import Ubuntu.Gestures 0.1
2121import Unity.Application 0.1
22+import "../Components"
2223
2324FocusScope {
2425 id: root
tests/plugins/Ubuntu/Gestures/CMakeLists.txt+1−1
@@ -41,7 +41,7 @@ macro(add_gesture_ui_test CLASSNAME)
4141 add_manual_qml_test(. ${CLASSNAME} IMPORT_PATHS ${UNITY_PLUGINPATH})
4242endmacro()
4343
44−# TODO add_gesture_ui_test(FloatingFlickable)
44+add_gesture_ui_test(FloatingFlickable)
4545add_gesture_ui_test(PressedOutsideNotifier)
4646add_gesture_ui_test(TouchDispatcher)
4747add_gesture_ui_test(TouchGate)
tests/plugins/Ubuntu/Gestures/tst_FloatingFlickable.cpp+14−17
@@ -17,12 +17,9 @@
1717#include <QtTest>
1818#include <QQuickView>
1919
20−// Ubuntu.Gestures plugin
21−#include <DirectionalDragArea.h>
22−#include <FloatingFlickable.h>
23−
2420#include "GestureTest.h"
2521#include "TestItem.h"
22+#include "Direction.h"
2623
2724using namespace UbuntuGestures;
2825
@@ -44,8 +41,8 @@ tst_FloatingFlickable::tst_FloatingFlickable()
4441
4542void tst_FloatingFlickable::tapGoesThrough()
4643{
47− FloatingFlickable *floatingFlickable =
48− m_view->rootObject()->findChild<FloatingFlickable*>("floatingFlickable");
44+ QQuickItem *floatingFlickable =
45+ m_view->rootObject()->findChild<QQuickItem*>("floatingFlickable");
4946 QVERIFY(floatingFlickable != nullptr);
5047
5148 TestItem *testItem = new TestItem;
@@ -64,13 +61,13 @@ void tst_FloatingFlickable::tapGoesThrough()
6461
6562void tst_FloatingFlickable::flickChangesContentX()
6663{
67− FloatingFlickable *floatingFlickable =
68− m_view->rootObject()->findChild<FloatingFlickable*>("floatingFlickable");
64+ QQuickItem *floatingFlickable =
65+ m_view->rootObject()->findChild<QQuickItem*>("floatingFlickable");
6966 QVERIFY(floatingFlickable != nullptr);
7067
71− floatingFlickable->m_dragArea->removeTimeConstraints();
68+// TODO? floatingFlickable->m_dragArea->removeTimeConstraints();
7269
73− qreal startContentX = floatingFlickable->contentX();
70+ qreal startContentX = floatingFlickable->property("contentX").toReal();
7471
7572 QPoint startPos(floatingFlickable->width() - 5, 10);
7673 int stepCount = 20;
@@ -86,19 +83,19 @@ void tst_FloatingFlickable::flickChangesContentX()
8683 QTest::qWait(10);
8784 QTest::touchEvent(m_view, m_device).release(0, QPoint(5, 10));
8885
89− QVERIFY(floatingFlickable->contentX() > (startContentX + floatingFlickable->width()/2));
86+ QVERIFY(floatingFlickable->property("contentX").toReal() > (startContentX + floatingFlickable->width()/2));
9087}
9188
9289void tst_FloatingFlickable::flickChangesContentY()
9390{
94− FloatingFlickable *floatingFlickable =
95− m_view->rootObject()->findChild<FloatingFlickable*>("floatingFlickable");
91+ QQuickItem *floatingFlickable =
92+ m_view->rootObject()->findChild<QQuickItem*>("floatingFlickable");
9693 QVERIFY(floatingFlickable != nullptr);
9794
98− floatingFlickable->setDirection(Direction::Vertical);
99− floatingFlickable->m_dragArea->removeTimeConstraints();
95+ floatingFlickable->setProperty("direction", Direction::Vertical);
96+// TODO? floatingFlickable->m_dragArea->removeTimeConstraints();
10097
101− qreal startContentY = floatingFlickable->contentY();
98+ qreal startContentY = floatingFlickable->property("contentY").toReal();
10299
103100 QPoint startPos(10, floatingFlickable->height() - 5);
104101 int stepCount = 20;
@@ -114,7 +111,7 @@ void tst_FloatingFlickable::flickChangesContentY()
114111 QTest::qWait(10);
115112 QTest::touchEvent(m_view, m_device).release(0, QPoint(10, 5));
116113
117− QVERIFY(floatingFlickable->contentY() > (startContentY + floatingFlickable->height()/2));
114+ QVERIFY(floatingFlickable->property("contentY").toReal() > (startContentY + floatingFlickable->height()/2));
118115}
119116
120117QTEST_MAIN(tst_FloatingFlickable)
tests/plugins/Ubuntu/Gestures/tst_FloatingFlickable.qml+1
@@ -18,6 +18,7 @@ import QtQuick 2.4
1818import Ubuntu.Components 1.3
1919import Ubuntu.Gestures 0.1
2020import Unity.Test 0.1
21+import "../../../../../qml/Components"
2122
2223Rectangle {
2324 id: root
tests/qmltests/Components/CMakeLists.txt+5−6
@@ -12,13 +12,12 @@ include_directories(
1212 ${Qt5Quick_PRIVATE_INCLUDE_DIRS}
1313 )
1414
15−# TODO
16−# add_executable(DragHandleTestExec tst_DragHandle.cpp)
17−# qt5_use_modules(DragHandleTestExec Test Core Qml Gui Quick)
18−# target_link_libraries(DragHandleTestExec UbuntuGesturesQml ${UBUNTUGESTURES_LIBRARIES})
15+add_executable(DragHandleTestExec tst_DragHandle.cpp)
16+qt5_use_modules(DragHandleTestExec Test Core Qml Gui Quick)
17+target_link_libraries(DragHandleTestExec UbuntuGesturesQml ${UBUNTUGESTURES_LIBRARIES})
1918
20−# add_unity8_uitest(DragHandle DragHandleTestExec ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/plugins/Ubuntu/Gestures)
21−# add_manual_qml_test(. DragHandle IMPORT_PATHS ${UNITY_PLUGINPATH})
19+add_unity8_uitest(DragHandle DragHandleTestExec ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/plugins/Ubuntu/Gestures)
20+add_manual_qml_test(. DragHandle IMPORT_PATHS ${UNITY_PLUGINPATH})
2221
2322########## tst_EdgeDragEvaluator
2423add_executable(EdgeDragEvaluatorTestExec tst_EdgeDragEvaluator.cpp)
tests/qmltests/Components/tst_DragHandle.cpp+20−18
@@ -24,6 +24,7 @@
2424
2525#include <AxisVelocityCalculator.h>
2626#include <Timer>
27+#include "Direction.h"
2728
2829using namespace UbuntuGestures;
2930
@@ -49,11 +50,11 @@ private Q_SLOTS:
4950 void hintingAnimation_dontRestartAfterFinishedAndStillPressed();
5051
5152private:
52− void flickAndHold(DirectionalDragArea *dragHandle, qreal distance);
53+ void flickAndHold(QQuickItem *dragHandle, qreal distance);
5354 void drag(QPointF &touchPoint, const QPointF& direction, qreal distance,
5455 int numSteps, qint64 timeMs = 500);
55− DirectionalDragArea *fetchAndSetupDragHandle(const char *objectName);
56− qreal fetchDragThreshold(DirectionalDragArea *dragHandle);
56+ QQuickItem *fetchAndSetupDragHandle(const char *objectName);
57+ qreal fetchDragThreshold(QQuickItem *dragHandle);
5758 void tryCompare(std::function<qreal ()> actualFunc, qreal expectedValue);
5859
5960 QQuickView *createView();
@@ -128,11 +129,11 @@ void tst_DragHandle::tryCompare(std::function<qreal ()> actualFunc,
128129}
129130
130131namespace {
131−QPointF calculateDirectionVector(DirectionalDragArea *edgeDragArea)
132+QPointF calculateDirectionVector(QQuickItem *edgeDragArea)
132133{
133134 QPointF localOrigin(0., 0.);
134135 QPointF localDirection;
135− switch (edgeDragArea->direction()) {
136+ switch (edgeDragArea->property("direction").toInt()) {
136137 case Direction::Upwards:
137138 localDirection.rx() = 0.;
138139 localDirection.ry() = -1.;
@@ -156,7 +157,7 @@ QPointF calculateDirectionVector(DirectionalDragArea *edgeDragArea)
156157}
157158}
158159
159−void tst_DragHandle::flickAndHold(DirectionalDragArea *dragHandle,
160+void tst_DragHandle::flickAndHold(QQuickItem *dragHandle,
160161 qreal distance)
161162{
162163 QPointF initialTouchPos = dragHandle->mapToScene(
@@ -194,13 +195,14 @@ void tst_DragHandle::drag(QPointF &touchPoint, const QPointF& direction, qreal d
194195 }
195196}
196197
197−DirectionalDragArea *tst_DragHandle::fetchAndSetupDragHandle(const char *objectName)
198+QQuickItem *tst_DragHandle::fetchAndSetupDragHandle(const char *objectName)
198199{
199− DirectionalDragArea *dragHandle =
200− m_view->rootObject()->findChild<DirectionalDragArea*>(objectName);
200+ QQuickItem *dragHandle =
201+ m_view->rootObject()->findChild<QQuickItem*>(objectName);
201202 Q_ASSERT(dragHandle != 0);
202− dragHandle->d->setRecognitionTimer(m_fakeTimer);
203− dragHandle->d->setTimeSource(m_fakeTimeSource);
203+ QObject *swipeAreaPrivate = dragHandle->findChild<QObject*>("UCSwipeAreaPrivate");
204+ QMetaObject::invokeMethod(swipeAreaPrivate, "setRecognitionTimer", Q_ARG(UbuntuGestures::AbstractTimer*, m_fakeTimer));
205+ QMetaObject::invokeMethod(swipeAreaPrivate, "setTimeSource", Q_ARG(UbuntuGestures::SharedTimeSource, m_fakeTimeSource));
204206
205207 AxisVelocityCalculator *edgeDragEvaluator =
206208 dragHandle->findChild<AxisVelocityCalculator*>("edgeDragEvaluator");
@@ -210,7 +212,7 @@ DirectionalDragArea *tst_DragHandle::fetchAndSetupDragHandle(const char *objectN
210212 return dragHandle;
211213}
212214
213−qreal tst_DragHandle::fetchDragThreshold(DirectionalDragArea *dragHandle)
215+qreal tst_DragHandle::fetchDragThreshold(QQuickItem *dragHandle)
214216{
215217 AxisVelocityCalculator *edgeDragEvaluator =
216218 dragHandle->findChild<AxisVelocityCalculator*>("edgeDragEvaluator");
@@ -231,7 +233,7 @@ void tst_DragHandle::dragThreshold_horizontal()
231233 QQuickItem *baseItem = m_view->rootObject()->findChild<QQuickItem*>("baseItem");
232234 baseItem->setRotation(rotation);
233235
234− DirectionalDragArea *dragHandle = fetchAndSetupDragHandle("rightwardsDragHandle");
236+ QQuickItem *dragHandle = fetchAndSetupDragHandle("rightwardsDragHandle");
235237 QQuickItem *parentItem = dragHandle->parentItem();
236238
237239 qreal dragThreshold = fetchDragThreshold(dragHandle);
@@ -284,7 +286,7 @@ void tst_DragHandle::dragThreshold_vertical()
284286 QQuickItem *baseItem = m_view->rootObject()->findChild<QQuickItem*>("baseItem");
285287 baseItem->setRotation(rotation);
286288
287− DirectionalDragArea *dragHandle = fetchAndSetupDragHandle("downwardsDragHandle");
289+ QQuickItem *dragHandle = fetchAndSetupDragHandle("downwardsDragHandle");
288290
289291 qreal dragThreshold = fetchDragThreshold(dragHandle);
290292
@@ -336,7 +338,7 @@ void tst_DragHandle::dragThreshold_vertical_data()
336338 */
337339void tst_DragHandle::stretch_horizontal()
338340{
339− DirectionalDragArea *dragHandle = fetchAndSetupDragHandle("rightwardsDragHandle");
341+ QQuickItem *dragHandle = fetchAndSetupDragHandle("rightwardsDragHandle");
340342 qreal totalDragDistance = dragHandle->property("maxTotalDragDistance").toReal();
341343 QQuickItem *parentItem = dragHandle->parentItem();
342344
@@ -366,7 +368,7 @@ void tst_DragHandle::stretch_horizontal()
366368
367369void tst_DragHandle::stretch_vertical()
368370{
369− DirectionalDragArea *dragHandle = fetchAndSetupDragHandle("downwardsDragHandle");
371+ QQuickItem *dragHandle = fetchAndSetupDragHandle("downwardsDragHandle");
370372 qreal totalDragDistance = dragHandle->property("maxTotalDragDistance").toReal();
371373 QQuickItem *parentItem = dragHandle->parentItem();
372374
@@ -402,7 +404,7 @@ void tst_DragHandle::stretch_vertical()
402404 */
403405void tst_DragHandle::hintingAnimation()
404406{
405− DirectionalDragArea *dragHandle = fetchAndSetupDragHandle("downwardsDragHandle");
407+ QQuickItem *dragHandle = fetchAndSetupDragHandle("downwardsDragHandle");
406408 QQuickItem *parentItem = dragHandle->parentItem();
407409 qreal hintDisplacement = 100.0;
408410
@@ -443,7 +445,7 @@ void tst_DragHandle::hintingAnimation()
443445 */
444446void tst_DragHandle::hintingAnimation_dontRestartAfterFinishedAndStillPressed()
445447{
446− DirectionalDragArea *dragHandle = fetchAndSetupDragHandle("downwardsDragHandle");
448+ QQuickItem *dragHandle = fetchAndSetupDragHandle("downwardsDragHandle");
447449 QQuickItem *parentItem = dragHandle->parentItem();
448450 qreal hintDisplacement = 100.0;
449451