1 | /* |
2 | SPDX-FileCopyrightText: 2009 Michael Leupold <lemma@confuego.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
5 | */ |
6 | |
7 | #ifndef KMODIFIERKEYINFOPROVIDER_P_H |
8 | #define KMODIFIERKEYINFOPROVIDER_P_H |
9 | |
10 | #include "kguiaddons_export.h" |
11 | |
12 | #include <QHash> |
13 | #include <QObject> |
14 | #include <QSharedData> |
15 | |
16 | /*! |
17 | * Background class that implements the behaviour of KModifierKeyInfo for |
18 | * the different supported platforms. |
19 | * \internal |
20 | */ |
21 | class KGUIADDONS_EXPORT KModifierKeyInfoProvider : public QObject, public QSharedData |
22 | { |
23 | Q_OBJECT |
24 | |
25 | public: |
26 | enum ModifierState { |
27 | Nothing = 0x0, |
28 | Pressed = 0x1, |
29 | Latched = 0x2, |
30 | Locked = 0x4, |
31 | }; |
32 | Q_ENUM(ModifierState) |
33 | Q_DECLARE_FLAGS(ModifierStates, ModifierState) |
34 | |
35 | KModifierKeyInfoProvider(); |
36 | ~KModifierKeyInfoProvider() override; |
37 | |
38 | /*! |
39 | * Detect if a key is pressed. |
40 | * |
41 | * \a key Modifier key to query |
42 | * |
43 | * Returns true if the key is pressed, false if it isn't. |
44 | */ |
45 | bool isKeyPressed(Qt::Key key) const; |
46 | |
47 | /*! |
48 | * Detect if a key is latched. |
49 | * \a key Modifier key to query |
50 | * Returns true if the key is latched, false if it isn't. |
51 | */ |
52 | bool isKeyLatched(Qt::Key key) const; |
53 | |
54 | /*! |
55 | * Set the latched state of a key. |
56 | * \a key Modifier to set the latched state for |
57 | * \a latched true to latch the key, false to unlatch it |
58 | * Returns true if the key is known, false else |
59 | */ |
60 | virtual bool setKeyLatched(Qt::Key key, bool latched); |
61 | |
62 | /*! |
63 | * Detect if a key is locked. |
64 | * \a key Modifier key to query |
65 | * Returns true if the key is locked, false if it isn't. |
66 | */ |
67 | bool isKeyLocked(Qt::Key key) const; |
68 | |
69 | /*! |
70 | * Set the locked state of a key. |
71 | * \a key Modifier to set the locked state for |
72 | * \a latched true to lock the key, false to unlock it |
73 | * Returns true if the key is known, false else |
74 | */ |
75 | virtual bool setKeyLocked(Qt::Key key, bool locked); |
76 | |
77 | /*! |
78 | * Check if a mouse button is pressed. |
79 | * \a button Mouse button to check |
80 | * Returns true if pressed, false else |
81 | */ |
82 | bool isButtonPressed(Qt::MouseButton button) const; |
83 | |
84 | /*! |
85 | * Check if a key is known/can be queried |
86 | * \a key Modifier key to check |
87 | * Returns true if the key is known, false if it isn't. |
88 | */ |
89 | bool knowsKey(Qt::Key key) const; |
90 | |
91 | /*! |
92 | * Get a list of known keys |
93 | * Returns List of known keys. |
94 | */ |
95 | const QList<Qt::Key> knownKeys() const; |
96 | |
97 | Q_SIGNALS: |
98 | void keyLatched(Qt::Key key, bool state); |
99 | void keyLocked(Qt::Key key, bool state); |
100 | void keyPressed(Qt::Key key, bool state); |
101 | void buttonPressed(Qt::MouseButton button, bool state); |
102 | void keyAdded(Qt::Key key); |
103 | void keyRemoved(Qt::Key key); |
104 | |
105 | protected: |
106 | void stateUpdated(Qt::Key key, KModifierKeyInfoProvider::ModifierStates state); |
107 | |
108 | // the state of each known modifier |
109 | QHash<Qt::Key, ModifierStates> m_modifierStates; |
110 | |
111 | // the state of each known mouse button |
112 | QHash<Qt::MouseButton, bool> m_buttonStates; |
113 | }; |
114 | |
115 | Q_DECLARE_INTERFACE(KModifierKeyInfoProvider, "org.kde.kguiaddons.KModifierKeyInfoProvider" ) |
116 | Q_DECLARE_OPERATORS_FOR_FLAGS(KModifierKeyInfoProvider::ModifierStates) |
117 | |
118 | #endif |
119 | |