Qt 4.8
Public Functions | Private Functions | Properties | Friends | List of all members
QPixmapIconEngine Class Reference

#include <qicon_p.h>

Inheritance diagram for QPixmapIconEngine:
QIconEngineV2 QIconEngine

Public Functions

QSize actualSize (const QSize &size, QIcon::Mode mode, QIcon::State state)
 Returns the actual size of the icon the engine provides for the requested size, mode and state. More...
 
void addFile (const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state)
 Called by QIcon::addFile(). More...
 
void addPixmap (const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state)
 Called by QIcon::addPixmap(). More...
 
QPixmapIconEngineEntrybestMatch (const QSize &size, QIcon::Mode mode, QIcon::State state, bool sizeOnly)
 
QIconEngineV2clone () const
 Returns a clone of this icon engine. More...
 
QString key () const
 Returns a key that identifies this icon engine. More...
 
void paint (QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state)
 Uses the given painter to paint the icon with the required mode and state into the rectangle rect. More...
 
QPixmap pixmap (const QSize &size, QIcon::Mode mode, QIcon::State state)
 Returns the icon as a pixmap with the required size, mode, and state. More...
 
 QPixmapIconEngine ()
 
 QPixmapIconEngine (const QPixmapIconEngine &)
 
bool read (QDataStream &in)
 Reads icon engine contents from the QDataStream in. More...
 
void virtual_hook (int id, void *data)
 Additional method to allow extending QIconEngineV2 without adding new virtual methods (and without breaking binary compatibility). More...
 
bool write (QDataStream &out) const
 Writes the contents of this engine to the QDataStream out. More...
 
 ~QPixmapIconEngine ()
 
- Public Functions inherited from QIconEngineV2
QList< QSizeavailableSizes (QIcon::Mode mode=QIcon::Normal, QIcon::State state=QIcon::Off)
 Returns sizes of all images that are contained in the engine for the specific mode and state. More...
 
QString iconName ()
 Returns the name used to create the engine, if available. More...
 
- Public Functions inherited from QIconEngine
virtual ~QIconEngine ()
 Destroys the icon engine. More...
 

Private Functions

QPixmapIconEngineEntrytryMatch (const QSize &size, QIcon::Mode mode, QIcon::State state)
 

Properties

QVector< QPixmapIconEngineEntrypixmaps
 

Friends

QDataStreamoperator<< (QDataStream &s, const QIcon &icon)
 
class QIconThemeEngine
 

Additional Inherited Members

- Public Types inherited from QIconEngineV2
enum  IconEngineHook { AvailableSizesHook = 1, IconNameHook }
 These enum values are used for virtual_hook() to allow additional queries to icon engine without breaking binary compatibility. More...
 

Detailed Description

Definition at line 110 of file qicon_p.h.

Constructors and Destructors

◆ QPixmapIconEngine() [1/2]

QPixmapIconEngine::QPixmapIconEngine ( )

Definition at line 133 of file qicon.cpp.

Referenced by clone().

134 {
135 }

◆ QPixmapIconEngine() [2/2]

QPixmapIconEngine::QPixmapIconEngine ( const QPixmapIconEngine other)

Definition at line 137 of file qicon.cpp.

138  : QIconEngineV2(other), pixmaps(other.pixmaps)
139 {
140 }
QVector< QPixmapIconEngineEntry > pixmaps
Definition: qicon_p.h:131
The QIconEngineV2 class provides an abstract base class for QIcon renderers.
Definition: qiconengine.h:73

◆ ~QPixmapIconEngine()

QPixmapIconEngine::~QPixmapIconEngine ( )

Definition at line 142 of file qicon.cpp.

143 {
144 }

Functions

◆ actualSize()

QSize QPixmapIconEngine::actualSize ( const QSize size,
QIcon::Mode  mode,
QIcon::State  state 
)
virtual

Returns the actual size of the icon the engine provides for the requested size, mode and state.

The default implementation returns the given size.

Reimplemented from QIconEngine.

Definition at line 306 of file qicon.cpp.

Referenced by pixmap().

