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 | #include "kmodifierkeyinfoprovider_p.h" |
8 | |
9 | KModifierKeyInfoProvider::KModifierKeyInfoProvider() |
10 | : QObject(nullptr) |
11 | { |
12 | } |
13 | |
14 | KModifierKeyInfoProvider::~KModifierKeyInfoProvider() |
15 | { |
16 | } |
17 | |
18 | bool KModifierKeyInfoProvider::setKeyLatched(Qt::Key key, bool latched) |
19 | { |
20 | Q_UNUSED(key); |
21 | Q_UNUSED(latched); |
22 | return false; |
23 | } |
24 | |
25 | bool KModifierKeyInfoProvider::setKeyLocked(Qt::Key key, bool locked) |
26 | { |
27 | Q_UNUSED(key); |
28 | Q_UNUSED(locked); |
29 | return false; |
30 | } |
31 | |
32 | bool KModifierKeyInfoProvider::isKeyPressed(Qt::Key key) const |
33 | { |
34 | auto it = m_modifierStates.constFind(key); |
35 | if (it != m_modifierStates.constEnd()) { |
36 | return *it & Pressed; |
37 | } |
38 | return false; |
39 | } |
40 | |
41 | bool KModifierKeyInfoProvider::isKeyLatched(Qt::Key key) const |
42 | { |
43 | auto it = m_modifierStates.constFind(key); |
44 | if (it != m_modifierStates.constEnd()) { |
45 | return *it & Latched; |
46 | } |
47 | return false; |
48 | } |
49 | |
50 | bool KModifierKeyInfoProvider::isKeyLocked(Qt::Key key) const |
51 | { |
52 | auto it = m_modifierStates.constFind(key); |
53 | if (it != m_modifierStates.constEnd()) { |
54 | return *it & Locked; |
55 | } |
56 | return false; |
57 | } |
58 | |
59 | bool KModifierKeyInfoProvider::isButtonPressed(Qt::MouseButton button) const |
60 | { |
61 | if (m_buttonStates.contains(key: button)) { |
62 | return m_buttonStates[button]; |
63 | } |
64 | return false; |
65 | } |
66 | |
67 | bool KModifierKeyInfoProvider::knowsKey(Qt::Key key) const |
68 | { |
69 | return m_modifierStates.contains(key); |
70 | } |
71 | |
72 | const QList<Qt::Key> KModifierKeyInfoProvider::knownKeys() const |
73 | { |
74 | return m_modifierStates.keys(); |
75 | } |
76 | |
77 | void KModifierKeyInfoProvider::stateUpdated(Qt::Key key, KModifierKeyInfoProvider::ModifierStates newState) |
78 | { |
79 | auto &state = m_modifierStates[key]; |
80 | if (newState != state) { |
81 | const auto difference = (newState ^ state); |
82 | state = newState; |
83 | if (difference & Pressed) { |
84 | Q_EMIT keyPressed(key, state: newState & Pressed); |
85 | } |
86 | if (difference & Latched) { |
87 | Q_EMIT keyLatched(key, state: newState & Latched); |
88 | } |
89 | if (difference & Locked) { |
90 | Q_EMIT keyLocked(key, state: newState & Locked); |
91 | } |
92 | } |
93 | } |
94 | |
95 | #include "moc_kmodifierkeyinfoprovider_p.cpp" |
96 |