File indexing completed on 2024-05-12 04:19:52

0001 /*
0002 Gwenview: an image viewer
0003 Copyright 2019 Steffen Hartleib <steffenhartleib@t-online.de>
0004 
0005 This program is free software; you can redistribute it and/or
0006 modify it under the terms of the GNU General Public License
0007 as published by the Free Software Foundation; either version 2
0008 of the License, or (at your option) any later version.
0009 
0010 This program is distributed in the hope that it will be useful,
0011 but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 GNU General Public License for more details.
0014 
0015 You should have received a copy of the GNU General Public License
0016 along with this program; if not, write to the Free Software
0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0018 
0019 */
0020 #include "touch_helper.h"
0021 
0022 // Qt
0023 #include "gwenview_lib_debug.h"
0024 #include <QEvent>
0025 #include <QGraphicsWidget>
0026 #include <QPoint>
0027 #include <QTouchEvent>
0028 
0029 namespace Gwenview
0030 {
0031 namespace Touch_Helper
0032 {
0033 QPoint simpleTapPosition(QEvent *event)
0034 {
0035     if (event->type() == QEvent::TouchEnd) {
0036         event->accept();
0037         if (touchStationary(event)) {
0038             return simpleTouchPosition(event);
0039         }
0040     }
0041     return QPoint(-1, -1);
0042 }
0043 
0044 QPoint simpleTouchPosition(QEvent *event, int at)
0045 {
0046     if (auto touchEvent = static_cast<QTouchEvent *>(event)) {
0047         if (touchEvent->touchPoints().size() > at) {
0048             return touchEvent->touchPoints().at(at).pos().toPoint();
0049         }
0050     }
0051     return QPoint(-1, -1);
0052 }
0053 
0054 bool touchStationary(QEvent *event)
0055 {
0056     if (auto touchEvent = static_cast<QTouchEvent *>(event)) {
0057         const QPointF distance = touchEvent->touchPoints().first().startPos() - touchEvent->touchPoints().first().pos();
0058         if (distance.manhattanLength() <= Touch::wiggleRoomForTap) {
0059             return true;
0060         }
0061     }
0062     return false;
0063 }
0064 
0065 } // namespace
0066 } // namespace