307 {
309  if (QPixmapIconEngineEntry *pe = bestMatch(size, mode, state, true))
310  actualSize = pe->size;
311 
312  if (actualSize.isNull())
313  return actualSize;
314 
315  if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height()))
316  actualSize.scale(size, Qt::KeepAspectRatio);
317  return actualSize;
318 }
QPixmapIconEngineEntry * bestMatch(const QSize &size, QIcon::Mode mode, QIcon::State state, bool sizeOnly)
Definition: qicon.cpp:195
int width() const
Returns the width.
Definition: qsize.h:126
int height() const
Returns the height.
Definition: qsize.h:129
void scale(int w, int h, Qt::AspectRatioMode mode)
Scales the size to a rectangle with the given width and height, according to the specified mode: ...
Definition: qsize.h:138
bool isNull() const
Returns true if both the width and height is 0; otherwise returns false.
Definition: qsize.h:117
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state)
Returns the actual size of the icon the engine provides for the requested size, mode and state...
Definition: qicon.cpp:306

◆ addFile()

void QPixmapIconEngine::addFile ( const QString fileName,
const QSize size,
QIcon::Mode  mode,
QIcon::State  state 
)
virtual

Called by QIcon::addFile().

Adds a specialized pixmap from the file with the given fileName, size, mode and state. The default pixmap-based engine stores any supplied file names, and it loads the pixmaps on demand instead of using scaled pixmaps if the size of a pixmap matches the size of icon requested. Custom icon engines that implement scalable vector formats are free to ignores any extra files.

Reimplemented from QIconEngine.

Definition at line 333 of file qicon.cpp.

Referenced by read().

334 {
335  if (!fileName.isEmpty()) {
336  QSize size = _size;
337  QPixmap pixmap;
338 
339  QString abs = fileName;
340  if (fileName.at(0) != QLatin1Char(':'))
341  abs = QFileInfo(fileName).absoluteFilePath();
342 
343  for (int i = 0; i < pixmaps.count(); ++i) {
344  if (pixmaps.at(i).mode == mode && pixmaps.at(i).state == state) {
346  if(size == QSize()) {
347  pixmap = QPixmap(abs);
348  size = pixmap.size();
349  }
350  if (pe->size == QSize() && pe->pixmap.isNull()) {
351  pe->pixmap = QPixmap(pe->fileName);
352  pe->size = pe->pixmap.size();
353  }
354  if(pe->size == size) {
355  pe->pixmap = pixmap;
356  pe->fileName = abs;
357  return;
358  }
359  }
360  }
361  QPixmapIconEngineEntry e(abs, size, mode, state);
362  e.pixmap = pixmap;
363  pixmaps += e;
364  }
365 }
QVector< QPixmapIconEngineEntry > pixmaps
Definition: qicon_p.h:131
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QString absoluteFilePath() const
Returns an absolute path including the file name.
Definition: qfileinfo.cpp:534
The QString class provides a Unicode character string.
Definition: qstring.h:83
QIcon::State state
Definition: qicon_p.h:104
QIcon::Mode mode
Definition: qicon_p.h:103
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
Returns the icon as a pixmap with the required size, mode, and state.
Definition: qicon.cpp:247
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
static QString fileName(const QString &fileUrl)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ addPixmap()

void QPixmapIconEngine::addPixmap ( const QPixmap pixmap,
QIcon::Mode  mode,
QIcon::State  state 
)
virtual

Called by QIcon::addPixmap().

Adds a specialized pixmap for the given mode and state. The default pixmap-based engine stores any supplied pixmaps, and it uses them instead of scaled pixmaps if the size of a pixmap matches the size of icon requested. Custom icon engines that implement scalable vector formats are free to ignores any extra pixmaps.

Reimplemented from QIconEngine.

Definition at line 320 of file qicon.cpp.

321 {
322  if (!pixmap.isNull()) {
323  QPixmapIconEngineEntry *pe = tryMatch(pixmap.size(), mode, state);
324  if(pe && pe->size == pixmap.size()) {
325  pe->pixmap = pixmap;
326  pe->fileName.clear();
327  } else {
328  pixmaps += QPixmapIconEngineEntry(pixmap, mode, state);
329  }
330  }
331 }
QVector< QPixmapIconEngineEntry > pixmaps
Definition: qicon_p.h:131
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
Returns the icon as a pixmap with the required size, mode, and state.
Definition: qicon.cpp:247
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
QPixmapIconEngineEntry * tryMatch(const QSize &size, QIcon::Mode mode, QIcon::State state)
Definition: qicon.cpp:181

◆ bestMatch()

