1 | /* $Id: UIIconPool.cpp 100240 2023-06-21 14:27:20Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIIconPool class implementation.
|
---|
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 | /* Qt includes: */
|
---|
29 | #include <QApplication>
|
---|
30 | #include <QFile>
|
---|
31 | #include <QPainter>
|
---|
32 | #include <QStyle>
|
---|
33 | #include <QWidget>
|
---|
34 | #ifdef VBOX_IS_QT6_OR_LATER
|
---|
35 | # include <QWindow>
|
---|
36 | #endif
|
---|
37 |
|
---|
38 | /* GUI includes: */
|
---|
39 | #include "UIIconPool.h"
|
---|
40 | #include "UIExtraDataManager.h"
|
---|
41 | #include "UIModalWindowManager.h"
|
---|
42 |
|
---|
43 | /* COM includes: */
|
---|
44 | #include "COMEnums.h"
|
---|
45 | #include "CMachine.h"
|
---|
46 |
|
---|
47 | /* Other VBox includes: */
|
---|
48 | #include <iprt/assert.h>
|
---|
49 |
|
---|
50 |
|
---|
51 | /*********************************************************************************************************************************
|
---|
52 | * Class UIIconPool implementation. *
|
---|
53 | *********************************************************************************************************************************/
|
---|
54 |
|
---|
55 | /* static */
|
---|
56 | QPixmap UIIconPool::pixmap(const QString &strName)
|
---|
57 | {
|
---|
58 | /* Reuse iconSet API: */
|
---|
59 | QIcon icon = iconSet(strName);
|
---|
60 |
|
---|
61 | /* Return pixmap of first available size: */
|
---|
62 | const int iHint = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
|
---|
63 | return icon.pixmap(icon.availableSizes().value(0, QSize(iHint, iHint)));
|
---|
64 | }
|
---|
65 |
|
---|
66 | /* static */
|
---|
67 | QIcon UIIconPool::iconSet(const QString &strNormal,
|
---|
68 | const QString &strDisabled /* = QString() */,
|
---|
69 | const QString &strActive /* = QString() */)
|
---|
70 | {
|
---|
71 | /* Prepare fallback icon: */
|
---|
72 | static QIcon nullIcon;
|
---|
73 |
|
---|
74 | /* Prepare icon: */
|
---|
75 | QIcon icon;
|
---|
76 |
|
---|
77 | /* Add 'normal' pixmap: */
|
---|
78 | AssertReturn(!strNormal.isEmpty(), nullIcon);
|
---|
79 | addName(icon, strNormal, QIcon::Normal);
|
---|
80 |
|
---|
81 | /* Add 'disabled' pixmap (if any): */
|
---|
82 | if (!strDisabled.isEmpty())
|
---|
83 | addName(icon, strDisabled, QIcon::Disabled);
|
---|
84 |
|
---|
85 | /* Add 'active' pixmap (if any): */
|
---|
86 | if (!strActive.isEmpty())
|
---|
87 | addName(icon, strActive, QIcon::Active);
|
---|
88 |
|
---|
89 | /* Return icon: */
|
---|
90 | return icon;
|
---|
91 | }
|
---|
92 |
|
---|
93 | /* static */
|
---|
94 | QIcon UIIconPool::iconSetOnOff(const QString &strNormal, const QString strNormalOff,
|
---|
95 | const QString &strDisabled /* = QString() */, const QString &strDisabledOff /* = QString() */,
|
---|
96 | const QString &strActive /* = QString() */, const QString &strActiveOff /* = QString() */)
|
---|
97 | {
|
---|
98 | /* Prepare fallback icon: */
|
---|
99 | static QIcon nullIcon;
|
---|
100 |
|
---|
101 | /* Prepare icon: */
|
---|
102 | QIcon icon;
|
---|
103 |
|
---|
104 | /* Add 'normal' on/off pixmaps: */
|
---|
105 | AssertReturn(!strNormal.isEmpty(), nullIcon);
|
---|
106 | addName(icon, strNormal, QIcon::Normal, QIcon::On);
|
---|
107 | AssertReturn(!strNormalOff.isEmpty(), nullIcon);
|
---|
108 | addName(icon, strNormalOff, QIcon::Normal, QIcon::Off);
|
---|
109 |
|
---|
110 | /* Add 'disabled' on/off pixmaps (if any): */
|
---|
111 | if (!strDisabled.isEmpty())
|
---|
112 | addName(icon, strDisabled, QIcon::Disabled, QIcon::On);
|
---|
113 | if (!strDisabledOff.isEmpty())
|
---|
114 | addName(icon, strDisabledOff, QIcon::Disabled, QIcon::Off);
|
---|
115 |
|
---|
116 | /* Add 'active' on/off pixmaps (if any): */
|
---|
117 | if (!strActive.isEmpty())
|
---|
118 | addName(icon, strActive, QIcon::Active, QIcon::On);
|
---|
119 | if (!strActiveOff.isEmpty())
|
---|
120 | addName(icon, strActiveOff, QIcon::Active, QIcon::Off);
|
---|
121 |
|
---|
122 | /* Return icon: */
|
---|
123 | return icon;
|
---|
124 | }
|
---|
125 |
|
---|
126 | /* static */
|
---|
127 | QIcon UIIconPool::iconSetFull(const QString &strNormal, const QString &strSmall,
|
---|
128 | const QString &strNormalDisabled /* = QString() */, const QString &strSmallDisabled /* = QString() */,
|
---|
129 | const QString &strNormalActive /* = QString() */, const QString &strSmallActive /* = QString() */)
|
---|
130 | {
|
---|
131 | /* Prepare fallback icon: */
|
---|
132 | static QIcon nullIcon;
|
---|
133 |
|
---|
134 | /* Prepare icon: */
|
---|
135 | QIcon icon;
|
---|
136 |
|
---|
137 | /* Add 'normal' & 'small normal' pixmaps: */
|
---|
138 | AssertReturn(!strNormal.isEmpty(), nullIcon);
|
---|
139 | addName(icon, strNormal, QIcon::Normal);
|
---|
140 | AssertReturn(!strSmall.isEmpty(), nullIcon);
|
---|
141 | addName(icon, strSmall, QIcon::Normal);
|
---|
142 |
|
---|
143 | /* Add 'disabled' & 'small disabled' pixmaps (if any): */
|
---|
144 | if (!strNormalDisabled.isEmpty())
|
---|
145 | addName(icon, strNormalDisabled, QIcon::Disabled);
|
---|
146 | if (!strSmallDisabled.isEmpty())
|
---|
147 | addName(icon, strSmallDisabled, QIcon::Disabled);
|
---|
148 |
|
---|
149 | /* Add 'active' & 'small active' pixmaps (if any): */
|
---|
150 | if (!strNormalActive.isEmpty())
|
---|
151 | addName(icon, strNormalActive, QIcon::Active);
|
---|
152 | if (!strSmallActive.isEmpty())
|
---|
153 | addName(icon, strSmallActive, QIcon::Active);
|
---|
154 |
|
---|
155 | /* Return icon: */
|
---|
156 | return icon;
|
---|
157 | }
|
---|
158 |
|
---|
159 | /* static */
|
---|
160 | QIcon UIIconPool::iconSet(const QPixmap &normal,
|
---|
161 | const QPixmap &disabled /* = QPixmap() */,
|
---|
162 | const QPixmap &active /* = QPixmap() */)
|
---|
163 | {
|
---|
164 | QIcon iconSet;
|
---|
165 |
|
---|
166 | Assert(!normal.isNull());
|
---|
167 | iconSet.addPixmap(normal, QIcon::Normal);
|
---|
168 |
|
---|
169 | if (!disabled.isNull())
|
---|
170 | iconSet.addPixmap(disabled, QIcon::Disabled);
|
---|
171 |
|
---|
172 | if (!active.isNull())
|
---|
173 | iconSet.addPixmap(active, QIcon::Active);
|
---|
174 |
|
---|
175 | return iconSet;
|
---|
176 | }
|
---|
177 |
|
---|
178 | /* static */
|
---|
179 | QIcon UIIconPool::defaultIcon(UIDefaultIconType defaultIconType, const QWidget *pWidget /* = 0 */)
|
---|
180 | {
|
---|
181 | QIcon icon;
|
---|
182 | QStyle *pStyle = pWidget ? pWidget->style() : QApplication::style();
|
---|
183 | switch (defaultIconType)
|
---|
184 | {
|
---|
185 | case UIDefaultIconType_MessageBoxInformation:
|
---|
186 | {
|
---|
187 | icon = pStyle->standardIcon(QStyle::SP_MessageBoxInformation, 0, pWidget);
|
---|
188 | break;
|
---|
189 | }
|
---|
190 | case UIDefaultIconType_MessageBoxQuestion:
|
---|
191 | {
|
---|
192 | icon = pStyle->standardIcon(QStyle::SP_MessageBoxQuestion, 0, pWidget);
|
---|
193 | break;
|
---|
194 | }
|
---|
195 | case UIDefaultIconType_MessageBoxWarning:
|
---|
196 | {
|
---|
197 | #ifdef VBOX_WS_MAC
|
---|
198 | /* At least in Qt 4.3.4/4.4 RC1 SP_MessageBoxWarning is the application
|
---|
199 | * icon. So change this to the critical icon. (Maybe this would be
|
---|
200 | * fixed in a later Qt version) */
|
---|
201 | icon = pStyle->standardIcon(QStyle::SP_MessageBoxCritical, 0, pWidget);
|
---|
202 | #else /* VBOX_WS_MAC */
|
---|
203 | icon = pStyle->standardIcon(QStyle::SP_MessageBoxWarning, 0, pWidget);
|
---|
204 | #endif /* !VBOX_WS_MAC */
|
---|
205 | break;
|
---|
206 | }
|
---|
207 | case UIDefaultIconType_MessageBoxCritical:
|
---|
208 | {
|
---|
209 | icon = pStyle->standardIcon(QStyle::SP_MessageBoxCritical, 0, pWidget);
|
---|
210 | break;
|
---|
211 | }
|
---|
212 | case UIDefaultIconType_DialogCancel:
|
---|
213 | {
|
---|
214 | icon = pStyle->standardIcon(QStyle::SP_DialogCancelButton, 0, pWidget);
|
---|
215 | if (icon.isNull())
|
---|
216 | icon = iconSet(":/cancel_16px.png");
|
---|
217 | break;
|
---|
218 | }
|
---|
219 | case UIDefaultIconType_DialogHelp:
|
---|
220 | {
|
---|
221 | icon = pStyle->standardIcon(QStyle::SP_DialogHelpButton, 0, pWidget);
|
---|
222 | if (icon.isNull())
|
---|
223 | icon = iconSet(":/help_16px.png");
|
---|
224 | break;
|
---|
225 | }
|
---|
226 | case UIDefaultIconType_ArrowBack:
|
---|
227 | {
|
---|
228 | icon = pStyle->standardIcon(QStyle::SP_ArrowBack, 0, pWidget);
|
---|
229 | if (icon.isNull())
|
---|
230 | icon = iconSet(":/list_moveup_16px.png",
|
---|
231 | ":/list_moveup_disabled_16px.png");
|
---|
232 | break;
|
---|
233 | }
|
---|
234 | case UIDefaultIconType_ArrowForward:
|
---|
235 | {
|
---|
236 | icon = pStyle->standardIcon(QStyle::SP_ArrowForward, 0, pWidget);
|
---|
237 | if (icon.isNull())
|
---|
238 | icon = iconSet(":/list_movedown_16px.png",
|
---|
239 | ":/list_movedown_disabled_16px.png");
|
---|
240 | break;
|
---|
241 | }
|
---|
242 | default:
|
---|
243 | {
|
---|
244 | AssertMsgFailed(("Unknown default icon type!"));
|
---|
245 | break;
|
---|
246 | }
|
---|
247 | }
|
---|
248 | return icon;
|
---|
249 | }
|
---|
250 |
|
---|
251 | /* static */
|
---|
252 | QPixmap UIIconPool::joinPixmaps(const QPixmap &pixmap1, const QPixmap &pixmap2)
|
---|
253 | {
|
---|
254 | if (pixmap1.isNull())
|
---|
255 | return pixmap2;
|
---|
256 | if (pixmap2.isNull())
|
---|
257 | return pixmap1;
|
---|
258 |
|
---|
259 | QPixmap result(pixmap1.width() + pixmap2.width() + 2,
|
---|
260 | qMax(pixmap1.height(), pixmap2.height()));
|
---|
261 | result.fill(Qt::transparent);
|
---|
262 |
|
---|
263 | QPainter painter(&result);
|
---|
264 | painter.drawPixmap(0, 0, pixmap1);
|
---|
265 | painter.drawPixmap(pixmap1.width() + 2, result.height() - pixmap2.height(), pixmap2);
|
---|
266 | painter.end();
|
---|
267 |
|
---|
268 | return result;
|
---|
269 | }
|
---|
270 |
|
---|
271 | /* static */
|
---|
272 | void UIIconPool::addName(QIcon &icon, const QString &strName,
|
---|
273 | QIcon::Mode mode /* = QIcon::Normal */, QIcon::State state /* = QIcon::Off */)
|
---|
274 | {
|
---|
275 | /* Prepare pixmap on the basis of passed value: */
|
---|
276 | QPixmap pixmap(strName);
|
---|
277 | /* Add pixmap: */
|
---|
278 | icon.addPixmap(pixmap, mode, state);
|
---|
279 |
|
---|
280 | #if defined(VBOX_WS_MAC) && !defined(VBOX_IS_QT6_OR_LATER)
|
---|
281 | /* Test if HiDPI icons are enabled on macOS @ Qt5 only: */
|
---|
282 | if (!qApp->testAttribute(Qt::AA_UseHighDpiPixmaps))
|
---|
283 | return;
|
---|
284 | #endif /* VBOX_WS_MAC */
|
---|
285 |
|
---|
286 | /* Parse name to prefix and suffix: */
|
---|
287 | QString strPrefix = strName.section('.', 0, -2);
|
---|
288 | QString strSuffix = strName.section('.', -1, -1);
|
---|
289 | /* Prepare HiDPI pixmaps: */
|
---|
290 | const QStringList aPixmapNames = QStringList() << (strPrefix + "_x2." + strSuffix)
|
---|
291 | << (strPrefix + "_x3." + strSuffix)
|
---|
292 | << (strPrefix + "_x4." + strSuffix);
|
---|
293 | foreach (const QString &strPixmapName, aPixmapNames)
|
---|
294 | {
|
---|
295 | QPixmap pixmapHiDPI(strPixmapName);
|
---|
296 | if (!pixmapHiDPI.isNull())
|
---|
297 | icon.addPixmap(pixmapHiDPI, mode, state);
|
---|
298 | }
|
---|
299 | }
|
---|
300 |
|
---|
301 |
|
---|
302 | /*********************************************************************************************************************************
|
---|
303 | * Class UIIconPoolGeneral implementation. *
|
---|
304 | *********************************************************************************************************************************/
|
---|
305 |
|
---|
306 | /* static */
|
---|
307 | UIIconPoolGeneral *UIIconPoolGeneral::s_pInstance = 0;
|
---|
308 |
|
---|
309 | /* static */
|
---|
310 | void UIIconPoolGeneral::create()
|
---|
311 | {
|
---|
312 | AssertReturnVoid(!s_pInstance);
|
---|
313 | new UIIconPoolGeneral;
|
---|
314 | }
|
---|
315 |
|
---|
316 | /* static */
|
---|
317 | void UIIconPoolGeneral::destroy()
|
---|
318 | {
|
---|
319 | AssertPtrReturnVoid(s_pInstance);
|
---|
320 | delete s_pInstance;
|
---|
321 | }
|
---|
322 |
|
---|
323 | /* static */
|
---|
324 | UIIconPoolGeneral *UIIconPoolGeneral::instance()
|
---|
325 | {
|
---|
326 | return s_pInstance;
|
---|
327 | }
|
---|
328 |
|
---|
329 | UIIconPoolGeneral::UIIconPoolGeneral()
|
---|
330 | {
|
---|
331 | /* Init instance: */
|
---|
332 | s_pInstance = this;
|
---|
333 |
|
---|
334 | /* Prepare OS type icon-name hash: */
|
---|
335 | m_guestOSTypeIconNames.insert("Other", ":/os_other_32.png");
|
---|
336 | m_guestOSTypeIconNames.insert("Other_64", ":/os_other.png");
|
---|
337 | m_guestOSTypeIconNames.insert("DOS", ":/os_dos.png");
|
---|
338 | m_guestOSTypeIconNames.insert("Netware", ":/os_netware.png");
|
---|
339 | m_guestOSTypeIconNames.insert("L4", ":/os_l4.png");
|
---|
340 | m_guestOSTypeIconNames.insert("Windows31", ":/os_win31.png");
|
---|
341 | m_guestOSTypeIconNames.insert("Windows95", ":/os_win95.png");
|
---|
342 | m_guestOSTypeIconNames.insert("Windows98", ":/os_win98.png");
|
---|
343 | m_guestOSTypeIconNames.insert("WindowsMe", ":/os_winme.png");
|
---|
344 | m_guestOSTypeIconNames.insert("WindowsNT3x", ":/os_winnt4.png");
|
---|
345 | m_guestOSTypeIconNames.insert("WindowsNT4", ":/os_winnt4.png");
|
---|
346 | m_guestOSTypeIconNames.insert("Windows2000", ":/os_win2k.png");
|
---|
347 | m_guestOSTypeIconNames.insert("WindowsXP", ":/os_winxp_32.png");
|
---|
348 | m_guestOSTypeIconNames.insert("WindowsXP_64", ":/os_winxp.png");
|
---|
349 | m_guestOSTypeIconNames.insert("Windows2003", ":/os_win2k3_32.png");
|
---|
350 | m_guestOSTypeIconNames.insert("Windows2003_64", ":/os_win2k3.png");
|
---|
351 | m_guestOSTypeIconNames.insert("WindowsVista", ":/os_winvista_32.png");
|
---|
352 | m_guestOSTypeIconNames.insert("WindowsVista_64", ":/os_winvista.png");
|
---|
353 | m_guestOSTypeIconNames.insert("Windows2008", ":/os_win2k8_32.png");
|
---|
354 | m_guestOSTypeIconNames.insert("Windows2008_64", ":/os_win2k8.png");
|
---|
355 | m_guestOSTypeIconNames.insert("Windows7", ":/os_win7_32.png");
|
---|
356 | m_guestOSTypeIconNames.insert("Windows7_64", ":/os_win7.png");
|
---|
357 | m_guestOSTypeIconNames.insert("Windows8", ":/os_win8_32.png");
|
---|
358 | m_guestOSTypeIconNames.insert("Windows8_64", ":/os_win8.png");
|
---|
359 | m_guestOSTypeIconNames.insert("Windows81", ":/os_win81_32.png");
|
---|
360 | m_guestOSTypeIconNames.insert("Windows81_64", ":/os_win81.png");
|
---|
361 | m_guestOSTypeIconNames.insert("Windows2012_64", ":/os_win2k12.png");
|
---|
362 | m_guestOSTypeIconNames.insert("Windows10", ":/os_win10_32.png");
|
---|
363 | m_guestOSTypeIconNames.insert("Windows10_64", ":/os_win10.png");
|
---|
364 | m_guestOSTypeIconNames.insert("Windows11_64", ":/os_win11.png");
|
---|
365 | m_guestOSTypeIconNames.insert("Windows2016_64", ":/os_win2k16.png");
|
---|
366 | m_guestOSTypeIconNames.insert("Windows2019_64", ":/os_win2k19.png");
|
---|
367 | m_guestOSTypeIconNames.insert("Windows2022_64", ":/os_win2k22.png");
|
---|
368 | m_guestOSTypeIconNames.insert("WindowsNT", ":/os_win_other_32.png");
|
---|
369 | m_guestOSTypeIconNames.insert("WindowsNT_64", ":/os_win_other.png");
|
---|
370 | m_guestOSTypeIconNames.insert("OS2Warp3", ":/os_os2warp3.png");
|
---|
371 | m_guestOSTypeIconNames.insert("OS2Warp4", ":/os_os2warp4.png");
|
---|
372 | m_guestOSTypeIconNames.insert("OS2Warp45", ":/os_os2warp45.png");
|
---|
373 | m_guestOSTypeIconNames.insert("OS2eCS", ":/os_os2ecs.png");
|
---|
374 | m_guestOSTypeIconNames.insert("OS2ArcaOS", ":/os_os2_other.png"); /** @todo icon? */
|
---|
375 | m_guestOSTypeIconNames.insert("OS21x", ":/os_os2_other.png");
|
---|
376 | m_guestOSTypeIconNames.insert("OS2", ":/os_os2_other.png");
|
---|
377 | m_guestOSTypeIconNames.insert("Linux22", ":/os_linux22_32.png");
|
---|
378 | m_guestOSTypeIconNames.insert("Linux24", ":/os_linux24_32.png");
|
---|
379 | m_guestOSTypeIconNames.insert("Linux24_64", ":/os_linux24.png");
|
---|
380 | m_guestOSTypeIconNames.insert("Linux26", ":/os_linux26_32.png");
|
---|
381 | m_guestOSTypeIconNames.insert("Linux26_64", ":/os_linux26.png");
|
---|
382 | m_guestOSTypeIconNames.insert("ArchLinux", ":/os_archlinux_32.png");
|
---|
383 | m_guestOSTypeIconNames.insert("ArchLinux_64", ":/os_archlinux.png");
|
---|
384 | m_guestOSTypeIconNames.insert("Debian", ":/os_debian_32.png");
|
---|
385 | m_guestOSTypeIconNames.insert("Debian_64", ":/os_debian.png");
|
---|
386 | m_guestOSTypeIconNames.insert("Debian31", ":/os_debian_32.png");
|
---|
387 | m_guestOSTypeIconNames.insert("Debian4", ":/os_debian_32.png");
|
---|
388 | m_guestOSTypeIconNames.insert("Debian4_64", ":/os_debian.png");
|
---|
389 | m_guestOSTypeIconNames.insert("Debian5", ":/os_debian_32.png");
|
---|
390 | m_guestOSTypeIconNames.insert("Debian5_64", ":/os_debian.png");
|
---|
391 | m_guestOSTypeIconNames.insert("Debian5", ":/os_debian_32.png");
|
---|
392 | m_guestOSTypeIconNames.insert("Debian5_64", ":/os_debian.png");
|
---|
393 | m_guestOSTypeIconNames.insert("Debian6", ":/os_debian_32.png");
|
---|
394 | m_guestOSTypeIconNames.insert("Debian6_64", ":/os_debian.png");
|
---|
395 | m_guestOSTypeIconNames.insert("Debian7", ":/os_debian_32.png");
|
---|
396 | m_guestOSTypeIconNames.insert("Debian7_64", ":/os_debian.png");
|
---|
397 | m_guestOSTypeIconNames.insert("Debian8", ":/os_debian_32.png");
|
---|
398 | m_guestOSTypeIconNames.insert("Debian8_64", ":/os_debian.png");
|
---|
399 | m_guestOSTypeIconNames.insert("Debian9", ":/os_debian_32.png");
|
---|
400 | m_guestOSTypeIconNames.insert("Debian9_64", ":/os_debian.png");
|
---|
401 | m_guestOSTypeIconNames.insert("Debian10", ":/os_debian_32.png");
|
---|
402 | m_guestOSTypeIconNames.insert("Debian10_64", ":/os_debian.png");
|
---|
403 | m_guestOSTypeIconNames.insert("Debian11", ":/os_debian_32.png");
|
---|
404 | m_guestOSTypeIconNames.insert("Debian11_64", ":/os_debian.png");
|
---|
405 | m_guestOSTypeIconNames.insert("OpenSUSE", ":/os_opensuse_32.png");
|
---|
406 | m_guestOSTypeIconNames.insert("OpenSUSE_64", ":/os_opensuse.png");
|
---|
407 | m_guestOSTypeIconNames.insert("OpenSUSE_Leap_64", ":/os_opensuse.png");
|
---|
408 | m_guestOSTypeIconNames.insert("OpenSUSE_Tumbleweed", ":/os_opensuse_32.png");
|
---|
409 | m_guestOSTypeIconNames.insert("OpenSUSE_Tumbleweed_64", ":/os_opensuse.png");
|
---|
410 | m_guestOSTypeIconNames.insert("SUSE_LE", ":/os_opensuse_32.png");
|
---|
411 | m_guestOSTypeIconNames.insert("SUSE_LE_64", ":/os_opensuse.png");
|
---|
412 | m_guestOSTypeIconNames.insert("Fedora", ":/os_fedora_32.png");
|
---|
413 | m_guestOSTypeIconNames.insert("Fedora_64", ":/os_fedora.png");
|
---|
414 | m_guestOSTypeIconNames.insert("Gentoo", ":/os_gentoo_32.png");
|
---|
415 | m_guestOSTypeIconNames.insert("Gentoo_64", ":/os_gentoo.png");
|
---|
416 | m_guestOSTypeIconNames.insert("Mandriva", ":/os_mandriva_32.png");
|
---|
417 | m_guestOSTypeIconNames.insert("Mandriva_64", ":/os_mandriva.png");
|
---|
418 | m_guestOSTypeIconNames.insert("OpenMandriva_Lx", ":/os_mandriva_32.png");
|
---|
419 | m_guestOSTypeIconNames.insert("OpenMandriva_Lx_64", ":/os_mandriva.png");
|
---|
420 | m_guestOSTypeIconNames.insert("PCLinuxOS", ":/os_mandriva_32.png");
|
---|
421 | m_guestOSTypeIconNames.insert("PCLinuxOS_64", ":/os_mandriva.png");
|
---|
422 | m_guestOSTypeIconNames.insert("Mageia", ":/os_mandriva_32.png");
|
---|
423 | m_guestOSTypeIconNames.insert("Mageia_64", ":/os_mandriva.png");
|
---|
424 | m_guestOSTypeIconNames.insert("RedHat", ":/os_redhat_32.png");
|
---|
425 | m_guestOSTypeIconNames.insert("RedHat_64", ":/os_redhat.png");
|
---|
426 | m_guestOSTypeIconNames.insert("RedHat3", ":/os_redhat_32.png");
|
---|
427 | m_guestOSTypeIconNames.insert("RedHat3_64", ":/os_redhat.png");
|
---|
428 | m_guestOSTypeIconNames.insert("RedHat4", ":/os_redhat_32.png");
|
---|
429 | m_guestOSTypeIconNames.insert("RedHat4_64", ":/os_redhat.png");
|
---|
430 | m_guestOSTypeIconNames.insert("RedHat5", ":/os_redhat_32.png");
|
---|
431 | m_guestOSTypeIconNames.insert("RedHat5_64", ":/os_redhat.png");
|
---|
432 | m_guestOSTypeIconNames.insert("RedHat6", ":/os_redhat_32.png");
|
---|
433 | m_guestOSTypeIconNames.insert("RedHat6_64", ":/os_redhat.png");
|
---|
434 | m_guestOSTypeIconNames.insert("RedHat7_64", ":/os_redhat.png");
|
---|
435 | m_guestOSTypeIconNames.insert("RedHat8_64", ":/os_redhat.png");
|
---|
436 | m_guestOSTypeIconNames.insert("RedHat9_64", ":/os_redhat.png");
|
---|
437 | m_guestOSTypeIconNames.insert("Turbolinux", ":/os_turbolinux_32.png");
|
---|
438 | m_guestOSTypeIconNames.insert("Turbolinux_64", ":/os_turbolinux.png");
|
---|
439 | m_guestOSTypeIconNames.insert("Ubuntu", ":/os_ubuntu_32.png");
|
---|
440 | m_guestOSTypeIconNames.insert("Ubuntu_64", ":/os_ubuntu.png");
|
---|
441 | m_guestOSTypeIconNames.insert("Ubuntu10_LTS", ":/os_ubuntu_32.png");
|
---|
442 | m_guestOSTypeIconNames.insert("Ubuntu10_LTS_64", ":/os_ubuntu.png");
|
---|
443 | m_guestOSTypeIconNames.insert("Ubuntu10", ":/os_ubuntu_32.png");
|
---|
444 | m_guestOSTypeIconNames.insert("Ubuntu10_64", ":/os_ubuntu.png");
|
---|
445 | m_guestOSTypeIconNames.insert("Ubuntu11", ":/os_ubuntu_32.png");
|
---|
446 | m_guestOSTypeIconNames.insert("Ubuntu11_64", ":/os_ubuntu.png");
|
---|
447 | m_guestOSTypeIconNames.insert("Ubuntu12_LTS", ":/os_ubuntu_32.png");
|
---|
448 | m_guestOSTypeIconNames.insert("Ubuntu12_LTS_64", ":/os_ubuntu.png");
|
---|
449 | m_guestOSTypeIconNames.insert("Ubuntu12", ":/os_ubuntu_32.png");
|
---|
450 | m_guestOSTypeIconNames.insert("Ubuntu12_64", ":/os_ubuntu.png");
|
---|
451 | m_guestOSTypeIconNames.insert("Ubuntu13", ":/os_ubuntu_32.png");
|
---|
452 | m_guestOSTypeIconNames.insert("Ubuntu13_64", ":/os_ubuntu.png");
|
---|
453 | m_guestOSTypeIconNames.insert("Ubuntu14_LTS", ":/os_ubuntu_32.png");
|
---|
454 | m_guestOSTypeIconNames.insert("Ubuntu14_LTS_64", ":/os_ubuntu.png");
|
---|
455 | m_guestOSTypeIconNames.insert("Ubuntu14", ":/os_ubuntu_32.png");
|
---|
456 | m_guestOSTypeIconNames.insert("Ubuntu14_64", ":/os_ubuntu.png");
|
---|
457 | m_guestOSTypeIconNames.insert("Ubuntu15", ":/os_ubuntu_32.png");
|
---|
458 | m_guestOSTypeIconNames.insert("Ubuntu15_64", ":/os_ubuntu.png");
|
---|
459 | m_guestOSTypeIconNames.insert("Ubuntu16_LTS", ":/os_ubuntu_32.png");
|
---|
460 | m_guestOSTypeIconNames.insert("Ubuntu16_LTS_64", ":/os_ubuntu.png");
|
---|
461 | m_guestOSTypeIconNames.insert("Ubuntu16", ":/os_ubuntu_32.png");
|
---|
462 | m_guestOSTypeIconNames.insert("Ubuntu16_64", ":/os_ubuntu.png");
|
---|
463 | m_guestOSTypeIconNames.insert("Ubuntu17", ":/os_ubuntu_32.png");
|
---|
464 | m_guestOSTypeIconNames.insert("Ubuntu17_64", ":/os_ubuntu.png");
|
---|
465 | m_guestOSTypeIconNames.insert("Ubuntu18_LTS", ":/os_ubuntu_32.png");
|
---|
466 | m_guestOSTypeIconNames.insert("Ubuntu18_LTS_64", ":/os_ubuntu.png");
|
---|
467 | m_guestOSTypeIconNames.insert("Ubuntu18", ":/os_ubuntu_32.png");
|
---|
468 | m_guestOSTypeIconNames.insert("Ubuntu18_64", ":/os_ubuntu.png");
|
---|
469 | m_guestOSTypeIconNames.insert("Ubuntu19", ":/os_ubuntu_32.png");
|
---|
470 | m_guestOSTypeIconNames.insert("Ubuntu19_64", ":/os_ubuntu.png");
|
---|
471 | m_guestOSTypeIconNames.insert("Ubuntu20_LTS_64", ":/os_ubuntu.png");
|
---|
472 | m_guestOSTypeIconNames.insert("Ubuntu20_64", ":/os_ubuntu.png");
|
---|
473 | m_guestOSTypeIconNames.insert("Ubuntu21_LTS_64", ":/os_ubuntu.png");
|
---|
474 | m_guestOSTypeIconNames.insert("Ubuntu21_64", ":/os_ubuntu.png");
|
---|
475 | m_guestOSTypeIconNames.insert("Ubuntu22_LTS_64", ":/os_ubuntu.png");
|
---|
476 | m_guestOSTypeIconNames.insert("Ubuntu22_64", ":/os_ubuntu.png");
|
---|
477 | m_guestOSTypeIconNames.insert("Lubuntu", ":/os_ubuntu_32.png");
|
---|
478 | m_guestOSTypeIconNames.insert("Lubuntu_64", ":/os_ubuntu.png");
|
---|
479 | m_guestOSTypeIconNames.insert("Xubuntu", ":/os_ubuntu_32.png");
|
---|
480 | m_guestOSTypeIconNames.insert("Xubuntu_64", ":/os_ubuntu.png");
|
---|
481 | m_guestOSTypeIconNames.insert("Xandros", ":/os_xandros_32.png");
|
---|
482 | m_guestOSTypeIconNames.insert("Xandros_64", ":/os_xandros.png");
|
---|
483 | m_guestOSTypeIconNames.insert("Oracle", ":/os_oracle_32.png");
|
---|
484 | m_guestOSTypeIconNames.insert("Oracle_64", ":/os_oracle.png");
|
---|
485 | m_guestOSTypeIconNames.insert("Oracle3", ":/os_oracle_32.png");
|
---|
486 | m_guestOSTypeIconNames.insert("Oracle3_64", ":/os_oracle.png");
|
---|
487 | m_guestOSTypeIconNames.insert("Oracle4", ":/os_oracle_32.png");
|
---|
488 | m_guestOSTypeIconNames.insert("Oracle4_64", ":/os_oracle.png");
|
---|
489 | m_guestOSTypeIconNames.insert("Oracle5", ":/os_oracle_32.png");
|
---|
490 | m_guestOSTypeIconNames.insert("Oracle5_64", ":/os_oracle.png");
|
---|
491 | m_guestOSTypeIconNames.insert("Oracle6", ":/os_oracle_32.png");
|
---|
492 | m_guestOSTypeIconNames.insert("Oracle6_64", ":/os_oracle.png");
|
---|
493 | m_guestOSTypeIconNames.insert("Oracle7_64", ":/os_oracle.png");
|
---|
494 | m_guestOSTypeIconNames.insert("Oracle8_64", ":/os_oracle.png");
|
---|
495 | m_guestOSTypeIconNames.insert("Oracle9_64", ":/os_oracle.png");
|
---|
496 | m_guestOSTypeIconNames.insert("Oracle", ":/os_oracle_32.png");
|
---|
497 | m_guestOSTypeIconNames.insert("Oracle_64", ":/os_oracle.png");
|
---|
498 | m_guestOSTypeIconNames.insert("Linux", ":/os_linux_32.png");
|
---|
499 | m_guestOSTypeIconNames.insert("Linux_64", ":/os_linux.png");
|
---|
500 | m_guestOSTypeIconNames.insert("FreeBSD", ":/os_freebsd_32.png");
|
---|
501 | m_guestOSTypeIconNames.insert("FreeBSD_64", ":/os_freebsd.png");
|
---|
502 | m_guestOSTypeIconNames.insert("OpenBSD", ":/os_openbsd_32.png");
|
---|
503 | m_guestOSTypeIconNames.insert("OpenBSD_64", ":/os_openbsd.png");
|
---|
504 | m_guestOSTypeIconNames.insert("NetBSD", ":/os_netbsd_32.png");
|
---|
505 | m_guestOSTypeIconNames.insert("NetBSD_64", ":/os_netbsd.png");
|
---|
506 | m_guestOSTypeIconNames.insert("Solaris", ":/os_solaris_32.png");
|
---|
507 | m_guestOSTypeIconNames.insert("Solaris_64", ":/os_solaris.png");
|
---|
508 | m_guestOSTypeIconNames.insert("Solaris10U8_or_later", ":/os_solaris_32.png");
|
---|
509 | m_guestOSTypeIconNames.insert("Solaris10U8_or_later_64", ":/os_solaris.png");
|
---|
510 | m_guestOSTypeIconNames.insert("OpenSolaris", ":/os_oraclesolaris_32.png");
|
---|
511 | m_guestOSTypeIconNames.insert("OpenSolaris_64", ":/os_oraclesolaris.png");
|
---|
512 | m_guestOSTypeIconNames.insert("Solaris11_64", ":/os_oraclesolaris.png");
|
---|
513 | m_guestOSTypeIconNames.insert("QNX", ":/os_qnx.png");
|
---|
514 | m_guestOSTypeIconNames.insert("MacOS", ":/os_macosx_32.png");
|
---|
515 | m_guestOSTypeIconNames.insert("MacOS_64", ":/os_macosx.png");
|
---|
516 | m_guestOSTypeIconNames.insert("MacOS106", ":/os_macosx_32.png");
|
---|
517 | m_guestOSTypeIconNames.insert("MacOS106_64", ":/os_macosx.png");
|
---|
518 | m_guestOSTypeIconNames.insert("MacOS107_64", ":/os_macosx.png");
|
---|
519 | m_guestOSTypeIconNames.insert("MacOS108_64", ":/os_macosx.png");
|
---|
520 | m_guestOSTypeIconNames.insert("MacOS109_64", ":/os_macosx.png");
|
---|
521 | m_guestOSTypeIconNames.insert("MacOS1010_64", ":/os_macosx.png");
|
---|
522 | m_guestOSTypeIconNames.insert("MacOS1011_64", ":/os_macosx.png");
|
---|
523 | m_guestOSTypeIconNames.insert("MacOS1012_64", ":/os_macosx.png");
|
---|
524 | m_guestOSTypeIconNames.insert("MacOS1013_64", ":/os_macosx.png");
|
---|
525 | m_guestOSTypeIconNames.insert("JRockitVE", ":/os_jrockitve.png");
|
---|
526 | m_guestOSTypeIconNames.insert("VBoxBS_64", ":/os_other.png");
|
---|
527 | m_guestOSTypeIconNames.insert("Cloud", ":/os_cloud.png");
|
---|
528 |
|
---|
529 | /* Prepare warning/error icons: */
|
---|
530 | m_pixWarning = defaultIcon(UIDefaultIconType_MessageBoxWarning).pixmap(16, 16);
|
---|
531 | Assert(!m_pixWarning.isNull());
|
---|
532 | m_pixError = defaultIcon(UIDefaultIconType_MessageBoxCritical).pixmap(16, 16);
|
---|
533 | Assert(!m_pixError.isNull());
|
---|
534 | }
|
---|
535 |
|
---|
536 | UIIconPoolGeneral::~UIIconPoolGeneral()
|
---|
537 | {
|
---|
538 | /* Deinit instance: */
|
---|
539 | s_pInstance = 0;
|
---|
540 | }
|
---|
541 |
|
---|
542 | QIcon UIIconPoolGeneral::userMachineIcon(const CMachine &comMachine) const
|
---|
543 | {
|
---|
544 | /* Make sure machine is not NULL: */
|
---|
545 | AssertReturn(comMachine.isNotNull(), QIcon());
|
---|
546 |
|
---|
547 | /* Get machine ID: */
|
---|
548 | const QUuid uMachineId = comMachine.GetId();
|
---|
549 | AssertReturn(comMachine.isOk(), QIcon());
|
---|
550 |
|
---|
551 | /* Prepare icon: */
|
---|
552 | QIcon icon;
|
---|
553 |
|
---|
554 | /* 1. First, load icon from IMachine extra-data: */
|
---|
555 | if (icon.isNull())
|
---|
556 | {
|
---|
557 | foreach (const QString &strIconName, gEDataManager->machineWindowIconNames(uMachineId))
|
---|
558 | if (!strIconName.isEmpty() && QFile::exists(strIconName))
|
---|
559 | icon.addFile(strIconName);
|
---|
560 | }
|
---|
561 |
|
---|
562 | /* 2. Otherwise, load icon from IMachine interface itself: */
|
---|
563 | if (icon.isNull())
|
---|
564 | {
|
---|
565 | const QVector<BYTE> byteVector = comMachine.GetIcon();
|
---|
566 | AssertReturn(comMachine.isOk(), QPixmap());
|
---|
567 | const QByteArray byteArray = QByteArray::fromRawData(reinterpret_cast<const char*>(byteVector.constData()), byteVector.size());
|
---|
568 | const QImage image = QImage::fromData(byteArray);
|
---|
569 | if (!image.isNull())
|
---|
570 | {
|
---|
571 | QPixmap pixmap = QPixmap::fromImage(image);
|
---|
572 | const int iMinimumLength = qMin(pixmap.width(), pixmap.height());
|
---|
573 | if (pixmap.width() != iMinimumLength || pixmap.height() != iMinimumLength)
|
---|
574 | pixmap = pixmap.scaled(QSize(iMinimumLength, iMinimumLength), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
---|
575 | icon.addPixmap(pixmap);
|
---|
576 | }
|
---|
577 | }
|
---|
578 |
|
---|
579 | /* Return icon: */
|
---|
580 | return icon;
|
---|
581 | }
|
---|
582 |
|
---|
583 | QPixmap UIIconPoolGeneral::userMachinePixmap(const CMachine &comMachine, const QSize &size) const
|
---|
584 | {
|
---|
585 | /* Acquire icon: */
|
---|
586 | const QIcon icon = userMachineIcon(comMachine);
|
---|
587 |
|
---|
588 | /* Prepare pixmap: */
|
---|
589 | QPixmap pixmap;
|
---|
590 |
|
---|
591 | /* Check whether we have valid icon: */
|
---|
592 | if (!icon.isNull())
|
---|
593 | {
|
---|
594 | /* Get pixmap of requested size: */
|
---|
595 | pixmap = icon.pixmap(size);
|
---|
596 | /* And even scale it if size is not valid: */
|
---|
597 | if (pixmap.size() != size)
|
---|
598 | pixmap = pixmap.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
---|
599 | }
|
---|
600 |
|
---|
601 | /* Return pixmap: */
|
---|
602 | return pixmap;
|
---|
603 | }
|
---|
604 |
|
---|
605 | QPixmap UIIconPoolGeneral::userMachinePixmapDefault(const CMachine &comMachine, QSize *pLogicalSize /* = 0 */) const
|
---|
606 | {
|
---|
607 | /* Acquire icon: */
|
---|
608 | const QIcon icon = userMachineIcon(comMachine);
|
---|
609 |
|
---|
610 | /* Prepare pixmap: */
|
---|
611 | QPixmap pixmap;
|
---|
612 |
|
---|
613 | /* Check whether we have valid icon: */
|
---|
614 | if (!icon.isNull())
|
---|
615 | {
|
---|
616 | /* Determine desired icon size: */
|
---|
617 | const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);
|
---|
618 | const QSize iconSize = QSize(iIconMetric, iIconMetric);
|
---|
619 |
|
---|
620 | /* Pass up logical size if necessary: */
|
---|
621 | if (pLogicalSize)
|
---|
622 | *pLogicalSize = iconSize;
|
---|
623 |
|
---|
624 | /* Get pixmap of requested size: */
|
---|
625 | pixmap = icon.pixmap(iconSize);
|
---|
626 | }
|
---|
627 |
|
---|
628 | /* Return pixmap: */
|
---|
629 | return pixmap;
|
---|
630 | }
|
---|
631 |
|
---|
632 | QIcon UIIconPoolGeneral::guestOSTypeIcon(const QString &strOSTypeID) const
|
---|
633 | {
|
---|
634 | /* Prepare fallback icon: */
|
---|
635 | static QPixmap nullIcon(":/os_other.png");
|
---|
636 |
|
---|
637 | /* If we do NOT have that 'guest OS type' icon cached already: */
|
---|
638 | if (!m_guestOSTypeIcons.contains(strOSTypeID))
|
---|
639 | {
|
---|
640 | /* Compose proper icon if we have that 'guest OS type' known: */
|
---|
641 | if (m_guestOSTypeIconNames.contains(strOSTypeID))
|
---|
642 | m_guestOSTypeIcons[strOSTypeID] = iconSet(m_guestOSTypeIconNames[strOSTypeID]);
|
---|
643 | /* Assign fallback icon if we do NOT have that 'guest OS type' registered: */
|
---|
644 | else if (!strOSTypeID.isNull())
|
---|
645 | m_guestOSTypeIcons[strOSTypeID] = iconSet(m_guestOSTypeIconNames["Other"]);
|
---|
646 | /* Assign fallback icon if we do NOT have that 'guest OS type' known: */
|
---|
647 | else
|
---|
648 | m_guestOSTypeIcons[strOSTypeID] = iconSet(nullIcon);
|
---|
649 | }
|
---|
650 |
|
---|
651 | /* Retrieve corresponding icon: */
|
---|
652 | const QIcon &icon = m_guestOSTypeIcons[strOSTypeID];
|
---|
653 | AssertMsgReturn(!icon.isNull(),
|
---|
654 | ("Undefined icon for type '%s'.", strOSTypeID.toLatin1().constData()),
|
---|
655 | nullIcon);
|
---|
656 |
|
---|
657 | /* Return icon: */
|
---|
658 | return icon;
|
---|
659 | }
|
---|
660 |
|
---|
661 | QPixmap UIIconPoolGeneral::guestOSTypePixmap(const QString &strOSTypeID, const QSize &size) const
|
---|
662 | {
|
---|
663 | /* Acquire icon: */
|
---|
664 | const QIcon icon = guestOSTypeIcon(strOSTypeID);
|
---|
665 |
|
---|
666 | /* Prepare pixmap: */
|
---|
667 | QPixmap pixmap;
|
---|
668 |
|
---|
669 | /* Check whether we have valid icon: */
|
---|
670 | if (!icon.isNull())
|
---|
671 | {
|
---|
672 | /* Get pixmap of requested size: */
|
---|
673 | pixmap = icon.pixmap(size);
|
---|
674 | /* And even scale it if size is not valid: */
|
---|
675 | if (pixmap.size() != size)
|
---|
676 | pixmap = pixmap.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
---|
677 | }
|
---|
678 |
|
---|
679 | /* Return pixmap: */
|
---|
680 | return pixmap;
|
---|
681 | }
|
---|
682 |
|
---|
683 | QPixmap UIIconPoolGeneral::guestOSTypePixmapDefault(const QString &strOSTypeID, QSize *pLogicalSize /* = 0 */) const
|
---|
684 | {
|
---|
685 | /* Acquire icon: */
|
---|
686 | const QIcon icon = guestOSTypeIcon(strOSTypeID);
|
---|
687 |
|
---|
688 | /* Prepare pixmap: */
|
---|
689 | QPixmap pixmap;
|
---|
690 |
|
---|
691 | /* Check whether we have valid icon: */
|
---|
692 | if (!icon.isNull())
|
---|
693 | {
|
---|
694 | /* Determine desired icon size: */
|
---|
695 | const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);
|
---|
696 | const QSize iconSize = QSize(iIconMetric, iIconMetric);
|
---|
697 |
|
---|
698 | /* Pass up logical size if necessary: */
|
---|
699 | if (pLogicalSize)
|
---|
700 | *pLogicalSize = iconSize;
|
---|
701 |
|
---|
702 | /* Get pixmap of requested size (take into account the DPI of the main shown window, if possible): */
|
---|
703 | if (windowManager().mainWindowShown() && windowManager().mainWindowShown()->windowHandle())
|
---|
704 | #ifndef VBOX_IS_QT6_OR_LATER /* QIcon::pixmap taking QWindow is deprecated in Qt6 */
|
---|
705 | pixmap = icon.pixmap(windowManager().mainWindowShown()->windowHandle(), iconSize);
|
---|
706 | #else
|
---|
707 | {
|
---|
708 | const qreal fDevicePixelRatio = windowManager().mainWindowShown()->windowHandle()->devicePixelRatio();
|
---|
709 | pixmap = icon.pixmap(iconSize, fDevicePixelRatio);
|
---|
710 | }
|
---|
711 | #endif
|
---|
712 | else
|
---|
713 | pixmap = icon.pixmap(iconSize);
|
---|
714 | }
|
---|
715 |
|
---|
716 | /* Return pixmap: */
|
---|
717 | return pixmap;
|
---|
718 | }
|
---|