Changeset View
Changeset View
Standalone View
Standalone View
lib/touch/touch_helper.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Gwenview: an image viewer | ||||
3 | Copyright 2019 Steffen Hartleib <steffenhartleib@t-online.de> | ||||
4 | | ||||
5 | This program is free software; you can redistribute it and/or | ||||
6 | modify it under the terms of the GNU General Public License | ||||
7 | as published by the Free Software Foundation; either version 2 | ||||
8 | of the License, or (at your option) any later version. | ||||
9 | | ||||
10 | This program is distributed in the hope that it will be useful, | ||||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
13 | GNU General Public License for more details. | ||||
14 | | ||||
15 | You should have received a copy of the GNU General Public License | ||||
16 | along with this program; if not, write to the Free Software | ||||
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
18 | | ||||
19 | */ | ||||
20 | #include "touch_helper.h" | ||||
21 | | ||||
22 | // Qt | ||||
23 | #include <QEvent> | ||||
24 | #include <QPoint> | ||||
25 | #include <QTouchEvent> | ||||
26 | #include <QGraphicsWidget> | ||||
27 | #include <QCoreApplication> | ||||
28 | #include <QDebug> | ||||
29 | | ||||
30 | | ||||
31 | namespace Gwenview | ||||
32 | { | ||||
33 | namespace Touch_Helper | ||||
34 | { | ||||
35 | | ||||
36 | QPoint simpleTapPosition (QEvent* event) | ||||
37 | { | ||||
38 | if (event->type() == QEvent::TouchEnd) { | ||||
39 | event->accept(); | ||||
40 | if (touchStationary(event)) { | ||||
41 | return simpleTouchPosition(event); | ||||
42 | } | ||||
43 | } | ||||
44 | return QPoint(-1, -1); | ||||
45 | } | ||||
46 | | ||||
47 | QPoint simpleTouchPosition(QEvent* event, int at) | ||||
48 | { | ||||
49 | if (QTouchEvent* touchEvent = static_cast<QTouchEvent*>(event)) { | ||||
50 | if (touchEvent->touchPoints().size() > at) { | ||||
51 | return touchEvent->touchPoints().at(at).pos().toPoint(); | ||||
52 | } | ||||
53 | } | ||||
54 | return QPoint(-1, -1); | ||||
55 | } | ||||
56 | | ||||
57 | bool touchStationary(QEvent* event) | ||||
58 | { | ||||
59 | if (QTouchEvent* touchEvent = static_cast<QTouchEvent*>(event)) { | ||||
60 | const QPointF distance = touchEvent->touchPoints().first().startPos() - touchEvent->touchPoints().first().pos(); | ||||
61 | if (distance.manhattanLength() <= Touch::wiggleRoomForTap) { | ||||
62 | return true; | ||||
63 | } | ||||
64 | } | ||||
65 | return false; | ||||
66 | } | ||||
67 | | ||||
68 | } // namespace | ||||
69 | } // namespace |