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 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
25public:
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
47private:
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
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-2025 The KDE developers.
Generated on Fri Jan 3 2025 11:47:07 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.