VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHotKeyEditor.h@ 74942

Last change on this file since 74942 was 71921, checked in by vboxsync, 6 years ago

FE/Qt: bugref:9049: Full and heavy cleanup for UIHotKeyEditor and move it to VBoxGlobal library.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
  • Property svn:mergeinfo set to (toggle deleted branches)
    /branches/VBox-3.0/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h58652,​70973
    /branches/VBox-3.2/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h66309,​66318
    /branches/VBox-4.0/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h70873
    /branches/VBox-4.1/src/VBox/Frontends/VBoxHeadless/VirtualBox/src/widgets/UIHostComboEditor.h82454
    /branches/VBox-4.1/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h74233,​78414,​78691,​81841,​82127
    /branches/VBox-4.2/src/VBox/Frontends/VirtualBox/src/widgets/UIHotKeyEditor.h91503-91504,​91506-91508,​91510,​91514-91515,​91521
    /branches/VBox-4.3/src/VBox/Frontends/VirtualBox/src/widgets/UIHotKeyEditor.h91223
    /branches/VBox-4.3/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHotKeyEditor.h91223
    /branches/andy/guestctrl20/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h78916,​78930
    /branches/dsen/gui/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h79076-79078,​79089,​79109-79110,​79112-79113,​79127-79130,​79134,​79141,​79151,​79155,​79157-79159,​79193,​79197
    /branches/dsen/gui2/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h79224,​79228,​79233,​79235,​79258,​79262-79263,​79273,​79341,​79345,​79354,​79357,​79387-79388,​79559-79569,​79572-79573,​79578,​79581-79582,​79590-79591,​79598-79599,​79602-79603,​79605-79606,​79632,​79635,​79637,​79644
    /branches/dsen/gui3/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h79645-79692
File size: 5.5 KB
Line 
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: */
31class QHBoxLayout;
32class QIToolButton;
33class UIHotKeyLineEdit;
34
35
36/** Hot key types. */
37enum UIHotKeyType
38{
39 UIHotKeyType_Simple,
40 UIHotKeyType_WithModifiers
41};
42
43
44/** A string pair wrapper for hot-key sequence. */
45class UIHotKey
46{
47public:
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
85private:
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};
94Q_DECLARE_METATYPE(UIHotKey);
95
96
97/** QWidget subclass wrapping real hot-key editor. */
98class SHARED_LIBRARY_STUFF UIHotKeyEditor : public QIWithRetranslateUI<QWidget>
99{
100 Q_OBJECT;
101 Q_PROPERTY(UIHotKey hotKey READ hotKey WRITE setHotKey USER true);
102
103signals:
104
105 /** Notifies listener about data should be committed. */
106 void sigCommitData(QWidget *pThis);
107
108public:
109
110 /** Constructs hot-key editor passing @a pParent to the base-class. */
111 UIHotKeyEditor(QWidget *pParent);
112
113private slots:
114
115 /** Resets hot-key sequence to default. */
116 void sltReset();
117 /** Clears hot-key sequence. */
118 void sltClear();
119
120protected:
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
133private:
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___ */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use