VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/UIIconPool.cpp@ 102493

Last change on this file since 102493 was 102102, checked in by vboxsync, 10 months ago

FE/Qt: bugref:10535. Using API properties rather than string comparison to determine verlay string.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 42.8 KB
Line 
1/* $Id: UIIconPool.cpp 102102 2023-11-15 13:35:02Z 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#include <QWindow>
35
36/* GUI includes: */
37#include "UICommon.h"
38#include "UIIconPool.h"
39#include "UIExtraDataManager.h"
40#include "UIGuestOSType.h"
41#include "UIModalWindowManager.h"
42
43/* COM includes: */
44#include "COMEnums.h"
45#include "CMachine.h"
46#include <VBox/com/VirtualBox.h> /* Need GUEST_OS_ID_STR_X86 and friends. */
47
48/* Other VBox includes: */
49#include <iprt/assert.h>
50
51
52/*********************************************************************************************************************************
53* Class UIIconPool implementation. *
54*********************************************************************************************************************************/
55
56/* static */
57QPixmap UIIconPool::pixmap(const QString &strName)
58{
59 /* Reuse iconSet API: */
60 QIcon icon = iconSet(strName);
61
62 /* Return pixmap of first available size: */
63 const int iHint = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
64 return icon.pixmap(icon.availableSizes().value(0, QSize(iHint, iHint)));
65}
66
67/* static */
68QIcon UIIconPool::iconSet(const QString &strNormal,
69 const QString &strDisabled /* = QString() */,
70 const QString &strActive /* = QString() */)
71{
72 /* Prepare fallback icon: */
73 static QIcon nullIcon;
74
75 /* Prepare icon: */
76 QIcon icon;
77
78 /* Add 'normal' pixmap: */
79 AssertReturn(!strNormal.isEmpty(), nullIcon);
80 addName(icon, strNormal, QIcon::Normal);
81
82 /* Add 'disabled' pixmap (if any): */
83 if (!strDisabled.isEmpty())
84 addName(icon, strDisabled, QIcon::Disabled);
85
86 /* Add 'active' pixmap (if any): */
87 if (!strActive.isEmpty())
88 addName(icon, strActive, QIcon::Active);
89
90 /* Return icon: */
91 return icon;
92}
93
94/* static */
95QIcon UIIconPool::iconSetOnOff(const QString &strNormal, const QString strNormalOff,
96 const QString &strDisabled /* = QString() */, const QString &strDisabledOff /* = QString() */,
97 const QString &strActive /* = QString() */, const QString &strActiveOff /* = QString() */)
98{
99 /* Prepare fallback icon: */
100 static QIcon nullIcon;
101
102 /* Prepare icon: */
103 QIcon icon;
104
105 /* Add 'normal' on/off pixmaps: */
106 AssertReturn(!strNormal.isEmpty(), nullIcon);
107 addName(icon, strNormal, QIcon::Normal, QIcon::On);
108 AssertReturn(!strNormalOff.isEmpty(), nullIcon);
109 addName(icon, strNormalOff, QIcon::Normal, QIcon::Off);
110
111 /* Add 'disabled' on/off pixmaps (if any): */
112 if (!strDisabled.isEmpty())
113 addName(icon, strDisabled, QIcon::Disabled, QIcon::On);
114 if (!strDisabledOff.isEmpty())
115 addName(icon, strDisabledOff, QIcon::Disabled, QIcon::Off);
116
117 /* Add 'active' on/off pixmaps (if any): */
118 if (!strActive.isEmpty())
119 addName(icon, strActive, QIcon::Active, QIcon::On);
120 if (!strActiveOff.isEmpty())
121 addName(icon, strActiveOff, QIcon::Active, QIcon::Off);
122
123 /* Return icon: */
124 return icon;
125}
126
127/* static */
128QIcon UIIconPool::iconSetFull(const QString &strNormal, const QString &strSmall,
129 const QString &strNormalDisabled /* = QString() */, const QString &strSmallDisabled /* = QString() */,
130 const QString &strNormalActive /* = QString() */, const QString &strSmallActive /* = QString() */)
131{
132 /* Prepare fallback icon: */
133 static QIcon nullIcon;
134
135 /* Prepare icon: */
136 QIcon icon;
137
138 /* Add 'normal' & 'small normal' pixmaps: */
139 AssertReturn(!strNormal.isEmpty(), nullIcon);
140 addName(icon, strNormal, QIcon::Normal);
141 AssertReturn(!strSmall.isEmpty(), nullIcon);
142 addName(icon, strSmall, QIcon::Normal);
143
144 /* Add 'disabled' & 'small disabled' pixmaps (if any): */
145 if (!strNormalDisabled.isEmpty())
146 addName(icon, strNormalDisabled, QIcon::Disabled);
147 if (!strSmallDisabled.isEmpty())
148 addName(icon, strSmallDisabled, QIcon::Disabled);
149
150 /* Add 'active' & 'small active' pixmaps (if any): */
151 if (!strNormalActive.isEmpty())
152 addName(icon, strNormalActive, QIcon::Active);
153 if (!strSmallActive.isEmpty())
154 addName(icon, strSmallActive, QIcon::Active);
155
156 /* Return icon: */
157 return icon;
158}
159
160/* static */
161QIcon UIIconPool::iconSet(const QPixmap &normal,
162 const QPixmap &disabled /* = QPixmap() */,
163 const QPixmap &active /* = QPixmap() */)
164{
165 QIcon iconSet;
166
167 Assert(!normal.isNull());
168 iconSet.addPixmap(normal, QIcon::Normal);
169
170 if (!disabled.isNull())
171 iconSet.addPixmap(disabled, QIcon::Disabled);
172
173 if (!active.isNull())
174 iconSet.addPixmap(active, QIcon::Active);
175
176 return iconSet;
177}
178
179/* static */
180QIcon UIIconPool::defaultIcon(UIDefaultIconType defaultIconType, const QWidget *pWidget /* = 0 */)
181{
182 QIcon icon;
183 QStyle *pStyle = pWidget ? pWidget->style() : QApplication::style();
184 switch (defaultIconType)
185 {
186 case UIDefaultIconType_MessageBoxInformation:
187 {
188 icon = pStyle->standardIcon(QStyle::SP_MessageBoxInformation, 0, pWidget);
189 break;
190 }
191 case UIDefaultIconType_MessageBoxQuestion:
192 {
193 icon = pStyle->standardIcon(QStyle::SP_MessageBoxQuestion, 0, pWidget);
194 break;
195 }
196 case UIDefaultIconType_MessageBoxWarning:
197 {
198#ifdef VBOX_WS_MAC
199 /* At least in Qt 4.3.4/4.4 RC1 SP_MessageBoxWarning is the application
200 * icon. So change this to the critical icon. (Maybe this would be
201 * fixed in a later Qt version) */
202 icon = pStyle->standardIcon(QStyle::SP_MessageBoxCritical, 0, pWidget);
203#else /* VBOX_WS_MAC */
204 icon = pStyle->standardIcon(QStyle::SP_MessageBoxWarning, 0, pWidget);
205#endif /* !VBOX_WS_MAC */
206 break;
207 }
208 case UIDefaultIconType_MessageBoxCritical:
209 {
210 icon = pStyle->standardIcon(QStyle::SP_MessageBoxCritical, 0, pWidget);
211 break;
212 }
213 case UIDefaultIconType_DialogCancel:
214 {
215 icon = pStyle->standardIcon(QStyle::SP_DialogCancelButton, 0, pWidget);
216 if (icon.isNull())
217 icon = iconSet(":/cancel_16px.png");
218 break;
219 }
220 case UIDefaultIconType_DialogHelp:
221 {
222 icon = pStyle->standardIcon(QStyle::SP_DialogHelpButton, 0, pWidget);
223 if (icon.isNull())
224 icon = iconSet(":/help_16px.png");
225 break;
226 }
227 case UIDefaultIconType_ArrowBack:
228 {
229 icon = pStyle->standardIcon(QStyle::SP_ArrowBack, 0, pWidget);
230 if (icon.isNull())
231 icon = iconSet(":/list_moveup_16px.png",
232 ":/list_moveup_disabled_16px.png");
233 break;
234 }
235 case UIDefaultIconType_ArrowForward:
236 {
237 icon = pStyle->standardIcon(QStyle::SP_ArrowForward, 0, pWidget);
238 if (icon.isNull())
239 icon = iconSet(":/list_movedown_16px.png",
240 ":/list_movedown_disabled_16px.png");
241 break;
242 }
243 default:
244 {
245 AssertMsgFailed(("Unknown default icon type!"));
246 break;
247 }
248 }
249 return icon;
250}
251
252/* static */
253QPixmap UIIconPool::joinPixmaps(const QPixmap &pixmap1, const QPixmap &pixmap2)
254{
255 if (pixmap1.isNull())
256 return pixmap2;
257 if (pixmap2.isNull())
258 return pixmap1;
259
260 QPixmap result(pixmap1.width() + pixmap2.width() + 2,
261 qMax(pixmap1.height(), pixmap2.height()));
262 result.fill(Qt::transparent);
263
264 QPainter painter(&result);
265 painter.drawPixmap(0, 0, pixmap1);
266 painter.drawPixmap(pixmap1.width() + 2, result.height() - pixmap2.height(), pixmap2);
267 painter.end();
268
269 return result;
270}
271
272/* static */
273void UIIconPool::addName(QIcon &icon, const QString &strName,
274 QIcon::Mode mode /* = QIcon::Normal */, QIcon::State state /* = QIcon::Off */)
275{
276 /* Prepare pixmap on the basis of passed value: */
277 QPixmap pixmap(strName);
278 /* Add pixmap: */
279 icon.addPixmap(pixmap, mode, state);
280
281 /* Parse name to prefix and suffix: */
282 QString strPrefix = strName.section('.', 0, -2);
283 QString strSuffix = strName.section('.', -1, -1);
284 /* Prepare HiDPI pixmaps: */
285 const QStringList aPixmapNames = QStringList() << (strPrefix + "_x2." + strSuffix)
286 << (strPrefix + "_x3." + strSuffix)
287 << (strPrefix + "_x4." + strSuffix);
288 foreach (const QString &strPixmapName, aPixmapNames)
289 {
290 QPixmap pixmapHiDPI(strPixmapName);
291 if (!pixmapHiDPI.isNull())
292 icon.addPixmap(pixmapHiDPI, mode, state);
293 }
294}
295
296
297/*********************************************************************************************************************************
298* Class UIIconPoolGeneral implementation. *
299*********************************************************************************************************************************/
300
301/* static */
302UIIconPoolGeneral *UIIconPoolGeneral::s_pInstance = 0;
303
304/* static */
305void UIIconPoolGeneral::create()
306{
307 AssertReturnVoid(!s_pInstance);
308 new UIIconPoolGeneral;
309}
310
311/* static */
312void UIIconPoolGeneral::destroy()
313{
314 AssertPtrReturnVoid(s_pInstance);
315 delete s_pInstance;
316}
317
318/* static */
319UIIconPoolGeneral *UIIconPoolGeneral::instance()
320{
321 return s_pInstance;
322}
323
324UIIconPoolGeneral::UIIconPoolGeneral()
325{
326 /* Init instance: */
327 s_pInstance = this;
328
329 /* Prepare OS type icon-name hash: */
330 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Other"), ":/os_other.png");
331 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Other"), ":/os_other.png");
332 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("Other"), ":/os_other.png");
333 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("DOS"), ":/os_dos.png");
334 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Netware"), ":/os_netware.png");
335 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("L4"), ":/os_l4.png");
336 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Windows31"), ":/os_win31.png");
337 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Windows95"), ":/os_win95.png");
338 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Windows98"), ":/os_win98.png");
339 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("WindowsMe"), ":/os_winme.png");
340 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("WindowsNT3x"), ":/os_winnt4.png");
341 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("WindowsNT4"), ":/os_winnt4.png");
342 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Windows2000"), ":/os_win2k.png");
343 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("WindowsXP"), ":/os_winxp.png");
344 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("WindowsXP"), ":/os_winxp.png");
345 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Windows2003"), ":/os_win2k3.png");
346 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Windows2003"), ":/os_win2k3.png");
347 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("WindowsVista"), ":/os_winvista.png");
348 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("WindowsVista"), ":/os_winvista.png");
349 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Windows2008"), ":/os_win2k8.png");
350 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Windows2008"), ":/os_win2k8.png");
351 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Windows7"), ":/os_win7.png");
352 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Windows7"), ":/os_win7.png");
353 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Windows8"), ":/os_win8.png");
354 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Windows8"), ":/os_win8.png");
355 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Windows81"), ":/os_win81.png");
356 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Windows81"), ":/os_win81.png");
357 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Windows2012"), ":/os_win2k12.png");
358 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Windows10"), ":/os_win10.png");
359 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Windows10"), ":/os_win10.png");
360 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Windows11"), ":/os_win11.png");
361 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Windows2016"), ":/os_win2k16.png");
362 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Windows2019"), ":/os_win2k19.png");
363 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Windows2022"), ":/os_win2k22.png");
364 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("WindowsNT"), ":/os_win_other.png");
365 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("WindowsNT"), ":/os_win_other.png");
366 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("OS2Warp3"), ":/os_os2warp3.png");
367 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("OS2Warp4"), ":/os_os2warp4.png");
368 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("OS2Warp45"), ":/os_os2warp45.png");
369 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("OS2eCS"), ":/os_os2ecs.png");
370 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("OS2ArcaOS"), ":/os_os2_other.png"); /** @todo icon? */
371 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("OS21x"), ":/os_os2_other.png");
372 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("OS2"), ":/os_os2_other.png");
373 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Linux22"), ":/os_linux22.png");
374 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Linux24"), ":/os_linux24.png");
375 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Linux24"), ":/os_linux24.png");
376 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Linux26"), ":/os_linux26.png");
377 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Linux26"), ":/os_linux26.png");
378 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("ArchLinux"), ":/os_archlinux.png");
379 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("ArchLinux"), ":/os_archlinux.png");
380 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("ArchLinux"), ":/os_archlinux.png");
381 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Debian"), ":/os_debian.png");
382 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Debian"), ":/os_debian.png");
383 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("Debian"), ":/os_debian.png");
384 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Debian31"), ":/os_debian.png");
385 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Debian4"), ":/os_debian.png");
386 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Debian4"), ":/os_debian.png");
387 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Debian5"), ":/os_debian.png");
388 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Debian5"), ":/os_debian.png");
389 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Debian5"), ":/os_debian.png");
390 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Debian5"), ":/os_debian.png");
391 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Debian6"), ":/os_debian.png");
392 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Debian6"), ":/os_debian.png");
393 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Debian7"), ":/os_debian.png");
394 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Debian7"), ":/os_debian.png");
395 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Debian8"), ":/os_debian.png");
396 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Debian8"), ":/os_debian.png");
397 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Debian9"), ":/os_debian.png");
398 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Debian9"), ":/os_debian.png");
399 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("Debian9"), ":/os_debian.png");
400 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Debian10"), ":/os_debian.png");
401 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Debian10"), ":/os_debian.png");
402 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("Debian10"), ":/os_debian.png");
403 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Debian11"), ":/os_debian.png");
404 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Debian11"), ":/os_debian.png");
405 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("Debian11"), ":/os_debian.png");
406 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Debian12"), ":/os_debian.png");
407 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Debian12"), ":/os_debian.png");
408 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("Debian12"), ":/os_debian.png");
409 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("OpenSUSE"), ":/os_opensuse.png");
410 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("OpenSUSE"), ":/os_opensuse.png");
411 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("OpenSUSE_Leap"), ":/os_opensuse.png");
412 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("OpenSUSE_Leap"), ":/os_opensuse.png");
413 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("OpenSUSE_Tumbleweed"), ":/os_opensuse.png");
414 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("OpenSUSE_Tumbleweed"), ":/os_opensuse.png");
415 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("OpenSUSE_Tumbleweed"), ":/os_opensuse.png");
416 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("SUSE_LE"), ":/os_opensuse.png");
417 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("SUSE_LE"), ":/os_opensuse.png");
418 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Fedora"), ":/os_fedora.png");
419 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Fedora"), ":/os_fedora.png");
420 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("Fedora"), ":/os_fedora.png");
421 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Gentoo"), ":/os_gentoo.png");
422 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Gentoo"), ":/os_gentoo.png");
423 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Mandriva"), ":/os_mandriva.png");
424 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Mandriva"), ":/os_mandriva.png");
425 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("OpenMandriva_Lx"), ":/os_mandriva.png");
426 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("OpenMandriva_Lx"), ":/os_mandriva.png");
427 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("PCLinuxOS"), ":/os_mandriva.png");
428 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("PCLinuxOS"), ":/os_mandriva.png");
429 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Mageia"), ":/os_mandriva.png");
430 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Mageia"), ":/os_mandriva.png");
431 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("RedHat"), ":/os_redhat.png");
432 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("RedHat"), ":/os_redhat.png");
433 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("RedHat3"), ":/os_redhat.png");
434 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("RedHat3"), ":/os_redhat.png");
435 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("RedHat4"), ":/os_redhat.png");
436 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("RedHat4"), ":/os_redhat.png");
437 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("RedHat5"), ":/os_redhat.png");
438 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("RedHat5"), ":/os_redhat.png");
439 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("RedHat6"), ":/os_redhat.png");
440 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("RedHat6"), ":/os_redhat.png");
441 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("RedHat7"), ":/os_redhat.png");
442 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("RedHat8"), ":/os_redhat.png");
443 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("RedHat9"), ":/os_redhat.png");
444 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Turbolinux"), ":/os_turbolinux.png");
445 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Turbolinux"), ":/os_turbolinux.png");
446 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Ubuntu"), ":/os_ubuntu.png");
447 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu"), ":/os_ubuntu.png");
448 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("Ubuntu"), ":/os_ubuntu.png");
449 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Ubuntu10_LTS"), ":/os_ubuntu.png");
450 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu10_LTS"), ":/os_ubuntu.png");
451 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Ubuntu10"), ":/os_ubuntu.png");
452 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu10"), ":/os_ubuntu.png");
453 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Ubuntu11"), ":/os_ubuntu.png");
454 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu11"), ":/os_ubuntu.png");
455 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Ubuntu12_LTS"), ":/os_ubuntu.png");
456 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu12_LTS"), ":/os_ubuntu.png");
457 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Ubuntu12"), ":/os_ubuntu.png");
458 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu12"), ":/os_ubuntu.png");
459 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Ubuntu13"), ":/os_ubuntu.png");
460 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu13"), ":/os_ubuntu.png");
461 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Ubuntu14_LTS"), ":/os_ubuntu.png");
462 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu14_LTS"), ":/os_ubuntu.png");
463 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Ubuntu14"), ":/os_ubuntu.png");
464 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu14"), ":/os_ubuntu.png");
465 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Ubuntu15"), ":/os_ubuntu.png");
466 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu15"), ":/os_ubuntu.png");
467 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Ubuntu16_LTS"), ":/os_ubuntu.png");
468 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu16_LTS"), ":/os_ubuntu.png");
469 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Ubuntu16"), ":/os_ubuntu.png");
470 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu16"), ":/os_ubuntu.png");
471 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Ubuntu17"), ":/os_ubuntu.png");
472 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu17"), ":/os_ubuntu.png");
473 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Ubuntu18_LTS"), ":/os_ubuntu.png");
474 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu18_LTS"), ":/os_ubuntu.png");
475 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Ubuntu18"), ":/os_ubuntu.png");
476 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu18"), ":/os_ubuntu.png");
477 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Ubuntu19"), ":/os_ubuntu.png");
478 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu19"), ":/os_ubuntu.png");
479 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu20_LTS"), ":/os_ubuntu.png");
480 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu20"), ":/os_ubuntu.png");
481 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu21_LTS"), ":/os_ubuntu.png");
482 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu21"), ":/os_ubuntu.png");
483 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu22_LTS"), ":/os_ubuntu.png");
484 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu22"), ":/os_ubuntu.png");
485 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("Ubuntu22"), ":/os_ubuntu.png");
486 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Ubuntu23"), ":/os_ubuntu.png");
487 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("Ubuntu23"), ":/os_ubuntu.png");
488 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Lubuntu"), ":/os_ubuntu.png");
489 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Lubuntu"), ":/os_ubuntu.png");
490 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Xubuntu"), ":/os_ubuntu.png");
491 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Xubuntu"), ":/os_ubuntu.png");
492 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Xandros"), ":/os_xandros.png");
493 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Xandros"), ":/os_xandros.png");
494 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Oracle"), ":/os_oracle.png");
495 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Oracle"), ":/os_oracle.png");
496 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Oracle3"), ":/os_oracle.png");
497 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Oracle3"), ":/os_oracle.png");
498 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Oracle4"), ":/os_oracle.png");
499 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Oracle4"), ":/os_oracle.png");
500 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Oracle5"), ":/os_oracle.png");
501 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Oracle5"), ":/os_oracle.png");
502 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Oracle6"), ":/os_oracle.png");
503 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Oracle6"), ":/os_oracle.png");
504 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Oracle7"), ":/os_oracle.png");
505 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Oracle8"), ":/os_oracle.png");
506 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Oracle9"), ":/os_oracle.png");
507 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("Oracle9"), ":/os_oracle.png");
508 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Oracle"), ":/os_oracle.png");
509 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Oracle"), ":/os_oracle.png");
510 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("Oracle"), ":/os_oracle.png");
511 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Linux"), ":/os_linux.png");
512 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Linux"), ":/os_linux.png");
513 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("FreeBSD"), ":/os_freebsd.png");
514 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("FreeBSD"), ":/os_freebsd.png");
515 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("FreeBSD"), ":/os_freebsd.png");
516 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("OpenBSD"), ":/os_openbsd.png");
517 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("OpenBSD"), ":/os_openbsd.png");
518 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("OpenBSD"), ":/os_openbsd.png");
519 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("NetBSD"), ":/os_netbsd.png");
520 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("NetBSD"), ":/os_netbsd.png");
521 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_A64("NetBSD"), ":/os_netbsd.png");
522 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Solaris"), ":/os_solaris.png");
523 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Solaris"), ":/os_solaris.png");
524 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Solaris10U8_or_later"), ":/os_solaris.png");
525 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Solaris10U8_or_later"), ":/os_solaris.png");
526 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("OpenSolaris"), ":/os_oraclesolaris.png");
527 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("OpenSolaris"), ":/os_oraclesolaris.png");
528 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("Solaris11"), ":/os_oraclesolaris.png");
529 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("QNX"), ":/os_qnx.png");
530 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("MacOS"), ":/os_macosx.png");
531 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("MacOS"), ":/os_macosx.png");
532 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("MacOS106"), ":/os_macosx.png");
533 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("MacOS106"), ":/os_macosx.png");
534 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("MacOS107"), ":/os_macosx.png");
535 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("MacOS108"), ":/os_macosx.png");
536 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("MacOS109"), ":/os_macosx.png");
537 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("MacOS1010"), ":/os_macosx.png");
538 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("MacOS1011"), ":/os_macosx.png");
539 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("MacOS1012"), ":/os_macosx.png");
540 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("MacOS1013"), ":/os_macosx.png");
541 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("JRockitVE"), ":/os_jrockitve.png");
542 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X64("VBoxBS"), ":/os_other.png");
543 m_guestOSTypeIconNames.insert(GUEST_OS_ID_STR_X86("Cloud"), ":/os_cloud.png");
544
545 /* Prepare warning/error icons: */
546 m_pixWarning = defaultIcon(UIDefaultIconType_MessageBoxWarning).pixmap(16, 16);
547 Assert(!m_pixWarning.isNull());
548 m_pixError = defaultIcon(UIDefaultIconType_MessageBoxCritical).pixmap(16, 16);
549 Assert(!m_pixError.isNull());
550}
551
552UIIconPoolGeneral::~UIIconPoolGeneral()
553{
554 /* Deinit instance: */
555 s_pInstance = 0;
556}
557
558/* static */
559QIcon UIIconPoolGeneral::overlayedIconSet(const QString &strGuestOSTypeId,
560 const QString &strNormal,
561 const QString &strDisabled /* = QString() */,
562 const QString &strActive /* = QString() */)
563{
564 /* Prepare fallback icon: */
565 static QIcon nullIcon;
566
567 /* Prepare icon: */
568 QIcon icon;
569
570 /* Add 'normal' pixmap: */
571 AssertReturn(!strNormal.isEmpty(), nullIcon);
572 addNameAndOverlay(icon, strNormal, strGuestOSTypeId, QIcon::Normal);
573
574 /* Add 'disabled' pixmap (if any): */
575 if (!strDisabled.isEmpty())
576 addNameAndOverlay(icon, strDisabled, strGuestOSTypeId, QIcon::Disabled);
577
578 /* Add 'active' pixmap (if any): */
579 if (!strActive.isEmpty())
580 addNameAndOverlay(icon, strActive, strGuestOSTypeId, QIcon::Active);
581
582 /* Return icon: */
583 return icon;
584}
585
586/* static */
587void UIIconPoolGeneral::addNameAndOverlay(QIcon &icon, const QString &strName, const QString &strGuestOSTypeId,
588 QIcon::Mode mode /* = QIcon::Normal */, QIcon::State state /* = QIcon::Off */ )
589{
590 /* Prepare pixmap on the basis of passed value: */
591 QPixmap pixmap(strName);
592 overlayArchitectureTextOnPixmap(determineOSArchString(strGuestOSTypeId), pixmap);
593 /* Add pixmap: */
594 icon.addPixmap(pixmap, mode, state);
595
596 /* Parse name to prefix and suffix: */
597 QString strPrefix = strName.section('.', 0, -2);
598 QString strSuffix = strName.section('.', -1, -1);
599 /* Prepare HiDPI pixmaps: */
600 const QStringList aPixmapNames = QStringList() << (strPrefix + "_x2." + strSuffix)
601 << (strPrefix + "_x3." + strSuffix)
602 << (strPrefix + "_x4." + strSuffix);
603 foreach (const QString &strPixmapName, aPixmapNames)
604 {
605 QPixmap pixmapHiDPI(strPixmapName);
606 if (!pixmapHiDPI.isNull())
607 {
608 overlayArchitectureTextOnPixmap(determineOSArchString(strGuestOSTypeId), pixmapHiDPI);
609 icon.addPixmap(pixmapHiDPI, mode, state);
610 }
611 }
612}
613
614QIcon UIIconPoolGeneral::userMachineIcon(const CMachine &comMachine) const
615{
616 /* Make sure machine is not NULL: */
617 AssertReturn(comMachine.isNotNull(), QIcon());
618
619 /* Get machine ID: */
620 const QUuid uMachineId = comMachine.GetId();
621 AssertReturn(comMachine.isOk(), QIcon());
622
623 /* Prepare icon: */
624 QIcon icon;
625
626 /* 1. First, load icon from IMachine extra-data: */
627 if (icon.isNull())
628 {
629 foreach (const QString &strIconName, gEDataManager->machineWindowIconNames(uMachineId))
630 if (!strIconName.isEmpty() && QFile::exists(strIconName))
631 icon.addFile(strIconName);
632 }
633
634 /* 2. Otherwise, load icon from IMachine interface itself: */
635 if (icon.isNull())
636 {
637 const QVector<BYTE> byteVector = comMachine.GetIcon();
638 AssertReturn(comMachine.isOk(), QPixmap());
639 const QByteArray byteArray = QByteArray::fromRawData(reinterpret_cast<const char*>(byteVector.constData()), byteVector.size());
640 const QImage image = QImage::fromData(byteArray);
641 if (!image.isNull())
642 {
643 QPixmap pixmap = QPixmap::fromImage(image);
644 const int iMinimumLength = qMin(pixmap.width(), pixmap.height());
645 if (pixmap.width() != iMinimumLength || pixmap.height() != iMinimumLength)
646 pixmap = pixmap.scaled(QSize(iMinimumLength, iMinimumLength), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
647 icon.addPixmap(pixmap);
648 }
649 }
650
651 /* Return icon: */
652 return icon;
653}
654
655QPixmap UIIconPoolGeneral::userMachinePixmap(const CMachine &comMachine, const QSize &size) const
656{
657 /* Acquire icon: */
658 const QIcon icon = userMachineIcon(comMachine);
659
660 /* Prepare pixmap: */
661 QPixmap pixmap;
662
663 /* Check whether we have valid icon: */
664 if (!icon.isNull())
665 {
666 /* Get pixmap of requested size: */
667 pixmap = icon.pixmap(size);
668 /* And even scale it if size is not valid: */
669 if (pixmap.size() != size)
670 pixmap = pixmap.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
671 }
672
673 /* Return pixmap: */
674 return pixmap;
675}
676
677QPixmap UIIconPoolGeneral::userMachinePixmapDefault(const CMachine &comMachine, QSize *pLogicalSize /* = 0 */) const
678{
679 /* Acquire icon: */
680 const QIcon icon = userMachineIcon(comMachine);
681
682 /* Prepare pixmap: */
683 QPixmap pixmap;
684
685 /* Check whether we have valid icon: */
686 if (!icon.isNull())
687 {
688 /* Determine desired icon size: */
689 const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);
690 const QSize iconSize = QSize(iIconMetric, iIconMetric);
691
692 /* Pass up logical size if necessary: */
693 if (pLogicalSize)
694 *pLogicalSize = iconSize;
695
696 /* Get pixmap of requested size: */
697 pixmap = icon.pixmap(iconSize);
698 }
699
700 /* Return pixmap: */
701 return pixmap;
702}
703
704QIcon UIIconPoolGeneral::guestOSTypeIcon(const QString &strOSTypeID) const
705{
706 /* Prepare fallback icon: */
707 static QPixmap nullIcon(":/os_other.png");
708
709 /* If we do NOT have that 'guest OS type' icon cached already: */
710 if (!m_guestOSTypeIcons.contains(strOSTypeID))
711 {
712 /* Compose proper icon if we have that 'guest OS type' known: */
713 if (m_guestOSTypeIconNames.contains(strOSTypeID))
714 m_guestOSTypeIcons[strOSTypeID] = overlayedIconSet(strOSTypeID, m_guestOSTypeIconNames[strOSTypeID]);
715 /* Assign fallback icon if we do NOT have that 'guest OS type' registered: */
716 else if (!strOSTypeID.isNull())
717 m_guestOSTypeIcons[strOSTypeID] = overlayedIconSet(strOSTypeID, m_guestOSTypeIconNames[GUEST_OS_ID_STR_X86("Other")]);
718 /* Assign fallback icon if we do NOT have that 'guest OS type' known: */
719 else
720 m_guestOSTypeIcons[strOSTypeID] = iconSet(nullIcon);
721 }
722
723 /* Retrieve corresponding icon: */
724 const QIcon &icon = m_guestOSTypeIcons[strOSTypeID];
725 AssertMsgReturn(!icon.isNull(),
726 ("Undefined icon for type '%s'.", strOSTypeID.toLatin1().constData()),
727 nullIcon);
728
729 /* Return icon: */
730 return icon;
731}
732
733QPixmap UIIconPoolGeneral::guestOSTypePixmap(const QString &strOSTypeID, const QSize &size) const
734{
735 /* Acquire icon: */
736 const QIcon icon = guestOSTypeIcon(strOSTypeID);
737
738 /* Prepare pixmap: */
739 QPixmap pixmap;
740
741 /* Check whether we have valid icon: */
742 if (!icon.isNull())
743 {
744 /* Get pixmap of requested size: */
745 pixmap = icon.pixmap(size);
746 /* And even scale it if size is not valid: */
747 if (pixmap.size() != size)
748 pixmap = pixmap.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
749 }
750
751 /* Return pixmap: */
752 return pixmap;
753}
754
755QPixmap UIIconPoolGeneral::guestOSTypePixmapDefault(const QString &strOSTypeID, QSize *pLogicalSize /* = 0 */) const
756{
757 /* Acquire icon: */
758 const QIcon icon = guestOSTypeIcon(strOSTypeID);
759
760 /* Prepare pixmap: */
761 QPixmap pixmap;
762
763 /* Check whether we have valid icon: */
764 if (!icon.isNull())
765 {
766 /* Determine desired icon size: */
767 const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);
768 const QSize iconSize = QSize(iIconMetric, iIconMetric);
769
770 /* Pass up logical size if necessary: */
771 if (pLogicalSize)
772 *pLogicalSize = iconSize;
773
774 /* Get pixmap of requested size (take into account the DPI of the main shown window, if possible): */
775 const qreal fDevicePixelRatio = windowManager().mainWindowShown() && windowManager().mainWindowShown()->windowHandle()
776 ? windowManager().mainWindowShown()->windowHandle()->devicePixelRatio() : 1;
777 pixmap = icon.pixmap(iconSize, fDevicePixelRatio);
778 }
779
780 /* Return pixmap: */
781 return pixmap;
782}
783
784/* static */
785QString UIIconPoolGeneral::determineOSArchString(const QString &strOSTypeId)
786{
787 bool fIs64Bit = uiCommon().guestOSTypeManager().is64Bit(strOSTypeId);
788 KPlatformArchitecture enmPlatformArchitecture = uiCommon().guestOSTypeManager().getPlatformArchitecture(strOSTypeId);
789
790 if (enmPlatformArchitecture == KPlatformArchitecture_ARM)
791 {
792 if (fIs64Bit)
793 return QString("A64");
794 else
795 return QString("A32");
796 }
797 else if (enmPlatformArchitecture == KPlatformArchitecture_x86)
798 {
799 if (fIs64Bit)
800 return QString("x64");
801 else
802 return QString("32");
803 }
804 return QString();
805}
806
807/* static */
808void UIIconPoolGeneral::overlayArchitectureTextOnPixmap(const QString &strArch, QPixmap &pixmap)
809{
810#if 0
811 /* First create a pixmap and draw a background and text on it: */
812 QFontMetrics fontMetrics = qApp->fontMetrics();
813 QRect rect(0, 0, fontMetrics.boundingRect(strArch).width(), fontMetrics.boundingRect(strArch).height());
814 QPixmap textPixmap(rect.size());
815
816 QPainter painter(&textPixmap);
817 QFont font = qApp->font();
818 font.setBold(true);
819 painter.setFont(font);
820 painter.setRenderHint(QPainter::Antialiasing);
821 painter.setRenderHint(QPainter::SmoothPixmapTransform);
822 painter.setRenderHint(QPainter::TextAntialiasing);
823 painter.setPen(QPen(Qt::black, 1));
824 painter.setBrush(QColor(255, 255, 255, 80));
825 painter.drawRect(rect);
826 painter.drawText(rect, Qt::AlignHCenter | Qt::AlignVCenter, strArch);
827
828 /* Now draw that^^ pixmap onto our original pixmap:*/
829 QPainter originalPixmapPainter(&pixmap);
830 originalPixmapPainter.setRenderHint(QPainter::Antialiasing);
831 originalPixmapPainter.setRenderHint(QPainter::SmoothPixmapTransform);
832 QRect targetRect(QPoint(0, 0), QSize(0.34 * pixmap.rect().width(), 0.3 * pixmap.rect().height()));
833 originalPixmapPainter.drawPixmap(targetRect, textPixmap, textPixmap.rect());
834#endif
835#if 1
836 QFont font = qApp->font();
837 /* Set font' size wrt. @p pixmap height/dpr: */
838 font.setPixelSize(0.31 * pixmap.height() / pixmap.devicePixelRatio());
839 font.setBold(true);
840 QPainter painter(&pixmap);
841 painter.setFont(font);
842 /* Make a rectangle just a bit larger than text's bounding rect. to have some spacing around the text: */
843 int w = 1.2 * painter.fontMetrics().boundingRect(strArch).size().width();
844 int h = 1.0 * painter.fontMetrics().boundingRect(strArch).size().height();
845 QRect textRect(QPoint(0, 0), QSize(w, h));
846 painter.setRenderHint(QPainter::Antialiasing);
847 painter.setRenderHint(QPainter::SmoothPixmapTransform);
848 painter.setRenderHint(QPainter::TextAntialiasing);
849 painter.setPen(QPen(Qt::black, 1));
850 painter.setBrush(QColor(255, 255, 255, 200));
851 /* x and y radii are relative to rectangle's width and height and should be in [0, 100]: */
852 painter.drawRoundedRect(textRect, 50 /* xRadius */, 50 /* yRadius*/, Qt::RelativeSize);
853 painter.drawText(textRect, Qt::AlignHCenter | Qt::AlignVCenter, strArch);
854#endif
855}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle
ContactPrivacy/Do Not Sell My InfoTerms of Use