QPixmapIconEngineEntry * QPixmapIconEngine::bestMatch ( const QSize size,
QIcon::Mode  mode,
QIcon::State  state,
bool  sizeOnly 
)

Definition at line 195 of file qicon.cpp.

Referenced by actualSize(), and pixmap().

196 {
197  QPixmapIconEngineEntry *pe = tryMatch(size, mode, state);
198  while (!pe){
199  QIcon::State oppositeState = (state == QIcon::On) ? QIcon::Off : QIcon::On;
200  if (mode == QIcon::Disabled || mode == QIcon::Selected) {
201  QIcon::Mode oppositeMode = (mode == QIcon::Disabled) ? QIcon::Selected : QIcon::Disabled;
202  if ((pe = tryMatch(size, QIcon::Normal, state)))
203  break;
204  if ((pe = tryMatch(size, QIcon::Active, state)))
205  break;
206  if ((pe = tryMatch(size, mode, oppositeState)))
207  break;
208  if ((pe = tryMatch(size, QIcon::Normal, oppositeState)))
209  break;
210  if ((pe = tryMatch(size, QIcon::Active, oppositeState)))
211  break;
212  if ((pe = tryMatch(size, oppositeMode, state)))
213  break;
214  if ((pe = tryMatch(size, oppositeMode, oppositeState)))
215  break;
216  } else {
217  QIcon::Mode oppositeMode = (mode == QIcon::Normal) ? QIcon::Active : QIcon::Normal;
218  if ((pe = tryMatch(size, oppositeMode, state)))
219  break;
220  if ((pe = tryMatch(size, mode, oppositeState)))
221  break;
222  if ((pe = tryMatch(size, oppositeMode, oppositeState)))
223  break;
224  if ((pe = tryMatch(size, QIcon::Disabled, state)))
225  break;
226  if ((pe = tryMatch(size, QIcon::Selected, state)))
227  break;
228  if ((pe = tryMatch(size, QIcon::Disabled, oppositeState)))
229  break;
230  if ((pe = tryMatch(size, QIcon::Selected, oppositeState)))
231  break;
232  }
233 
234  if (!pe)
235  return pe;
236  }
237 
238  if (sizeOnly ? (pe->size.isNull() || !pe->size.isValid()) : pe->pixmap.isNull()) {
239  pe->pixmap = QPixmap(pe->fileName);
240  if (!pe->pixmap.isNull())
241  pe->size = pe->pixmap.size();
242  }
243 
244  return pe;
245 }
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
State
This enum describes the state for which a pixmap is intended to be used.
Definition: qicon.h:64
Mode
This enum type describes the mode for which a pixmap is intended to be used.
Definition: qicon.h:63
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
bool isNull() const
Returns true if both the width and height is 0; otherwise returns false.
Definition: qsize.h:117
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
QPixmapIconEngineEntry * tryMatch(const QSize &size, QIcon::Mode mode, QIcon::State state)
Definition: qicon.cpp:181

◆ clone()

QIconEngineV2 * QPixmapIconEngine::clone ( ) const
virtual

Returns a clone of this icon engine.

Reimplemented from QIconEngineV2.

Definition at line 372 of file qicon.cpp.

373 {
374  return new QPixmapIconEngine(*this);
375 }

◆ key()

QString QPixmapIconEngine::key ( ) const
virtual

Returns a key that identifies this icon engine.

Reimplemented from QIconEngineV2.

Definition at line 367 of file qicon.cpp.

Referenced by pixmap().

368 {
369  return QLatin1String("QPixmapIconEngine");
370 }
QLatin1String("/iconengines")

◆ paint()

void QPixmapIconEngine::paint ( QPainter painter,
const QRect rect,
QIcon::Mode  mode,
QIcon::State  state 
)
virtual

Uses the given painter to paint the icon with the required mode and state into the rectangle rect.

Implements QIconEngine.

Definition at line 146 of file qicon.cpp.

147 {
148  QSize pixmapSize = rect.size();
149 #if defined(Q_WS_MAC)
150  pixmapSize *= qt_mac_get_scalefactor();
151 #endif
152  painter->drawPixmap(rect, pixmap(pixmapSize, mode, state));
153 }
CGFloat qt_mac_get_scalefactor()
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
Returns the icon as a pixmap with the required size, mode, and state.
Definition: qicon.cpp:247
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ pixmap()

