1 | /* $Id: UIHotKeyEditor.h 71921 2018-04-19 13:09:04Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIHotKeyEditor class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2018 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ___UIHotKeyEditor_h___
|
---|
19 | #define ___UIHotKeyEditor_h___
|
---|
20 |
|
---|
21 | /* Qt includes: */
|
---|
22 | #include <QMetaType>
|
---|
23 | #include <QSet>
|
---|
24 | #include <QWidget>
|
---|
25 |
|
---|
26 | /* GUI includes: */
|
---|
27 | #include "QIWithRetranslateUI.h"
|
---|
28 | #include "UILibraryDefs.h"
|
---|
29 |
|
---|
30 | /* Forward declarations: */
|
---|
31 | class QHBoxLayout;
|
---|
32 | class QIToolButton;
|
---|
33 | class UIHotKeyLineEdit;
|
---|
34 |
|
---|
35 |
|
---|
36 | /** Hot key types. */
|
---|
37 | enum UIHotKeyType
|
---|
38 | {
|
---|
39 | UIHotKeyType_Simple,
|
---|
40 | UIHotKeyType_WithModifiers
|
---|
41 | };
|
---|
42 |
|
---|
43 |
|
---|
44 | /** A string pair wrapper for hot-key sequence. */
|
---|
45 | class UIHotKey
|
---|
46 | {
|
---|
47 | public:
|
---|
48 |
|
---|
49 | /** Constructs null hot-key sequence. */
|
---|
50 | UIHotKey()
|
---|
51 | : m_enmType(UIHotKeyType_Simple)
|
---|
52 | {}
|
---|
53 | /** Constructs hot-key sequence on the basis of passed @a enmType, @a strSequence and @a strDefaultSequence. */
|
---|
54 | UIHotKey(UIHotKeyType enmType, const QString &strSequence, const QString &strDefaultSequence)
|
---|
55 | : m_enmType(enmType)
|
---|
56 | , m_strSequence(strSequence)
|
---|
57 | , m_strDefaultSequence(strDefaultSequence)
|
---|
58 | {}
|
---|
59 | /** Constructs hot-key sequence on the basis of @a other hot-key sequence. */
|
---|
60 | UIHotKey(const UIHotKey &other)
|
---|
61 | : m_enmType(other.type())
|
---|
62 | , m_strSequence(other.sequence())
|
---|
63 | , m_strDefaultSequence(other.defaultSequence())
|
---|
64 | {}
|
---|
65 |
|
---|
66 | /** Makes a copy of the given other hot-key sequence and assigns it to this one. */
|
---|
67 | UIHotKey &operator=(const UIHotKey &other)
|
---|
68 | {
|
---|
69 | m_enmType = other.type();
|
---|
70 | m_strSequence = other.sequence();
|
---|
71 | m_strDefaultSequence = other.defaultSequence();
|
---|
72 | return *this;
|
---|
73 | }
|
---|
74 |
|
---|
75 | /** Returns the type of this hot-key sequence. */
|
---|
76 | UIHotKeyType type() const { return m_enmType; }
|
---|
77 |
|
---|
78 | /** Returns hot-key sequence. */
|
---|
79 | const QString &sequence() const { return m_strSequence; }
|
---|
80 | /** Returns default hot-key sequence. */
|
---|
81 | const QString &defaultSequence() const { return m_strDefaultSequence; }
|
---|
82 | /** Defines hot-key @a strSequence. */
|
---|
83 | void setSequence(const QString &strSequence) { m_strSequence = strSequence; }
|
---|
84 |
|
---|
85 | private:
|
---|
86 |
|
---|
87 | /** Holds the type of this hot-key sequence. */
|
---|
88 | UIHotKeyType m_enmType;
|
---|
89 | /** Holds the hot-key sequence. */
|
---|
90 | QString m_strSequence;
|
---|
91 | /** Holds the default hot-key sequence. */
|
---|
92 | QString m_strDefaultSequence;
|
---|
93 | };
|
---|
94 | Q_DECLARE_METATYPE(UIHotKey);
|
---|
95 |
|
---|
96 |
|
---|
97 | /** QWidget subclass wrapping real hot-key editor. */
|
---|
98 | class SHARED_LIBRARY_STUFF UIHotKeyEditor : public QIWithRetranslateUI<QWidget>
|
---|
99 | {
|
---|
100 | Q_OBJECT;
|
---|
101 | Q_PROPERTY(UIHotKey hotKey READ hotKey WRITE setHotKey USER true);
|
---|
102 |
|
---|
103 | signals:
|
---|
104 |
|
---|
105 | /** Notifies listener about data should be committed. */
|
---|
106 | void sigCommitData(QWidget *pThis);
|
---|
107 |
|
---|
108 | public:
|
---|
109 |
|
---|
110 | /** Constructs hot-key editor passing @a pParent to the base-class. */
|
---|
111 | UIHotKeyEditor(QWidget *pParent);
|
---|
112 |
|
---|
113 | private slots:
|
---|
114 |
|
---|
115 | /** Resets hot-key sequence to default. */
|
---|
116 | void sltReset();
|
---|
117 | /** Clears hot-key sequence. */
|
---|
118 | void sltClear();
|
---|
119 |
|
---|
120 | protected:
|
---|
121 |
|
---|
122 | /** Preprocesses any Qt @a pEvent for passed @a pObject. */
|
---|
123 | virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
|
---|
124 |
|
---|
125 | /** Handles translation event. */
|
---|
126 | virtual void retranslateUi() /* override */;
|
---|
127 |
|
---|
128 | /** Handles key-press @a pEvent. */
|
---|
129 | virtual void keyPressEvent(QKeyEvent *pEvent) /* override */;
|
---|
130 | /** Handles key-release @a pEvent. */
|
---|
131 | virtual void keyReleaseEvent(QKeyEvent *pEvent) /* override */;
|
---|
132 |
|
---|
133 | private:
|
---|
134 |
|
---|
135 | /** Returns whether we hould skip key-event to line-edit. */
|
---|
136 | bool shouldWeSkipKeyEventToLineEdit(QKeyEvent *pEvent);
|
---|
137 |
|
---|
138 | /** Returns whether key @a pEvent is ignored. */
|
---|
139 | bool isKeyEventIgnored(QKeyEvent *pEvent);
|
---|
140 |
|
---|
141 | /** Fetches actual modifier states. */
|
---|
142 | void fetchModifiersState();
|
---|
143 | /** Returns whether Host+ modifier is required. */
|
---|
144 | void checkIfHostModifierNeeded();
|
---|
145 |
|
---|
146 | /** Handles approved key-press @a pEvent. */
|
---|
147 | bool approvedKeyPressed(QKeyEvent *pEvent);
|
---|
148 | /** Handles key-press @a pEvent. */
|
---|
149 | void handleKeyPress(QKeyEvent *pEvent);
|
---|
150 | /** Handles key-release @a pEvent. */
|
---|
151 | void handleKeyRelease(QKeyEvent *pEvent);
|
---|
152 | /** Reflects recorded sequence in editor. */
|
---|
153 | void reflectSequence();
|
---|
154 | /** Draws recorded sequence in editor. */
|
---|
155 | void drawSequence();
|
---|
156 |
|
---|
157 | /** Returns hot-key. */
|
---|
158 | UIHotKey hotKey() const;
|
---|
159 | /** Defines @a hotKey. */
|
---|
160 | void setHotKey(const UIHotKey &hotKey);
|
---|
161 |
|
---|
162 | /** Holds the hot-key. */
|
---|
163 | UIHotKey m_hotKey;
|
---|
164 |
|
---|
165 | /** Holds whether the modifiers are allowed. */
|
---|
166 | bool m_fIsModifiersAllowed;
|
---|
167 |
|
---|
168 | /** Holds the main-layout instance. */
|
---|
169 | QHBoxLayout *m_pMainLayout;
|
---|
170 | /** Holds the button-layout instance. */
|
---|
171 | QHBoxLayout *m_pButtonLayout;
|
---|
172 | /** Holds the line-edit instance. */
|
---|
173 | UIHotKeyLineEdit *m_pLineEdit;
|
---|
174 | /** Holds the reset-button instance. */
|
---|
175 | QIToolButton *m_pResetButton;
|
---|
176 | /** Holds the clear-button instance. */
|
---|
177 | QIToolButton *m_pClearButton;
|
---|
178 |
|
---|
179 | /** Holds the taken modifiers. */
|
---|
180 | QSet<int> m_takenModifiers;
|
---|
181 | /** Holds the taken key. */
|
---|
182 | int m_iTakenKey;
|
---|
183 | /** Holds whether sequence is taken. */
|
---|
184 | bool m_fSequenceTaken;
|
---|
185 | };
|
---|
186 |
|
---|
187 |
|
---|
188 | #endif /* !___UIHotKeyEditor_h___ */
|
---|