File indexing completed on 2024-12-22 04:12:44

0001 /*
0002  *  This file is part of the KDE project
0003  *  SPDX-FileCopyrightText: 2012 Arjen Hiemstra <ahiemstra@heimr.nl>
0004  *
0005  *  SPDX-License-Identifier: GPL-2.0-or-later
0006  *
0007  */
0008 
0009 #include "kis_touch_shortcut.h"
0010 #include "kis_abstract_input_action.h"
0011 
0012 #include <QTouchEvent>
0013 
0014 class KisTouchShortcut::Private
0015 {
0016 public:
0017     Private(GestureAction type)
0018         : minTouchPoints(0)
0019         , maxTouchPoints(0)
0020         , type(type)
0021     { }
0022 
0023     int minTouchPoints;
0024     int maxTouchPoints;
0025     GestureAction type;
0026 };
0027 
0028 KisTouchShortcut::KisTouchShortcut(KisAbstractInputAction* action, int index, GestureAction type)
0029     : KisAbstractShortcut(action, index)
0030     , d(new Private(type))
0031 {
0032 
0033 }
0034 
0035 KisTouchShortcut::~KisTouchShortcut()
0036 {
0037     delete d;
0038 }
0039 
0040 int KisTouchShortcut::priority() const
0041 {
0042     return action()->priority();
0043 }
0044 
0045 void KisTouchShortcut::setMinimumTouchPoints(int min)
0046 {
0047     d->minTouchPoints = min;
0048 }
0049 
0050 void KisTouchShortcut::setMaximumTouchPoints(int max)
0051 {
0052     d->maxTouchPoints = max;
0053 }
0054 
0055 bool KisTouchShortcut::matchTapType(QTouchEvent *event)
0056 {
0057     return matchTouchPoint(event)
0058 #ifndef Q_OS_MACOS
0059         && (d->type >= KisShortcutConfiguration::OneFingerTap && d->type <= KisShortcutConfiguration::FiveFingerTap)
0060 #endif
0061         ;
0062 }
0063 
0064 bool KisTouchShortcut::matchDragType(QTouchEvent *event)
0065 {
0066     return matchTouchPoint(event)
0067 #ifndef Q_OS_MACOS
0068         && (d->type >= KisShortcutConfiguration::OneFingerDrag && d->type <= KisShortcutConfiguration::FiveFingerDrag)
0069 #endif
0070         ;
0071 }
0072 
0073 bool KisTouchShortcut::matchTouchPoint(QTouchEvent *event)
0074 {
0075     return event->touchPoints().count() >= d->minTouchPoints && event->touchPoints().count() <= d->maxTouchPoints;
0076 }