File indexing completed on 2024-05-19 05:32:24
0001 /* 0002 SPDX-FileCopyrightText: 2023 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QKeySequence> 0010 #include <QObject> 0011 #include <QQmlParserStatus> 0012 #include <QVariant> 0013 0014 class QAction; 0015 0016 namespace KWin 0017 { 0018 0019 /** 0020 * The ShortcutHandler type provides a way to register global key shorcuts. 0021 * 0022 * Example usage: 0023 * @code 0024 * ShortcutHandler { 0025 * name: "Activate Something" 0026 * text: i18n("Activate Something") 0027 * sequence: "Meta+Ctrl+S" 0028 * onActivated: doSomething() 0029 * } 0030 * @endcode 0031 */ 0032 class ShortcutHandler : public QObject, public QQmlParserStatus 0033 { 0034 Q_OBJECT 0035 Q_INTERFACES(QQmlParserStatus) 0036 0037 /** 0038 * This property specifies the unique shortcut identifier, not localized. 0039 * 0040 * The shortcut name cannot be changed once the ShortcutHandler is constructed. 0041 */ 0042 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 0043 /** 0044 * This property specifies human readable name of the shortcut. 0045 */ 0046 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) 0047 /** 0048 * This property holds the key sequence for this shortcut. The key sequence 0049 * can be specified using a string containing a sequence of keys that are needed 0050 * to be pressed to activate the shortcut, e.g. `Meta+K`. 0051 * 0052 * The key sequence is optional. If omitted, the user can assign a key sequence 0053 * to this shortcut in system settings. 0054 * 0055 * The key sequence cannot be changed once the ShortcutHandler is constructed. 0056 */ 0057 Q_PROPERTY(QVariant sequence READ sequence WRITE setSequence NOTIFY sequenceChanged) 0058 0059 public: 0060 explicit ShortcutHandler(QObject *parent = nullptr); 0061 0062 void classBegin() override; 0063 void componentComplete() override; 0064 0065 QString name() const; 0066 void setName(const QString &name); 0067 0068 QString text() const; 0069 void setText(const QString &text); 0070 0071 QVariant sequence() const; 0072 void setSequence(const QVariant &sequence); 0073 0074 Q_SIGNALS: 0075 void nameChanged(); 0076 void textChanged(); 0077 void sequenceChanged(); 0078 void activated(); 0079 0080 private: 0081 QString m_name; 0082 QString m_text; 0083 QVariant m_userSequence; 0084 QKeySequence m_keySequence; 0085 QAction *m_action = nullptr; 0086 }; 0087 0088 } // namespace KWin