1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
reset()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 
event(QEvent * event)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 }
136