VirtualBox

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

Last change on this file was 104358, checked in by vboxsync, 5 weeks ago

FE/Qt. bugref:10622. More refactoring around the retranslation functionality.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use