VirtualBox

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

Last change on this file since 102493 was 98103, checked in by vboxsync, 20 months ago

Copyright year updates by scm.

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