| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
#include "touchwidget.h" |
| 5 |
|
| 6 |
#include <QApplication> |
| 7 |
#include <QtEvents> |
| 8 |
#include <QTimer> |
| 9 |
#include <QTouchEvent> |
| 10 |
|
| 11 |
void TouchWidget::reset() |
| 12 |
{ |
| 13 |
acceptTouchBegin |
| 14 |
= acceptTouchUpdate |
| 15 |
= acceptTouchEnd |
| 16 |
= seenTouchBegin |
| 17 |
= seenTouchUpdate |
| 18 |
= seenTouchEnd |
| 19 |
= closeWindowOnTouchEnd |
| 20 |
|
| 21 |
= acceptMousePress |
| 22 |
= acceptMouseMove |
| 23 |
= acceptMouseRelease |
| 24 |
= seenMousePress |
| 25 |
= seenMouseMove |
| 26 |
= seenMouseRelease |
| 27 |
= closeWindowOnMouseRelease |
| 28 |
|
| 29 |
= false; |
| 30 |
touchPointCount = 0; |
| 31 |
} |
| 32 |
|
| 33 |
bool TouchWidget::event(QEvent *event) |
| 34 |
{ |
| 35 |
switch (event->type()) { |
| 36 |
case QEvent::TouchBegin: |
| 37 |
if (seenTouchBegin) qWarning("TouchBegin: already seen a TouchBegin"); |
| 38 |
if (seenTouchUpdate) qWarning("TouchBegin: TouchUpdate cannot happen before TouchBegin"); |
| 39 |
if (seenTouchEnd) qWarning("TouchBegin: TouchEnd cannot happen before TouchBegin"); |
| 40 |
seenTouchBegin = !seenTouchBegin && !seenTouchUpdate && !seenTouchEnd; |
| 41 |
touchPointCount = qMax(touchPointCount, static_cast<QTouchEvent *>(event)->touchPoints().count()); |
| 42 |
if (acceptTouchBegin) { |
| 43 |
event->accept(); |
| 44 |
return true; |
| 45 |
} |
| 46 |
break; |
| 47 |
case QEvent::TouchUpdate: |
| 48 |
if (!seenTouchBegin) qWarning("TouchUpdate: have not seen TouchBegin"); |
| 49 |
if (seenTouchEnd) qWarning("TouchUpdate: TouchEnd cannot happen before TouchUpdate"); |
| 50 |
seenTouchUpdate = seenTouchBegin && !seenTouchEnd; |
| 51 |
touchPointCount = qMax(touchPointCount, static_cast<QTouchEvent *>(event)->touchPoints().count()); |
| 52 |
if (acceptTouchUpdate) { |
| 53 |
event->accept(); |
| 54 |
return true; |
| 55 |
} |
| 56 |
break; |
| 57 |
case QEvent::TouchEnd: |
| 58 |
if (!seenTouchBegin) qWarning("TouchEnd: have not seen TouchBegin"); |
| 59 |
if (seenTouchEnd) qWarning("TouchEnd: already seen a TouchEnd"); |
| 60 |
seenTouchEnd = seenTouchBegin && !seenTouchEnd; |
| 61 |
touchPointCount = qMax(touchPointCount, static_cast<QTouchEvent *>(event)->touchPoints().count()); |
| 62 |
if (closeWindowOnTouchEnd) |
| 63 |
window()->close(); |
| 64 |
if (acceptTouchEnd) { |
| 65 |
event->accept(); |
| 66 |
return true; |
| 67 |
} |
| 68 |
break; |
| 69 |
case QEvent::MouseButtonPress: |
| 70 |
case QEvent::MouseButtonDblClick: |
| 71 |
seenMousePress = true; |
| 72 |
if (acceptMousePress) { |
| 73 |
event->accept(); |
| 74 |
return true; |
| 75 |
} |
| 76 |
break; |
| 77 |
case QEvent::MouseMove: |
| 78 |
seenMouseMove = true; |
| 79 |
if (acceptMouseMove) { |
| 80 |
event->accept(); |
| 81 |
return true; |
| 82 |
} |
| 83 |
break; |
| 84 |
case QEvent::MouseButtonRelease: |
| 85 |
seenMouseRelease = true; |
| 86 |
if (closeWindowOnMouseRelease) |
| 87 |
window()->close(); |
| 88 |
if (acceptMouseRelease) { |
| 89 |
event->accept(); |
| 90 |
return true; |
| 91 |
} |
| 92 |
break; |
| 93 |
default: |
| 94 |
break; |
| 95 |
} |
| 96 |
return QWidget::event(event); |
| 97 |
} |