KDeclarative

keysequencevalidator.h
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
18class KeySequenceValidator : public QObject
19{
21 Q_PROPERTY(QKeySequence currentKeySequence READ currentKeySequence WRITE setCurrentKeySequence NOTIFY currentKeySequenceChanged)
22 Q_PROPERTY(KeySequenceHelper::ShortcutTypes validateTypes READ validateTypes WRITE setValidateTypes NOTIFY validateTypesChanged)
23
24public:
25 /**
26 * Constructor.
27 */
28 explicit KeySequenceValidator(QObject *parent = nullptr);
29
30 QKeySequence currentKeySequence() const;
31 void setCurrentKeySequence(const QKeySequence &sequence);
32 Q_SIGNAL void currentKeySequenceChanged();
33
34 KeySequenceHelper::ShortcutTypes validateTypes() const;
35 void setValidateTypes(KeySequenceHelper::ShortcutTypes types);
36 Q_SIGNAL void validateTypesChanged();
37
38 Q_INVOKABLE void validateSequence(const QKeySequence &keySequence);
39 Q_INVOKABLE void accept();
40 Q_INVOKABLE void reject();
41
42 Q_SIGNAL void error(const QString &title, const QString &message);
43 Q_SIGNAL void question(const QString &title, const QString &message);
44 Q_SIGNAL void finished(const QKeySequence &keySequence);
45
46private:
47 enum class ValidationResult {
48 Reject,
49 Accept,
50 QuestionPending,
51 };
52
53 ValidationResult validateGlobalShortcut(const QKeySequence &keySequence);
54 ValidationResult validateStandardShortcut(const QKeySequence &keySequence);
55
56 KeySequenceHelper::ShortcutTypes m_validateTypes = KeySequenceHelper::GlobalShortcuts | KeySequenceHelper::StandardShortcuts;
57 QKeySequence m_currentKeySequence;
58 QKeySequence m_pendingKeySequence;
59 bool m_validateGlobalPending = false;
60};
61
62#endif // KEYSEQUENCEVALIDATOR_H
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALQ_SIGNAL
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.