Qt 4.8
qicon.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qicon.h"
43 #include "qicon_p.h"
44 #include "qiconengine.h"
45 #include "qiconengineplugin.h"
46 #include "private/qfactoryloader_p.h"
47 #include "private/qiconloader_p.h"
48 #include "qapplication.h"
49 #include "qstyleoption.h"
50 #include "qpainter.h"
51 #include "qfileinfo.h"
52 #include "qstyle.h"
53 #include "qpixmapcache.h"
54 #include "qvariant.h"
55 #include "qcache.h"
56 #include "qdebug.h"
57 #include "private/qguiplatformplugin_p.h"
58 
59 #ifdef Q_WS_MAC
60 #include <private/qt_mac_p.h>
61 #include <private/qt_cocoa_helpers_mac_p.h>
62 #endif
63 
64 #ifdef Q_WS_X11
65 #include "private/qt_x11_p.h"
66 #include "private/qkde_p.h"
67 #endif
68 
69 #include "private/qstylehelper_p.h"
70 
71 #ifndef QT_NO_ICON
73 
114 
115 static void qt_cleanup_icon_cache();
118 
120 {
121  qtIconCache()->clear();
122 }
123 
125  : engine(0), ref(1),
126  serialNum(serialNumCounter.fetchAndAddRelaxed(1)),
127  detach_no(0),
128  engine_version(2),
129  v1RefCount(0)
130 {
131 }
132 
134 {
135 }
136 
138  : QIconEngineV2(other), pixmaps(other.pixmaps)
139 {
140 }
141 
143 {
144 }
145 
146 void QPixmapIconEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state)
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 }
154 
155 static inline int area(const QSize &s) { return s.width() * s.height(); }
156 
157 // returns the smallest of the two that is still larger than or equal to size.
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 }
180 
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 }
193 
194 
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 }
246 
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);
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);
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 }
305 
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 }
319 
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 }
332 
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 }
366 
368 {
369  return QLatin1String("QPixmapIconEngine");
370 }
371 
373 {
374  return new QPixmapIconEngine(*this);
375 }
376 
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 }
407 
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 }
424 
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:
444  QIconEngineV2::virtual_hook(id, data);
445  }
446 }
447 
448 #ifndef QT_NO_LIBRARY
453 #endif
454 
455 
456 
529  : d(0)
530 {
531 }
532 
537  :d(0)
538 {
539  addPixmap(pixmap);
540 }
541 
545 QIcon::QIcon(const QIcon &other)
546  :d(other.d)
547 {
548  if (d)
549  d->ref.ref();
550 }
551 
570  : d(0)
571 {
572  addFile(fileName);
573 }
574 
575 
581  :d(new QIconPrivate)
582 {
583  d->engine_version = 1;
584  d->engine = engine;
585  d->v1RefCount = new QAtomicInt(1);
586 }
587 
593  :d(new QIconPrivate)
594 {
595  d->engine_version = 2;
596  d->engine = engine;
597 }
598 
603 {
604  if (d && !d->ref.deref())
605  delete d;
606 }
607 
613 {
614  if (other.d)
615  other.d->ref.ref();
616  if (d && !d->ref.deref())
617  delete d;
618  d = other.d;
619  return *this;
620 }
621 
636 QIcon::operator QVariant() const
637 {
638  return QVariant(QVariant::Icon, this);
639 }
640 
662 {
663  return d ? d->serialNum : 0;
664 }
665 
680 {
681  if (!d)
682  return 0;
683  return (((qint64) d->serialNum) << 32) | ((qint64) (d->detach_no));
684 }
685 
693 QPixmap QIcon::pixmap(const QSize &size, Mode mode, State state) const
694 {
695  if (!d)
696  return QPixmap();
697  return d->engine->pixmap(size, mode, state);
698 }
699 
730 QSize QIcon::actualSize(const QSize &size, Mode mode, State state) const
731 {
732  if (!d)
733  return QSize();
734  return d->engine->actualSize(size, mode, state);
735 }
736 
737 
744 void QIcon::paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment, Mode mode, State state) const
745 {
746  if (!d || !painter)
747  return;
748  QRect alignedRect = QStyle::alignedRect(painter->layoutDirection(), alignment, d->engine->actualSize(rect.size(), mode, state), rect);
749  d->engine->paint(painter, alignedRect, mode, state);
750 }
751 
769 bool QIcon::isNull() const
770 {
771  return !d;
772 }
773 
776 bool QIcon::isDetached() const
777 {
778  return !d || d->ref == 1;
779 }
780 
784 {
785  if (d) {
786  if (d->ref != 1) {
787  QIconPrivate *x = new QIconPrivate;
788  if (d->engine_version > 1) {
789  QIconEngineV2 *engine = static_cast<QIconEngineV2 *>(d->engine);
790  x->engine = engine->clone();
791  } else {
792  x->engine = d->engine;
793  x->v1RefCount = d->v1RefCount;
794  x->v1RefCount->ref();
795  }
797  if (!d->ref.deref())
798  delete d;
799  d = x;
800  }
801  ++d->detach_no;
802  }
803 }
804 
814 void QIcon::addPixmap(const QPixmap &pixmap, Mode mode, State state)
815 {
816  if (pixmap.isNull())
817  return;
818  if (!d) {
819  d = new QIconPrivate;
820  d->engine = new QPixmapIconEngine;
821  } else {
822  detach();
823  }
824  d->engine->addPixmap(pixmap, mode, state);
825 }
826 
827 
851 void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State state)
852 {
853  if (fileName.isEmpty())
854  return;
855  if (!d) {
856 #if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
857  QFileInfo info(fileName);
858  QString suffix = info.suffix();
859  if (!suffix.isEmpty()) {
860  // first try version 2 engines..
861  if (QIconEngineFactoryInterfaceV2 *factory = qobject_cast<QIconEngineFactoryInterfaceV2*>(loaderV2()->instance(suffix))) {
862  if (QIconEngine *engine = factory->create(fileName)) {
863  d = new QIconPrivate;
864  d->engine = engine;
865  }
866  }
867  // ..then fall back and try to load version 1 engines
868  if (!d) {
869  if (QIconEngineFactoryInterface *factory = qobject_cast<QIconEngineFactoryInterface*>(loader()->instance(suffix))) {
870  if (QIconEngine *engine = factory->create(fileName)) {
871  d = new QIconPrivate;
872  d->engine = engine;
873  d->engine_version = 1;
874  d->v1RefCount = new QAtomicInt(1);
875  }
876  }
877  }
878  }
879 #endif
880  // ...then fall back to the default engine
881  if (!d) {
882  d = new QIconPrivate;
883  d->engine = new QPixmapIconEngine;
884  }
885  } else {
886  detach();
887  }
888  d->engine->addFile(fileName, size, mode, state);
889 }
890 
901 {
902  if (!d || !d->engine || d->engine_version < 2)
903  return QList<QSize>();
904  QIconEngineV2 *engine = static_cast<QIconEngineV2*>(d->engine);
905  return engine->availableSizes(mode, state);
906 }
907 
923 {
924  if (!d || !d->engine || d->engine_version < 2)
925  return QString();
926  QIconEngineV2 *engine = static_cast<QIconEngineV2*>(d->engine);
927  return engine->iconName();
928 }
929 
940 {
942 }
943 
964 {
966 }
967 
983 {
985 }
986 
1002 {
1003  return QIconLoader::instance()->themeName();
1004 }
1005 
1040 {
1041  QIcon icon;
1042 
1043  if (qtIconCache()->contains(name)) {
1044  icon = *qtIconCache()->object(name);
1045  } else {
1046  QIcon *cachedIcon = new QIcon(new QIconLoaderEngine(name));
1047  qtIconCache()->insert(name, cachedIcon);
1048  icon = *cachedIcon;
1049  }
1050 
1051  // Note the qapp check is to allow lazy loading of static icons
1052  // Supporting fallbacks will not work for this case.
1053  if (qApp && icon.availableSizes().isEmpty())
1054  return fallback;
1055 
1056  return icon;
1057 }
1058 
1071 {
1072  QIcon icon = fromTheme(name);
1073 
1074  return !icon.isNull();
1075 }
1076 
1077 
1078 /*****************************************************************************
1079  QIcon stream functions
1080  *****************************************************************************/
1081 #if !defined(QT_NO_DATASTREAM)
1082 
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 }
1131 
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 }
1197 
1198 #endif //QT_NO_DATASTREAM
1199 
1200 
1201 #ifdef QT3_SUPPORT
1202 
1203 static int widths[2] = { 22, 32 };
1204 static int heights[2] = { 22, 32 };
1205 
1206 static QSize pixmapSizeHelper(QIcon::Size which)
1207 {
1208  int i = 0;
1209  if (which == QIcon::Large)
1210  i = 1;
1211  return QSize(widths[i], heights[i]);
1212 }
1213 
1229 QPixmap QIcon::pixmap(Size size, Mode mode, State state) const
1230 { return pixmap(pixmapSizeHelper(size), mode, state); }
1231 
1240 QPixmap QIcon::pixmap(Size size, bool enabled, State state) const
1241 { return pixmap(pixmapSizeHelper(size), enabled ? Normal : Disabled, state); }
1242 
1246 QPixmap QIcon::pixmap() const
1247 { return pixmap(pixmapSizeHelper(Small), Normal, Off); }
1248 
1253 void QIcon::setPixmapSize(Size which, const QSize &size)
1254 {
1255  int i = 0;
1256  if (which == Large)
1257  i = 1;
1258  widths[i] = size.width();
1259  heights[i] = size.height();
1260 }
1261 
1267 QSize QIcon::pixmapSize(Size which)
1268 {
1269  return pixmapSizeHelper(which);
1270 }
1271 
1301 #endif // QT3_SUPPORT
1302 
1314 #endif //QT_NO_ICON
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
virtual QString key() const
Returns a key that identifies this icon engine.
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 QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
static QRect alignedRect(Qt::LayoutDirection direction, Qt::Alignment alignment, const QSize &size, const QRect &rectangle)
Returns a new rectangle of the specified size that is aligned to the given rectangle according to the...
Definition: qstyle.cpp:2120
int serialNum
Definition: qicon_p.h:85
static void setThemeName(const QString &path)
Sets the current icon theme to name.
Definition: qicon.cpp:982
The QLatin1Literal class provides a thin wrapper around string literals used in source code...
void push_back(const T &t)
This function is provided for STL compatibility.
Definition: qlist.h:296
QList< QSize > availableSizes(Mode mode=Normal, State state=Off) const
Returns a list of available icon sizes for the specified mode and state.
Definition: qicon.cpp:900
int serialNumber() const
Returns a number that identifies the contents of this QIcon object.
Definition: qicon.cpp:661
QCache< QString, QIcon > IconCache
Definition: qicon.cpp:116
static mach_timebase_info_data_t info
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
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QVector< QPixmapIconEngineEntry > pixmaps
Definition: qicon_p.h:131
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QString iconName()
Returns the name used to create the engine, if available.
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
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
void remove(int i)
Removes the element at index position i.
Definition: qvector.h:374
The QAtomicInt class provides platform-independent atomic operations on integers. ...
Definition: qatomic.h:55
friend Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QIcon &)
Writes the given icon to the given stream as a PNG image.
Definition: qicon.cpp:1096
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
static void setThemeSearchPaths(const QStringList &searchpath)
Sets the search paths for icon themes to paths.
Definition: qicon.cpp:939
static QIcon fromTheme(const QString &name, const QIcon &fallback=QIcon())
Returns the QIcon corresponding to name in the current icon theme.
Definition: qicon.cpp:1039
virtual 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: qiconengine.cpp:87
QIconPrivate * d
Definition: qicon.h:135
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...
Definition: qcache.h:54
CGFloat qt_mac_get_scalefactor()
QAtomicInt * v1RefCount
Definition: qicon_p.h:89
qint64 cacheKey() const
Returns a number that identifies the contents of this QPalette object.
Definition: qpalette.cpp:1093
virtual QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
Returns the icon as a pixmap with the required size, mode, and state.
void setThemeName(const QString &themeName)
State
This enum describes the state for which a pixmap is intended to be used.
Definition: qicon.h:64
void setThemeSearchPath(const QStringList &searchPaths)
QAtomicInt ref
Definition: qicon_p.h:84
QPixmap scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
Definition: qpixmap.h:132
QString absoluteFilePath() const
Returns an absolute path including the file name.
Definition: qfileinfo.cpp:534
long ASN1_INTEGER_get ASN1_INTEGER * a
static QPalette palette()
Returns the application palette.
static QStyle * style()
Returns the application&#39;s style object.
bool ref()
Atomically increments the value of this QAtomicInt.
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
~QIcon()
Destroys the icon.
Definition: qicon.cpp:602
#define Q_BASIC_ATOMIC_INITIALIZER(a)
Definition: qbasicatomic.h:218
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...
Definition: qicon.cpp:146
static QStringList themeSearchPaths()
Returns the search paths for icon themes.
Definition: qicon.cpp:963
QIcon::Mode mode
the requested mode of an image.
Definition: qiconengine.h:87
#define QIconEngineFactoryInterface_iid
int engine_version
Definition: qicon_p.h:87
QIconEngineV2 * clone() const
Returns a clone of this icon engine.
Definition: qicon.cpp:372
void virtual_hook(int id, void *data)
Additional method to allow extending QIconEngineV2 without adding new virtual methods (and without br...
Definition: qicon.cpp:425
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
static QPixmap * find(const QString &key)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QIcon::State state
Definition: qicon_p.h:104
static QBasicAtomicInt serialNumCounter
Definition: qicon.cpp:113
QIcon::Mode mode
Definition: qicon_p.h:103
int width() const
Returns the width.
Definition: qsize.h:126
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QLatin1String("/iconengines")
This struct represents arguments to virtual_hook() function when id parameter is QIconEngineV2::Avail...
Definition: qiconengine.h:85
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
QIcon()
Constructs a null icon.
Definition: qicon.cpp:528
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString name() const
Returns the name used to create the icon, if available.
Definition: qicon.cpp:922
#define qApp
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
Mode
This enum type describes the mode for which a pixmap is intended to be used.
Definition: qicon.h:63
virtual void virtual_hook(int id, void *data)
Additional method to allow extending QIconEngineV2 without adding new virtual methods (and without br...
bool deref()
Atomically decrements the value of this QAtomicInt.
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
virtual void addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state)
Called by QIcon::addPixmap().
QList< QSize > sizes
image sizes that are available with specified mode and
Definition: qiconengine.h:89
Q_CORE_EXPORT void qWarning(const char *,...)
static QString themeName()
Returns the name of the current icon theme.
Definition: qicon.cpp:1001
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
virtual bool read(QDataStream &in)
Reads icon engine contents from the QDataStream in.
friend Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QIcon &)
Reads an image, or a set of images, from the given stream into the given icon.
Definition: qicon.cpp:1144
void clear()
Removes all items from the list.
Definition: qlist.h:764
__int64 qint64
Definition: qglobal.h:942
The State element defines configurations of objects and properties.
virtual QIconEngineV2 * clone() const
Returns a clone of this icon engine.
void detach()
Definition: qicon.cpp:783
The QIconEngineV2 class provides an abstract base class for QIcon renderers.
Definition: qiconengine.h:73
void addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state)
Called by QIcon::addPixmap().
Definition: qicon.cpp:320
static void qt_cleanup_icon_cache()
Definition: qicon.cpp:119
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QStringList themeSearchPaths() const
bool read(QDataStream &in)
Reads icon engine contents from the QDataStream in.
Definition: qicon.cpp:377
static QIconLoader * instance()
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
Qt::LayoutDirection layoutDirection() const
Returns the layout direction used by the painter when drawing text.
Definition: qpainter.cpp:8729
virtual bool write(QDataStream &out) const
Writes the contents of this engine to the QDataStream out.
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
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
QString themeName() const
qint64 cacheKey() const
Returns a number that identifies the contents of this QIcon object.
Definition: qicon.cpp:679
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,(QIconEngineFactoryInterface_iid, QLatin1String("/iconengines"), Qt::CaseInsensitive)) Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader
QSize actualSize(const QSize &size, Mode mode=Normal, State state=Off) const
Returns the actual size of the icon for the requested size, mode, and state.
Definition: qicon.cpp:730
bool isDetached() const
Definition: qicon.cpp:776
QIcon & operator=(const QIcon &other)
Assigns the other icon to this icon and returns a reference to this icon.
Definition: qicon.cpp:612
#define Q_GLOBAL_STATIC_WITH_INITIALIZER(TYPE, NAME, INITIALIZER)
Definition: qglobal.h:1996
QString suffix() const
Returns the suffix of the file.
Definition: qfileinfo.cpp:834
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
int key
QByteArray suffix
The QIconEngine class provides an abstract base class for QIcon renderers.
Definition: qiconengine.h:55
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
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
Definition: qnamespace.h:54
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
Definition: qpixmap.cpp:1136
loaderV2
Definition: qicon.cpp:451
static bool hasThemeIcon(const QString &name)
Returns true if there is an icon available for name in the current icon theme, otherwise returns fals...
Definition: qicon.cpp:1070
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
int detach_no
Definition: qicon_p.h:86
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
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
bool isNull() const
Returns true if both the width and height is 0; otherwise returns false.
Definition: qsize.h:117
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
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
QIconEngine * engine
Definition: qicon_p.h:82
QIconEngineFactoryInterfaceV2_iid
Definition: qicon.cpp:451
QIcon::State state
the requested state of an image.
Definition: qiconengine.h:88
QIconPrivate()
Definition: qicon.cpp:124
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
virtual void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state)=0
Uses the given painter to paint the icon with the required mode and state into the rectangle rect...
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
void qAddPostRoutine(QtCleanUpFunction ptr)
Adds a global routine that will be called from the QApplication destructor.
static QString fileName(const QString &fileUrl)
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
static QPixmapIconEngineEntry * bestSizeMatch(const QSize &size, QPixmapIconEngineEntry *pa, QPixmapIconEngineEntry *pb)
Definition: qicon.cpp:158
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
#define enabled
bool write(QDataStream &out) const
Writes the contents of this engine to the QDataStream out.
Definition: qicon.cpp:408
QPixmapIconEngineEntry * tryMatch(const QSize &size, QIcon::Mode mode, QIcon::State state)
Definition: qicon.cpp:181
void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state)
Called by QIcon::addFile().
Definition: qicon.cpp:333
virtual void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state)
Called by QIcon::addFile().
static QMenuBar * fallback
Definition: qmenu_mac.mm:1617
void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment=Qt::AlignCenter, Mode mode=Normal, State state=Off) const
Uses the painter to paint the icon with specified alignment, required mode, and state into the rectan...
Definition: qicon.cpp:744
static int area(const QSize &s)
Definition: qicon.cpp:155
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
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60