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 */
21class KGUIADDONS_EXPORT KModifierKeyInfoProvider : public QObject, public QSharedData
22{
23 Q_OBJECT
24
25public:
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 * @param key Modifier key to query
41 * @return true if the key is pressed, false if it isn't.
42 */
43 bool isKeyPressed(Qt::Key key) const;
44
45 /**
46 * Detect if a key is latched.
47 * @param key Modifier key to query
48 * @return true if the key is latched, false if it isn't.
49 */
50 bool isKeyLatched(Qt::Key key) const;
51
52 /**
53 * Set the latched state of a key.
54 * @param key Modifier to set the latched state for
55 * @param latched true to latch the key, false to unlatch it
56 * @return true if the key is known, false else
57 */
58 virtual bool setKeyLatched(Qt::Key key, bool latched);
59
60 /**
61 * Detect if a key is locked.
62 * @param key Modifier key to query
63 * @return true if the key is locked, false if it isn't.
64 */
65 bool isKeyLocked(Qt::Key key) const;
66
67 /**
68 * Set the locked state of a key.
69 * @param key Modifier to set the locked state for
70 * @param latched true to lock the key, false to unlock it
71 * @return true if the key is known, false else
72 */
73 virtual bool setKeyLocked(Qt::Key key, bool locked);
74
75 /**
76 * Check if a mouse button is pressed.
77 * @param button Mouse button to check
78 * @return true if pressed, false else
79 */
80 bool isButtonPressed(Qt::MouseButton button) const;
81
82 /**
83 * Check if a key is known/can be queried
84 * @param key Modifier key to check
85 * @return true if the key is known, false if it isn't.
86 */
87 bool knowsKey(Qt::Key key) const;
88
89 /**
90 * Get a list of known keys
91 * @return List of known keys.
92 */
93 const QList<Qt::Key> knownKeys() const;
94
95Q_SIGNALS:
96 void keyLatched(Qt::Key key, bool state);
97 void keyLocked(Qt::Key key, bool state);
98 void keyPressed(Qt::Key key, bool state);
99 void buttonPressed(Qt::MouseButton button, bool state);
100 void keyAdded(Qt::Key key);
101 void keyRemoved(Qt::Key key);
102
103protected:
104 void stateUpdated(Qt::Key key, KModifierKeyInfoProvider::ModifierStates state);
105
106 // the state of each known modifier
107 QHash<Qt::Key, ModifierStates> m_modifierStates;
108
109 // the state of each known mouse button
110 QHash<Qt::MouseButton, bool> m_buttonStates;
111};
112
113Q_DECLARE_INTERFACE(KModifierKeyInfoProvider, "org.kde.kguiaddons.KModifierKeyInfoProvider")
114Q_DECLARE_OPERATORS_FOR_FLAGS(KModifierKeyInfoProvider::ModifierStates)
115
116#endif
117

source code of kguiaddons/src/util/kmodifierkeyinfoprovider_p.h