author | Maciej Seroka <maciejs@symbian.org> |
Tue, 15 Jun 2010 11:06:30 +0100 | |
branch | Symbian3 |
changeset 45 | 49affa6ecf23 |
parent 43 | 14fcccfb4c0c |
permissions | -rw-r--r-- |
41
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
1 |
/**************************************************************************** |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
2 |
** |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
4 |
** All rights reserved. |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
6 |
** |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
8 |
** |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
10 |
** No Commercial Usage |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
11 |
** This file contains pre-release code and may not be distributed. |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
12 |
** You may use this file in accordance with the terms and conditions |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
13 |
** contained in the Technology Preview License Agreement accompanying |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
14 |
** this package. |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
15 |
** |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
16 |
** GNU Lesser General Public License Usage |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
18 |
** General Public License version 2.1 as published by the Free Software |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
20 |
** packaging of this file. Please review the following information to |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
23 |
** |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
27 |
** |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
28 |
** If you have questions regarding the use of this file, please contact |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
29 |
** Nokia at qt-info@nokia.com. |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
30 |
** |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
31 |
** |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
32 |
** |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
33 |
** |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
34 |
** |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
35 |
** |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
36 |
** |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
37 |
** |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
38 |
** $QT_END_LICENSE$ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
39 |
** |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
40 |
****************************************************************************/ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
41 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
42 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
43 |
#include <QtTest/QtTest> |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
44 |
#include "../shared/util.h" |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
45 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
46 |
#include <qevent.h> |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
47 |
#include <qwidget.h> |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
48 |
#include <qlayout.h> |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
49 |
#include <qgesture.h> |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
50 |
#include <qgesturerecognizer.h> |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
51 |
#include <qgraphicsitem.h> |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
52 |
#include <qgraphicsview.h> |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
53 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
54 |
#include <qdebug.h> |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
55 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
56 |
//TESTED_CLASS= |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
57 |
//TESTED_FILES= |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
58 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
59 |
static QPointF mapToGlobal(const QPointF &pt, QGraphicsItem *item, QGraphicsView *view) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
60 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
61 |
return view->mapToGlobal(view->mapFromScene(item->mapToScene(pt))); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
62 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
63 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
64 |
class CustomGesture : public QGesture |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
65 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
66 |
Q_OBJECT |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
67 |
public: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
68 |
static Qt::GestureType GestureType; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
69 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
70 |
CustomGesture(QObject *parent = 0) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
71 |
: QGesture(parent), serial(0) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
72 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
73 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
74 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
75 |
int serial; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
76 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
77 |
static const int SerialMaybeThreshold; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
78 |
static const int SerialStartedThreshold; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
79 |
static const int SerialFinishedThreshold; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
80 |
}; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
81 |
Qt::GestureType CustomGesture::GestureType = Qt::CustomGesture; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
82 |
const int CustomGesture::SerialMaybeThreshold = 1; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
83 |
const int CustomGesture::SerialStartedThreshold = 3; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
84 |
const int CustomGesture::SerialFinishedThreshold = 6; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
85 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
86 |
class CustomEvent : public QEvent |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
87 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
88 |
public: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
89 |
static int EventType; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
90 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
91 |
CustomEvent(int serial_ = 0) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
92 |
: QEvent(QEvent::Type(CustomEvent::EventType)), |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
93 |
serial(serial_), hasHotSpot(false) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
94 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
95 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
96 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
97 |
int serial; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
98 |
QPointF hotSpot; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
99 |
bool hasHotSpot; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
100 |
}; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
101 |
int CustomEvent::EventType = 0; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
102 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
103 |
class CustomGestureRecognizer : public QGestureRecognizer |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
104 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
105 |
public: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
106 |
static bool ConsumeEvents; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
107 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
108 |
CustomGestureRecognizer() |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
109 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
110 |
if (!CustomEvent::EventType) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
111 |
CustomEvent::EventType = QEvent::registerEventType(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
112 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
113 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
114 |
QGesture* create(QObject *) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
115 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
116 |
return new CustomGesture; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
117 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
118 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
119 |
QGestureRecognizer::Result recognize(QGesture *state, QObject*, QEvent *event) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
120 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
121 |
if (event->type() == CustomEvent::EventType) { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
122 |
QGestureRecognizer::Result result = 0; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
123 |
if (CustomGestureRecognizer::ConsumeEvents) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
124 |
result |= QGestureRecognizer::ConsumeEventHint; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
125 |
CustomGesture *g = static_cast<CustomGesture*>(state); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
126 |
CustomEvent *e = static_cast<CustomEvent*>(event); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
127 |
g->serial = e->serial; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
128 |
if (e->hasHotSpot) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
129 |
g->setHotSpot(e->hotSpot); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
130 |
if (g->serial >= CustomGesture::SerialFinishedThreshold) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
131 |
result |= QGestureRecognizer::FinishGesture; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
132 |
else if (g->serial >= CustomGesture::SerialStartedThreshold) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
133 |
result |= QGestureRecognizer::TriggerGesture; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
134 |
else if (g->serial >= CustomGesture::SerialMaybeThreshold) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
135 |
result |= QGestureRecognizer::MayBeGesture; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
136 |
else |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
137 |
result = QGestureRecognizer::CancelGesture; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
138 |
return result; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
139 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
140 |
return QGestureRecognizer::Ignore; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
141 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
142 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
143 |
void reset(QGesture *state) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
144 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
145 |
CustomGesture *g = static_cast<CustomGesture *>(state); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
146 |
g->serial = 0; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
147 |
QGestureRecognizer::reset(state); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
148 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
149 |
}; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
150 |
bool CustomGestureRecognizer::ConsumeEvents = false; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
151 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
152 |
// same as CustomGestureRecognizer but triggers early without the maybe state |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
153 |
class CustomContinuousGestureRecognizer : public QGestureRecognizer |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
154 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
155 |
public: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
156 |
CustomContinuousGestureRecognizer() |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
157 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
158 |
if (!CustomEvent::EventType) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
159 |
CustomEvent::EventType = QEvent::registerEventType(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
160 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
161 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
162 |
QGesture* create(QObject *) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
163 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
164 |
return new CustomGesture; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
165 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
166 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
167 |
QGestureRecognizer::Result recognize(QGesture *state, QObject*, QEvent *event) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
168 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
169 |
if (event->type() == CustomEvent::EventType) { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
170 |
QGestureRecognizer::Result result = QGestureRecognizer::ConsumeEventHint; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
171 |
CustomGesture *g = static_cast<CustomGesture *>(state); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
172 |
CustomEvent *e = static_cast<CustomEvent *>(event); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
173 |
g->serial = e->serial; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
174 |
if (e->hasHotSpot) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
175 |
g->setHotSpot(e->hotSpot); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
176 |
if (g->serial >= CustomGesture::SerialFinishedThreshold) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
177 |
result |= QGestureRecognizer::FinishGesture; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
178 |
else if (g->serial >= CustomGesture::SerialMaybeThreshold) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
179 |
result |= QGestureRecognizer::TriggerGesture; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
180 |
else |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
181 |
result = QGestureRecognizer::CancelGesture; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
182 |
return result; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
183 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
184 |
return QGestureRecognizer::Ignore; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
185 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
186 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
187 |
void reset(QGesture *state) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
188 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
189 |
CustomGesture *g = static_cast<CustomGesture *>(state); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
190 |
g->serial = 0; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
191 |
QGestureRecognizer::reset(state); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
192 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
193 |
}; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
194 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
195 |
class GestureWidget : public QWidget |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
196 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
197 |
Q_OBJECT |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
198 |
public: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
199 |
GestureWidget(const char *name = 0, QWidget *parent = 0) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
200 |
: QWidget(parent) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
201 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
202 |
if (name) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
203 |
setObjectName(QLatin1String(name)); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
204 |
reset(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
205 |
acceptGestureOverride = false; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
206 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
207 |
void reset() |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
208 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
209 |
customEventsReceived = 0; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
210 |
gestureEventsReceived = 0; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
211 |
gestureOverrideEventsReceived = 0; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
212 |
events.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
213 |
overrideEvents.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
214 |
ignoredGestures.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
215 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
216 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
217 |
int customEventsReceived; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
218 |
int gestureEventsReceived; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
219 |
int gestureOverrideEventsReceived; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
220 |
struct Events |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
221 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
222 |
QList<Qt::GestureType> all; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
223 |
QList<Qt::GestureType> started; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
224 |
QList<Qt::GestureType> updated; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
225 |
QList<Qt::GestureType> finished; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
226 |
QList<Qt::GestureType> canceled; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
227 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
228 |
void clear() |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
229 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
230 |
all.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
231 |
started.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
232 |
updated.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
233 |
finished.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
234 |
canceled.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
235 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
236 |
} events, overrideEvents; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
237 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
238 |
bool acceptGestureOverride; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
239 |
QSet<Qt::GestureType> ignoredGestures; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
240 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
241 |
protected: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
242 |
bool event(QEvent *event) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
243 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
244 |
Events *eventsPtr = 0; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
245 |
if (event->type() == QEvent::Gesture) { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
246 |
QGestureEvent *e = static_cast<QGestureEvent*>(event); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
247 |
++gestureEventsReceived; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
248 |
eventsPtr = &events; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
249 |
foreach(Qt::GestureType type, ignoredGestures) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
250 |
e->ignore(e->gesture(type)); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
251 |
} else if (event->type() == QEvent::GestureOverride) { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
252 |
++gestureOverrideEventsReceived; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
253 |
eventsPtr = &overrideEvents; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
254 |
if (acceptGestureOverride) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
255 |
event->accept(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
256 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
257 |
if (eventsPtr) { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
258 |
QGestureEvent *e = static_cast<QGestureEvent*>(event); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
259 |
QList<QGesture*> gestures = e->gestures(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
260 |
foreach(QGesture *g, gestures) { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
261 |
eventsPtr->all << g->gestureType(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
262 |
switch(g->state()) { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
263 |
case Qt::GestureStarted: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
264 |
eventsPtr->started << g->gestureType(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
265 |
break; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
266 |
case Qt::GestureUpdated: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
267 |
eventsPtr->updated << g->gestureType(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
268 |
break; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
269 |
case Qt::GestureFinished: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
270 |
eventsPtr->finished << g->gestureType(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
271 |
break; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
272 |
case Qt::GestureCanceled: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
273 |
eventsPtr->canceled << g->gestureType(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
274 |
break; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
275 |
default: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
276 |
Q_ASSERT(false); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
277 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
278 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
279 |
} else if (event->type() == CustomEvent::EventType) { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
280 |
++customEventsReceived; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
281 |
} else { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
282 |
return QWidget::event(event); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
283 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
284 |
return true; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
285 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
286 |
}; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
287 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
288 |
// TODO rename to sendGestureSequence |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
289 |
static void sendCustomGesture(CustomEvent *event, QObject *object, QGraphicsScene *scene = 0) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
290 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
291 |
for (int i = CustomGesture::SerialMaybeThreshold; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
292 |
i <= CustomGesture::SerialFinishedThreshold; ++i) { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
293 |
event->serial = i; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
294 |
if (scene) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
295 |
scene->sendEvent(qobject_cast<QGraphicsObject *>(object), event); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
296 |
else |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
297 |
QApplication::sendEvent(object, event); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
298 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
299 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
300 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
301 |
class tst_Gestures : public QObject |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
302 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
303 |
Q_OBJECT |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
304 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
305 |
public: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
306 |
tst_Gestures(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
307 |
virtual ~tst_Gestures(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
308 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
309 |
public slots: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
310 |
void initTestCase(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
311 |
void cleanupTestCase(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
312 |
void init(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
313 |
void cleanup(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
314 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
315 |
private slots: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
316 |
void customGesture(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
317 |
}; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
318 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
319 |
tst_Gestures::tst_Gestures() |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
320 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
321 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
322 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
323 |
tst_Gestures::~tst_Gestures() |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
324 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
325 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
326 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
327 |
void tst_Gestures::initTestCase() |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
328 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
329 |
CustomGesture::GestureType = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
330 |
QVERIFY(CustomGesture::GestureType != Qt::GestureType(0)); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
331 |
QVERIFY(CustomGesture::GestureType != Qt::CustomGesture); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
332 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
333 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
334 |
void tst_Gestures::cleanupTestCase() |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
335 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
336 |
QGestureRecognizer::unregisterRecognizer(CustomGesture::GestureType); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
337 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
338 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
339 |
void tst_Gestures::init() |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
340 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
341 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
342 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
343 |
void tst_Gestures::cleanup() |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
344 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
345 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
346 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
347 |
void tst_Gestures::customGesture() |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
348 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
349 |
GestureWidget widget; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
350 |
widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
351 |
CustomEvent event; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
352 |
sendCustomGesture(&event, &widget); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
353 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
354 |
static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
355 |
static const int TotalCustomEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
356 |
QCOMPARE(widget.customEventsReceived, TotalCustomEventsCount); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
357 |
QCOMPARE(widget.gestureEventsReceived, TotalGestureEventsCount); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
358 |
QCOMPARE(widget.gestureOverrideEventsReceived, 0); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
359 |
QCOMPARE(widget.events.all.size(), TotalGestureEventsCount); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
360 |
for(int i = 0; i < widget.events.all.size(); ++i) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
361 |
QCOMPARE(widget.events.all.at(i), CustomGesture::GestureType); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
362 |
QCOMPARE(widget.events.started.size(), 1); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
363 |
QCOMPARE(widget.events.updated.size(), TotalGestureEventsCount - 2); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
364 |
QCOMPARE(widget.events.finished.size(), 1); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
365 |
QCOMPARE(widget.events.canceled.size(), 0); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
366 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
367 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
368 |
static const QColor InstanceColors[] = { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
369 |
Qt::blue, Qt::red, Qt::green, Qt::gray, Qt::yellow |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
370 |
}; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
371 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
372 |
class GestureItem : public QGraphicsObject |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
373 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
374 |
static int InstanceCount; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
375 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
376 |
public: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
377 |
GestureItem(const char *name = 0) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
378 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
379 |
instanceNumber = InstanceCount++; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
380 |
if (name) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
381 |
setObjectName(QLatin1String(name)); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
382 |
size = QRectF(0, 0, 100, 100); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
383 |
customEventsReceived = 0; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
384 |
gestureEventsReceived = 0; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
385 |
gestureOverrideEventsReceived = 0; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
386 |
events.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
387 |
overrideEvents.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
388 |
acceptGestureOverride = false; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
389 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
390 |
~GestureItem() |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
391 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
392 |
--InstanceCount; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
393 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
394 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
395 |
int customEventsReceived; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
396 |
int gestureEventsReceived; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
397 |
int gestureOverrideEventsReceived; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
398 |
struct Events |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
399 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
400 |
QList<Qt::GestureType> all; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
401 |
QList<Qt::GestureType> started; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
402 |
QList<Qt::GestureType> updated; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
403 |
QList<Qt::GestureType> finished; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
404 |
QList<Qt::GestureType> canceled; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
405 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
406 |
void clear() |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
407 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
408 |
all.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
409 |
started.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
410 |
updated.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
411 |
finished.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
412 |
canceled.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
413 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
414 |
} events, overrideEvents; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
415 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
416 |
bool acceptGestureOverride; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
417 |
QSet<Qt::GestureType> ignoredGestures; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
418 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
419 |
QRectF size; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
420 |
int instanceNumber; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
421 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
422 |
void reset() |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
423 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
424 |
customEventsReceived = 0; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
425 |
gestureEventsReceived = 0; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
426 |
gestureOverrideEventsReceived = 0; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
427 |
events.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
428 |
overrideEvents.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
429 |
ignoredGestures.clear(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
430 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
431 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
432 |
protected: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
433 |
QRectF boundingRect() const |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
434 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
435 |
return size; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
436 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
437 |
void paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
438 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
439 |
QColor color = InstanceColors[instanceNumber % (sizeof(InstanceColors)/sizeof(InstanceColors[0]))]; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
440 |
p->fillRect(boundingRect(), color); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
441 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
442 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
443 |
bool event(QEvent *event) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
444 |
{ |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
445 |
Events *eventsPtr = 0; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
446 |
if (event->type() == QEvent::Gesture) { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
447 |
++gestureEventsReceived; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
448 |
eventsPtr = &events; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
449 |
QGestureEvent *e = static_cast<QGestureEvent *>(event); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
450 |
foreach(Qt::GestureType type, ignoredGestures) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
451 |
e->ignore(e->gesture(type)); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
452 |
} else if (event->type() == QEvent::GestureOverride) { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
453 |
++gestureOverrideEventsReceived; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
454 |
eventsPtr = &overrideEvents; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
455 |
if (acceptGestureOverride) |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
456 |
event->accept(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
457 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
458 |
if (eventsPtr) { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
459 |
QGestureEvent *e = static_cast<QGestureEvent*>(event); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
460 |
QList<QGesture*> gestures = e->gestures(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
461 |
foreach(QGesture *g, gestures) { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
462 |
eventsPtr->all << g->gestureType(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
463 |
switch(g->state()) { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
464 |
case Qt::GestureStarted: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
465 |
eventsPtr->started << g->gestureType(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
466 |
break; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
467 |
case Qt::GestureUpdated: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
468 |
eventsPtr->updated << g->gestureType(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
469 |
break; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
470 |
case Qt::GestureFinished: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
471 |
eventsPtr->finished << g->gestureType(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
472 |
break; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
473 |
case Qt::GestureCanceled: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
474 |
eventsPtr->canceled << g->gestureType(); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
475 |
break; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
476 |
default: |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
477 |
Q_ASSERT(false); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
478 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
479 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
480 |
} else if (event->type() == CustomEvent::EventType) { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
481 |
++customEventsReceived; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
482 |
} else { |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
483 |
return QGraphicsObject::event(event); |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
484 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
485 |
return true; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
486 |
} |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
487 |
}; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
488 |
int GestureItem::InstanceCount = 0; |
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
489 |
|
72f7e4177ac7
Smoketest for Qt: Gestures and QApplication
Brendan Donegan <brendand@symbian.org>
parents:
diff
changeset
|
490 |
QTEST_MAIN(tst_Gestures) |
43
14fcccfb4c0c
Cleaning up the new Qt tests, removing redundant code
Brendan Donegan <brendand@symbian.org>
parents:
41
diff
changeset
|
491 |
#include "smoke_qtgestures.moc" |