KGuiAddons 5.109.0
keysequencerecorder.h
1/*
2 SPDX-FileCopyrightText: 2001, 2002 Ellis Whitehead <ellis@kde.org>
3 SPDX-FileCopyrightText: 2007 Andreas Hartmetz <ahartmetz@gmail.com>
4 SPDX-FileCopyrightText: 2020 David Redondo <kde@david-redondo.de>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef KSHORTCUTRECORDER_H
10#define KSHORTCUTRECORDER_H
11
12#include <kguiaddons_export.h>
13
14#include <QKeySequence>
15#include <QObject>
16#include <QWindow>
17
18#include <memory>
19
20class KeySequenceRecorderPrivate;
21
41class KGUIADDONS_EXPORT KeySequenceRecorder : public QObject
42{
43 Q_OBJECT
44
48 Q_PROPERTY(bool isRecording READ isRecording NOTIFY recordingChanged)
57 Q_PROPERTY(QKeySequence currentKeySequence READ currentKeySequence WRITE setCurrentKeySequence NOTIFY currentKeySequenceChanged)
61 Q_PROPERTY(QWindow *window READ window WRITE setWindow NOTIFY windowChanged)
70 Q_PROPERTY(bool modifierlessAllowed READ modifierlessAllowed WRITE setModifierlessAllowed NOTIFY modifierlessAllowedChanged)
81 Q_PROPERTY(bool multiKeyShortcutsAllowed READ multiKeyShortcutsAllowed WRITE setMultiKeyShortcutsAllowed NOTIFY multiKeyShortcutsAllowedChanged)
82
83
91 Q_PROPERTY(bool modifierOnlyAllowed READ modifierOnlyAllowed WRITE setModifierOnlyAllowed NOTIFY modifierOnlyAllowedChanged)
92public:
99 explicit KeySequenceRecorder(QWindow *window, QObject *parent = nullptr);
100 ~KeySequenceRecorder() override;
101
106 Q_INVOKABLE void startRecording();
107
108 bool isRecording() const;
109
110 QKeySequence currentKeySequence() const;
111 void setCurrentKeySequence(const QKeySequence &sequence);
112
113 QWindow *window() const;
114 void setWindow(QWindow *window);
115
116 bool multiKeyShortcutsAllowed() const;
117 void setMultiKeyShortcutsAllowed(bool allowed);
118
119 void setModifierlessAllowed(bool allowed);
120 bool modifierlessAllowed() const;
121
122 void setModifierOnlyAllowed(bool allowed);
123 bool modifierOnlyAllowed() const;
124
125public Q_SLOTS:
130
131Q_SIGNALS:
138 void gotKeySequence(const QKeySequence &keySequence);
139
140 void recordingChanged();
141 void windowChanged();
142 void currentKeySequenceChanged();
143 void multiKeyShortcutsAllowedChanged();
144 void modifierlessAllowedChanged();
145 void modifierOnlyAllowedChanged();
146
147private:
148 friend class KeySequenceRecorderPrivate;
149 std::unique_ptr<KeySequenceRecorderPrivate> const d;
150};
151
152#endif
Record a QKeySequence by listening to key events in a window.
Definition keysequencerecorder.h:42
void startRecording()
Start recording.
KeySequenceRecorder(QWindow *window, QObject *parent=nullptr)
Constructor.
void cancelRecording()
Stops the recording session.
void gotKeySequence(const QKeySequence &keySequence)
This signal is emitted when a key sequence has been recorded.