-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshortcutlineedit.h
46 lines (36 loc) · 1.18 KB
/
shortcutlineedit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef SHORTCUTLINEEDIT_H
#define SHORTCUTLINEEDIT_H
#include <QLineEdit>
#include <QKeyEvent>
#include <QKeySequence>
#ifdef Q_OS_WIN
#include <windows.h> // For global keyboard hook
#endif
class ShortcutLineEdit : public QLineEdit
{
Q_OBJECT
public:
explicit ShortcutLineEdit(QWidget *parent = nullptr);
explicit ShortcutLineEdit(const QKeySequence &keySequence, QWidget *parent = nullptr);
virtual ~ShortcutLineEdit();
void setKeySequence(const QKeySequence &keySequence);
QKeySequence keySequence() const;
signals:
void keySequenceChanged(const QKeySequence &keySequence);
protected:
void keyPressEvent(QKeyEvent *event) override;
void keyReleaseEvent(QKeyEvent *event) override;
void focusInEvent(QFocusEvent *event) override;
void focusOutEvent(QFocusEvent *event) override;
private:
void initUI();
void updateText();
void handlePrintScreen();
#ifdef Q_OS_WIN
static HHOOK hook;
static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
#endif
QKeySequence m_keySequence;
static ShortcutLineEdit* focusedInstance; // Static pointer to the focused instance
};
#endif // SHORTCUTLINEEDIT_H