Changeset 561 for trunk/src/gui/image/qicon.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/image/qicon.cpp
r261 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 41 41 42 42 #include "qicon.h" 43 #include "qicon_p.h" 43 44 #include "qiconengine.h" 44 45 #include "qiconengineplugin.h" 45 46 #include "private/qfactoryloader_p.h" 47 #include "private/qiconloader_p.h" 46 48 #include "qapplication.h" 47 49 #include "qstyleoption.h" … … 51 53 #include "qpixmapcache.h" 52 54 #include "qvariant.h" 55 #include "qcache.h" 53 56 #include "qdebug.h" 57 #include "private/qguiplatformplugin_p.h" 54 58 55 59 #ifdef Q_WS_MAC 56 60 #include <private/qt_mac_p.h> 57 #include < Carbon/Carbon.h>61 #include <private/qt_cocoa_helpers_mac_p.h> 58 62 #endif 59 63 64 #ifdef Q_WS_X11 65 #include "private/qt_x11_p.h" 66 #include "private/qkde_p.h" 67 #endif 68 69 #ifndef QT_NO_ICON 60 70 QT_BEGIN_NAMESPACE 61 71 … … 95 105 static QBasicAtomicInt serialNumCounter = Q_BASIC_ATOMIC_INITIALIZER(1); 96 106 97 class QIconPrivate 98 { 99 public: 100 QIconPrivate(): engine(0), ref(1), serialNum(serialNumCounter.fetchAndAddRelaxed(1)), detach_no(0), engine_version(2), v1RefCount(0) {} 101 102 ~QIconPrivate() { 103 if (engine_version == 1) { 104 if (!v1RefCount->deref()) { 105 delete engine; 106 delete v1RefCount; 107 } 108 } else if (engine_version == 2) { 109 delete engine; 110 } 111 } 112 113 QIconEngine *engine; 114 115 QAtomicInt ref; 116 int serialNum; 117 int detach_no; 118 int engine_version; 119 120 QAtomicInt *v1RefCount; 121 }; 122 123 124 struct QPixmapIconEngineEntry 125 { 126 QPixmapIconEngineEntry():mode(QIcon::Normal), state(QIcon::Off){} 127 QPixmapIconEngineEntry(const QPixmap &pm, QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off) 128 :pixmap(pm), size(pm.size()), mode(m), state(s){} 129 QPixmapIconEngineEntry(const QString &file, const QSize &sz = QSize(), QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off) 130 :fileName(file), size(sz), mode(m), state(s){} 131 QPixmap pixmap; 132 QString fileName; 133 QSize size; 134 QIcon::Mode mode; 135 QIcon::State state; 136 bool isNull() const {return (fileName.isEmpty() && pixmap.isNull()); } 137 }; 138 139 class QPixmapIconEngine : public QIconEngineV2 { 140 public: 141 QPixmapIconEngine(); 142 QPixmapIconEngine(const QPixmapIconEngine &); 143 ~QPixmapIconEngine(); 144 void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state); 145 QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state); 146 QPixmapIconEngineEntry *bestMatch(const QSize &size, QIcon::Mode mode, QIcon::State state, bool sizeOnly); 147 QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state); 148 void addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state); 149 void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state); 150 151 // v2 functions 152 QString key() const; 153 QIconEngineV2 *clone() const; 154 bool read(QDataStream &in); 155 bool write(QDataStream &out) const; 156 void virtual_hook(int id, void *data); 157 158 private: 159 QPixmapIconEngineEntry *tryMatch(const QSize &size, QIcon::Mode mode, QIcon::State state); 160 QVector<QPixmapIconEngineEntry> pixmaps; 161 162 friend QDataStream &operator<<(QDataStream &s, const QIcon &icon); 163 }; 107 QIconPrivate::QIconPrivate() 108 : engine(0), ref(1), 109 serialNum(serialNumCounter.fetchAndAddRelaxed(1)), 110 detach_no(0), 111 engine_version(2), 112 v1RefCount(0) 113 { 114 } 164 115 165 116 QPixmapIconEngine::QPixmapIconEngine() … … 179 130 { 180 131 QSize pixmapSize = rect.size(); 181 #if defined(Q_WS_MAC) && !defined(Q_WS_MAC64)182 pixmapSize *= (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) ? HIGetScaleFactor() : 1;132 #if defined(Q_WS_MAC) 133 pixmapSize *= qt_mac_get_scalefactor(); 183 134 #endif 184 135 painter->drawPixmap(rect, pixmap(pixmapSize, mode, state)); … … 316 267 + QString::number(pm.cacheKey()) 317 268 + QString::number(pe->mode) 269 + QString::number(QApplication::palette().cacheKey()) 270 + QLatin1Char('_') 318 271 + QString::number(actualSize.width()) 319 272 + QLatin1Char('_') … … 440 393 in >> mode; 441 394 in >> state; 442 if (pm.isNull()) 395 if (pm.isNull()) { 443 396 addFile(fileName, sz, QIcon::Mode(mode), QIcon::State(state)); 444 else 445 addPixmap(pm, QIcon::Mode(mode), QIcon::State(state)); 397 } else { 398 QPixmapIconEngineEntry pe(fileName, sz, QIcon::Mode(mode), QIcon::State(state)); 399 pe.pixmap = pm; 400 pixmaps += pe; 401 } 446 402 } 447 403 return true; … … 503 459 and states. 504 460 505 \ingroup multimedia461 \ingroup painting 506 462 \ingroup shared 507 \mainclass 463 508 464 509 465 A QIcon can generate smaller, larger, active, and disabled pixmaps … … 865 821 QImageWriter::supportedImageFormats() functions to retrieve a 866 822 complete list of the supported file formats. 823 824 Note: When you add a non-empty filename to a QIcon, the icon becomes 825 non-null, even if the file doesn't exist or points to a corrupt file. 867 826 868 827 \sa addPixmap() … … 922 881 } 923 882 883 /*! 884 \since 4.6 885 886 Sets the search paths for icon themes to \a paths. 887 \sa themeSearchPaths(), fromTheme(), setThemeName() 888 */ 889 void QIcon::setThemeSearchPaths(const QStringList &paths) 890 { 891 QIconLoader::instance()->setThemeSearchPath(paths); 892 } 893 894 /*! 895 \since 4.6 896 897 Returns the search paths for icon themes. 898 899 The default value will depend on the platform: 900 901 On X11, the search path will use the XDG_DATA_DIRS environment 902 variable if available. 903 904 By default all platforms will have the resource directory 905 \c{:\icons} as a fallback. You can use "rcc -project" to generate a 906 resource file from your icon theme. 907 908 \sa setThemeSearchPaths(), fromTheme(), setThemeName() 909 */ 910 QStringList QIcon::themeSearchPaths() 911 { 912 return QIconLoader::instance()->themeSearchPaths(); 913 } 914 915 /*! 916 \since 4.6 917 918 Sets the current icon theme to \a name. 919 920 The \a name should correspond to a directory name in the 921 themeSearchPath() containing an index.theme 922 file describing it's contents. 923 924 \sa themeSearchPaths(), themeName() 925 */ 926 void QIcon::setThemeName(const QString &name) 927 { 928 QIconLoader::instance()->setThemeName(name); 929 } 930 931 /*! 932 \since 4.6 933 934 Returns the name of the current icon theme. 935 936 On X11, the current icon theme depends on your desktop 937 settings. On other platforms it is not set by default. 938 939 \sa setThemeName(), themeSearchPaths(), fromTheme(), 940 hasThemeIcon() 941 */ 942 QString QIcon::themeName() 943 { 944 return QIconLoader::instance()->themeName(); 945 } 946 947 /*! 948 \since 4.6 949 950 Returns the QIcon corresponding to \a name in the current 951 icon theme. If no such icon is found in the current theme 952 \a fallback is return instead. 953 954 The lastest version of the freedesktop icon specification and naming 955 spesification can be obtained here: 956 http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html 957 http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html 958 959 To fetch an icon from the current icon theme: 960 961 \snippet doc/src/snippets/code/src_gui_image_qicon.cpp 3 962 963 Or if you want to provide a guaranteed fallback for platforms that 964 do not support theme icons, you can use the second argument: 965 966 \snippet doc/src/snippets/code/src_gui_image_qicon.cpp 4 967 968 \note By default, only X11 will support themed icons. In order to 969 use themed icons on Mac and Windows, you will have to bundle a 970 compliant theme in one of your themeSearchPaths() and set the 971 appropriate themeName(). 972 973 \sa themeName(), setThemeName(), themeSearchPaths() 974 */ 975 QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback) 976 { 977 static QCache <QString, QIcon> iconCache; 978 979 QIcon icon; 980 981 if (iconCache.contains(name)) { 982 icon = *iconCache.object(name); 983 } else { 984 QIcon *cachedIcon = new QIcon(new QIconLoaderEngine(name)); 985 iconCache.insert(name, cachedIcon); 986 icon = *cachedIcon; 987 } 988 989 if (icon.availableSizes().isEmpty()) 990 return fallback; 991 992 return icon; 993 } 994 995 /*! 996 \since 4.6 997 998 Returns true if there is an icon available for \a name in the 999 current icon theme, otherwise returns false. 1000 1001 \sa themeSearchPaths(), fromTheme(), setThemeName() 1002 */ 1003 bool QIcon::hasThemeIcon(const QString &name) 1004 { 1005 QIcon icon = fromTheme(name); 1006 1007 return !icon.isNull(); 1008 } 1009 1010 924 1011 /***************************************************************************** 925 1012 QIcon stream functions … … 931 1018 \since 4.2 932 1019 933 Writes the given \a icon to the thegiven \a stream as a PNG1020 Writes the given \a icon to the given \a stream as a PNG 934 1021 image. If the icon contains more than one image, all images will 935 1022 be written to the stream. Note that writing the stream to a file … … 993 1080 icon.d->engine = engine; 994 1081 engine->read(s); 1082 } else if (key == QLatin1String("QIconLoaderEngine")) { 1083 icon.d = new QIconPrivate; 1084 QIconEngineV2 *engine = new QIconLoaderEngine(); 1085 icon.d->engine = engine; 1086 engine->read(s); 995 1087 #if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) 996 1088 } else if (QIconEngineFactoryInterfaceV2 *factory = qobject_cast<QIconEngineFactoryInterfaceV2*>(loaderV2()->instance(key))) { … … 1138 1230 1139 1231 QT_END_NAMESPACE 1232 #endif //QT_NO_ICON
Note:
See TracChangeset
for help on using the changeset viewer.