1 /* This file is part of the KDE libraries
2     Copyright (C) 2006,2007 Andreas Hartmetz (ahartmetz@gmail.com)
3 
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License as published by the Free Software Foundation; either
7     version 2 of the License, or (at your option) any later version.
8 
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13 
14     You should have received a copy of the GNU Library General Public License
15     along with this library; see the file COPYING.LIB.  If not, write to
16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef KGESTUREMAP_H
21 #define KGESTUREMAP_H
22 
23 #include <QObject>
24 #include <QHash>
25 #include <QTimer>
26 #include <QPolygon>
27 
28 #include "kgesture_p.h"
29 
30 class QApplication;
31 class QAction;
32 class QEvent;
33 
34 class KRITAWIDGETUTILS_EXPORT KGestureMap : public QObject
35 {
36     Q_OBJECT
37 public:
38     static KGestureMap *self();
39 
40     bool eventFilter(QObject *obj, QEvent *e) override;
41     void setShapeGesture(QAction *kact, const KShapeGesture &gesture);
42     void setRockerGesture(QAction *kact, const KRockerGesture &gesture);
43     void setDefaultShapeGesture(QAction *kact, const KShapeGesture &gesture);
44     void setDefaultRockerGesture(QAction *kact, const KRockerGesture &gesture);
45     /**
46      * This method will remove all gestures defined for a given action
47      */
48     void removeAllGestures(QAction *kact);
49     QAction *findAction(const KShapeGesture &gesture) const;
50     QAction *findAction(const KRockerGesture &gesture) const;
51     KShapeGesture shapeGesture(const QAction *kact) const;
52     KShapeGesture defaultShapeGesture(const QAction *kact) const;
53     KRockerGesture rockerGesture(const QAction *kact) const;
54     KRockerGesture defaultRockerGesture(const QAction *kact) const;
55 
56 private Q_SLOTS:
57     void stopAcquisition();
58 
59 private:
60     friend class KGestureMapContainer;
61     KGestureMap();
62     ~KGestureMap() override;
63 
64     friend class KApplicationPrivate;
65     //intended to be used at application initialization
66     void installEventFilterOnMe(QApplication *app);
67 
68     inline int bitCount(int n);
69     void handleAction(QAction *kact);
70     void matchShapeGesture();
71 
72     //this is an internal class so don't bother with a d-pointer
73     typedef QHash< KShapeGesture, QAction * > ShapeGestureHash;
74     typedef QHash< KRockerGesture, QAction * > RockerGestureHash;
75     ShapeGestureHash m_shapeGestures;
76     ShapeGestureHash m_defaultShapeGestures;
77     RockerGestureHash m_rockerGestures;
78     RockerGestureHash m_defaultRockerGestures;
79     QPolygon m_points;
80     QTimer m_gestureTimeout;
81     bool m_acquiring;
82 
83     KShapeGesture m_shapeGesture;
84     KRockerGesture m_rockerGesture;
85 };
86 
87 #endif //KGESTUREMAP_H
88