VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h@ 76553

Last change on this file since 76553 was 76553, checked in by vboxsync, 5 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1/* $Id: UIHostComboEditor.h 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIHostComboEditor class declaration.
4 */
5
6/*
7 * Copyright (C) 2006-2019 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 ___UIHostComboEditor_h___
19#define ___UIHostComboEditor_h___
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24/* Qt includes: */
25#include <QLineEdit>
26#include <QMap>
27#include <QMetaType>
28#include <QSet>
29
30/* GUI includes: */
31#include "QIWithRetranslateUI.h"
32#include "UILibraryDefs.h"
33
34/* Forward declarations: */
35class QString;
36class QWidget;
37class QIToolButton;
38class UIHostComboEditorPrivate;
39#if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN)
40class ComboEditorEventFilter;
41#endif
42#ifdef VBOX_WS_WIN
43class WinAltGrMonitor;
44#endif
45
46
47/** Native hot-key namespace to unify
48 * all the related hot-key processing stuff. */
49namespace UINativeHotKey
50{
51 /** Translates passed @a iKeyCode to string. */
52 SHARED_LIBRARY_STUFF QString toString(int iKeyCode);
53
54 /** Returns whether passed @a iKeyCode is valid. */
55 SHARED_LIBRARY_STUFF bool isValidKey(int iKeyCode);
56
57 /** Translates passed @a iKeyCode in host platform
58 * encoding to the corresponding set 1 PC scan code.
59 * @note Non-modifier keys will return zero. */
60 SHARED_LIBRARY_STUFF unsigned modifierToSet1ScanCode(int iKeyCode);
61
62#if defined(VBOX_WS_WIN)
63 /** Distinguishes modifier VKey by @a wParam and @a lParam. */
64 SHARED_LIBRARY_STUFF int distinguishModifierVKey(int wParam, int lParam);
65#elif defined(VBOX_WS_X11)
66 /** Retranslates key names. */
67 SHARED_LIBRARY_STUFF void retranslateKeyNames();
68#endif
69}
70
71
72/** Host-combo namespace to unify
73 * all the related hot-combo processing stuff. */
74namespace UIHostCombo
75{
76 /** Returns host-combo modifier index. */
77 SHARED_LIBRARY_STUFF int hostComboModifierIndex();
78 /** Returns host-combo modifier name. */
79 SHARED_LIBRARY_STUFF QString hostComboModifierName();
80 /** Returns host-combo cached key. */
81 SHARED_LIBRARY_STUFF QString hostComboCacheKey();
82
83 /** Translates passed @strKeyCombo to readable string. */
84 SHARED_LIBRARY_STUFF QString toReadableString(const QString &strKeyCombo);
85 /** Translates passed @strKeyCombo to key codes list. */
86 SHARED_LIBRARY_STUFF QList<int> toKeyCodeList(const QString &strKeyCombo);
87
88 /** Returns a sequence of the set 1 PC scan codes for all
89 * modifiers contained in the (host platform format) sequence passed. */
90 SHARED_LIBRARY_STUFF QList<unsigned> modifiersToScanCodes(const QString &strKeyCombo);
91
92 /** Returns whether passed @a strKeyCombo is valid. */
93 SHARED_LIBRARY_STUFF bool isValidKeyCombo(const QString &strKeyCombo);
94}
95
96
97/** Host-combo QString wrapper. */
98class SHARED_LIBRARY_STUFF UIHostComboWrapper
99{
100public:
101
102 /** Constructs host-combo wrapper on the basis of passed @a strHostCombo. */
103 UIHostComboWrapper(const QString &strHostCombo = QString())
104 : m_strHostCombo(strHostCombo)
105 {}
106
107 /** Returns the host-combo. */
108 const QString &toString() const { return m_strHostCombo; }
109
110private:
111
112 /** Holds the host-combo. */
113 QString m_strHostCombo;
114};
115Q_DECLARE_METATYPE(UIHostComboWrapper);
116
117
118/** Host-combo editor widget. */
119class SHARED_LIBRARY_STUFF UIHostComboEditor : public QIWithRetranslateUI<QWidget>
120{
121 Q_OBJECT;
122 Q_PROPERTY(UIHostComboWrapper combo READ combo WRITE setCombo USER true);
123
124signals:
125
126 /** Notifies listener about data should be committed. */
127 void sigCommitData(QWidget *pThis);
128
129public:
130
131 /** Constructs host-combo editor passing @a pParent to the base-class. */
132 UIHostComboEditor(QWidget *pParent);
133
134protected:
135
136 /** Handles translation event. */
137 virtual void retranslateUi() /* override */;
138
139private slots:
140
141 /** Notifies listener about data should be committed. */
142 void sltCommitData();
143
144private:
145
146 /** Prepares all. */
147 void prepare();
148
149 /** Defines host @a strCombo sequence. */
150 void setCombo(const UIHostComboWrapper &strCombo);
151 /** Returns host-combo sequence. */
152 UIHostComboWrapper combo() const;
153
154 /** UIHostComboEditorPrivate instance. */
155 UIHostComboEditorPrivate *m_pEditor;
156 /** <b>Clear</b> QIToolButton instance. */
157 QIToolButton *m_pButtonClear;
158};
159
160
161/** Host-combo editor widget private stuff. */
162class SHARED_LIBRARY_STUFF UIHostComboEditorPrivate : public QLineEdit
163{
164 Q_OBJECT;
165
166signals:
167
168 /** Notifies parent about data changed. */
169 void sigDataChanged();
170
171public:
172
173 /** Constructs host-combo editor private part. */
174 UIHostComboEditorPrivate();
175 /** Destructs host-combo editor private part. */
176 ~UIHostComboEditorPrivate();
177
178 /** Defines host @a strCombo sequence. */
179 void setCombo(const UIHostComboWrapper &strCombo);
180 /** Returns host-combo sequence. */
181 UIHostComboWrapper combo() const;
182
183public slots:
184
185 /** Clears the host-combo selection. */
186 void sltDeselect();
187 /** Clears the host-combo editor. */
188 void sltClear();
189
190protected:
191
192 /** Handles native events. */
193 virtual bool nativeEvent(const QByteArray &eventType, void *pMessage, long *pResult) /* override */;
194
195 /** Handles key-press @a pEvent. */
196 virtual void keyPressEvent(QKeyEvent *pEvent) /* override */;
197 /** Handles key-release @a pEvent. */
198 virtual void keyReleaseEvent(QKeyEvent *pEvent) /* override */;
199 /** Handles mouse-press @a pEvent. */
200 virtual void mousePressEvent(QMouseEvent *pEvent) /* override */;
201 /** Handles mouse-release @a pEvent. */
202 virtual void mouseReleaseEvent(QMouseEvent *pEvent) /* override */;
203
204private slots:
205
206 /** Releases pending keys. */
207 void sltReleasePendingKeys();
208
209private:
210
211 /** PRocesses key event of @a fKeyPress type for a passed @a iKeyCode. */
212 bool processKeyEvent(int iKeyCode, bool fKeyPress);
213
214 /** Updates text. */
215 void updateText();
216
217 /** Holds the pressed keys. */
218 QSet<int> m_pressedKeys;
219 /** Holds the released keys. */
220 QSet<int> m_releasedKeys;
221 /** Holds the shown keys. */
222 QMap<int, QString> m_shownKeys;
223
224 /** Holds the release timer instance. */
225 QTimer *m_pReleaseTimer;
226
227 /** Holds whether new sequence should be started. */
228 bool m_fStartNewSequence;
229
230#if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN)
231 /** Mac, Win: Holds the native event filter instance. */
232 ComboEditorEventFilter *m_pPrivateEventFilter;
233 /** Mac, Win: Allows the native event filter to redirect events directly to nativeEvent handler. */
234 friend class ComboEditorEventFilter;
235#endif /* VBOX_WS_MAC || VBOX_WS_WIN */
236
237#if defined(VBOX_WS_MAC)
238 /** Mac: Holds the current modifier key mask. */
239 uint32_t m_uDarwinKeyModifiers;
240#elif defined(VBOX_WS_WIN)
241 /** Win: Holds the object monitoring key event stream for problematic AltGr events. */
242 WinAltGrMonitor *m_pAltGrMonitor;
243#endif /* VBOX_WS_WIN */
244};
245
246
247#endif /* !___UIHostComboEditor_h___ */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use