1 | /* $Id: UIHostComboEditor.h 104313 2024-04-12 13:10:30Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIHostComboEditor class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef FEQT_INCLUDED_SRC_settings_editors_UIHostComboEditor_h
|
---|
29 | #define FEQT_INCLUDED_SRC_settings_editors_UIHostComboEditor_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QLineEdit>
|
---|
36 | #include <QMap>
|
---|
37 | #include <QMetaType>
|
---|
38 | #include <QSet>
|
---|
39 |
|
---|
40 | /* GUI includes: */
|
---|
41 | #include "UILibraryDefs.h"
|
---|
42 |
|
---|
43 | /* Forward declarations: */
|
---|
44 | class QString;
|
---|
45 | class QWidget;
|
---|
46 | class QIToolButton;
|
---|
47 | class UIHostComboEditorPrivate;
|
---|
48 | #if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN)
|
---|
49 | class ComboEditorEventFilter;
|
---|
50 | #endif
|
---|
51 | #ifdef VBOX_WS_WIN
|
---|
52 | class WinAltGrMonitor;
|
---|
53 | #endif
|
---|
54 |
|
---|
55 |
|
---|
56 | /** Native hot-key namespace to unify
|
---|
57 | * all the related hot-key processing stuff. */
|
---|
58 | namespace UINativeHotKey
|
---|
59 | {
|
---|
60 | /** Translates passed @a iKeyCode to string. */
|
---|
61 | SHARED_LIBRARY_STUFF QString toString(int iKeyCode);
|
---|
62 |
|
---|
63 | /** Returns whether passed @a iKeyCode is valid. */
|
---|
64 | SHARED_LIBRARY_STUFF bool isValidKey(int iKeyCode);
|
---|
65 |
|
---|
66 | /** Translates passed @a iKeyCode in host platform
|
---|
67 | * encoding to the corresponding set 1 PC scan code.
|
---|
68 | * @note Non-modifier keys will return zero. */
|
---|
69 | SHARED_LIBRARY_STUFF unsigned modifierToSet1ScanCode(int iKeyCode);
|
---|
70 |
|
---|
71 | #if defined(VBOX_WS_WIN)
|
---|
72 | /** Distinguishes modifier VKey by @a wParam and @a lParam. */
|
---|
73 | SHARED_LIBRARY_STUFF int distinguishModifierVKey(int wParam, int lParam);
|
---|
74 | #elif defined(VBOX_WS_NIX)
|
---|
75 | /** Retranslates key names. */
|
---|
76 | SHARED_LIBRARY_STUFF void retranslateKeyNames();
|
---|
77 | #endif
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 | /** Host-combo namespace to unify
|
---|
82 | * all the related hot-combo processing stuff. */
|
---|
83 | namespace UIHostCombo
|
---|
84 | {
|
---|
85 | /** Returns host-combo modifier index. */
|
---|
86 | SHARED_LIBRARY_STUFF int hostComboModifierIndex();
|
---|
87 | /** Returns host-combo modifier name. */
|
---|
88 | SHARED_LIBRARY_STUFF QString hostComboModifierName();
|
---|
89 | /** Returns host-combo cached key. */
|
---|
90 | SHARED_LIBRARY_STUFF QString hostComboCacheKey();
|
---|
91 |
|
---|
92 | /** Translates passed @strKeyCombo to readable string. */
|
---|
93 | SHARED_LIBRARY_STUFF QString toReadableString(const QString &strKeyCombo);
|
---|
94 | /** Translates passed @strKeyCombo to key codes list. */
|
---|
95 | SHARED_LIBRARY_STUFF QList<int> toKeyCodeList(const QString &strKeyCombo);
|
---|
96 |
|
---|
97 | /** Returns a sequence of the set 1 PC scan codes for all
|
---|
98 | * modifiers contained in the (host platform format) sequence passed. */
|
---|
99 | SHARED_LIBRARY_STUFF QList<unsigned> modifiersToScanCodes(const QString &strKeyCombo);
|
---|
100 |
|
---|
101 | /** Returns whether passed @a strKeyCombo is valid. */
|
---|
102 | SHARED_LIBRARY_STUFF bool isValidKeyCombo(const QString &strKeyCombo);
|
---|
103 | }
|
---|
104 |
|
---|
105 |
|
---|
106 | /** Host-combo QString wrapper. */
|
---|
107 | class SHARED_LIBRARY_STUFF UIHostComboWrapper
|
---|
108 | {
|
---|
109 | public:
|
---|
110 |
|
---|
111 | /** Constructs wrapper on the basis of passed @a strHostCombo. */
|
---|
112 | UIHostComboWrapper(const QString &strHostCombo = QString())
|
---|
113 | : m_strHostCombo(strHostCombo)
|
---|
114 | {}
|
---|
115 |
|
---|
116 | /** Returns the host-combo. */
|
---|
117 | const QString &toString() const { return m_strHostCombo; }
|
---|
118 |
|
---|
119 | private:
|
---|
120 |
|
---|
121 | /** Holds the host-combo. */
|
---|
122 | QString m_strHostCombo;
|
---|
123 | };
|
---|
124 | Q_DECLARE_METATYPE(UIHostComboWrapper);
|
---|
125 |
|
---|
126 |
|
---|
127 | /** Host-combo editor widget. */
|
---|
128 | class SHARED_LIBRARY_STUFF UIHostComboEditor : public QWidget
|
---|
129 | {
|
---|
130 | Q_OBJECT;
|
---|
131 | Q_PROPERTY(UIHostComboWrapper combo READ combo WRITE setCombo USER true);
|
---|
132 |
|
---|
133 | signals:
|
---|
134 |
|
---|
135 | /** Notifies listener about data should be committed. */
|
---|
136 | void sigCommitData(QWidget *pThis);
|
---|
137 |
|
---|
138 | public:
|
---|
139 |
|
---|
140 | /** Constructs editor passing @a pParent to the base-class. */
|
---|
141 | UIHostComboEditor(QWidget *pParent);
|
---|
142 |
|
---|
143 | private slots:
|
---|
144 |
|
---|
145 | /** Handles translation event. */
|
---|
146 | void sltRetranslateUI();
|
---|
147 |
|
---|
148 | /** Notifies listener about data should be committed. */
|
---|
149 | void sltCommitData();
|
---|
150 |
|
---|
151 | private:
|
---|
152 |
|
---|
153 | /** Prepares all. */
|
---|
154 | void prepare();
|
---|
155 |
|
---|
156 | /** Defines host @a strCombo sequence. */
|
---|
157 | void setCombo(const UIHostComboWrapper &strCombo);
|
---|
158 | /** Returns host-combo sequence. */
|
---|
159 | UIHostComboWrapper combo() const;
|
---|
160 |
|
---|
161 | /** UIHostComboEditorPrivate instance. */
|
---|
162 | UIHostComboEditorPrivate *m_pEditor;
|
---|
163 | /** <b>Clear</b> QIToolButton instance. */
|
---|
164 | QIToolButton *m_pButtonClear;
|
---|
165 | };
|
---|
166 |
|
---|
167 |
|
---|
168 | /** Host-combo editor widget private stuff. */
|
---|
169 | class SHARED_LIBRARY_STUFF UIHostComboEditorPrivate : public QLineEdit
|
---|
170 | {
|
---|
171 | Q_OBJECT;
|
---|
172 |
|
---|
173 | signals:
|
---|
174 |
|
---|
175 | /** Notifies parent about data changed. */
|
---|
176 | void sigDataChanged();
|
---|
177 |
|
---|
178 | public:
|
---|
179 |
|
---|
180 | /** Constructs editor private part. */
|
---|
181 | UIHostComboEditorPrivate();
|
---|
182 | /** Destructs editor private part. */
|
---|
183 | ~UIHostComboEditorPrivate();
|
---|
184 |
|
---|
185 | /** Defines host @a strCombo sequence. */
|
---|
186 | void setCombo(const UIHostComboWrapper &strCombo);
|
---|
187 | /** Returns host-combo sequence. */
|
---|
188 | UIHostComboWrapper combo() const;
|
---|
189 |
|
---|
190 | public slots:
|
---|
191 |
|
---|
192 | /** Clears the host-combo selection. */
|
---|
193 | void sltDeselect();
|
---|
194 | /** Clears the host-combo editor. */
|
---|
195 | void sltClear();
|
---|
196 |
|
---|
197 | protected:
|
---|
198 |
|
---|
199 | /** Handles native events. */
|
---|
200 | virtual bool nativeEvent(const QByteArray &eventType, void *pMessage, qintptr *pResult) RT_OVERRIDE;
|
---|
201 |
|
---|
202 | /** Handles key-press @a pEvent. */
|
---|
203 | virtual void keyPressEvent(QKeyEvent *pEvent) RT_OVERRIDE;
|
---|
204 | /** Handles key-release @a pEvent. */
|
---|
205 | virtual void keyReleaseEvent(QKeyEvent *pEvent) RT_OVERRIDE;
|
---|
206 | /** Handles mouse-press @a pEvent. */
|
---|
207 | virtual void mousePressEvent(QMouseEvent *pEvent) RT_OVERRIDE;
|
---|
208 | /** Handles mouse-release @a pEvent. */
|
---|
209 | virtual void mouseReleaseEvent(QMouseEvent *pEvent) RT_OVERRIDE;
|
---|
210 |
|
---|
211 | private slots:
|
---|
212 |
|
---|
213 | /** Releases pending keys. */
|
---|
214 | void sltReleasePendingKeys();
|
---|
215 |
|
---|
216 | private:
|
---|
217 |
|
---|
218 | /** PRocesses key event of @a fKeyPress type for a passed @a iKeyCode. */
|
---|
219 | bool processKeyEvent(int iKeyCode, bool fKeyPress);
|
---|
220 |
|
---|
221 | /** Updates text. */
|
---|
222 | void updateText();
|
---|
223 |
|
---|
224 | /** Holds the pressed keys. */
|
---|
225 | QSet<int> m_pressedKeys;
|
---|
226 | /** Holds the released keys. */
|
---|
227 | QSet<int> m_releasedKeys;
|
---|
228 | /** Holds the shown keys. */
|
---|
229 | QMap<int, QString> m_shownKeys;
|
---|
230 |
|
---|
231 | /** Holds the release timer instance. */
|
---|
232 | QTimer *m_pReleaseTimer;
|
---|
233 |
|
---|
234 | /** Holds whether new sequence should be started. */
|
---|
235 | bool m_fStartNewSequence;
|
---|
236 |
|
---|
237 | #if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN)
|
---|
238 | /** Mac, Win: Holds the native event filter instance. */
|
---|
239 | ComboEditorEventFilter *m_pPrivateEventFilter;
|
---|
240 | /** Mac, Win: Allows the native event filter to redirect events directly to nativeEvent handler. */
|
---|
241 | friend class ComboEditorEventFilter;
|
---|
242 | #endif /* VBOX_WS_MAC || VBOX_WS_WIN */
|
---|
243 |
|
---|
244 | #if defined(VBOX_WS_MAC)
|
---|
245 | /** Mac: Holds the current modifier key mask. */
|
---|
246 | uint32_t m_uDarwinKeyModifiers;
|
---|
247 | #elif defined(VBOX_WS_WIN)
|
---|
248 | /** Win: Holds the object monitoring key event stream for problematic AltGr events. */
|
---|
249 | WinAltGrMonitor *m_pAltGrMonitor;
|
---|
250 | #endif /* VBOX_WS_WIN */
|
---|
251 | };
|
---|
252 |
|
---|
253 |
|
---|
254 | #endif /* !FEQT_INCLUDED_SRC_settings_editors_UIHostComboEditor_h */
|
---|