| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2014 David Edmundson <davidedmundson@kde.org> |
| 3 | SPDX-FileCopyrightText: 2020 David Redondo <kde@david-redondo.de> |
| 4 | SPDX-FileCopyrightText: 2024 Arjen Hiemstra <ahiemstra@heimr.nl> |
| 5 | |
| 6 | SPDX-License-Identifier: LGPL-2.1-or-later |
| 7 | */ |
| 8 | |
| 9 | #ifndef KEYSEQUENCEVALIDATOR_H |
| 10 | #define KEYSEQUENCEVALIDATOR_H |
| 11 | |
| 12 | #include <QKeySequence> |
| 13 | #include <QObject> |
| 14 | #include <QQuickItem> |
| 15 | |
| 16 | #include "keysequencehelper.h" |
| 17 | |
| 18 | class KeySequenceValidator : public QObject |
| 19 | { |
| 20 | Q_OBJECT |
| 21 | QML_ELEMENT |
| 22 | Q_PROPERTY(QKeySequence currentKeySequence READ currentKeySequence WRITE setCurrentKeySequence NOTIFY currentKeySequenceChanged) |
| 23 | Q_PROPERTY(KeySequenceEnums::ShortcutTypes validateTypes READ validateTypes WRITE setValidateTypes NOTIFY validateTypesChanged) |
| 24 | |
| 25 | public: |
| 26 | /** |
| 27 | * Constructor. |
| 28 | */ |
| 29 | explicit KeySequenceValidator(QObject *parent = nullptr); |
| 30 | |
| 31 | QKeySequence currentKeySequence() const; |
| 32 | void setCurrentKeySequence(const QKeySequence &sequence); |
| 33 | Q_SIGNAL void currentKeySequenceChanged(); |
| 34 | |
| 35 | KeySequenceEnums::ShortcutTypes validateTypes() const; |
| 36 | void setValidateTypes(KeySequenceEnums::ShortcutTypes types); |
| 37 | Q_SIGNAL void validateTypesChanged(); |
| 38 | |
| 39 | Q_INVOKABLE void validateSequence(const QKeySequence &keySequence); |
| 40 | Q_INVOKABLE void accept(); |
| 41 | Q_INVOKABLE void reject(); |
| 42 | |
| 43 | Q_SIGNAL void error(const QString &title, const QString &message); |
| 44 | Q_SIGNAL void question(const QString &title, const QString &message); |
| 45 | Q_SIGNAL void finished(const QKeySequence &keySequence); |
| 46 | |
| 47 | private: |
| 48 | enum class ValidationResult { |
| 49 | Reject, |
| 50 | Accept, |
| 51 | QuestionPending, |
| 52 | }; |
| 53 | |
| 54 | ValidationResult validateGlobalShortcut(const QKeySequence &keySequence); |
| 55 | ValidationResult validateStandardShortcut(const QKeySequence &keySequence); |
| 56 | |
| 57 | KeySequenceEnums::ShortcutTypes m_validateTypes = KeySequenceEnums::GlobalShortcuts | KeySequenceEnums::StandardShortcuts; |
| 58 | QKeySequence m_currentKeySequence; |
| 59 | QKeySequence m_pendingKeySequence; |
| 60 | bool m_validateGlobalPending = false; |
| 61 | }; |
| 62 | |
| 63 | #endif // KEYSEQUENCEVALIDATOR_H |
| 64 | |