QPixmap QPixmapIconEngine::pixmap ( const QSize size,
QIcon::Mode  mode,
QIcon::State  state 
)
virtual

Returns the icon as a pixmap with the required size, mode, and state.

The default implementation creates a new pixmap and calls paint() to fill it.

Reimplemented from QIconEngine.

Definition at line 247 of file qicon.cpp.

Referenced by addFile(), addPixmap(), and paint().

248 {
249  QPixmap pm;
250  QPixmapIconEngineEntry *pe = bestMatch(size, mode, state, false);
251  if (pe)
252  pm = pe->pixmap;
253 
254  if (pm.isNull()) {
255  int idx = pixmaps.count();
256  while (--idx >= 0) {
257  if (pe == &pixmaps[idx]) {
258  pixmaps.remove(idx);
259  break;
260  }
261  }
262  if (pixmaps.isEmpty())
263  return pm;
264  else
265  return pixmap(size, mode, state);
266  }
267 
268  QSize actualSize = pm.size();
269  if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height()))
270  actualSize.scale(size, Qt::KeepAspectRatio);
271 
272  QString key = QLatin1Literal("qt_")
274  % HexString<uint>(pe->mode)
276  % HexString<uint>(actualSize.width())
277  % HexString<uint>(actualSize.height());
278 
279  if (mode == QIcon::Active) {
280  if (QPixmapCache::find(key % HexString<uint>(mode), pm))
281  return pm; // horray
283  QStyleOption opt(0);
284  opt.palette = QApplication::palette();
286  if (pm.cacheKey() == active.cacheKey())
287  return pm;
288  }
289  }
290 
291  if (!QPixmapCache::find(key % HexString<uint>(mode), pm)) {
292  if (pm.size() != actualSize)
294  if (pe->mode != mode && mode != QIcon::Normal) {
295  QStyleOption opt(0);
296  opt.palette = QApplication::palette();
297  QPixmap generated = QApplication::style()->generatedIconPixmap(mode, pm, &opt);
298  if (!generated.isNull())
299  pm = generated;
300  }
301  QPixmapCache::insert(key % HexString<uint>(mode), pm);
302  }
303  return pm;
304 }
virtual QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const =0
Returns a copy of the given pixmap, styled to conform to the specified iconMode and taking into accou...
The QLatin1Literal class provides a thin wrapper around string literals used in source code...
QVector< QPixmapIconEngineEntry > pixmaps
Definition: qicon_p.h:131
QPixmapIconEngineEntry * bestMatch(const QSize &size, QIcon::Mode mode, QIcon::State state, bool sizeOnly)
Definition: qicon.cpp:195
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
void remove(int i)
Removes the element at index position i.
Definition: qvector.h:374
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
qint64 cacheKey() const
Returns a number that identifies the contents of this QPalette object.
Definition: qpalette.cpp:1093
QPixmap scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
Definition: qpixmap.h:132
static QPalette palette()
Returns the application palette.
static QStyle * style()
Returns the application&#39;s style object.
QString key() const
Returns a key that identifies this icon engine.
Definition: qicon.cpp:367
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QPixmap * find(const QString &key)
QIcon::Mode mode
Definition: qicon_p.h:103
int width() const
Returns the width.
Definition: qsize.h:126
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
Returns the icon as a pixmap with the required size, mode, and state.
Definition: qicon.cpp:247
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
int height() const
Returns the height.
Definition: qsize.h:129
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
Definition: qpixmap.cpp:1136
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
void scale(int w, int h, Qt::AspectRatioMode mode)
Scales the size to a rectangle with the given width and height, according to the specified mode: ...
Definition: qsize.h:138
bool isNull() const
Returns true if both the width and height is 0; otherwise returns false.
Definition: qsize.h:117
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state)
Returns the actual size of the icon the engine provides for the requested size, mode and state...
Definition: qicon.cpp:306

◆ read()

bool QPixmapIconEngine::read ( QDataStream in)
virtual

Reads icon engine contents from the QDataStream in.

Returns true if the contents were read; otherwise returns false.

QIconEngineV2's default implementation always return false.

Reimplemented from QIconEngineV2.

Definition at line 377 of file qicon.cpp.

378 {
379  int num_entries;
380  QPixmap pm;
382  QSize sz;
383  uint mode;
384  uint state;
385 
386  in >> num_entries;
387  for (int i=0; i < num_entries; ++i) {
388  if (in.atEnd()) {
389  pixmaps.clear();
390  return false;
391  }
392  in >> pm;
393  in >> fileName;
394  in >> sz;
395  in >> mode;
396  in >> state;
397  if (pm.isNull()) {
398  addFile(fileName, sz, QIcon::Mode(mode), QIcon::State(state));
399  } else {
400  QPixmapIconEngineEntry pe(fileName, sz, QIcon::Mode(mode), QIcon::State(state));
401  pe.pixmap = pm;
402  pixmaps += pe;
403  }
404  }
405  return true;
406 }
QVector< QPixmapIconEngineEntry > pixmaps
Definition: qicon_p.h:131
bool atEnd() const
Returns true if the I/O device has reached the end position (end of the stream or file) or if there i...
State
This enum describes the state for which a pixmap is intended to be used.
Definition: qicon.h:64
The QString class provides a Unicode character string.
Definition: qstring.h:83
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
Mode
This enum type describes the mode for which a pixmap is intended to be used.
Definition: qicon.h:63
unsigned int uint
Definition: qglobal.h:996
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static QString fileName(const QString &fileUrl)
void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state)
Called by QIcon::addFile().
Definition: qicon.cpp:333

◆ tryMatch()

QPixmapIconEngineEntry * QPixmapIconEngine::tryMatch ( const QSize size,
QIcon::Mode  mode,
QIcon::State  state 
)
private

Definition at line 181 of file qicon.cpp.

Referenced by addPixmap(), and bestMatch().

182 {
183  QPixmapIconEngineEntry *pe = 0;
184  for (int i = 0; i < pixmaps.count(); ++i)
185  if (pixmaps.at(i).mode == mode && pixmaps.at(i).state == state) {
186  if (pe)
187  pe = bestSizeMatch(size, &pixmaps[i], pe);
188  else
189  pe = &pixmaps[i];
190  }
191  return pe;
192 }
QVector< QPixmapIconEngineEntry > pixmaps
Definition: qicon_p.h:131
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QIcon::State state
Definition: qicon_p.h:104
QIcon::Mode mode
Definition: qicon_p.h:103
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
static QPixmapIconEngineEntry * bestSizeMatch(const QSize &size, QPixmapIconEngineEntry *pa, QPixmapIconEngineEntry *pb)
Definition: qicon.cpp:158

◆ virtual_hook()

void QPixmapIconEngine::virtual_hook ( int  id,
void *  data 
)
virtual

Additional method to allow extending QIconEngineV2 without adding new virtual methods (and without breaking binary compatibility).

Since
4.5

The actual action and format of data depends on id argument which is in fact a constant from IconEngineHook enum.

See also
IconEngineHook

Reimplemented from QIconEngineV2.

Definition at line 425 of file qicon.cpp.

426 {
427  switch (id) {
430  *reinterpret_cast<QIconEngineV2::AvailableSizesArgument*>(data);
431  arg.sizes.clear();
432  for (int i = 0; i < pixmaps.size(); ++i) {
434  if (pe.size == QSize() && pe.pixmap.isNull()) {
435  pe.pixmap = QPixmap(pe.fileName);
436  pe.size = pe.pixmap.size();
437  }
438  if (pe.mode == arg.mode && pe.state == arg.state && !pe.size.isEmpty())
439  arg.sizes.push_back(pe.size);
440  }
441  break;
442  }
443  default:
445  }
446 }
void push_back(const T &t)
This function is provided for STL compatibility.
Definition: qlist.h:296
QVector< QPixmapIconEngineEntry > pixmaps
Definition: qicon_p.h:131
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
QIcon::Mode mode
the requested mode of an image.
Definition: qiconengine.h:87
QIcon::State state
Definition: qicon_p.h:104
QIcon::Mode mode
Definition: qicon_p.h:103
This struct represents arguments to virtual_hook() function when id parameter is QIconEngineV2::Avail...
Definition: qiconengine.h:85
virtual void virtual_hook(int id, void *data)
Additional method to allow extending QIconEngineV2 without adding new virtual methods (and without br...
QList< QSize > sizes
image sizes that are available with specified mode and
Definition: qiconengine.h:89
static const char * data(const QByteArray &arr)
void clear()
Removes all items from the list.
Definition: qlist.h:764
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QIcon::State state
the requested state of an image.
Definition: qiconengine.h:88
bool isEmpty() const
Returns true if either of the width and height is less than or equal to 0; otherwise returns false...
Definition: qsize.h:120
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ write()

bool QPixmapIconEngine::write ( QDataStream out) const
virtual

Writes the contents of this engine to the QDataStream out.

Returns true if the contents were written; otherwise returns false.

QIconEngineV2's default implementation always return false.

Reimplemented from QIconEngineV2.

Definition at line 408 of file qicon.cpp.

409 {
410  int num_entries = pixmaps.size();
411  out << num_entries;
412  for (int i=0; i < num_entries; ++i) {
413  if (pixmaps.at(i).pixmap.isNull())
414  out << QPixmap(pixmaps.at(i).fileName);
415  else
416  out << pixmaps.at(i).pixmap;
417  out << pixmaps.at(i).fileName;
418  out << pixmaps.at(i).size;
419  out << (uint) pixmaps.at(i).mode;
420  out << (uint) pixmaps.at(i).state;
421  }
422  return true;
423 }
QVector< QPixmapIconEngineEntry > pixmaps
Definition: qicon_p.h:131
QIcon::State state
Definition: qicon_p.h:104
QIcon::Mode mode
Definition: qicon_p.h:103
unsigned int uint
Definition: qglobal.h:996
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

Friends and Related Functions

◆ operator<<

QDataStream& operator<< ( QDataStream s,
const QIcon icon 
)
friend

Definition at line 1096 of file qicon.cpp.

1097 {
1098  if (s.version() >= QDataStream::Qt_4_3) {
1099  if (icon.isNull()) {
1100  s << QString();
1101  } else {
1102  if (icon.d->engine_version > 1) {
1103  QIconEngineV2 *engine = static_cast<QIconEngineV2 *>(icon.d->engine);
1104  s << engine->key();
1105  engine->write(s);
1106  } else {
1107  // not really supported
1108  qWarning("QIcon: Cannot stream QIconEngine. Use QIconEngineV2 instead.");
1109  }
1110  }
1111  } else if (s.version() == QDataStream::Qt_4_2) {
1112  if (icon.isNull()) {
1113  s << 0;
1114  } else {
1115  QPixmapIconEngine *engine = static_cast<QPixmapIconEngine *>(icon.d->engine);
1116  int num_entries = engine->pixmaps.size();
1117  s << num_entries;
1118  for (int i=0; i < num_entries; ++i) {
1119  s << engine->pixmaps.at(i).pixmap;
1120  s << engine->pixmaps.at(i).fileName;
1121  s << engine->pixmaps.at(i).size;
1122  s << (uint) engine->pixmaps.at(i).mode;
1123  s << (uint) engine->pixmaps.at(i).state;
1124  }
1125  }
1126  } else {
1127  s << QPixmap(icon.pixmap(22,22));
1128  }
1129  return s;
1130 }
virtual QString key() const
Returns a key that identifies this icon engine.
QVector< QPixmapIconEngineEntry > pixmaps
Definition: qicon_p.h:131
QIconPrivate * d
Definition: qicon.h:135
The QString class provides a Unicode character string.
Definition: qstring.h:83
int engine_version
Definition: qicon_p.h:87
QIcon::State state
Definition: qicon_p.h:104
QIcon::Mode mode
Definition: qicon_p.h:103
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int uint
Definition: qglobal.h:996
The QIconEngineV2 class provides an abstract base class for QIcon renderers.
Definition: qiconengine.h:73
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
virtual bool write(QDataStream &out) const
Writes the contents of this engine to the QDataStream out.
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QPixmap pixmap(const QSize &size, Mode mode=Normal, State state=Off) const
Returns a pixmap with the requested size, mode, and state, generating one if necessary.
Definition: qicon.cpp:693
QIconEngine * engine
Definition: qicon_p.h:82
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ QIconThemeEngine

friend class QIconThemeEngine
friend

Definition at line 134 of file qicon_p.h.

Properties

◆ pixmaps

QVector<QPixmapIconEngineEntry> QPixmapIconEngine::pixmaps
private

Definition at line 131 of file qicon_p.h.

Referenced by addFile(), addPixmap(), operator<<(), pixmap(), read(), tryMatch(), virtual_hook(), and write().


The documentation for this class was generated from the following files: