Qt 4.8
Typedefs | Functions | Variables
qicon.cpp File Reference
#include "qicon.h"
#include "qicon_p.h"
#include "qiconengine.h"
#include "qiconengineplugin.h"
#include "private/qfactoryloader_p.h"
#include "private/qiconloader_p.h"
#include "qapplication.h"
#include "qstyleoption.h"
#include "qpainter.h"
#include "qfileinfo.h"
#include "qstyle.h"
#include "qpixmapcache.h"
#include "qvariant.h"
#include "qcache.h"
#include "qdebug.h"
#include "private/qguiplatformplugin_p.h"
#include <private/qt_mac_p.h>
#include <private/qt_cocoa_helpers_mac_p.h>
#include "private/qt_x11_p.h"
#include "private/qkde_p.h"
#include "private/qstylehelper_p.h"

Go to the source code of this file.

Typedefs

typedef QCache< QString, QIconIconCache
 

Functions

static int area (const QSize &s)
 
static QPixmapIconEngineEntrybestSizeMatch (const QSize &size, QPixmapIconEngineEntry *pa, QPixmapIconEngineEntry *pb)
 
QDataStreamoperator<< (QDataStream &s, const QIcon &icon)
 
QDataStreamoperator>> (QDataStream &s, QIcon &icon)
 
 Q_GLOBAL_STATIC_WITH_ARGS (QFactoryLoader, loader,(QIconEngineFactoryInterface_iid, QLatin1String("/iconengines"), Qt::CaseInsensitive)) Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader
 
 QLatin1String ("/iconengines")
 
static void qt_cleanup_icon_cache ()
 

Variables

 loaderV2
 
 QIconEngineFactoryInterfaceV2_iid
 
static QBasicAtomicInt serialNumCounter = Q_BASIC_ATOMIC_INITIALIZER(1)
 

Typedef Documentation

◆ IconCache

Definition at line 116 of file qicon.cpp.

Function Documentation

◆ area()

static int area ( const QSize s)
inlinestatic

Definition at line 155 of file qicon.cpp.

Referenced by QTableViewPrivate::accessibleTable2Index(), bestSizeMatch(), QPrintPreviewWidgetPrivate::calcCurrentPage(), QAbstractItemView::doAutoScroll(), QWindowsXPStylePrivate::drawBackgroundDirectly(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QTreeView::drawTree(), QTabBar::event(), QMdiArea::eventFilter(), QBspTree::firstChildIndex(), QRasterWindowSurface::flush(), QListViewPrivate::horizontalScrollToValue(), QBspTree::init(), QToolBar::isAreaAllowed(), QDockWidget::isAreaAllowed(), QDirectFBWindowSurface::key(), QMdiSubWindow::mdiArea(), mdiAreaNavigate(), mdiAreaParent(), QDeclarativePaintedItem::paint(), QFbWindowSurface::paintDevice(), QWSMemorySurface::paintDevice(), qt_mainwindow_layout(), QtWndProc(), QWidgetBackingStore::removeDirtyWidget(), QBspTree::removeLeaf(), QBBRasterWindowSurface::scroll(), QTreeView::scrollTo(), QMainWindowLayout::setCorner(), QToolBarLayout::setGeometry(), QDeclarativePaintedItem::setPixelCacheSize(), QListModeViewBase::setRowCount(), QAbstractItemViewPrivate::shouldAutoScroll(), QDirectFBScreen::surfaceForWidget(), QVGEGLWindowSurfaceDirect::surfaceSize(), QXIMInputContext::update(), QRegionPrivate::updateInnerRect(), QListViewPrivate::verticalScrollToValue(), and QCommonListViewBase::~QCommonListViewBase().

155 { return s.width() * s.height(); }
int width() const
Returns the width.
Definition: qsize.h:126
int height() const
Returns the height.
Definition: qsize.h:129

◆ bestSizeMatch()

static QPixmapIconEngineEntry* bestSizeMatch ( const QSize size,
QPixmapIconEngineEntry pa,
QPixmapIconEngineEntry pb 
)
static

Definition at line 158 of file qicon.cpp.

Referenced by QPixmapIconEngine::tryMatch().

159 {
160  int s = area(size);
161  if (pa->size == QSize() && pa->pixmap.isNull()) {
162  pa->pixmap = QPixmap(pa->fileName);
163  pa->size = pa->pixmap.size();
164  }
165  int a = area(pa->size);
166  if (pb->size == QSize() && pb->pixmap.isNull()) {
167  pb->pixmap = QPixmap(pb->fileName);
168  pb->size = pb->pixmap.size();
169  }
170  int b = area(pb->size);
171  int res = a;
172  if (qMin(a,b) >= s)
173  res = qMin(a,b);
174  else
175  res = qMax(a,b);
176  if (res == a)
177  return pa;
178  return pb;
179 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
long ASN1_INTEGER_get ASN1_INTEGER * a
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
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
static int area(const QSize &s)
Definition: qicon.cpp:155

◆ operator<<()

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

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
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

◆ operator>>()

QDataStream& operator>> ( QDataStream s,
QIcon icon 
)

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 }
void addPixmap(const QPixmap &pixmap, Mode mode=Normal, State state=Off)
Adds pixmap to the icon, as a specialization for mode and state.
Definition: qicon.cpp:814
QIconPrivate * d
Definition: qicon.h:135
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 version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
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)
void addFile(const QString &fileName, const QSize &size=QSize(), Mode mode=Normal, State state=Off)
Adds an image from the file with the given fileName to the icon, as a specialization for size...
Definition: qicon.cpp:851
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ Q_GLOBAL_STATIC_WITH_ARGS()

Q_GLOBAL_STATIC_WITH_ARGS ( QFactoryLoader  ,
loader  ,
(QIconEngineFactoryInterface_iid, QLatin1String("/iconengines"), Qt::CaseInsensitive)   
)

◆ QLatin1String()

QLatin1String ( "/iconengines"  )

◆ qt_cleanup_icon_cache()

static void qt_cleanup_icon_cache ( )
static

Definition at line 119 of file qicon.cpp.

120 {
121  qtIconCache()->clear();
122 }

Variable Documentation

◆ loaderV2

loaderV2

Definition at line 451 of file qicon.cpp.

Referenced by QIcon::addFile(), and operator>>().

◆ QIconEngineFactoryInterfaceV2_iid

QIconEngineFactoryInterfaceV2_iid

Definition at line 451 of file qicon.cpp.

Referenced by QIconLoader::ensureInitialized().

◆ serialNumCounter

QBasicAtomicInt serialNumCounter = Q_BASIC_ATOMIC_INITIALIZER(1)
static

Definition at line 113 of file qicon.cpp.