1 | /* $Id: UIIconPool.cpp 30206 2010-06-15 15:41:05Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
5 | * UIIconPool class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2010 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | /* Local includes */
|
---|
21 | #include "UIIconPool.h"
|
---|
22 |
|
---|
23 | /* Global includes */
|
---|
24 | #include <iprt/assert.h>
|
---|
25 |
|
---|
26 | #include <QApplication>
|
---|
27 | #include <QWidget>
|
---|
28 |
|
---|
29 | /* static */
|
---|
30 | QIcon UIIconPool::iconSet(const QPixmap &normal,
|
---|
31 | const QPixmap &disabled /* = QPixmap() */,
|
---|
32 | const QPixmap &active /* = QPixmap() */)
|
---|
33 | {
|
---|
34 | QIcon iconSet;
|
---|
35 |
|
---|
36 | Assert(!normal.isNull());
|
---|
37 | iconSet.addPixmap(normal, QIcon::Normal);
|
---|
38 |
|
---|
39 | if (!disabled.isNull())
|
---|
40 | iconSet.addPixmap(disabled, QIcon::Disabled);
|
---|
41 |
|
---|
42 | if (!active.isNull())
|
---|
43 | iconSet.addPixmap(active, QIcon::Active);
|
---|
44 |
|
---|
45 | return iconSet;
|
---|
46 | }
|
---|
47 |
|
---|
48 | /* static */
|
---|
49 | QIcon UIIconPool::iconSet(const QString &strNormal,
|
---|
50 | const QString &strDisabled /* = QString() */,
|
---|
51 | const QString &strActive /* = QString() */)
|
---|
52 | {
|
---|
53 | QIcon iconSet;
|
---|
54 |
|
---|
55 | Assert(!strNormal.isEmpty());
|
---|
56 | iconSet.addFile(strNormal, QSize(),
|
---|
57 | QIcon::Normal);
|
---|
58 | if (!strDisabled.isEmpty())
|
---|
59 | iconSet.addFile(strDisabled, QSize(),
|
---|
60 | QIcon::Disabled);
|
---|
61 | if (!strActive.isEmpty())
|
---|
62 | iconSet.addFile(strActive, QSize(),
|
---|
63 | QIcon::Active);
|
---|
64 | return iconSet;
|
---|
65 | }
|
---|
66 |
|
---|
67 | /* static */
|
---|
68 | QIcon UIIconPool::iconSetOnOff(const QString &strNormal, const QString strNormalOff,
|
---|
69 | const QString &strDisabled /* = QString() */,
|
---|
70 | const QString &strDisabledOff /* = QString() */,
|
---|
71 | const QString &strActive /* = QString() */,
|
---|
72 | const QString &strActiveOff /* = QString() */)
|
---|
73 | {
|
---|
74 | QIcon iconSet;
|
---|
75 |
|
---|
76 | Assert(!strNormal.isEmpty());
|
---|
77 | iconSet.addFile(strNormal, QSize(), QIcon::Normal, QIcon::On);
|
---|
78 | if (!strNormalOff.isEmpty())
|
---|
79 | iconSet.addFile(strNormalOff, QSize(), QIcon::Normal, QIcon::Off);
|
---|
80 |
|
---|
81 | if (!strDisabled.isEmpty())
|
---|
82 | iconSet.addFile(strDisabled, QSize(), QIcon::Disabled, QIcon::On);
|
---|
83 | if (!strDisabledOff.isEmpty())
|
---|
84 | iconSet.addFile(strDisabledOff, QSize(), QIcon::Disabled, QIcon::Off);
|
---|
85 |
|
---|
86 | if (!strActive.isEmpty())
|
---|
87 | iconSet.addFile(strActive, QSize(), QIcon::Active, QIcon::On);
|
---|
88 | if (!strActiveOff.isEmpty())
|
---|
89 | iconSet.addFile(strActive, QSize(), QIcon::Active, QIcon::Off);
|
---|
90 |
|
---|
91 | return iconSet;
|
---|
92 | }
|
---|
93 |
|
---|
94 | /* static */
|
---|
95 | QIcon UIIconPool::iconSetFull(const QSize &normalSize, const QSize &smallSize,
|
---|
96 | const QString &strNormal, const QString &strSmallNormal,
|
---|
97 | const QString &strDisabled /* = QString() */,
|
---|
98 | const QString &strSmallDisabled /* = QString() */,
|
---|
99 | const QString &strActive /* = QString() */,
|
---|
100 | const QString &strSmallActive /* = QString() */)
|
---|
101 | {
|
---|
102 | QIcon iconSet;
|
---|
103 |
|
---|
104 | Assert(!strNormal.isEmpty());
|
---|
105 | Assert(!strSmallNormal.isEmpty());
|
---|
106 | iconSet.addFile(strNormal, normalSize, QIcon::Normal);
|
---|
107 | iconSet.addFile(strSmallNormal, smallSize, QIcon::Normal);
|
---|
108 |
|
---|
109 | if (!strSmallDisabled.isEmpty())
|
---|
110 | {
|
---|
111 | iconSet.addFile(strDisabled, normalSize, QIcon::Disabled);
|
---|
112 | iconSet.addFile(strSmallDisabled, smallSize, QIcon::Disabled);
|
---|
113 | }
|
---|
114 |
|
---|
115 | if (!strSmallActive.isEmpty())
|
---|
116 | {
|
---|
117 | iconSet.addFile(strActive, normalSize, QIcon::Active);
|
---|
118 | iconSet.addFile(strSmallActive, smallSize, QIcon::Active);
|
---|
119 | }
|
---|
120 |
|
---|
121 | return iconSet;
|
---|
122 | }
|
---|
123 |
|
---|
124 | /* static */
|
---|
125 | QIcon UIIconPool::defaultIcon(UIDefaultIcon def, const QWidget *pWidget /* = 0 */)
|
---|
126 | {
|
---|
127 | QIcon icon;
|
---|
128 | QStyle *pStyle = pWidget ? pWidget->style() : QApplication::style();
|
---|
129 | switch (def)
|
---|
130 | {
|
---|
131 | case MessageBoxInformationIcon:
|
---|
132 | {
|
---|
133 | icon = pStyle->standardIcon(QStyle::SP_MessageBoxInformation, 0, pWidget);
|
---|
134 | break;
|
---|
135 | }
|
---|
136 | case MessageBoxQuestionIcon:
|
---|
137 | {
|
---|
138 | icon = pStyle->standardIcon(QStyle::SP_MessageBoxQuestion, 0, pWidget);
|
---|
139 | break;
|
---|
140 | }
|
---|
141 | case MessageBoxWarningIcon:
|
---|
142 | {
|
---|
143 | #ifdef Q_WS_MAC
|
---|
144 | /* At least in Qt 4.3.4/4.4 RC1 SP_MessageBoxWarning is the application
|
---|
145 | * icon. So change this to the critical icon. (Maybe this would be
|
---|
146 | * fixed in a later Qt version) */
|
---|
147 | icon = pStyle->standardIcon(QStyle::SP_MessageBoxCritical, 0, pWidget);
|
---|
148 | #else /* Q_WS_MAC */
|
---|
149 | icon = pStyle->standardIcon(QStyle::SP_MessageBoxWarning, 0, pWidget);
|
---|
150 | #endif /* !Q_WS_MAC */
|
---|
151 | break;
|
---|
152 | }
|
---|
153 | case MessageBoxCriticalIcon:
|
---|
154 | {
|
---|
155 | icon = pStyle->standardIcon(QStyle::SP_MessageBoxCritical, 0, pWidget);
|
---|
156 | break;
|
---|
157 | }
|
---|
158 | case DialogCancelIcon:
|
---|
159 | {
|
---|
160 | icon = pStyle->standardIcon(QStyle::SP_DialogCancelButton, 0, pWidget);
|
---|
161 | if (icon.isNull())
|
---|
162 | icon = iconSet(":/delete_16px.png",
|
---|
163 | ":/delete_dis_16px.png");
|
---|
164 | break;
|
---|
165 | }
|
---|
166 | case DialogHelpIcon:
|
---|
167 | {
|
---|
168 | icon = pStyle->standardIcon(QStyle::SP_DialogHelpButton, 0, pWidget);
|
---|
169 | if (icon.isNull())
|
---|
170 | icon = iconSet(":/help_16px.png");
|
---|
171 | break;
|
---|
172 | }
|
---|
173 | case ArrowBackIcon:
|
---|
174 | {
|
---|
175 | icon = pStyle->standardIcon(QStyle::SP_ArrowBack, 0, pWidget);
|
---|
176 | if (icon.isNull())
|
---|
177 | icon = iconSet(":/list_moveup_16px.png",
|
---|
178 | ":/list_moveup_disabled_16px.png");
|
---|
179 | break;
|
---|
180 | }
|
---|
181 | case ArrowForwardIcon:
|
---|
182 | {
|
---|
183 | icon = pStyle->standardIcon(QStyle::SP_ArrowForward, 0, pWidget);
|
---|
184 | if (icon.isNull())
|
---|
185 | icon = iconSet(":/list_movedown_16px.png",
|
---|
186 | ":/list_movedown_disabled_16px.png");
|
---|
187 | break;
|
---|
188 | }
|
---|
189 | default:
|
---|
190 | {
|
---|
191 | AssertMsgFailed(("Unknown default icon type!"));
|
---|
192 | break;
|
---|
193 | }
|
---|
194 | }
|
---|
195 | return icon;
|
---|
196 | }
|
---|
197 |
|
---|