File indexing completed on 2024-12-22 04:14:05

0001 /* This file is part of the KDE libraries
0002     SPDX-FileCopyrightText: 2006, 2007 Andreas Hartmetz (ahartmetz@gmail.com)
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KGESTUREMAP_H
0008 #define KGESTUREMAP_H
0009 
0010 #include <QObject>
0011 #include <QHash>
0012 #include <QTimer>
0013 #include <QPolygon>
0014 
0015 #include "kgesture_p.h"
0016 
0017 class QApplication;
0018 class QAction;
0019 class QEvent;
0020 
0021 class KRITAWIDGETUTILS_EXPORT KisKGestureMap : public QObject
0022 {
0023     Q_OBJECT
0024 public:
0025     static KisKGestureMap *self();
0026 
0027     bool eventFilter(QObject *obj, QEvent *e) override;
0028     void setShapeGesture(QAction *kact, const KisKShapeGesture &gesture);
0029     void setRockerGesture(QAction *kact, const KisKRockerGesture &gesture);
0030     void setDefaultShapeGesture(QAction *kact, const KisKShapeGesture &gesture);
0031     void setDefaultRockerGesture(QAction *kact, const KisKRockerGesture &gesture);
0032     /**
0033      * This method will remove all gestures defined for a given action
0034      */
0035     void removeAllGestures(QAction *kact);
0036     QAction *findAction(const KisKShapeGesture &gesture) const;
0037     QAction *findAction(const KisKRockerGesture &gesture) const;
0038     KisKShapeGesture shapeGesture(const QAction *kact) const;
0039     KisKShapeGesture defaultShapeGesture(const QAction *kact) const;
0040     KisKRockerGesture rockerGesture(const QAction *kact) const;
0041     KisKRockerGesture defaultRockerGesture(const QAction *kact) const;
0042 
0043 private Q_SLOTS:
0044     void stopAcquisition();
0045 
0046 private:
0047     friend class KisKGestureMapContainer;
0048     KisKGestureMap();
0049     ~KisKGestureMap() override;
0050 
0051     friend class KApplicationPrivate;
0052     //intended to be used at application initialization
0053     void installEventFilterOnMe(QApplication *app);
0054 
0055     inline int bitCount(int n);
0056     void handleAction(QAction *kact);
0057     void matchShapeGesture();
0058 
0059     //this is an internal class so don't bother with a d-pointer
0060     typedef QHash< KisKShapeGesture, QAction * > ShapeGestureHash;
0061     typedef QHash< KisKRockerGesture, QAction * > RockerGestureHash;
0062     ShapeGestureHash m_shapeGestures;
0063     ShapeGestureHash m_defaultShapeGestures;
0064     RockerGestureHash m_rockerGestures;
0065     RockerGestureHash m_defaultRockerGestures;
0066     QPolygon m_points;
0067     QTimer m_gestureTimeout;
0068     bool m_acquiring {false};
0069 
0070     KisKShapeGesture m_shapeGesture;
0071     KisKRockerGesture m_rockerGesture;
0072 };
0073 
0074 #endif //KGESTUREMAP_H