File indexing completed on 2024-05-26 05:38:22
0001 /* 0002 SPDX-FileCopyrightText: 2009 Aaron Seigo <aseigo@kde.org> 0003 SPDX-FileCopyrightText: 2024 Fushan Wen <qydwhotmail@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include <QBindable> 0011 #include <QObject> 0012 #include <qqmlregistration.h> 0013 0014 class KModifierKeyInfo; 0015 0016 /** 0017 * This QML object provides the current state of the keyboard modifiers, 0018 * primarily useful for accessibility feature support. 0019 */ 0020 class KeyState : public QObject 0021 { 0022 Q_OBJECT 0023 QML_ELEMENT 0024 0025 /** 0026 * @param key a modifier key 0027 */ 0028 Q_PROPERTY(Qt::Key key READ key WRITE setKey NOTIFY keyChanged) 0029 0030 Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged) 0031 Q_PROPERTY(bool latched READ latched NOTIFY latchedChanged) 0032 Q_PROPERTY(bool locked READ locked NOTIFY lockedChanged) 0033 0034 public: 0035 explicit KeyState(QObject *parent = nullptr); 0036 ~KeyState() override; 0037 0038 Qt::Key key() const; 0039 void setKey(Qt::Key newKey); 0040 0041 bool pressed() const; 0042 bool latched() const; 0043 bool locked() const; 0044 0045 /// Unsupported in Wayland 0046 Q_INVOKABLE void lock(bool lock); 0047 /// Unsupported in Wayland 0048 Q_INVOKABLE void latch(bool latch); 0049 0050 Q_SIGNALS: 0051 void keyChanged(); 0052 void pressedChanged(); 0053 void latchedChanged(); 0054 void lockedChanged(); 0055 0056 private Q_SLOTS: 0057 void onKeyPressed(Qt::Key key, bool state); 0058 void onKeyLatched(Qt::Key key, bool state); 0059 void onKeyLocked(Qt::Key key, bool state); 0060 void onKeyAdded(Qt::Key key); 0061 void onKeyRemoved(Qt::Key key); 0062 0063 private: 0064 std::shared_ptr<KModifierKeyInfo> m_keyInfo; 0065 Qt::Key m_key = Qt::Key_Any; 0066 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(KeyState, bool, m_pressed, false, &KeyState::pressedChanged) 0067 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(KeyState, bool, m_latched, false, &KeyState::latchedChanged) 0068 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(KeyState, bool, m_locked, false, &KeyState::lockedChanged) 0069 }; 0070 0071 /** 0072 * This QML object provides the current state of the mouse buttons, 0073 * primarily useful for accessibility feature support. 0074 */ 0075 class MouseButtonState : public QObject 0076 { 0077 Q_OBJECT 0078 QML_ELEMENT 0079 0080 Q_PROPERTY(Qt::MouseButton button READ button WRITE setButton NOTIFY buttonChanged) 0081 0082 Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged) 0083 0084 public: 0085 explicit MouseButtonState(QObject *parent = nullptr); 0086 ~MouseButtonState() override; 0087 0088 Qt::MouseButton button() const; 0089 void setButton(Qt::MouseButton newButton); 0090 0091 bool pressed() const; 0092 0093 Q_SIGNALS: 0094 void buttonChanged(); 0095 void pressedChanged(); 0096 0097 private Q_SLOTS: 0098 void onMouseButtonPressed(Qt::MouseButton mouseButton, bool state); 0099 0100 private: 0101 std::shared_ptr<KModifierKeyInfo> m_keyInfo; 0102 Qt::MouseButton m_button = Qt::NoButton; 0103 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(MouseButtonState, bool, m_pressed, false, &MouseButtonState::pressedChanged) 0104 };