Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
5 | ** | - |
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - |
7 | ** | - |
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
9 | ** Commercial License Usage | - |
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
11 | ** accordance with the commercial license agreement provided with the | - |
12 | ** Software or, alternatively, in accordance with the terms contained in | - |
13 | ** a written agreement between you and Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
16 | ** | - |
17 | ** GNU Lesser General Public License Usage | - |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
19 | ** General Public License version 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include "qiconengine.h" | - |
43 | #include "qpainter.h" | - |
44 | | - |
45 | QT_BEGIN_NAMESPACE | - |
46 | | - |
47 | /*! | - |
48 | \class QIconEngine | - |
49 | | - |
50 | \brief The QIconEngine class provides an abstract base class for QIcon renderers. | - |
51 | | - |
52 | \ingroup painting | - |
53 | \inmodule QtGui | - |
54 | | - |
55 | An icon engine provides the rendering functions for a QIcon. Each icon has a | - |
56 | corresponding icon engine that is responsible for drawing the icon with a | - |
57 | requested size, mode and state. | - |
58 | | - |
59 | The icon is rendered by the paint() function, and the icon can additionally be | - |
60 | obtained as a pixmap with the pixmap() function (the default implementation | - |
61 | simply uses paint() to achieve this). The addPixmap() function can be used to | - |
62 | add new pixmaps to the icon engine, and is used by QIcon to add specialized | - |
63 | custom pixmaps. | - |
64 | | - |
65 | The paint(), pixmap(), and addPixmap() functions are all virtual, and can | - |
66 | therefore be reimplemented in subclasses of QIconEngine. | - |
67 | | - |
68 | \sa QIconEnginePlugin | - |
69 | | - |
70 | */ | - |
71 | | - |
72 | /*! | - |
73 | \fn virtual void QIconEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) = 0; | - |
74 | | - |
75 | Uses the given \a painter to paint the icon with the required \a mode and | - |
76 | \a state into the rectangle \a rect. | - |
77 | */ | - |
78 | | - |
79 | /*! Returns the actual size of the icon the engine provides for the | - |
80 | requested \a size, \a mode and \a state. The default implementation | - |
81 | returns the given \a size. | - |
82 | */ | - |
83 | QSize QIconEngine::actualSize(const QSize &size, QIcon::Mode /*mode*/, QIcon::State /*state*/) | - |
84 | { | - |
85 | return size; never executed: return size; | 0 |
86 | } | - |
87 | | - |
88 | | - |
89 | /*! | - |
90 | Destroys the icon engine. | - |
91 | */ | - |
92 | QIconEngine::~QIconEngine() | - |
93 | { | - |
94 | } | - |
95 | | - |
96 | | - |
97 | /*! | - |
98 | Returns the icon as a pixmap with the required \a size, \a mode, | - |
99 | and \a state. The default implementation creates a new pixmap and | - |
100 | calls paint() to fill it. | - |
101 | */ | - |
102 | QPixmap QIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) | - |
103 | { | - |
104 | QPixmap pm(size); never executed (the execution status of this line is deduced): QPixmap pm(size); | - |
105 | { | - |
106 | QPainter p(&pm); never executed (the execution status of this line is deduced): QPainter p(&pm); | - |
107 | paint(&p, QRect(QPoint(0,0),size), mode, state); never executed (the execution status of this line is deduced): paint(&p, QRect(QPoint(0,0),size), mode, state); | - |
108 | } | - |
109 | return pm; never executed: return pm; | 0 |
110 | } | - |
111 | | - |
112 | /*! | - |
113 | Called by QIcon::addPixmap(). Adds a specialized \a pixmap for the given | - |
114 | \a mode and \a state. The default pixmap-based engine stores any supplied | - |
115 | pixmaps, and it uses them instead of scaled pixmaps if the size of a pixmap | - |
116 | matches the size of icon requested. Custom icon engines that implement | - |
117 | scalable vector formats are free to ignores any extra pixmaps. | - |
118 | */ | - |
119 | void QIconEngine::addPixmap(const QPixmap &/*pixmap*/, QIcon::Mode /*mode*/, QIcon::State /*state*/) | - |
120 | { | - |
121 | } | - |
122 | | - |
123 | | - |
124 | /*! Called by QIcon::addFile(). Adds a specialized pixmap from the | - |
125 | file with the given \a fileName, \a size, \a mode and \a state. The | - |
126 | default pixmap-based engine stores any supplied file names, and it | - |
127 | loads the pixmaps on demand instead of using scaled pixmaps if the | - |
128 | size of a pixmap matches the size of icon requested. Custom icon | - |
129 | engines that implement scalable vector formats are free to ignores | - |
130 | any extra files. | - |
131 | */ | - |
132 | void QIconEngine::addFile(const QString &/*fileName*/, const QSize &/*size*/, QIcon::Mode /*mode*/, QIcon::State /*state*/) | - |
133 | { | - |
134 | } | - |
135 | | - |
136 | | - |
137 | /*! | - |
138 | \enum QIconEngine::IconEngineHook | - |
139 | \since 4.5 | - |
140 | | - |
141 | These enum values are used for virtual_hook() to allow additional | - |
142 | queries to icon engine without breaking binary compatibility. | - |
143 | | - |
144 | \value AvailableSizesHook Allows to query the sizes of the | - |
145 | contained pixmaps for pixmap-based engines. The \a data argument | - |
146 | of the virtual_hook() function is a AvailableSizesArgument pointer | - |
147 | that should be filled with icon sizes. Engines that work in terms | - |
148 | of a scalable, vectorial format normally return an empty list. | - |
149 | | - |
150 | \value IconNameHook Allows to query the name used to create the | - |
151 | icon, for example when instantiating an icon using | - |
152 | QIcon::fromTheme(). | - |
153 | | - |
154 | \sa virtual_hook() | - |
155 | */ | - |
156 | | - |
157 | /*! | - |
158 | \class QIconEngine::AvailableSizesArgument | - |
159 | \since 4.5 | - |
160 | | - |
161 | \inmodule QtGui | - |
162 | | - |
163 | This struct represents arguments to virtual_hook() function when | - |
164 | \a id parameter is QIconEngine::AvailableSizesHook. | - |
165 | | - |
166 | \sa virtual_hook(), QIconEngine::IconEngineHook | - |
167 | */ | - |
168 | | - |
169 | /*! | - |
170 | \variable QIconEngine::AvailableSizesArgument::mode | - |
171 | \brief the requested mode of an image. | - |
172 | | - |
173 | \sa QIcon::Mode | - |
174 | */ | - |
175 | | - |
176 | /*! | - |
177 | \variable QIconEngine::AvailableSizesArgument::state | - |
178 | \brief the requested state of an image. | - |
179 | | - |
180 | \sa QIcon::State | - |
181 | */ | - |
182 | | - |
183 | /*! | - |
184 | \variable QIconEngine::AvailableSizesArgument::sizes | - |
185 | | - |
186 | \brief image sizes that are available with specified \a mode and | - |
187 | \a state. This is an output parameter and is filled after call to | - |
188 | virtual_hook(). Engines that work in terms of a scalable, | - |
189 | vectorial format normally return an empty list. | - |
190 | */ | - |
191 | | - |
192 | | - |
193 | /*! | - |
194 | Returns a key that identifies this icon engine. | - |
195 | */ | - |
196 | QString QIconEngine::key() const | - |
197 | { | - |
198 | return QString(); never executed: return QString(); | 0 |
199 | } | - |
200 | | - |
201 | /*! \fn QIconEngine *QIconEngine::clone() const | - |
202 | | - |
203 | Reimplement this method to return a clone of this icon engine. | - |
204 | */ | - |
205 | | - |
206 | /*! | - |
207 | Reads icon engine contents from the QDataStream \a in. Returns | - |
208 | true if the contents were read; otherwise returns false. | - |
209 | | - |
210 | QIconEngine's default implementation always return false. | - |
211 | */ | - |
212 | bool QIconEngine::read(QDataStream &) | - |
213 | { | - |
214 | return false; never executed: return false; | 0 |
215 | } | - |
216 | | - |
217 | /*! | - |
218 | Writes the contents of this engine to the QDataStream \a out. | - |
219 | Returns true if the contents were written; otherwise returns false. | - |
220 | | - |
221 | QIconEngine's default implementation always return false. | - |
222 | */ | - |
223 | bool QIconEngine::write(QDataStream &) const | - |
224 | { | - |
225 | return false; never executed: return false; | 0 |
226 | } | - |
227 | | - |
228 | /*! | - |
229 | \since 4.5 | - |
230 | | - |
231 | Additional method to allow extending QIconEngine without | - |
232 | adding new virtual methods (and without breaking binary compatibility). | - |
233 | The actual action and format of \a data depends on \a id argument | - |
234 | which is in fact a constant from IconEngineHook enum. | - |
235 | | - |
236 | \sa IconEngineHook | - |
237 | */ | - |
238 | void QIconEngine::virtual_hook(int id, void *data) | - |
239 | { | - |
240 | switch (id) { | - |
241 | case QIconEngine::AvailableSizesHook: { | - |
242 | QIconEngine::AvailableSizesArgument &arg = never executed (the execution status of this line is deduced): QIconEngine::AvailableSizesArgument &arg = | - |
243 | *reinterpret_cast<QIconEngine::AvailableSizesArgument*>(data); never executed (the execution status of this line is deduced): *reinterpret_cast<QIconEngine::AvailableSizesArgument*>(data); | - |
244 | arg.sizes.clear(); never executed (the execution status of this line is deduced): arg.sizes.clear(); | - |
245 | break; | 0 |
246 | } | - |
247 | default: | - |
248 | break; executed: break; Execution Count:1 | 1 |
249 | } | - |
250 | } executed: } Execution Count:1 | 1 |
251 | | - |
252 | /*! | - |
253 | \since 4.5 | - |
254 | | - |
255 | Returns sizes of all images that are contained in the engine for the | - |
256 | specific \a mode and \a state. | - |
257 | | - |
258 | \note This is a helper method and the actual work is done by | - |
259 | virtual_hook() method, hence this method depends on icon engine support | - |
260 | and may not work with all icon engines. | - |
261 | */ | - |
262 | QList<QSize> QIconEngine::availableSizes(QIcon::Mode mode, QIcon::State state) const | - |
263 | { | - |
264 | AvailableSizesArgument arg; executed (the execution status of this line is deduced): AvailableSizesArgument arg; | - |
265 | arg.mode = mode; executed (the execution status of this line is deduced): arg.mode = mode; | - |
266 | arg.state = state; executed (the execution status of this line is deduced): arg.state = state; | - |
267 | const_cast<QIconEngine *>(this)->virtual_hook(QIconEngine::AvailableSizesHook, reinterpret_cast<void*>(&arg)); executed (the execution status of this line is deduced): const_cast<QIconEngine *>(this)->virtual_hook(QIconEngine::AvailableSizesHook, reinterpret_cast<void*>(&arg)); | - |
268 | return arg.sizes; executed: return arg.sizes; Execution Count:33 | 33 |
269 | } | - |
270 | | - |
271 | /*! | - |
272 | \since 4.7 | - |
273 | | - |
274 | Returns the name used to create the engine, if available. | - |
275 | | - |
276 | \note This is a helper method and the actual work is done by | - |
277 | virtual_hook() method, hence this method depends on icon engine support | - |
278 | and may not work with all icon engines. | - |
279 | */ | - |
280 | QString QIconEngine::iconName() const | - |
281 | { | - |
282 | QString name; executed (the execution status of this line is deduced): QString name; | - |
283 | const_cast<QIconEngine *>(this)->virtual_hook(QIconEngine::IconNameHook, reinterpret_cast<void*>(&name)); executed (the execution status of this line is deduced): const_cast<QIconEngine *>(this)->virtual_hook(QIconEngine::IconNameHook, reinterpret_cast<void*>(&name)); | - |
284 | return name; executed: return name; Execution Count:2 | 2 |
285 | } | - |
286 | | - |
287 | QT_END_NAMESPACE | - |
288 | | - |
| | |