diff --git a/src/util/kmodifierkeyinfo.cpp b/src/util/kmodifierkeyinfo.cpp index 3579da8..8aeadd3 100644 --- a/src/util/kmodifierkeyinfo.cpp +++ b/src/util/kmodifierkeyinfo.cpp @@ -1,99 +1,98 @@ /* Copyright 2009 Michael Leupold This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "kmodifierkeyinfo.h" #include "kmodifierkeyinfoprovider_p.h" #include #include #include KModifierKeyInfoProvider* createProvider() { QPluginLoader loader(QStringLiteral("kf5/kguiaddons/kmodifierkey/kmodifierkey_")+qGuiApp->platformName()); auto instance = dynamic_cast(loader.instance()); if (instance) return instance; qWarning() << "Error: could not load plugin for platform" << loader.fileName() << "error:" << loader.errorString() << loader.instance(); return new KModifierKeyInfoProvider; } KModifierKeyInfo::KModifierKeyInfo(QObject *parent) : QObject(parent), p(createProvider()) { - connect(p, &KModifierKeyInfoProvider::keyPressed, + connect(p.data(), &KModifierKeyInfoProvider::keyPressed, this, &KModifierKeyInfo::keyPressed); - connect(p, &KModifierKeyInfoProvider::keyLatched, + connect(p.data(), &KModifierKeyInfoProvider::keyLatched, this, &KModifierKeyInfo::keyLatched); - connect(p, &KModifierKeyInfoProvider::keyLocked, + connect(p.data(), &KModifierKeyInfoProvider::keyLocked, this, &KModifierKeyInfo::keyLocked); - connect(p, &KModifierKeyInfoProvider::buttonPressed, + connect(p.data(), &KModifierKeyInfoProvider::buttonPressed, this, &KModifierKeyInfo::buttonPressed); - connect(p, &KModifierKeyInfoProvider::keyAdded, + connect(p.data(), &KModifierKeyInfoProvider::keyAdded, this, &KModifierKeyInfo::keyAdded); - connect(p, &KModifierKeyInfoProvider::keyRemoved, + connect(p.data(), &KModifierKeyInfoProvider::keyRemoved, this, &KModifierKeyInfo::keyRemoved); } KModifierKeyInfo::~KModifierKeyInfo() { - delete p; } bool KModifierKeyInfo::knowsKey(Qt::Key key) const { return p->knowsKey(key); } const QList KModifierKeyInfo::knownKeys() const { return p->knownKeys(); } bool KModifierKeyInfo::isKeyPressed(Qt::Key key) const { return p->isKeyPressed(key); } bool KModifierKeyInfo::isKeyLatched(Qt::Key key) const { return p->isKeyLatched(key); } bool KModifierKeyInfo::setKeyLatched(Qt::Key key, bool latched) { return p->setKeyLatched(key, latched); } bool KModifierKeyInfo::isKeyLocked(Qt::Key key) const { return p->isKeyLocked(key); } bool KModifierKeyInfo::setKeyLocked(Qt::Key key, bool locked) { return p->setKeyLocked(key, locked); } bool KModifierKeyInfo::isButtonPressed(Qt::MouseButton button) const { return p->isButtonPressed(button); } diff --git a/src/util/kmodifierkeyinfo.h b/src/util/kmodifierkeyinfo.h index 03b7411..b11dbc8 100644 --- a/src/util/kmodifierkeyinfo.h +++ b/src/util/kmodifierkeyinfo.h @@ -1,191 +1,192 @@ /* Copyright 2009 Michael Leupold This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef KMODIFIERKEYINFO_H #define KMODIFIERKEYINFO_H #include +#include #include class KModifierKeyInfoProvider; /** * @class KModifierKeyInfo kmodifierkeyinfo.h KModifierKeyInfo * * Get information about the state of the keyboard's modifier keys. * * This class provides cross-platform information about the state of the * keyboard's modifier keys and the mouse buttons and allows to change the * state as well. * * It recognizes two states a key can be in: *
  • locked: eg. caps-locked (aka toggled)
  • *
  • latched: the key is temporarily locked but will be unlocked upon * the next keypress.
* * An application can either query the states synchronously (@see isKeyLatched, * @see isKeyLocked) or connect to KModifierKeyInfo's signals to be notified about * changes (@see keyLatched, @see keyLocked). */ class KGUIADDONS_EXPORT KModifierKeyInfo : public QObject { Q_OBJECT public: /** * Default constructor */ explicit KModifierKeyInfo(QObject *parent = nullptr); /** * Destructor */ virtual ~KModifierKeyInfo(); /** * Check if a key is known by the underlying window system and can be queried. * * @param key The key to check * @return true if the key is available, false if it is unknown */ bool knowsKey(Qt::Key key) const; /** * Get a list of known keys. * * @return A list of known keys of which states will be reported. */ const QList knownKeys() const; /** * Synchronously check if a key is pressed. * * @param key The key to check * @return true if the key is pressed, false if the key is not pressed or unknown. * @see isKeyLatched, @see isKeyLocked, @see keyPressed */ bool isKeyPressed(Qt::Key key) const; /** * Synchronously check if a key is latched. * * @param key The key to check * @return true if the key is latched, false if the key is not latched or unknown. * @see isKeyPressed, @see isKeyLocked, @see keyLatched */ bool isKeyLatched(Qt::Key key) const; /** * Set the latched state of a key. * * @param key The key to latch * @param latched true to latch the key, false to unlatch it. * @return false if the key is unknown. true doesn't guarantee you the * operation worked. */ bool setKeyLatched(Qt::Key key, bool latched); /** * Synchronously check if a key is locked. * * @param key The key to check * @return true if the key is locked, false if the key is not locked or unknown. * @see isKeyPressed, @see isKeyLatched, @see keyLocked */ bool isKeyLocked(Qt::Key key) const; /** * Set the locked state of a key. * * @param key The key to lock * @param latched true to lock the key, false to unlock it. * @return false if the key is unknown. true doesn't guarantee you the * operation worked. */ bool setKeyLocked(Qt::Key key, bool locked); /** * Synchronously check if a mouse button is pressed. * * @param button The mouse button to check * @return true if the mouse button is pressed, false if the mouse button * is not pressed or its state is unknown. */ bool isButtonPressed(Qt::MouseButton button) const; Q_SIGNALS: /** * This signal is emitted whenever the pressed state of a key changes * (key press or key release). * * @param key The key that changed state * @param pressed true if the key is now pressed, false if is released. */ void keyPressed(Qt::Key key, bool pressed); /** * This signal is emitted whenever the latched state of a key changes. * * @param key The key that changed state * @param latched true if the key is now latched, false if it isn't */ void keyLatched(Qt::Key key, bool latched); /** * This signal is emitted whenever the locked state of a key changes. * * @param key The key that changed state * @param locked true if the key is now locked, false if it isn't */ void keyLocked(Qt::Key key, bool locked); /** * This signal is emitted whenever the pressed state of a mouse button * changes (mouse button press or release). * * @param button The mouse button that changed state * @param pressed true if the mouse button is now pressed, false if * is released. */ void buttonPressed(Qt::MouseButton button, bool pressed); /** * This signal is emitted whenever a new modifier is found due to * the keyboard mapping changing. * * @param key The key that was discovered */ void keyAdded(Qt::Key key); /** * This signal is emitted whenever a previously known modifier no * longer exists due to the keyboard mapping changing. * * @param key The key that vanished */ void keyRemoved(Qt::Key key); private: Q_DISABLE_COPY(KModifierKeyInfo) - KModifierKeyInfoProvider *const p; // krazy:exclude=dpointer + QExplicitlySharedDataPointer const p; // krazy:exclude=dpointer }; #endif diff --git a/src/util/kmodifierkeyinfoprovider_p.h b/src/util/kmodifierkeyinfoprovider_p.h index 0e760a4..999e5e8 100644 --- a/src/util/kmodifierkeyinfoprovider_p.h +++ b/src/util/kmodifierkeyinfoprovider_p.h @@ -1,129 +1,130 @@ /* Copyright 2009 Michael Leupold This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef KMODIFIERKEYINFOPROVIDER_P_H #define KMODIFIERKEYINFOPROVIDER_P_H #include #include #include +#include #include "kguiaddons_export.h" /** * Background class that implements the behaviour of KModifierKeyInfo for * the different supported platforms. * @internal */ -class KGUIADDONS_EXPORT KModifierKeyInfoProvider : public QObject +class KGUIADDONS_EXPORT KModifierKeyInfoProvider : public QObject, public QSharedData { Q_OBJECT public: enum ModifierState { Nothing = 0x0, Pressed = 0x1, Latched = 0x2, Locked = 0x4 }; Q_ENUM(ModifierState); Q_DECLARE_FLAGS(ModifierStates, ModifierState) KModifierKeyInfoProvider(); ~KModifierKeyInfoProvider() override; /** * Detect if a key is pressed. * @param key Modifier key to query * @return true if the key is pressed, false if it isn't. */ bool isKeyPressed(Qt::Key key) const; /** * Detect if a key is latched. * @param key Modifier key to query * @return true if the key is latched, false if it isn't. */ bool isKeyLatched(Qt::Key key) const; /** * Set the latched state of a key. * @param key Modifier to set the latched state for * @param latched true to latch the key, false to unlatch it * @return true if the key is known, false else */ virtual bool setKeyLatched(Qt::Key key, bool latched); /** * Detect if a key is locked. * @param key Modifier key to query * @return true if the key is locked, false if it isn't. */ bool isKeyLocked(Qt::Key key) const; /** * Set the locked state of a key. * @param key Modifier to set the locked state for * @param latched true to lock the key, false to unlock it * @return true if the key is known, false else */ virtual bool setKeyLocked(Qt::Key key, bool locked); /** * Check if a mouse button is pressed. * @param button Mouse button to check * @return true if pressed, false else */ bool isButtonPressed(Qt::MouseButton button) const; /** * Check if a key is known/can be queried * @param key Modifier key to check * @return true if the key is known, false if it isn't. */ bool knowsKey(Qt::Key key) const; /** * Get a list of known keys * @return List of known keys. */ const QList knownKeys() const; Q_SIGNALS: void keyLatched(Qt::Key key, bool state); void keyLocked(Qt::Key key, bool state); void keyPressed(Qt::Key key, bool state); void buttonPressed(Qt::MouseButton button, bool state); void keyAdded(Qt::Key key); void keyRemoved(Qt::Key key); protected: void stateUpdated(Qt::Key key, KModifierKeyInfoProvider::ModifierStates state); // the state of each known modifier QHash m_modifierStates; // the state of each known mouse button QHash m_buttonStates; }; Q_DECLARE_INTERFACE(KModifierKeyInfoProvider, "org.kde.kguiaddons.KModifierKeyInfoProvider") Q_DECLARE_OPERATORS_FOR_FLAGS(KModifierKeyInfoProvider::ModifierStates) #endif