1 /*
2     SPDX-FileCopyrightText: 2014 David Edmundson <davidedmundson@kde.org>
3     SPDX-FileCopyrightText: 2020 David Redondo <kde@david-redondo.de>
4 
5     SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7 
8 #ifndef KEYSEQUENCEHELPER_H
9 #define KEYSEQUENCEHELPER_H
10 
11 #include <KeySequenceRecorder>
12 
13 #include <QKeySequence>
14 #include <QQuickItem>
15 
16 class KeySequenceHelperPrivate;
17 class QQuickWindow;
18 
19 class KeySequenceHelper : public KeySequenceRecorder
20 {
21     Q_OBJECT
22 
23     Q_PROPERTY(
24         ShortcutTypes checkAgainstShortcutTypes READ checkAgainstShortcutTypes WRITE setCheckAgainstShortcutTypes NOTIFY checkAgainstShortcutTypesChanged)
25 
26 public:
27     enum ShortcutType {
28         None = 0x00, //!< No checking for conflicts
29         StandardShortcuts = 0x01, //!< Check against standard shortcuts. @see KStandardShortcut
30         GlobalShortcuts = 0x02, //!< Check against global shortcuts. @see KGlobalAccel
31     };
32     Q_DECLARE_FLAGS(ShortcutTypes, ShortcutType)
33     Q_FLAG(ShortcutTypes)
34 
35     /**
36      * Constructor.
37      */
38     explicit KeySequenceHelper(QObject *parent = nullptr);
39 
40     /**
41      * Destructs the widget.
42      */
43     ~KeySequenceHelper() override;
44 
45     Q_INVOKABLE bool isKeySequenceAvailable(const QKeySequence &keySequence) const;
46     // FIXME why can't qml call the inherited method?
startRecording()47     Q_INVOKABLE void startRecording()
48     {
49         KeySequenceRecorder::startRecording();
50     }
51 
52     ShortcutTypes checkAgainstShortcutTypes();
53     void setCheckAgainstShortcutTypes(ShortcutTypes types);
54 
55     Q_INVOKABLE static bool keySequenceIsEmpty(const QKeySequence &keySequence);
56     Q_INVOKABLE static QString keySequenceNativeText(const QKeySequence &keySequence);
57     Q_INVOKABLE static QWindow *renderWindow(QQuickWindow *quickWindow);
58 
59 Q_SIGNALS:
60     void checkAgainstShortcutTypesChanged();
61 
62 private:
63     friend class KeySequenceHelperPrivate;
64     KeySequenceHelperPrivate *const d;
65 
66     Q_DISABLE_COPY(KeySequenceHelper)
67 };
68 
69 Q_DECLARE_OPERATORS_FOR_FLAGS(KeySequenceHelper::ShortcutTypes)
70 
71 #endif // KEYSEQUENCEHELPER_H
72