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