|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "touchwidget.h" |
|
43 |
|
44 #include <QApplication> |
|
45 #include <QtEvents> |
|
46 #include <QTimer> |
|
47 #include <QTouchEvent> |
|
48 |
|
49 void TouchWidget::reset() |
|
50 { |
|
51 acceptTouchBegin |
|
52 = acceptTouchUpdate |
|
53 = acceptTouchEnd |
|
54 = seenTouchBegin |
|
55 = seenTouchUpdate |
|
56 = seenTouchEnd |
|
57 = closeWindowOnTouchEnd |
|
58 |
|
59 = acceptMousePress |
|
60 = acceptMouseMove |
|
61 = acceptMouseRelease |
|
62 = seenMousePress |
|
63 = seenMouseMove |
|
64 = seenMouseRelease |
|
65 = closeWindowOnMouseRelease |
|
66 |
|
67 = false; |
|
68 touchPointCount = 0; |
|
69 } |
|
70 |
|
71 bool TouchWidget::event(QEvent *event) |
|
72 { |
|
73 switch (event->type()) { |
|
74 case QEvent::TouchBegin: |
|
75 if (seenTouchBegin) qWarning("TouchBegin: already seen a TouchBegin"); |
|
76 if (seenTouchUpdate) qWarning("TouchBegin: TouchUpdate cannot happen before TouchBegin"); |
|
77 if (seenTouchEnd) qWarning("TouchBegin: TouchEnd cannot happen before TouchBegin"); |
|
78 seenTouchBegin = !seenTouchBegin && !seenTouchUpdate && !seenTouchEnd; |
|
79 touchPointCount = qMax(touchPointCount, static_cast<QTouchEvent *>(event)->touchPoints().count()); |
|
80 if (acceptTouchBegin) { |
|
81 event->accept(); |
|
82 return true; |
|
83 } |
|
84 break; |
|
85 case QEvent::TouchUpdate: |
|
86 if (!seenTouchBegin) qWarning("TouchUpdate: have not seen TouchBegin"); |
|
87 if (seenTouchEnd) qWarning("TouchUpdate: TouchEnd cannot happen before TouchUpdate"); |
|
88 seenTouchUpdate = seenTouchBegin && !seenTouchEnd; |
|
89 touchPointCount = qMax(touchPointCount, static_cast<QTouchEvent *>(event)->touchPoints().count()); |
|
90 if (acceptTouchUpdate) { |
|
91 event->accept(); |
|
92 return true; |
|
93 } |
|
94 break; |
|
95 case QEvent::TouchEnd: |
|
96 if (!seenTouchBegin) qWarning("TouchEnd: have not seen TouchBegin"); |
|
97 if (seenTouchEnd) qWarning("TouchEnd: already seen a TouchEnd"); |
|
98 seenTouchEnd = seenTouchBegin && !seenTouchEnd; |
|
99 touchPointCount = qMax(touchPointCount, static_cast<QTouchEvent *>(event)->touchPoints().count()); |
|
100 if (closeWindowOnTouchEnd) |
|
101 window()->close(); |
|
102 if (acceptTouchEnd) { |
|
103 event->accept(); |
|
104 return true; |
|
105 } |
|
106 break; |
|
107 case QEvent::MouseButtonPress: |
|
108 case QEvent::MouseButtonDblClick: |
|
109 seenMousePress = true; |
|
110 if (acceptMousePress) { |
|
111 event->accept(); |
|
112 return true; |
|
113 } |
|
114 break; |
|
115 case QEvent::MouseMove: |
|
116 seenMouseMove = true; |
|
117 if (acceptMouseMove) { |
|
118 event->accept(); |
|
119 return true; |
|
120 } |
|
121 break; |
|
122 case QEvent::MouseButtonRelease: |
|
123 seenMouseRelease = true; |
|
124 if (closeWindowOnMouseRelease) |
|
125 window()->close(); |
|
126 if (acceptMouseRelease) { |
|
127 event->accept(); |
|
128 return true; |
|
129 } |
|
130 break; |
|
131 default: |
|
132 break; |
|
133 } |
|
134 return QWidget::event(event); |
|
135 } |