1 | /* $Id: UIIconPool.h 102102 2023-11-15 13:35:02Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIIconPool class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-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_UIIconPool_h
|
---|
29 | #define FEQT_INCLUDED_SRC_globals_UIIconPool_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QFileIconProvider>
|
---|
36 | #include <QIcon>
|
---|
37 | #include <QPixmap>
|
---|
38 | #include <QHash>
|
---|
39 |
|
---|
40 | /* GUI includes: */
|
---|
41 | #include "UILibraryDefs.h"
|
---|
42 |
|
---|
43 | /* Forward declarations: */
|
---|
44 | class CMachine;
|
---|
45 |
|
---|
46 | /** Interface which provides GUI with static API
|
---|
47 | * allowing to dynamically compose icons at runtime. */
|
---|
48 | class SHARED_LIBRARY_STUFF UIIconPool
|
---|
49 | {
|
---|
50 | public:
|
---|
51 |
|
---|
52 | /** Default icon types. */
|
---|
53 | enum UIDefaultIconType
|
---|
54 | {
|
---|
55 | /* Message-box related stuff: */
|
---|
56 | UIDefaultIconType_MessageBoxInformation,
|
---|
57 | UIDefaultIconType_MessageBoxQuestion,
|
---|
58 | UIDefaultIconType_MessageBoxWarning,
|
---|
59 | UIDefaultIconType_MessageBoxCritical,
|
---|
60 | /* Dialog related stuff: */
|
---|
61 | UIDefaultIconType_DialogCancel,
|
---|
62 | UIDefaultIconType_DialogHelp,
|
---|
63 | UIDefaultIconType_ArrowBack,
|
---|
64 | UIDefaultIconType_ArrowForward
|
---|
65 | };
|
---|
66 |
|
---|
67 | /** Creates pixmap from passed pixmap @a strName. */
|
---|
68 | static QPixmap pixmap(const QString &strName);
|
---|
69 |
|
---|
70 | /** Creates icon from passed pixmap names for
|
---|
71 | * @a strNormal, @a strDisabled and @a strActive icon states. */
|
---|
72 | static QIcon iconSet(const QString &strNormal,
|
---|
73 | const QString &strDisabled = QString(),
|
---|
74 | const QString &strActive = QString());
|
---|
75 |
|
---|
76 | /** Creates icon from passed pixmap names for
|
---|
77 | * @a strNormal, @a strDisabled, @a strActive icon states and
|
---|
78 | * their analogs for toggled-off case. Used for toggle actions. */
|
---|
79 | static QIcon iconSetOnOff(const QString &strNormal, const QString strNormalOff,
|
---|
80 | const QString &strDisabled = QString(), const QString &strDisabledOff = QString(),
|
---|
81 | const QString &strActive = QString(), const QString &strActiveOff = QString());
|
---|
82 |
|
---|
83 | /** Creates icon from passed pixmap names for
|
---|
84 | * @a strNormal, @a strDisabled, @a strActive icon states and
|
---|
85 | * their analogs for small-icon case. Used for setting pages. */
|
---|
86 | static QIcon iconSetFull(const QString &strNormal, const QString &strSmall,
|
---|
87 | const QString &strNormalDisabled = QString(), const QString &strSmallDisabled = QString(),
|
---|
88 | const QString &strNormalActive = QString(), const QString &strSmallActive = QString());
|
---|
89 |
|
---|
90 | /** Creates icon from passed pixmaps for
|
---|
91 | * @a normal, @a disabled and @a active icon states. */
|
---|
92 | static QIcon iconSet(const QPixmap &normal,
|
---|
93 | const QPixmap &disabled = QPixmap(),
|
---|
94 | const QPixmap &active = QPixmap());
|
---|
95 |
|
---|
96 | /** Creates icon of passed @a defaultIconType
|
---|
97 | * based on passed @a pWidget style (if any) or application style (otherwise). */
|
---|
98 | static QIcon defaultIcon(UIDefaultIconType defaultIconType, const QWidget *pWidget = 0);
|
---|
99 |
|
---|
100 | /** Joins two pixmaps horizontally with 2px space between them and returns the result. */
|
---|
101 | static QPixmap joinPixmaps(const QPixmap &pixmap1, const QPixmap &pixmap2);
|
---|
102 |
|
---|
103 | protected:
|
---|
104 |
|
---|
105 | /** Constructs icon-pool.
|
---|
106 | * Doesn't mean to be used directly,
|
---|
107 | * cause this class is a bunch of statics. */
|
---|
108 | UIIconPool() {}
|
---|
109 |
|
---|
110 | /** Destructs icon-pool. */
|
---|
111 | virtual ~UIIconPool() {}
|
---|
112 |
|
---|
113 | private:
|
---|
114 |
|
---|
115 | /** Adds resource named @a strName to passed @a icon
|
---|
116 | * for @a mode (QIcon::Normal by default) and @a state (QIcon::Off by default). */
|
---|
117 | static void addName(QIcon &icon, const QString &strName,
|
---|
118 | QIcon::Mode mode = QIcon::Normal, QIcon::State state = QIcon::Off);
|
---|
119 | };
|
---|
120 |
|
---|
121 | /** UIIconPool interface extension used as general GUI icon-pool.
|
---|
122 | * Provides GUI with guest OS types pixmap cache. */
|
---|
123 | class SHARED_LIBRARY_STUFF UIIconPoolGeneral : public UIIconPool
|
---|
124 | {
|
---|
125 | public:
|
---|
126 |
|
---|
127 | /** Creates singleton instance. */
|
---|
128 | static void create();
|
---|
129 | /** Destroys singleton instance. */
|
---|
130 | static void destroy();
|
---|
131 | /** Returns singleton instance. */
|
---|
132 | static UIIconPoolGeneral *instance();
|
---|
133 |
|
---|
134 | /** Returns icon defined for a passed @a comMachine. */
|
---|
135 | QIcon userMachineIcon(const CMachine &comMachine) const;
|
---|
136 | /** Returns pixmap of a passed @a size defined for a passed @a comMachine. */
|
---|
137 | QPixmap userMachinePixmap(const CMachine &comMachine, const QSize &size) const;
|
---|
138 | /** Returns pixmap defined for a passed @a comMachine.
|
---|
139 | * In case if non-null @a pLogicalSize pointer provided, it will be updated properly. */
|
---|
140 | QPixmap userMachinePixmapDefault(const CMachine &comMachine, QSize *pLogicalSize = 0) const;
|
---|
141 |
|
---|
142 | /** Returns icon corresponding to passed @a strOSTypeID. */
|
---|
143 | QIcon guestOSTypeIcon(const QString &strOSTypeID) const;
|
---|
144 | /** Returns pixmap corresponding to passed @a strOSTypeID and @a size. */
|
---|
145 | QPixmap guestOSTypePixmap(const QString &strOSTypeID, const QSize &size) const;
|
---|
146 | /** Returns pixmap corresponding to passed @a strOSTypeID.
|
---|
147 | * In case if non-null @a pLogicalSize pointer provided, it will be updated properly. */
|
---|
148 | QPixmap guestOSTypePixmapDefault(const QString &strOSTypeID, QSize *pLogicalSize = 0) const;
|
---|
149 |
|
---|
150 | /** Returns default system icon of certain @a enmType. */
|
---|
151 | QIcon defaultSystemIcon(QFileIconProvider::IconType enmType) { return m_fileIconProvider.icon(enmType); }
|
---|
152 | /** Returns file icon fetched from passed file @a info. */
|
---|
153 | QIcon defaultFileIcon(const QFileInfo &info) { return m_fileIconProvider.icon(info); }
|
---|
154 |
|
---|
155 | /** Returns cached default warning pixmap. */
|
---|
156 | QPixmap warningIcon() const { return m_pixWarning; }
|
---|
157 | /** Returns cached default error pixmap. */
|
---|
158 | QPixmap errorIcon() const { return m_pixError; }
|
---|
159 |
|
---|
160 | private:
|
---|
161 |
|
---|
162 | /** Creates icon from passed pixmap names for
|
---|
163 | * @a strNormal, @a strDisabled and @a strActive icon states. Utilizes addNameAndOverlay to overlay pixmaps. */
|
---|
164 | static QIcon overlayedIconSet(const QString &strGuestOSTypeId,
|
---|
165 | const QString &strNormal,
|
---|
166 | const QString &strDisabled = QString(),
|
---|
167 | const QString &strActive = QString());
|
---|
168 | /* Just like UIIconPool::addName add resources to icon but additionally overlays corresponding text wrt. strGuestOSTypeId. */
|
---|
169 | static void addNameAndOverlay(QIcon &icon, const QString &strName, const QString &strGuestOSTypeId,
|
---|
170 | QIcon::Mode mode = QIcon::Normal, QIcon::State state = QIcon::Off);
|
---|
171 |
|
---|
172 | /** Constructs general icon-pool. */
|
---|
173 | UIIconPoolGeneral();
|
---|
174 | /** Destructs general icon-pool. */
|
---|
175 | virtual ~UIIconPoolGeneral() /* override final */;
|
---|
176 | /** Overlay text @p strArch on top of @p pixmap. */
|
---|
177 | static void overlayArchitectureTextOnPixmap(const QString &strArch, QPixmap &pixmap);
|
---|
178 | /** Returns the architecture text we overlay on guest OS type id icon.*/
|
---|
179 | static QString determineOSArchString(const QString &strOSTypeId);
|
---|
180 | /** Holds the singleton instance. */
|
---|
181 | static UIIconPoolGeneral *s_pInstance;
|
---|
182 |
|
---|
183 | /** Holds the global file icon provider instance. */
|
---|
184 | QFileIconProvider m_fileIconProvider;
|
---|
185 |
|
---|
186 | /** Guest OS type icon-names cache. */
|
---|
187 | QHash<QString, QString> m_guestOSTypeIconNames;
|
---|
188 | /** Guest OS type icons cache. */
|
---|
189 | mutable QHash<QString, QIcon> m_guestOSTypeIcons;
|
---|
190 |
|
---|
191 | /** Holds the warning pixmap. */
|
---|
192 | QPixmap m_pixWarning;
|
---|
193 | /** Holds the error pixmap. */
|
---|
194 | QPixmap m_pixError;
|
---|
195 |
|
---|
196 | /** Allows for shortcut access. */
|
---|
197 | friend UIIconPoolGeneral &generalIconPool();
|
---|
198 | };
|
---|
199 |
|
---|
200 | /** Singleton UIIconPoolGeneral 'official' name. */
|
---|
201 | inline UIIconPoolGeneral &generalIconPool() { return *UIIconPoolGeneral::instance(); }
|
---|
202 |
|
---|
203 | #endif /* !FEQT_INCLUDED_SRC_globals_UIIconPool_h */
|
---|