Warning, file /frameworks/kguiaddons/src/util/kmodifierkeyinfoprovider.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2009 Michael Leupold <lemma@confuego.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "kmodifierkeyinfoprovider_p.h"
0008 
0009 KModifierKeyInfoProvider::KModifierKeyInfoProvider()
0010     : QObject(nullptr)
0011 {
0012 }
0013 
0014 KModifierKeyInfoProvider::~KModifierKeyInfoProvider()
0015 {
0016 }
0017 
0018 bool KModifierKeyInfoProvider::setKeyLatched(Qt::Key key, bool latched)
0019 {
0020     Q_UNUSED(key);
0021     Q_UNUSED(latched);
0022     return false;
0023 }
0024 
0025 bool KModifierKeyInfoProvider::setKeyLocked(Qt::Key key, bool locked)
0026 {
0027     Q_UNUSED(key);
0028     Q_UNUSED(locked);
0029     return false;
0030 }
0031 
0032 bool KModifierKeyInfoProvider::isKeyPressed(Qt::Key key) const
0033 {
0034     auto it = m_modifierStates.constFind(key);
0035     if (it != m_modifierStates.constEnd()) {
0036         return *it & Pressed;
0037     }
0038     return false;
0039 }
0040 
0041 bool KModifierKeyInfoProvider::isKeyLatched(Qt::Key key) const
0042 {
0043     auto it = m_modifierStates.constFind(key);
0044     if (it != m_modifierStates.constEnd()) {
0045         return *it & Latched;
0046     }
0047     return false;
0048 }
0049 
0050 bool KModifierKeyInfoProvider::isKeyLocked(Qt::Key key) const
0051 {
0052     auto it = m_modifierStates.constFind(key);
0053     if (it != m_modifierStates.constEnd()) {
0054         return *it & Locked;
0055     }
0056     return false;
0057 }
0058 
0059 bool KModifierKeyInfoProvider::isButtonPressed(Qt::MouseButton button) const
0060 {
0061     if (m_buttonStates.contains(button)) {
0062         return m_buttonStates[button];
0063     }
0064     return false;
0065 }
0066 
0067 bool KModifierKeyInfoProvider::knowsKey(Qt::Key key) const
0068 {
0069     return m_modifierStates.contains(key);
0070 }
0071 
0072 const QList<Qt::Key> KModifierKeyInfoProvider::knownKeys() const
0073 {
0074     return m_modifierStates.keys();
0075 }
0076 
0077 void KModifierKeyInfoProvider::stateUpdated(Qt::Key key, KModifierKeyInfoProvider::ModifierStates newState)
0078 {
0079     auto &state = m_modifierStates[key];
0080     if (newState != state) {
0081         const auto difference = (newState ^ state);
0082         state = newState;
0083         if (difference & Pressed) {
0084             Q_EMIT keyPressed(key, newState & Pressed);
0085         }
0086         if (difference & Latched) {
0087             Q_EMIT keyLatched(key, newState & Latched);
0088         }
0089         if (difference & Locked) {
0090             Q_EMIT keyLocked(key, newState & Locked);
0091         }
0092     }
0093 }