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