VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/UIShortcutPool.h@ 82781

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

FE/Qt: bugref:9609: Rework UIShortcut interface to support standard shortcut sequence; Update code accordingly to handle both default and standard sequences simultaneously.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/* $Id: UIShortcutPool.h 82187 2019-11-25 17:18:11Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIShortcutPool class declaration.
4 */
5
6/*
7 * Copyright (C) 2011-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 FEQT_INCLUDED_SRC_globals_UIShortcutPool_h
19#define FEQT_INCLUDED_SRC_globals_UIShortcutPool_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24/* Qt includes: */
25#include <QMap>
26
27/* GUI includes: */
28#include "QIWithRetranslateUI.h"
29#include "UILibraryDefs.h"
30
31/* Forward declarations: */
32class QKeySequence;
33class QString;
34class UIActionPool;
35class UIAction;
36
37
38/** Shortcut descriptor prototype. */
39class SHARED_LIBRARY_STUFF UIShortcut
40{
41public:
42
43 /** Constructs empty shortcut descriptor. */
44 UIShortcut()
45 : m_strScope(QString())
46 , m_strDescription(QString())
47 , m_sequences(QList<QKeySequence>())
48 , m_defaultSequence(QKeySequence())
49 , m_standardSequence(QKeySequence())
50 {}
51 /** Constructs shortcut descriptor.
52 * @param strScope Brings the shortcut scope.
53 * @param strDescription Brings the shortcut description.
54 * @param sequences Brings the shortcut sequences.
55 * @param defaultSequence Brings the default shortcut sequence.
56 * @param standardSequence Brings the standard shortcut sequence. */
57 UIShortcut(const QString &strScope,
58 const QString &strDescription,
59 const QList<QKeySequence> &sequences,
60 const QKeySequence &defaultSequence,
61 const QKeySequence &standardSequence)
62 : m_strScope(strScope)
63 , m_strDescription(strDescription)
64 , m_sequences(sequences)
65 , m_defaultSequence(defaultSequence)
66 , m_standardSequence(standardSequence)
67 {}
68
69 /** Defines the shortcut @a strScope. */
70 void setScope(const QString &strScope);
71 /** Returns the shortcut scope. */
72 const QString &scope() const;
73
74 /** Defines the shortcut @a strDescription. */
75 void setDescription(const QString &strDescription);
76 /** Returns the shortcut description. */
77 const QString &description() const;
78
79 /** Defines the shortcut @a sequences. */
80 void setSequences(const QList<QKeySequence> &sequences);
81 /** Returns the shortcut sequences. */
82 const QList<QKeySequence> &sequences() const;
83
84 /** Defines the default shortcut @a sequence. */
85 void setDefaultSequence(const QKeySequence &sequence);
86 /** Returns the default shortcut sequence. */
87 const QKeySequence &defaultSequence() const;
88
89 /** Defines the standard shortcut @a sequence. */
90 void setStandardSequence(const QKeySequence &sequence);
91 /** Returns the standard shortcut sequence. */
92 const QKeySequence &standardSequence() const;
93
94 /** Converts primary shortcut sequence to native text. */
95 QString primaryToNativeText() const;
96 /** Converts primary shortcut sequence to portable text. */
97 QString primaryToPortableText() const;
98
99private:
100
101 /** Holds the shortcut scope. */
102 QString m_strScope;
103 /** Holds the shortcut description. */
104 QString m_strDescription;
105 /** Holds the shortcut sequences. */
106 QList<QKeySequence> m_sequences;
107 /** Holds the default shortcut sequence. */
108 QKeySequence m_defaultSequence;
109 /** Holds the standard shortcut sequence. */
110 QKeySequence m_standardSequence;
111};
112
113
114/** QObject extension used as shortcut pool singleton. */
115class SHARED_LIBRARY_STUFF UIShortcutPool : public QIWithRetranslateUI3<QObject>
116{
117 Q_OBJECT;
118
119signals:
120
121 /** Notifies about Selector UI shortcuts changed. */
122 void sigSelectorShortcutsReloaded();
123 /** Notifies about Runtime UI shortcuts changed. */
124 void sigMachineShortcutsReloaded();
125
126public:
127
128 /** Returns singleton instance. */
129 static UIShortcutPool *instance() { return s_pInstance; }
130 /** Creates singleton instance. */
131 static void create();
132 /** Destroys singleton instance. */
133 static void destroy();
134
135 /** Returns shortcuts of particular @a pActionPool for specified @a pAction. */
136 UIShortcut &shortcut(UIActionPool *pActionPool, UIAction *pAction);
137 /** Returns shortcuts of action-pool with @a strPoolID for action with @a strActionID. */
138 UIShortcut &shortcut(const QString &strPoolID, const QString &strActionID);
139 /** Returns all the shortcuts. */
140 const QMap<QString, UIShortcut> &shortcuts() const { return m_shortcuts; }
141 /** Defines shortcut overrides. */
142 void setOverrides(const QMap<QString, QString> &overrides);
143
144 /** Applies shortcuts for specified @a pActionPool. */
145 void applyShortcuts(UIActionPool *pActionPool);
146
147protected:
148
149 /** Handles translation event. */
150 virtual void retranslateUi() /* override */;
151
152private slots:
153
154 /** Reloads Selector UI shortcuts. */
155 void sltReloadSelectorShortcuts();
156 /** Reloads Runtime UI shortcuts. */
157 void sltReloadMachineShortcuts();
158
159private:
160
161 /** Constructs shortcut pool. */
162 UIShortcutPool();
163 /** Destructs shortcut pool. */
164 ~UIShortcutPool();
165
166 /** Prepares all. */
167 void prepare();
168 /** Prepares connections. */
169 void prepareConnections();
170
171 /** Cleanups all. */
172 void cleanup() {}
173
174 /** Loads defaults. */
175 void loadDefaults();
176 /** Loads defaults for pool with specified @a strPoolExtraDataID. */
177 void loadDefaultsFor(const QString &strPoolExtraDataID);
178 /** Loads overrides. */
179 void loadOverrides();
180 /** Loads overrides for pool with specified @a strPoolExtraDataID. */
181 void loadOverridesFor(const QString &strPoolExtraDataID);
182 /** Saves overrides. */
183 void saveOverrides();
184 /** Saves overrides for pool with specified @a strPoolExtraDataID. */
185 void saveOverridesFor(const QString &strPoolExtraDataID);
186
187 /** Returns shortcut with specified @a strShortcutKey. */
188 UIShortcut &shortcut(const QString &strShortcutKey);
189
190 /** Holds the singleton instance. */
191 static UIShortcutPool *s_pInstance;
192 /** Shortcut key template. */
193 static const QString s_strShortcutKeyTemplate;
194 /** Shortcut key template for Runtime UI. */
195 static const QString s_strShortcutKeyTemplateRuntime;
196
197 /** Holds the pool shortcuts. */
198 QMap<QString, UIShortcut> m_shortcuts;
199};
200
201/** Singleton Shortcut Pool 'official' name. */
202#define gShortcutPool UIShortcutPool::instance()
203
204
205#endif /* !FEQT_INCLUDED_SRC_globals_UIShortcutPool_h */
206
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use