Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/image/qicon.cpp

    r261 r561  
    22**
    33** 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)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** 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.
    3838** $QT_END_LICENSE$
    3939**
     
    4141
    4242#include "qicon.h"
     43#include "qicon_p.h"
    4344#include "qiconengine.h"
    4445#include "qiconengineplugin.h"
    4546#include "private/qfactoryloader_p.h"
     47#include "private/qiconloader_p.h"
    4648#include "qapplication.h"
    4749#include "qstyleoption.h"
     
    5153#include "qpixmapcache.h"
    5254#include "qvariant.h"
     55#include "qcache.h"
    5356#include "qdebug.h"
     57#include "private/qguiplatformplugin_p.h"
    5458
    5559#ifdef Q_WS_MAC
    5660#include <private/qt_mac_p.h>
    57 #include <Carbon/Carbon.h>
     61#include <private/qt_cocoa_helpers_mac_p.h>
    5862#endif
    5963
     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
    6070QT_BEGIN_NAMESPACE
    6171
     
    95105static QBasicAtomicInt serialNumCounter = Q_BASIC_ATOMIC_INITIALIZER(1);
    96106
    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 };
     107QIconPrivate::QIconPrivate()
     108    : engine(0), ref(1),
     109    serialNum(serialNumCounter.fetchAndAddRelaxed(1)),
     110    detach_no(0),
     111    engine_version(2),
     112    v1RefCount(0)
     113{
     114}
    164115
    165116QPixmapIconEngine::QPixmapIconEngine()
     
    179130{
    180131    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();
    183134#endif
    184135    painter->drawPixmap(rect, pixmap(pixmapSize, mode, state));
     
    316267                  + QString::number(pm.cacheKey())
    317268                  + QString::number(pe->mode)
     269                  + QString::number(QApplication::palette().cacheKey())
     270                  + QLatin1Char('_')
    318271                  + QString::number(actualSize.width())
    319272                  + QLatin1Char('_')
     
    440393        in >> mode;
    441394        in >> state;
    442         if (pm.isNull())
     395        if (pm.isNull()) {
    443396            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        }
    446402    }
    447403    return true;
     
    503459  and states.
    504460
    505   \ingroup multimedia
     461  \ingroup painting
    506462  \ingroup shared
    507   \mainclass
     463
    508464
    509465  A QIcon can generate smaller, larger, active, and disabled pixmaps
     
    865821    QImageWriter::supportedImageFormats() functions to retrieve a
    866822    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.
    867826
    868827    \sa addPixmap()
     
    922881}
    923882
     883/*!
     884    \since 4.6
     885
     886    Sets the search paths for icon themes to \a paths.
     887    \sa themeSearchPaths(), fromTheme(), setThemeName()
     888*/
     889void 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*/
     910QStringList 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*/
     926void 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*/
     942QString 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*/
     975QIcon 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*/
     1003bool QIcon::hasThemeIcon(const QString &name)
     1004{
     1005    QIcon icon = fromTheme(name);
     1006
     1007    return !icon.isNull();
     1008}
     1009
     1010
    9241011/*****************************************************************************
    9251012  QIcon stream functions
     
    9311018    \since 4.2
    9321019
    933     Writes the given \a icon to the the given \a stream as a PNG
     1020    Writes the given \a icon to the given \a stream as a PNG
    9341021    image. If the icon contains more than one image, all images will
    9351022    be written to the stream. Note that writing the stream to a file
     
    9931080            icon.d->engine = engine;
    9941081            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);
    9951087#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
    9961088        } else if (QIconEngineFactoryInterfaceV2 *factory = qobject_cast<QIconEngineFactoryInterfaceV2*>(loaderV2()->instance(key))) {
     
    11381230
    11391231QT_END_NAMESPACE
     1232#endif //QT_NO_ICON
Note: See TracChangeset for help on using the changeset viewer.