~mterry/+junk/u8.2

« back to all changes in this revision

Viewing changes to tests/plugins/Ubuntu/Gestures/GestureTest.cpp

  • Committer: Michael Terry
  • Date: 2014-11-17 14:56:04 UTC
  • mfrom: (1317.1.118 unity8)
  • Revision ID: michael.terry@canonical.com-20141117145604-96dn9p5nwkifq2f4
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <QQuickView>
22
22
#include <QtTest>
23
23
 
 
24
#include <TouchRegistry.h>
 
25
 
24
26
GestureTest::GestureTest(const QString &qmlFilename)
25
27
    : QObject(), m_device(nullptr), m_view(nullptr), m_qmlFilename(qmlFilename)
26
28
{
44
46
    m_view->show();
45
47
    QVERIFY(QTest::qWaitForWindowExposed(m_view));
46
48
    QVERIFY(m_view->rootObject() != 0);
 
49
 
 
50
    m_touchRegistry = new TouchRegistry;
 
51
    m_view->installEventFilter(m_touchRegistry);
 
52
 
47
53
    qApp->processEvents();
48
54
}
49
55
 
50
56
void GestureTest::cleanup()
51
57
{
 
58
    m_view->removeEventFilter(m_touchRegistry);
 
59
    delete m_touchRegistry;
 
60
    m_touchRegistry = nullptr;
 
61
 
52
62
    delete m_view;
53
63
    m_view = nullptr;
54
64
}
 
65
 
 
66
////////////////////////// TouchMemento /////////////////////////////
 
67
 
 
68
TouchMemento::TouchMemento(const QTouchEvent *touchEvent)
 
69
    : touchPointStates(touchEvent->touchPointStates()), touchPoints(touchEvent->touchPoints())
 
70
{
 
71
 
 
72
}
 
73
 
 
74
bool TouchMemento::containsTouchWithId(int touchId) const
 
75
{
 
76
    for (int i = 0; i < touchPoints.count(); ++i) {
 
77
        if (touchPoints.at(i).id() == touchId) {
 
78
            return true;
 
79
        }
 
80
    }
 
81
    return false;
 
82
}
 
83
 
 
84
////////////////////////// DummyItem /////////////////////////////
 
85
 
 
86
DummyItem::DummyItem(QQuickItem *parent)
 
87
    : QQuickItem(parent)
 
88
{
 
89
    touchEventHandler = defaultTouchEventHandler;
 
90
    mousePressEventHandler = defaultMouseEventHandler;
 
91
    mouseMoveEventHandler = defaultMouseEventHandler;
 
92
    mouseReleaseEventHandler = defaultMouseEventHandler;
 
93
    mouseDoubleClickEventHandler = defaultMouseEventHandler;
 
94
}
 
95
 
 
96
void DummyItem::touchEvent(QTouchEvent *event)
 
97
{
 
98
    touchEvents.append(TouchMemento(event));
 
99
    touchEventHandler(event);
 
100
}
 
101
 
 
102
void DummyItem::mousePressEvent(QMouseEvent *event)
 
103
{
 
104
    mousePressEventHandler(event);
 
105
}
 
106
 
 
107
void DummyItem::mouseMoveEvent(QMouseEvent *event)
 
108
{
 
109
    mouseMoveEventHandler(event);
 
110
}
 
111
 
 
112
void DummyItem::mouseReleaseEvent(QMouseEvent *event)
 
113
{
 
114
    mouseReleaseEventHandler(event);
 
115
}
 
116
 
 
117
void DummyItem::mouseDoubleClickEvent(QMouseEvent *event)
 
118
{
 
119
    mouseDoubleClickEventHandler(event);
 
120
}
 
121
 
 
122
void DummyItem::defaultTouchEventHandler(QTouchEvent *event)
 
123
{
 
124
    event->accept();
 
125
}
 
126
 
 
127
void DummyItem::defaultMouseEventHandler(QMouseEvent *event)
 
128
{
 
129
    event->accept();
 
130
}