VirtualBox

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

Last change on this file since 103977 was 103579, checked in by vboxsync, 9 months ago

FE/Qt: UIShortcutPool: Make sure shortcuts for actions common for both Manager and Runtime action-pools not being overridden by temporary action-pools of other types; That means shortcut-pool is now aware of it's own type now.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette