Qt 4.8
Classes | Functions
qicon.h File Reference
#include <QtCore/qglobal.h>
#include <QtCore/qsize.h>
#include <QtCore/qlist.h>
#include <QtGui/qpixmap.h>

Go to the source code of this file.

Classes

class  QIcon
 The QIcon class provides scalable icons in different modes and states. More...
 

Functions

Q_GUI_EXPORT QDataStreamoperator<< (QDataStream &, const QIcon &)
 
Q_GUI_EXPORT QDataStreamoperator>> (QDataStream &, QIcon &)
 
 Q_DECLARE_TYPEINFO (QIcon, Q_MOVABLE_TYPE)
 

Function Documentation

◆ operator<<()

Q_GUI_EXPORT QDataStream& operator<< ( QDataStream ,
const QIcon  
)

Definition at line 1096 of file qicon.cpp.

Referenced by QIcon::data_ptr().

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
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
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
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
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ operator>>()

Q_GUI_EXPORT QDataStream& operator>> ( QDataStream ,
QIcon  
)

Definition at line 1144 of file qicon.cpp.

Referenced by QIcon::data_ptr().

1145 {
1146  if (s.version() >= QDataStream::Qt_4_3) {
1147  icon = QIcon();
1148  QString key;
1149  s >> key;
1150  if (key == QLatin1String("QPixmapIconEngine")) {
1151  icon.d = new QIconPrivate;
1152  QIconEngineV2 *engine = new QPixmapIconEngine;
1153  icon.d->engine = engine;
1154  engine->read(s);
1155  } else if (key == QLatin1String("QIconLoaderEngine")) {
1156  icon.d = new QIconPrivate;
1157  QIconEngineV2 *engine = new QIconLoaderEngine();
1158  icon.d->engine = engine;
1159  engine->read(s);
1160 #if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
1161  } else if (QIconEngineFactoryInterfaceV2 *factory = qobject_cast<QIconEngineFactoryInterfaceV2*>(loaderV2()->instance(key))) {
1162  if (QIconEngineV2 *engine= factory->create()) {
1163  icon.d = new QIconPrivate;
1164  icon.d->engine = engine;
1165  engine->read(s);
1166  }
1167 #endif
1168  }
1169  } else if (s.version() == QDataStream::Qt_4_2) {
1170  icon = QIcon();
1171  int num_entries;
1172  QPixmap pm;
1173  QString fileName;
1174  QSize sz;
1175  uint mode;
1176  uint state;
1177 
1178  s >> num_entries;
1179  for (int i=0; i < num_entries; ++i) {
1180  s >> pm;
1181  s >> fileName;
1182  s >> sz;
1183  s >> mode;
1184  s >> state;
1185  if (pm.isNull())
1186  icon.addFile(fileName, sz, QIcon::Mode(mode), QIcon::State(state));
1187  else
1188  icon.addPixmap(pm, QIcon::Mode(mode), QIcon::State(state));
1189  }
1190  } else {
1191  QPixmap pm;
1192  s >> pm;
1193  icon.addPixmap(pm);
1194  }
1195  return s;
1196 }
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
QLatin1String("/iconengines")
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
virtual bool read(QDataStream &in)
Reads icon engine contents from the QDataStream in.
The QIconEngineV2 class provides an abstract base class for QIcon renderers.
Definition: qiconengine.h:73
int key
loaderV2
Definition: qicon.cpp:451
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
QIconEngine * engine
Definition: qicon_p.h:82
static QString fileName(const QString &fileUrl)
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ Q_DECLARE_TYPEINFO()

Q_DECLARE_TYPEINFO ( QIcon  ,
Q_MOVABLE_TYPE   
)

Referenced by QIcon::data_ptr().