KGuiAddons

kmodifierkeyinfoprovider.cpp
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
9KModifierKeyInfoProvider::KModifierKeyInfoProvider()
10 : QObject(nullptr)
11{
12}
13
14KModifierKeyInfoProvider::~KModifierKeyInfoProvider()
15{
16}
17
18bool KModifierKeyInfoProvider::setKeyLatched(Qt::Key key, bool latched)
19{
20 Q_UNUSED(key);
21 Q_UNUSED(latched);
22 return false;
23}
24
25bool KModifierKeyInfoProvider::setKeyLocked(Qt::Key key, bool locked)
26{
27 Q_UNUSED(key);
28 Q_UNUSED(locked);
29 return false;
30}
31
32bool 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
41bool 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
50bool 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
59bool KModifierKeyInfoProvider::isButtonPressed(Qt::MouseButton button) const
60{
61 if (m_buttonStates.contains(button)) {
62 return m_buttonStates[button];
63 }
64 return false;
65}
66
67bool KModifierKeyInfoProvider::knowsKey(Qt::Key key) const
68{
69 return m_modifierStates.contains(key);
70}
71
72const QList<Qt::Key> KModifierKeyInfoProvider::knownKeys() const
73{
74 return m_modifierStates.keys();
75}
76
77void 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, newState & Pressed);
85 }
86 if (difference & Latched) {
87 Q_EMIT keyLatched(key, newState & Latched);
88 }
89 if (difference & Locked) {
90 Q_EMIT keyLocked(key, newState & Locked);
91 }
92 }
93}
94
95#include "moc_kmodifierkeyinfoprovider_p.cpp"
MouseButton
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:40 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.