summaryrefslogtreecommitdiffstats
path: root/src/gui/image
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/image')
-rw-r--r--src/gui/image/image.pri15
-rw-r--r--src/gui/image/qbitmap.cpp16
-rw-r--r--src/gui/image/qbitmap.h2
-rw-r--r--src/gui/image/qbmphandler.cpp8
-rw-r--r--src/gui/image/qicon.cpp240
-rw-r--r--src/gui/image/qicon.h10
-rw-r--r--src/gui/image/qicon_p.h138
-rw-r--r--src/gui/image/qiconengine.cpp4
-rw-r--r--src/gui/image/qiconloader.cpp604
-rw-r--r--src/gui/image/qiconloader_p.h187
-rw-r--r--src/gui/image/qimage.cpp162
-rw-r--r--src/gui/image/qimageiohandler.cpp1
-rw-r--r--src/gui/image/qimageiohandler.h3
-rw-r--r--src/gui/image/qimagepixmapcleanuphooks.cpp113
-rw-r--r--src/gui/image/qimagepixmapcleanuphooks_p.h89
-rw-r--r--src/gui/image/qimagereader.cpp2
-rw-r--r--src/gui/image/qimagewriter.cpp2
-rw-r--r--src/gui/image/qmovie.cpp4
-rw-r--r--src/gui/image/qnativeimage.cpp22
-rw-r--r--src/gui/image/qnativeimage_p.h3
-rw-r--r--src/gui/image/qpicture.cpp84
-rw-r--r--src/gui/image/qpicture.h9
-rw-r--r--src/gui/image/qpicture_p.h10
-rw-r--r--src/gui/image/qpixmap.cpp277
-rw-r--r--src/gui/image/qpixmap.h31
-rw-r--r--src/gui/image/qpixmap_mac.cpp205
-rw-r--r--src/gui/image/qpixmap_mac_p.h7
-rw-r--r--src/gui/image/qpixmap_qws.cpp13
-rw-r--r--src/gui/image/qpixmap_raster.cpp64
-rw-r--r--src/gui/image/qpixmap_raster_p.h8
-rw-r--r--src/gui/image/qpixmap_s60.cpp236
-rw-r--r--src/gui/image/qpixmap_win.cpp26
-rw-r--r--src/gui/image/qpixmap_x11.cpp51
-rw-r--r--src/gui/image/qpixmap_x11_p.h15
-rw-r--r--src/gui/image/qpixmapcache.cpp435
-rw-r--r--src/gui/image/qpixmapcache.h27
-rw-r--r--src/gui/image/qpixmapcache_p.h98
-rw-r--r--src/gui/image/qpixmapdata.cpp59
-rw-r--r--src/gui/image/qpixmapdata_p.h24
-rw-r--r--src/gui/image/qpixmapdatafactory.cpp6
-rw-r--r--src/gui/image/qpixmapdatafactory_p.h2
-rw-r--r--src/gui/image/qpixmapfilter.cpp286
-rw-r--r--src/gui/image/qpixmapfilter_p.h29
-rw-r--r--src/gui/image/qpnghandler.cpp2
-rw-r--r--src/gui/image/qppmhandler.cpp2
-rw-r--r--src/gui/image/qxpmhandler.cpp6
46 files changed, 2862 insertions, 775 deletions
diff --git a/src/gui/image/image.pri b/src/gui/image/image.pri
index ca52974..0970385 100644
--- a/src/gui/image/image.pri
+++ b/src/gui/image/image.pri
@@ -6,6 +6,8 @@
HEADERS += \
image/qbitmap.h \
image/qicon.h \
+ image/qicon_p.h \
+ image/qiconloader_p.h \
image/qiconengine.h \
image/qiconengineplugin.h \
image/qimage.h \
@@ -22,13 +24,17 @@ HEADERS += \
image/qpixmap.h \
image/qpixmap_raster_p.h \
image/qpixmapcache.h \
+ image/qpixmapcache_p.h \
image/qpixmapdata_p.h \
image/qpixmapdatafactory_p.h \
- image/qpixmapfilter_p.h
+ image/qpixmapfilter_p.h \
+ image/qimagepixmapcleanuphooks_p.h \
+
SOURCES += \
image/qbitmap.cpp \
image/qicon.cpp \
+ image/qiconloader.cpp \
image/qimage.cpp \
image/qimageiohandler.cpp \
image/qimagereader.cpp \
@@ -46,6 +52,8 @@ SOURCES += \
image/qmovie.cpp \
image/qpixmap_raster.cpp \
image/qnativeimage.cpp \
+ image/qimagepixmapcleanuphooks.cpp \
+
win32 {
SOURCES += image/qpixmap_win.cpp
@@ -61,6 +69,9 @@ mac {
HEADERS += image/qpixmap_mac_p.h
SOURCES += image/qpixmap_mac.cpp
}
+symbian {
+ SOURCES += image/qpixmap_s60.cpp
+}
# Built-in image format support
HEADERS += \
@@ -81,7 +92,7 @@ SOURCES += \
SOURCES += image/qpnghandler.cpp
contains(QT_CONFIG, system-png) {
- unix:LIBS += -lpng
+ unix:LIBS_PRIVATE += -lpng
win32:LIBS += libpng.lib
} else {
!isEqual(QT_ARCH, i386):!isEqual(QT_ARCH, x86_64):DEFINES += PNG_NO_ASSEMBLER_CODE
diff --git a/src/gui/image/qbitmap.cpp b/src/gui/image/qbitmap.cpp
index 820b25e..8c3b9be 100644
--- a/src/gui/image/qbitmap.cpp
+++ b/src/gui/image/qbitmap.cpp
@@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE
\class QBitmap
\brief The QBitmap class provides monochrome (1-bit depth) pixmaps.
- \ingroup multimedia
+ \ingroup painting
\ingroup shared
The QBitmap class is a monochrome off-screen paint device used
@@ -78,7 +78,7 @@ QT_BEGIN_NAMESPACE
0 for black and 1 for white.
The QBitmap class provides the transformed() function returning a
- transformed copy of the bitmap; use the QMatrix argument to
+ transformed copy of the bitmap; use the QTransform argument to
translate, scale, shear, and rotate the bitmap. In addition,
QBitmap provides the static fromData() function which returns a
bitmap constructed from the given \c uchar data, and the static
@@ -265,15 +265,12 @@ QBitmap QBitmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags)
img.setColor(1, c0);
}
- QPixmapData *d;
QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem();
- if (gs)
- d = gs->createPixmapData(QPixmapData::BitmapType);
- else
- d = QGraphicsSystem::createDefaultPixmapData(QPixmapData::BitmapType);
+ QScopedPointer<QPixmapData> data(gs ? gs->createPixmapData(QPixmapData::BitmapType)
+ : QGraphicsSystem::createDefaultPixmapData(QPixmapData::BitmapType));
- d->fromImage(img, flags | Qt::MonoOnly);
- return QPixmap(d);
+ data->fromImage(img, flags | Qt::MonoOnly);
+ return QPixmap(data.take());
}
/*!
@@ -318,6 +315,7 @@ QBitmap QBitmap::transformed(const QTransform &matrix) const
/*!
\overload
+ \obsolete
This convenience function converts the \a matrix to a QTransform
and calls the overloaded function.
diff --git a/src/gui/image/qbitmap.h b/src/gui/image/qbitmap.h
index d095b62..c531061 100644
--- a/src/gui/image/qbitmap.h
+++ b/src/gui/image/qbitmap.h
@@ -82,6 +82,8 @@ public:
QT3_SUPPORT_CONSTRUCTOR QBitmap(const QImage &image) { *this = fromImage(image); }
QT3_SUPPORT QBitmap &operator=(const QImage &image) { *this = fromImage(image); return *this; }
#endif
+
+ typedef QExplicitlySharedDataPointer<QPixmapData> DataPtr;
};
Q_DECLARE_SHARED(QBitmap)
diff --git a/src/gui/image/qbmphandler.cpp b/src/gui/image/qbmphandler.cpp
index e24fdcc..0380026 100644
--- a/src/gui/image/qbmphandler.cpp
+++ b/src/gui/image/qbmphandler.cpp
@@ -81,14 +81,14 @@ static void swapPixel01(QImage *image) // 1-bpp: swap 0 and 1 pixels
const int BMP_FILEHDR_SIZE = 14; // size of BMP_FILEHDR data
-QDataStream &operator>>(QDataStream &s, BMP_FILEHDR &bf)
+static QDataStream &operator>>(QDataStream &s, BMP_FILEHDR &bf)
{ // read file header
s.readRawData(bf.bfType, 2);
s >> bf.bfSize >> bf.bfReserved1 >> bf.bfReserved2 >> bf.bfOffBits;
return s;
}
-QDataStream &operator<<(QDataStream &s, const BMP_FILEHDR &bf)
+static QDataStream &operator<<(QDataStream &s, const BMP_FILEHDR &bf)
{ // write file header
s.writeRawData(bf.bfType, 2);
s << bf.bfSize << bf.bfReserved1 << bf.bfReserved2 << bf.bfOffBits;
@@ -106,7 +106,7 @@ const int BMP_RLE4 = 2; // run-length encoded, 4
const int BMP_BITFIELDS = 3; // RGB values encoded in data as bit-fields
-QDataStream &operator>>(QDataStream &s, BMP_INFOHDR &bi)
+static QDataStream &operator>>(QDataStream &s, BMP_INFOHDR &bi)
{
s >> bi.biSize;
if (bi.biSize == BMP_WIN || bi.biSize == BMP_OS2) {
@@ -128,7 +128,7 @@ QDataStream &operator>>(QDataStream &s, BMP_INFOHDR &bi)
return s;
}
-QDataStream &operator<<(QDataStream &s, const BMP_INFOHDR &bi)
+static QDataStream &operator<<(QDataStream &s, const BMP_INFOHDR &bi)
{
s << bi.biSize;
s << bi.biWidth << bi.biHeight;
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp
index 28796e3..a4ea6af 100644
--- a/src/gui/image/qicon.cpp
+++ b/src/gui/image/qicon.cpp
@@ -40,9 +40,11 @@
****************************************************************************/
#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"
@@ -50,11 +52,17 @@
#include "qstyle.h"
#include "qpixmapcache.h"
#include "qvariant.h"
+#include "qcache.h"
#include "qdebug.h"
#ifdef Q_WS_MAC
#include <private/qt_mac_p.h>
-#include <Carbon/Carbon.h>
+#include <private/qt_cocoa_helpers_mac_p.h>
+#endif
+
+#ifdef Q_WS_X11
+#include "private/qt_x11_p.h"
+#include "private/qkde_p.h"
#endif
QT_BEGIN_NAMESPACE
@@ -94,73 +102,14 @@ QT_BEGIN_NAMESPACE
static QBasicAtomicInt serialNumCounter = Q_BASIC_ATOMIC_INITIALIZER(1);
-class QIconPrivate
-{
-public:
- QIconPrivate(): engine(0), ref(1), serialNum(serialNumCounter.fetchAndAddRelaxed(1)), detach_no(0), engine_version(2), v1RefCount(0) {}
-
- ~QIconPrivate() {
- if (engine_version == 1) {
- if (!v1RefCount->deref()) {
- delete engine;
- delete v1RefCount;
- }
- } else if (engine_version == 2) {
- delete engine;
- }
- }
-
- QIconEngine *engine;
-
- QAtomicInt ref;
- int serialNum;
- int detach_no;
- int engine_version;
-
- QAtomicInt *v1RefCount;
-};
-
-
-struct QPixmapIconEngineEntry
+QIconPrivate::QIconPrivate()
+ : engine(0), ref(1),
+ serialNum(serialNumCounter.fetchAndAddRelaxed(1)),
+ detach_no(0),
+ engine_version(2),
+ v1RefCount(0)
{
- QPixmapIconEngineEntry():mode(QIcon::Normal), state(QIcon::Off){}
- QPixmapIconEngineEntry(const QPixmap &pm, QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off)
- :pixmap(pm), size(pm.size()), mode(m), state(s){}
- QPixmapIconEngineEntry(const QString &file, const QSize &sz = QSize(), QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off)
- :fileName(file), size(sz), mode(m), state(s){}
- QPixmap pixmap;
- QString fileName;
- QSize size;
- QIcon::Mode mode;
- QIcon::State state;
- bool isNull() const {return (fileName.isEmpty() && pixmap.isNull()); }
-};
-
-class QPixmapIconEngine : public QIconEngineV2 {
-public:
- QPixmapIconEngine();
- QPixmapIconEngine(const QPixmapIconEngine &);
- ~QPixmapIconEngine();
- void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state);
- QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
- QPixmapIconEngineEntry *bestMatch(const QSize &size, QIcon::Mode mode, QIcon::State state, bool sizeOnly);
- QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state);
- void addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state);
- void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state);
-
- // v2 functions
- QString key() const;
- QIconEngineV2 *clone() const;
- bool read(QDataStream &in);
- bool write(QDataStream &out) const;
- void virtual_hook(int id, void *data);
-
-private:
- QPixmapIconEngineEntry *tryMatch(const QSize &size, QIcon::Mode mode, QIcon::State state);
- QVector<QPixmapIconEngineEntry> pixmaps;
-
- friend QDataStream &operator<<(QDataStream &s, const QIcon &icon);
-};
+}
QPixmapIconEngine::QPixmapIconEngine()
{
@@ -178,8 +127,8 @@ QPixmapIconEngine::~QPixmapIconEngine()
void QPixmapIconEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state)
{
QSize pixmapSize = rect.size();
-#if defined(Q_WS_MAC) && !defined(Q_WS_MAC64)
- pixmapSize *= (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) ? HIGetScaleFactor() : 1;
+#if defined(Q_WS_MAC)
+ pixmapSize *= qt_mac_get_scalefactor();
#endif
painter->drawPixmap(rect, pixmap(pixmapSize, mode, state));
}
@@ -304,6 +253,8 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St
QString key = QLatin1String("$qt_icon_")
+ QString::number(pm.cacheKey())
+ QString::number(pe->mode)
+ + QString::number(QApplication::palette().cacheKey())
+ + QLatin1Char('_')
+ QString::number(actualSize.width())
+ QLatin1Char('_')
+ QString::number(actualSize.height())
@@ -494,9 +445,9 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loaderV2,
\brief The QIcon class provides scalable icons in different modes
and states.
- \ingroup multimedia
+ \ingroup painting
\ingroup shared
- \mainclass
+
A QIcon can generate smaller, larger, active, and disabled pixmaps
from the set of pixmaps it is given. Such pixmaps are used by Qt
@@ -916,6 +867,148 @@ QList<QSize> QIcon::availableSizes(Mode mode, State state) const
return engine->availableSizes(mode, state);
}
+/*!
+ \since 4.6
+
+ Sets the search paths for icon themes to \a paths.
+ \sa themeSearchPaths(), fromTheme(), setThemeName()
+*/
+void QIcon::setThemeSearchPaths(const QStringList &paths)
+{
+ QIconLoader::instance()->setThemeSearchPath(paths);
+}
+
+/*!
+ \since 4.6
+
+ Returns the search paths for icon themes.
+
+ The default value will depend on the platform:
+
+ On X11, the search path will use the XDG_DATA_DIRS environment
+ variable if available.
+
+ On Windows the search path defaults to [Application Directory]/icons
+
+ On Mac the default search path will search in the
+ [Contents/Resources/icons] part of the application bundle.
+
+ \sa setThemeSearchPaths(), fromTheme(), setThemeName()
+*/
+QStringList QIcon::themeSearchPaths()
+{
+ return QIconLoader::instance()->themeSearchPaths();
+}
+
+/*!
+ \since 4.6
+
+ Sets the current icon theme to \a name.
+
+ The \a name should correspond to a directory name in the
+ current themeSearchPath() containing an index.theme
+ file describing it's contents.
+
+ \sa themeSearchPaths(), themeName()
+*/
+void QIcon::setThemeName(const QString &name)
+{
+ QIconLoader::instance()->setThemeName(name);
+}
+
+/*!
+ \since 4.6
+
+ Returns the name of the current icon theme.
+
+ On X11, the current icon theme depends on your desktop
+ settings. On other platforms it is not set by default.
+
+ \sa setThemeName(), themeSearchPaths(), fromTheme(),
+ hasThemeIcon()
+*/
+QString QIcon::themeName()
+{
+ return QIconLoader::instance()->themeName();
+}
+
+/*!
+ \since 4.6
+
+ Returns the QIcon corresponding to \a name in the current
+ icon theme. If no such icon is found in the current theme
+ \a fallback is return instead.
+
+ To use an icon theme on Windows or Mac, you will need to
+ bundle a compliant theme with your application and make sure
+ it is located in your themeSarchPaths.
+
+ The lastest version of the freedesktop icon specification and naming
+ spesification can be obtained here:
+ http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
+ http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
+
+ To fetch an icon from the current icon theme:
+
+ \snippet doc/src/snippets/code/src_gui_image_qicon.cpp 3
+
+ Or if you want to provide a guaranteed fallback for platforms that
+ do not support theme icons, you can use the second argument:
+
+ \snippet doc/src/snippets/code/src_gui_image_qicon.cpp 4
+
+ \note By default, only X11 will support themed icons. In order to
+ use themed icons on Mac and Windows, you will have to bundle a
+ compliant theme in one of your themeSearchPaths() and set the
+ appropriate themeName().
+
+ \sa themeName(), setThemeName(), themeSearchPaths()
+*/
+QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback)
+{
+
+ static QCache <QString, QIcon> iconCache;
+
+ QIcon icon;
+
+#ifdef Q_WS_X11
+ if (X11->desktopEnvironment == DE_KDE) {
+ icon = QKde::kdeIcon(name);
+ if (!icon.isNull())
+ return icon;
+ }
+#endif
+
+ if (iconCache.contains(name)) {
+ icon = *iconCache.object(name);
+ } else {
+ QIcon *cachedIcon = new QIcon(new QIconLoaderEngine(name));
+ iconCache.insert(name, cachedIcon);
+ icon = *cachedIcon;
+ }
+
+ if (icon.availableSizes().isEmpty())
+ return fallback;
+
+ return icon;
+}
+
+/*!
+ \since 4.6
+
+ Returns true if there is an icon available for \a name in the
+ current icon theme, otherwise returns false.
+
+ \sa themeSearchPaths(), fromTheme(), setThemeName()
+*/
+bool QIcon::hasThemeIcon(const QString &name)
+{
+ QIcon icon = fromTheme(name);
+
+ return !icon.isNull();
+}
+
+
/*****************************************************************************
QIcon stream functions
*****************************************************************************/
@@ -987,6 +1080,11 @@ QDataStream &operator>>(QDataStream &s, QIcon &icon)
QIconEngineV2 *engine = new QPixmapIconEngine;
icon.d->engine = engine;
engine->read(s);
+ } else if (key == QLatin1String("QIconLoaderEngine")) {
+ icon.d = new QIconPrivate;
+ QIconEngineV2 *engine = new QIconLoaderEngine();
+ icon.d->engine = engine;
+ engine->read(s);
#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
} else if (QIconEngineFactoryInterfaceV2 *factory = qobject_cast<QIconEngineFactoryInterfaceV2*>(loaderV2()->instance(key))) {
if (QIconEngineV2 *engine= factory->create()) {
diff --git a/src/gui/image/qicon.h b/src/gui/image/qicon.h
index 7c412f1..676a055 100644
--- a/src/gui/image/qicon.h
+++ b/src/gui/image/qicon.h
@@ -97,6 +97,16 @@ public:
QList<QSize> availableSizes(Mode mode = Normal, State state = Off) const;
+ static QIcon fromTheme(const QString &name, const QIcon &fallback = QIcon());
+ static bool hasThemeIcon(const QString &name);
+
+ static QStringList themeSearchPaths();
+ static void setThemeSearchPaths(const QStringList &searchpath);
+
+ static QString themeName();
+ static void setThemeName(const QString &path);
+
+
#ifdef QT3_SUPPORT
enum Size { Small, Large, Automatic = Small };
static QT3_SUPPORT void setPixmapSize(Size which, const QSize &size);
diff --git a/src/gui/image/qicon_p.h b/src/gui/image/qicon_p.h
new file mode 100644
index 0000000..5525ac5
--- /dev/null
+++ b/src/gui/image/qicon_p.h
@@ -0,0 +1,138 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QICON_P_H
+#define QICON_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+#include <QtCore/qsize.h>
+#include <QtCore/qlist.h>
+#include <QtGui/qpixmap.h>
+#include <QtGui/qicon.h>
+#include <QtGui/qiconengine.h>
+
+QT_BEGIN_NAMESPACE
+
+class QIconPrivate
+{
+public:
+ QIconPrivate();
+
+ ~QIconPrivate() {
+ if (engine_version == 1) {
+ if (!v1RefCount->deref()) {
+ delete engine;
+ delete v1RefCount;
+ }
+ } else if (engine_version == 2) {
+ delete engine;
+ }
+ }
+
+ QIconEngine *engine;
+
+ QAtomicInt ref;
+ int serialNum;
+ int detach_no;
+ int engine_version;
+
+ QAtomicInt *v1RefCount;
+};
+
+
+struct QPixmapIconEngineEntry
+{
+ QPixmapIconEngineEntry():mode(QIcon::Normal), state(QIcon::Off){}
+ QPixmapIconEngineEntry(const QPixmap &pm, QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off)
+ :pixmap(pm), size(pm.size()), mode(m), state(s){}
+ QPixmapIconEngineEntry(const QString &file, const QSize &sz = QSize(), QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off)
+ :fileName(file), size(sz), mode(m), state(s){}
+ QPixmap pixmap;
+ QString fileName;
+ QSize size;
+ QIcon::Mode mode;
+ QIcon::State state;
+ bool isNull() const {return (fileName.isEmpty() && pixmap.isNull()); }
+};
+
+
+
+class QPixmapIconEngine : public QIconEngineV2 {
+public:
+ QPixmapIconEngine();
+ QPixmapIconEngine(const QPixmapIconEngine &);
+ ~QPixmapIconEngine();
+ void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state);
+ QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
+ QPixmapIconEngineEntry *bestMatch(const QSize &size, QIcon::Mode mode, QIcon::State state, bool sizeOnly);
+ QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state);
+ void addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state);
+ void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state);
+
+ // v2 functions
+ QString key() const;
+ QIconEngineV2 *clone() const;
+ bool read(QDataStream &in);
+ bool write(QDataStream &out) const;
+ void virtual_hook(int id, void *data);
+
+private:
+ QPixmapIconEngineEntry *tryMatch(const QSize &size, QIcon::Mode mode, QIcon::State state);
+ QVector<QPixmapIconEngineEntry> pixmaps;
+
+ friend QDataStream &operator<<(QDataStream &s, const QIcon &icon);
+ friend class QIconThemeEngine;
+};
+
+QT_END_NAMESPACE
+
+#endif // QICON_P_H
diff --git a/src/gui/image/qiconengine.cpp b/src/gui/image/qiconengine.cpp
index 7807f63..67bf401 100644
--- a/src/gui/image/qiconengine.cpp
+++ b/src/gui/image/qiconengine.cpp
@@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE
\brief The QIconEngine class provides an abstract base class for QIcon renderers.
- \ingroup multimedia
+ \ingroup painting
\bold {Use QIconEngineV2 instead.}
@@ -144,7 +144,7 @@ void QIconEngine::addFile(const QString &/*fileName*/, const QSize &/*size*/, QI
\brief The QIconEngineV2 class provides an abstract base class for QIcon renderers.
- \ingroup multimedia
+ \ingroup painting
\since 4.3
An icon engine renders \l{QIcon}s. With icon engines, you can
diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp
new file mode 100644
index 0000000..e5f0043
--- /dev/null
+++ b/src/gui/image/qiconloader.cpp
@@ -0,0 +1,604 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <private/qiconloader_p.h>
+
+#include <private/qapplication_p.h>
+#include <private/qicon_p.h>
+#include <private/qkde_p.h>
+
+#include <QtGui/QIconEnginePlugin>
+#include <QtGui/QPixmapCache>
+#include <QtGui/QIconEngine>
+#include <QtGui/QStyleOption>
+#include <QtCore/QList>
+#include <QtCore/QHash>
+#include <QtCore/QDir>
+#include <QtCore/QSettings>
+#include <QtGui/QPainter>
+
+#ifdef Q_WS_MAC
+#include <private/qt_cocoa_helpers_mac_p.h>
+#endif
+
+#ifdef Q_WS_X11
+#include <private/qt_x11_p.h>
+#include <private/gtksymbols_p.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+Q_GLOBAL_STATIC(QIconLoader, iconLoaderInstance)
+
+static QString systemThemeName()
+{
+ QString result;
+#ifdef Q_WS_X11
+ if (X11->desktopEnvironment == DE_GNOME) {
+#if defined(QT_NO_STYLE_GTK)
+ result = QLatin1String("gnome");
+#else
+ result = QGtk::getGConfString(QLatin1String("/desktop/gnome/interface/icon_theme"),
+ QLatin1String("gnome"));
+#endif
+ } else if (X11->desktopEnvironment == DE_KDE) {
+ QString kdeDefault = X11->desktopVersion >= 4 ?
+ QString::fromLatin1("oxygen") :
+ QString::fromLatin1("crystalsvg");
+
+ QSettings settings(QKde::kdeHome() +
+ QLatin1String("/share/config/kdeglobals"),
+ QSettings::IniFormat);
+
+ settings.beginGroup(QLatin1String("Icons"));
+
+ result = settings.value(QLatin1String("Theme"), kdeDefault).toString();
+ }
+#endif
+ return result;
+}
+
+static QString fallbackTheme()
+{
+ QString defaultTheme = systemThemeName();
+ if (defaultTheme.isEmpty())
+ defaultTheme = QLatin1String("hicolor");
+ return defaultTheme;
+}
+
+QIconLoader::QIconLoader() :
+ m_themeKey(1), m_supportsSvg(false)
+{
+ m_systemTheme = systemThemeName();
+
+ QFactoryLoader iconFactoryLoader(QIconEngineFactoryInterfaceV2_iid,
+ QLatin1String("/iconengines"),
+ Qt::CaseInsensitive);
+ if (iconFactoryLoader.keys().contains(QLatin1String("svg")))
+ m_supportsSvg = true;
+}
+
+QIconLoader *QIconLoader::instance()
+{
+ return iconLoaderInstance();
+}
+
+// Queries the system theme and invalidates existing
+// icons if the theme has changed.
+void QIconLoader::updateSystemTheme()
+{
+ // Only change if this is not explicitly set by the user
+ if (m_userTheme.isEmpty()) {
+ QString theme = systemThemeName();
+ if (theme != m_systemTheme) {
+ m_systemTheme = theme;
+ invalidateKey();
+ }
+ }
+}
+
+void QIconLoader::setThemeName(const QString &themeName)
+{
+ m_userTheme = themeName;
+ invalidateKey();
+}
+
+void QIconLoader::setThemeSearchPath(const QStringList &searchPaths)
+{
+ m_iconDirs = searchPaths;
+ themeList.clear();
+ invalidateKey();
+}
+
+QStringList QIconLoader::themeSearchPaths() const
+{
+ if (m_iconDirs.isEmpty()) {
+
+#if defined(Q_WS_X11)
+
+ QString xdgDirString = QFile::decodeName(getenv("XDG_DATA_DIRS"));
+ if (xdgDirString.isEmpty())
+ xdgDirString = QLatin1String("/usr/local/share/:/usr/share/");
+
+ QStringList xdgDirs = xdgDirString.split(QLatin1Char(':'));
+
+ for (int i = 0 ; i < xdgDirs.size() ; ++i) {
+ QDir dir(xdgDirs[i]);
+ if (dir.exists())
+ m_iconDirs.append(dir.path() +
+ QLatin1String("/icons"));
+ }
+
+ if (X11->desktopEnvironment == DE_KDE) {
+
+ m_iconDirs << QLatin1Char(':') +
+ QKde::kdeHome() +
+ QLatin1String("/share/icons");
+ QStringList kdeDirs =
+ QFile::decodeName(getenv("KDEDIRS")).split(QLatin1Char(':'));
+
+ for (int i = 0 ; i< kdeDirs.count() ; ++i) {
+ QDir dir(QLatin1Char(':') + kdeDirs.at(i) +
+ QLatin1String("/share/icons"));
+ if (dir.exists())
+ m_iconDirs.append(dir.path());
+ }
+ }
+
+ // Add home directory first in search path
+ QDir homeDir(QDir::homePath() + QLatin1String("/.icons"));
+ if (homeDir.exists())
+ m_iconDirs.prepend(homeDir.path());
+
+#elif defined(Q_WS_WIN)
+ m_iconDirs.append(qApp->applicationDirPath() +
+ QLatin1String("/icons"));
+#elif defined(Q_WS_MAC)
+ m_iconDirs.append(qApp->applicationDirPath() +
+ QLatin1String("/../Resources/icons"));
+#endif
+ }
+ return m_iconDirs;
+}
+
+QIconTheme::QIconTheme(const QString &themeName)
+ : m_valid(false)
+{
+ QFile themeIndex;
+
+ QList <QIconDirInfo> keyList;
+ QStringList iconDirs = QIcon::themeSearchPaths();
+ for ( int i = 0 ; i < iconDirs.size() ; ++i) {
+ QDir iconDir(iconDirs[i]);
+ QString themeDir = iconDir.path() + QLatin1Char('/') + themeName;
+ themeIndex.setFileName(themeDir + QLatin1String("/index.theme"));
+ if (themeIndex.exists()) {
+ m_contentDir = themeDir;
+ m_valid = true;
+ break;
+ }
+ }
+
+ if (themeIndex.exists()) {
+ const QSettings indexReader(themeIndex.fileName(), QSettings::IniFormat);
+ QStringListIterator keyIterator(indexReader.allKeys());
+ while (keyIterator.hasNext()) {
+
+ const QString key = keyIterator.next();
+ if (key.endsWith(QLatin1String("/Size"))) {
+ // Note the QSettings ini-format does not accept
+ // slashes in key names, hence we have to cheat
+ if (int size = indexReader.value(key).toInt()) {
+ QString directoryKey = key.left(key.size() - 5);
+ QIconDirInfo dirInfo(directoryKey);
+ dirInfo.size = size;
+ QString type = indexReader.value(directoryKey +
+ QLatin1String("/Type")
+ ).toString();
+
+ if (type == QLatin1String("Fixed"))
+ dirInfo.type = QIconDirInfo::Fixed;
+ else if (type == QLatin1String("Scalable"))
+ dirInfo.type = QIconDirInfo::Scalable;
+ else
+ dirInfo.type = QIconDirInfo::Threshold;
+
+ dirInfo.threshold = indexReader.value(directoryKey +
+ QLatin1String("/Threshold"),
+ 2).toInt();
+
+ dirInfo.minSize = indexReader.value(directoryKey +
+ QLatin1String("/MinSize"),
+ size).toInt();
+
+ dirInfo.maxSize = indexReader.value(directoryKey +
+ QLatin1String("/MaxSize"),
+ size).toInt();
+ m_keyList.append(dirInfo);
+ }
+ }
+ }
+
+ // Parent themes provide fallbacks for missing icons
+ m_parents = indexReader.value(
+ QLatin1String("Icon Theme/Inherits")).toStringList();
+
+ // Ensure a default platform fallback for all themes
+ if (m_parents.isEmpty())
+ m_parents.append(fallbackTheme());
+
+ // Ensure that all themes fall back to hicolor
+ if (!m_parents.isEmpty())
+ m_parents.append(QLatin1String("hicolor"));
+ }
+}
+
+QThemeIconEntries QIconLoader::findIconHelper(const QString &themeName,
+ const QString &iconName,
+ QStringList &visited) const
+{
+ QThemeIconEntries entries;
+ Q_ASSERT(!themeName.isEmpty());
+
+ QPixmap pixmap;
+
+ // Used to protect against potential recursions
+ visited << themeName;
+
+ QIconTheme theme = themeList.value(themeName);
+ if (!theme.isValid()) {
+ theme = QIconTheme(themeName);
+ if (!theme.isValid())
+ theme = fallbackTheme();
+
+ themeList.insert(themeName, theme);
+ }
+
+ QString contentDir = theme.contentDir() + QLatin1Char('/');
+ QList<QIconDirInfo> subDirs = theme.keyList();
+
+ const QString svgext(QLatin1String(".svg"));
+ const QString pngext(QLatin1String(".png"));
+
+ // Add all relevant files
+ for (int i = 0; i < subDirs.size() ; ++i) {
+ const QIconDirInfo &dirInfo = subDirs.at(i);
+ QString subdir = dirInfo.path;
+ QDir currentDir(contentDir + subdir);
+
+ if (dirInfo.type == QIconDirInfo::Scalable && m_supportsSvg &&
+ currentDir.exists(iconName + svgext)) {
+ ScalableEntry *iconEntry = new ScalableEntry;
+ iconEntry->dir = dirInfo;
+ iconEntry->filename = currentDir.filePath(iconName + svgext);
+ entries.append(iconEntry);
+
+ } else if (currentDir.exists(iconName + pngext)) {
+ PixmapEntry *iconEntry = new PixmapEntry;
+ iconEntry->dir = dirInfo;
+ iconEntry->filename = currentDir.filePath(iconName + pngext);
+ // Notice we ensure that pixmap entries allways come before
+ // scalable to preserve search order afterwards
+ entries.prepend(iconEntry);
+ }
+ }
+
+ if (entries.isEmpty()) {
+ const QStringList parents = theme.parents();
+ // Search recursively through inherited themes
+ for (int i = 0 ; i < parents.size() ; ++i) {
+
+ const QString parentTheme = parents.at(i).trimmed();
+
+ if (!visited.contains(parentTheme)) // guard against recursion
+ entries = findIconHelper(parentTheme, iconName, visited);
+
+ if (!entries.isEmpty()) // success
+ break;
+ }
+ }
+ return entries;
+}
+
+QThemeIconEntries QIconLoader::loadIcon(const QString &name) const
+{
+ if (!themeName().isEmpty()) {
+ QStringList visited;
+ return findIconHelper(themeName(), name, visited);
+ }
+
+ return QThemeIconEntries();
+}
+
+
+// -------- Icon Loader Engine -------- //
+
+
+QIconLoaderEngine::QIconLoaderEngine(const QString& iconName)
+ : m_iconName(iconName), m_key(0)
+{
+}
+
+QIconLoaderEngine::~QIconLoaderEngine()
+{
+ while (!m_entries.isEmpty())
+ delete m_entries.takeLast();
+ Q_ASSERT(m_entries.size() == 0);
+}
+
+QIconLoaderEngine::QIconLoaderEngine(const QIconLoaderEngine &other)
+ : QIconEngineV2(other),
+ m_iconName(other.m_iconName),
+ m_key(0)
+{
+}
+
+QIconEngineV2 *QIconLoaderEngine::clone() const
+{
+ return new QIconLoaderEngine(*this);
+}
+
+bool QIconLoaderEngine::read(QDataStream &in) {
+ in >> m_iconName;
+ return true;
+}
+
+bool QIconLoaderEngine::write(QDataStream &out) const
+{
+ out << m_iconName;
+ return true;
+}
+
+bool QIconLoaderEngine::hasIcon() const
+{
+ return !(m_entries.isEmpty());
+}
+
+// Lazily load the icon
+void QIconLoaderEngine::ensureLoaded()
+{
+ if (!(iconLoaderInstance()->themeKey() == m_key)) {
+
+ while (!m_entries.isEmpty())
+ delete m_entries.takeLast();
+
+ Q_ASSERT(m_entries.size() == 0);
+ m_entries = iconLoaderInstance()->loadIcon(m_iconName);
+ m_key = iconLoaderInstance()->themeKey();
+ }
+}
+
+void QIconLoaderEngine::paint(QPainter *painter, const QRect &rect,
+ QIcon::Mode mode, QIcon::State state)
+{
+ QSize pixmapSize = rect.size();
+#if defined(Q_WS_MAC)
+ pixmapSize *= qt_mac_get_scalefactor();
+#endif
+ painter->drawPixmap(rect, pixmap(pixmapSize, mode, state));
+}
+
+/*
+ * This algorithm is defined by the freedesktop spec:
+ * http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
+ */
+static bool directoryMatchesSize(const QIconDirInfo &dir, int iconsize)
+{
+ if (dir.type == QIconDirInfo::Fixed) {
+ return dir.size == iconsize;
+
+ } else if (dir.type == QIconDirInfo::Scalable) {
+ return dir.size <= dir.maxSize &&
+ iconsize >= dir.minSize;
+
+ } else if (dir.type == QIconDirInfo::Threshold) {
+ return iconsize >= dir.size - dir.threshold &&
+ iconsize <= dir.size + dir.threshold;
+ }
+
+ Q_ASSERT(1); // Not a valid value
+ return false;
+}
+
+/*
+ * This algorithm is defined by the freedesktop spec:
+ * http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
+ */
+static int directorySizeDistance(const QIconDirInfo &dir, int iconsize)
+{
+ if (dir.type == QIconDirInfo::Fixed) {
+ return qAbs(dir.size - iconsize);
+
+ } else if (dir.type == QIconDirInfo::Scalable) {
+ if (iconsize < dir.minSize)
+ return dir.minSize - iconsize;
+ else if (iconsize > dir.maxSize)
+ return iconsize - dir.maxSize;
+ else
+ return 0;
+
+ } else if (dir.type == QIconDirInfo::Threshold) {
+ if (iconsize < dir.size - dir.threshold)
+ return dir.minSize - iconsize;
+ else if (iconsize > dir.size + dir.threshold)
+ return iconsize - dir.maxSize;
+ else return 0;
+ }
+
+ Q_ASSERT(1); // Not a valid value
+ return INT_MAX;
+}
+
+QIconLoaderEngineEntry *QIconLoaderEngine::entryForSize(const QSize &size)
+{
+ int iconsize = qMin(size.width(), size.height());
+
+ // Note that m_entries are sorted so that png-files
+ // come first
+
+ // Search for exact matches first
+ for (int i = 0; i < m_entries.count(); ++i) {
+ QIconLoaderEngineEntry *entry = m_entries.at(i);
+ if (directoryMatchesSize(entry->dir, iconsize)) {
+ return entry;
+ }
+ }
+
+ // Find the minimum distance icon
+ int minimalSize = INT_MAX;
+ QIconLoaderEngineEntry *closestMatch = 0;
+ for (int i = 0; i < m_entries.count(); ++i) {
+ QIconLoaderEngineEntry *entry = m_entries.at(i);
+ int distance = directorySizeDistance(entry->dir, iconsize);
+ if (distance < minimalSize) {
+ minimalSize = distance;
+ closestMatch = entry;
+ }
+ }
+ return closestMatch;
+}
+
+/*
+ * Returns the actual icon size. For scalable svg's this is equivalent
+ * to the requested size. Otherwise the closest match is returned.
+ *
+ * todo: the spec is a bit fuzzy in this area, but we should probably
+ * allow scaling down pixmap icons as well.
+ *
+ */
+QSize QIconLoaderEngine::actualSize(const QSize &size, QIcon::Mode mode,
+ QIcon::State state)
+{
+ ensureLoaded();
+
+ QIconLoaderEngineEntry *entry = entryForSize(size);
+ if (entry) {
+ const QIconDirInfo &dir = entry->dir;
+ if (dir.type == QIconDirInfo::Scalable)
+ return size;
+ else
+ return QSize(dir.size, dir.size);
+ }
+ return QIconEngineV2::actualSize(size, mode, state);
+}
+
+QPixmap PixmapEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
+{
+ Q_UNUSED(state);
+
+ // Ensure that basePixmap is lazily initialized before generating the
+ // key, otherwise the cache key is not unique
+ if (basePixmap.isNull())
+ basePixmap.load(filename);
+
+ int actualSize = qMin(size.width(), size.height());
+ QString key = QLatin1String("$qt_theme_")
+ + QString::number(basePixmap.cacheKey(), 16)
+ + QLatin1Char('_')
+ + QString::number(mode)
+ + QLatin1Char('_')
+ + QString::number(qApp->palette().cacheKey(), 16)
+ + QLatin1Char('_')
+ + QString::number(actualSize);
+
+ QPixmap cachedPixmap;
+ if (QPixmapCache::find(key, &cachedPixmap)) {
+ return cachedPixmap;
+ } else {
+ QStyleOption opt(0);
+ opt.palette = qApp->palette();
+ cachedPixmap = qApp->style()->generatedIconPixmap(mode, basePixmap, &opt);
+ QPixmapCache::insert(key, cachedPixmap);
+ }
+ return cachedPixmap;
+}
+
+QPixmap ScalableEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
+{
+ if (svgIcon.isNull())
+ svgIcon = QIcon(filename);
+
+ // Simply reuse svg icon engine
+ return svgIcon.pixmap(size, mode, state);
+}
+
+QPixmap QIconLoaderEngine::pixmap(const QSize &size, QIcon::Mode mode,
+ QIcon::State state)
+{
+ ensureLoaded();
+
+ QIconLoaderEngineEntry *entry = entryForSize(size);
+ if (entry)
+ return entry->pixmap(size, mode, state);
+
+ return QPixmap();
+}
+
+QString QIconLoaderEngine::key() const
+{
+ return QLatin1String("QIconLoaderEngine");
+}
+
+void QIconLoaderEngine::virtual_hook(int id, void *data)
+{
+ ensureLoaded();
+
+ switch (id) {
+ case QIconEngineV2::AvailableSizesHook:
+ {
+ QIconEngineV2::AvailableSizesArgument &arg
+ = *reinterpret_cast<QIconEngineV2::AvailableSizesArgument*>(data);
+ const QList<QIconDirInfo> directoryKey = iconLoaderInstance()->theme().keyList();
+ arg.sizes.clear();
+
+ // Gets all sizes from the DirectoryInfo entries
+ for (int i = 0 ; i < m_entries.size() ; ++i) {
+ int size = m_entries.at(i)->dir.size;
+ arg.sizes.append(QSize(size, size));
+ }
+ }
+ break;
+ default:
+ QIconEngineV2::virtual_hook(id, data);
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/gui/image/qiconloader_p.h b/src/gui/image/qiconloader_p.h
new file mode 100644
index 0000000..5d5c211
--- /dev/null
+++ b/src/gui/image/qiconloader_p.h
@@ -0,0 +1,187 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDESKTOPICON_P_H
+#define QDESKTOPICON_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtGui/QIcon>
+#include <QtGui/QIconEngine>
+#include <QtGui/QPixmapCache>
+#include <private/qicon_p.h>
+#include <private/qfactoryloader_p.h>
+#include <QtCore/QHash>
+
+QT_BEGIN_NAMESPACE
+
+class QIconLoader;
+
+struct QIconDirInfo
+{
+ enum Type { Fixed, Scalable, Threshold };
+ QIconDirInfo(const QString &_path = QString()) :
+ path(_path),
+ size(0),
+ maxSize(0),
+ minSize(0),
+ threshold(0),
+ type(Threshold) {}
+ QString path;
+ short size;
+ short maxSize;
+ short minSize;
+ short threshold;
+ Type type : 4;
+};
+
+class QIconLoaderEngineEntry
+ {
+public:
+ virtual ~QIconLoaderEngineEntry() {}
+ virtual QPixmap pixmap(const QSize &size,
+ QIcon::Mode mode,
+ QIcon::State state) = 0;
+ QString filename;
+ QIconDirInfo dir;
+ static int count;
+};
+
+struct ScalableEntry : public QIconLoaderEngineEntry
+{
+ QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
+ QIcon svgIcon;
+};
+
+struct PixmapEntry : public QIconLoaderEngineEntry
+{
+ QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
+ QPixmap basePixmap;
+};
+
+typedef QList<QIconLoaderEngineEntry*> QThemeIconEntries;
+
+class QIconLoaderEngine : public QIconEngineV2
+{
+public:
+ QIconLoaderEngine(const QString& iconName = QString());
+ ~QIconLoaderEngine();
+
+ void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state);
+ QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
+ QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state);
+ QIconEngineV2 *clone() const;
+ bool read(QDataStream &in);
+ bool write(QDataStream &out) const;
+
+private:
+ QString key() const;
+ bool hasIcon() const;
+ void ensureLoaded();
+ void virtual_hook(int id, void *data);
+ QIconLoaderEngineEntry *entryForSize(const QSize &size);
+ QIconLoaderEngine(const QIconLoaderEngine &other);
+ QThemeIconEntries m_entries;
+ QString m_iconName;
+ uint m_key;
+
+ friend class QIconLoader;
+};
+
+class QIconTheme
+{
+public:
+ QIconTheme(const QString &name);
+ QIconTheme() : m_valid(false) {};
+ QStringList parents() { return m_parents; }
+ QList <QIconDirInfo> keyList() { return m_keyList; }
+ QString contentDir() { return m_contentDir; }
+ bool isValid() { return m_valid; }
+
+private:
+ QString m_contentDir;
+ QList <QIconDirInfo> m_keyList;
+ QStringList m_parents;
+ bool m_valid;
+};
+
+class QIconLoader : public QObject
+{
+public:
+ QIconLoader();
+ QThemeIconEntries loadIcon(const QString &iconName) const;
+ uint themeKey() const { return m_themeKey; }
+
+ QString themeName() const { return m_userTheme.isEmpty() ? m_systemTheme : m_userTheme; }
+ void setThemeName(const QString &themeName);
+ QIconTheme theme() { return themeList.value(themeName()); }
+ void setThemeSearchPath(const QStringList &searchPaths);
+ QStringList themeSearchPaths() const;
+ QIconDirInfo dirInfo(int dirindex);
+ static QIconLoader *instance();
+ void updateSystemTheme();
+ void invalidateKey() { m_themeKey++; }
+
+private:
+ QThemeIconEntries findIconHelper(const QString &themeName,
+ const QString &iconName,
+ QStringList &visited) const;
+ uint m_themeKey;
+ bool m_supportsSvg;
+
+ mutable QString m_userTheme;
+ mutable QString m_systemTheme;
+ mutable QStringList m_iconDirs;
+ mutable QHash <QString, QIconTheme> themeList;
+};
+
+QT_END_NAMESPACE
+
+#endif // QDESKTOPICON_P_H
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index d48d427..2b82f49 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -49,6 +49,7 @@
#include "qimagewriter.h"
#include "qstringlist.h"
#include "qvariant.h"
+#include "qimagepixmapcleanuphooks_p.h"
#include <ctype.h>
#include <stdlib.h>
#include <limits.h>
@@ -60,11 +61,7 @@
#include <qhash.h>
-#ifdef QT_RASTER_IMAGEENGINE
#include <private/qpaintengine_raster_p.h>
-#else
-#include <qpaintengine.h>
-#endif
#include <private/qimage_p.h>
@@ -106,14 +103,6 @@ static inline bool checkPixelSize(const QImage::Format format)
}
-// ### Qt 5: remove
-typedef void (*_qt_image_cleanup_hook)(int);
-Q_GUI_EXPORT _qt_image_cleanup_hook qt_image_cleanup_hook = 0;
-
-// ### Qt 5: rename
-typedef void (*_qt_image_cleanup_hook_64)(qint64);
-Q_GUI_EXPORT _qt_image_cleanup_hook_64 qt_image_cleanup_hook_64 = 0;
-
static QImage rotated90(const QImage &src);
static QImage rotated180(const QImage &src);
static QImage rotated270(const QImage &src);
@@ -185,6 +174,13 @@ static int depthForFormat(QImage::Format format)
return depth;
}
+/*! \fn QImageData * QImageData::create(const QSize &size, QImage::Format format, int numColors)
+
+ \internal
+
+ Creates a new image data.
+ Returns 0 if invalid parameters are give or anything else failed.
+*/
QImageData * QImageData::create(const QSize &size, QImage::Format format, int numColors)
{
if (!size.isValid() || numColors < 0 || format == QImage::Format_Invalid)
@@ -223,7 +219,7 @@ QImageData * QImageData::create(const QSize &size, QImage::Format format, int nu
|| INT_MAX/sizeof(uchar *) < uint(height))
return 0;
- QImageData *d = new QImageData;
+ QScopedPointer<QImageData> d(new QImageData);
d->colortable.resize(numColors);
if (depth == 1) {
d->colortable[0] = QColor(Qt::black).rgba();
@@ -246,19 +242,18 @@ QImageData * QImageData::create(const QSize &size, QImage::Format format, int nu
d->data = (uchar *)malloc(d->nbytes);
if (!d->data) {
- delete d;
return 0;
}
d->ref.ref();
- return d;
+ return d.take();
}
QImageData::~QImageData()
{
- if (is_cached && qt_image_cleanup_hook_64)
- qt_image_cleanup_hook_64((((qint64) ser_no) << 32) | ((qint64) detach_no));
+ if (is_cached)
+ QImagePixmapCleanupHooks::executeImageHooks((((qint64) ser_no) << 32) | ((qint64) detach_no));
delete paintEngine;
if (data && own_data)
free(data);
@@ -344,9 +339,9 @@ bool QImageData::checkForAlphaPixels() const
/*!
\class QImage
- \ingroup multimedia
+ \ingroup painting
\ingroup shared
- \mainclass
+
\reentrant
\brief The QImage class provides a hardware-independent image
@@ -590,9 +585,8 @@ bool QImageData::checkForAlphaPixels() const
The mirrored() function returns a mirror of the image in the
desired direction, the scaled() returns a copy of the image scaled
- to a rectangle of the desired measures, the rgbSwapped() function
- constructs a BGR image from a RGB image, and the alphaChannel()
- function constructs an image from this image's alpha channel.
+ to a rectangle of the desired measures, and the rgbSwapped() function
+ constructs a BGR image from a RGB image.
The scaledToWidth() and scaledToHeight() functions return scaled
copies of the image.
@@ -612,9 +606,6 @@ bool QImageData::checkForAlphaPixels() const
\table
\header \o Function \o Description
\row
- \o setAlphaChannel()
- \o Sets the alpha channel of the image.
- \row
\o setDotsPerMeterX()
\o Defines the aspect ratio by setting the number of pixels that fit
horizontally in a physical meter.
@@ -1346,8 +1337,8 @@ QImage::operator QVariant() const
void QImage::detach()
{
if (d) {
- if (d->is_cached && qt_image_cleanup_hook_64 && d->ref == 1)
- qt_image_cleanup_hook_64(cacheKey());
+ if (d->is_cached && d->ref == 1)
+ QImagePixmapCleanupHooks::executeImageHooks(cacheKey());
if (d->ref != 1 || d->ro_data)
*this = copy();
@@ -1621,6 +1612,7 @@ int QImage::numColors() const
/*!
Returns a pointer to the scanline pointer table. This is the
beginning of the data block for the image.
+ Returns 0 in case of an error.
Use the bits() or scanLine() function instead.
*/
@@ -1636,6 +1628,8 @@ uchar **QImage::jumpTable()
if (!d->jumptable) {
d->jumptable = (uchar **)malloc(d->height*sizeof(uchar *));
+ if (!d->jumptable)
+ return 0;
uchar *data = d->data;
int height = d->height;
uchar **p = d->jumptable;
@@ -1656,6 +1650,8 @@ const uchar * const *QImage::jumpTable() const
return 0;
if (!d->jumptable) {
d->jumptable = (uchar **)malloc(d->height*sizeof(uchar *));
+ if (!d->jumptable)
+ return 0;
uchar *data = d->data;
int height = d->height;
uchar **p = d->jumptable;
@@ -1691,8 +1687,12 @@ void QImage::setColorTable(const QVector<QRgb> colors)
d->colortable = colors;
d->has_alpha_clut = false;
- for (int i = 0; i < d->colortable.size(); ++i)
- d->has_alpha_clut |= (qAlpha(d->colortable.at(i)) != 255);
+ for (int i = 0; i < d->colortable.size(); ++i) {
+ if (qAlpha(d->colortable.at(i)) != 255) {
+ d->has_alpha_clut = true;
+ break;
+ }
+ }
}
/*!
@@ -2370,8 +2370,9 @@ static void dither_to_Mono(QImageData *dst, const QImageData *src,
switch (dithermode) {
case Diffuse: {
- int *line1 = new int[w];
- int *line2 = new int[w];
+ QScopedArrayPointer<int> lineBuffer(new int[w * 2]);
+ int *line1 = lineBuffer.data();
+ int *line2 = lineBuffer.data() + w;
int bmwidth = (w+7)/8;
int *b1, *b2;
@@ -2451,8 +2452,6 @@ static void dither_to_Mono(QImageData *dst, const QImageData *src,
b2++;
}
}
- delete [] line1;
- delete [] line2;
} break;
case Ordered: {
@@ -2593,10 +2592,9 @@ static void convert_X_to_Mono(QImageData *dst, const QImageData *src, Qt::ImageC
static void convert_ARGB_PM_to_Mono(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags)
{
- QImageData *tmp = QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32);
- convert_ARGB_PM_to_ARGB(tmp, src, flags);
- dither_to_Mono(dst, tmp, flags, false);
- delete tmp;
+ QScopedPointer<QImageData> tmp(QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32));
+ convert_ARGB_PM_to_ARGB(tmp.data(), src, flags);
+ dither_to_Mono(dst, tmp.data(), flags, false);
}
//
@@ -2745,15 +2743,16 @@ static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::
int* line1[3];
int* line2[3];
int* pv[3];
- line1[0] = new int[src->width];
- line2[0] = new int[src->width];
- line1[1] = new int[src->width];
- line2[1] = new int[src->width];
- line1[2] = new int[src->width];
- line2[2] = new int[src->width];
- pv[0] = new int[src->width];
- pv[1] = new int[src->width];
- pv[2] = new int[src->width];
+ QScopedArrayPointer<int> lineBuffer(new int[src->width * 9]);
+ line1[0] = lineBuffer.data();
+ line2[0] = lineBuffer.data() + src->width;
+ line1[1] = lineBuffer.data() + src->width * 2;
+ line2[1] = lineBuffer.data() + src->width * 3;
+ line1[2] = lineBuffer.data() + src->width * 4;
+ line2[2] = lineBuffer.data() + src->width * 5;
+ pv[0] = lineBuffer.data() + src->width * 6;
+ pv[1] = lineBuffer.data() + src->width * 7;
+ pv[2] = lineBuffer.data() + src->width * 8;
int endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian);
for (int y = 0; y < src->height; y++) {
@@ -2816,15 +2815,6 @@ static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::
src_data += src->bytes_per_line;
dest_data += dst->bytes_per_line;
}
- delete [] line1[0];
- delete [] line2[0];
- delete [] line1[1];
- delete [] line2[1];
- delete [] line1[2];
- delete [] line2[2];
- delete [] pv[0];
- delete [] pv[1];
- delete [] pv[2];
} else { // OrderedDither
for (int y = 0; y < src->height; y++) {
const QRgb *p = (const QRgb *)src_data;
@@ -2857,8 +2847,8 @@ static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::
const int trans = 216;
Q_ASSERT(dst->colortable.size() > trans);
dst->colortable[trans] = 0;
- QImageData *mask = QImageData::create(QSize(src->width, src->height), QImage::Format_Mono);
- dither_to_Mono(mask, src, flags, true);
+ QScopedPointer<QImageData> mask(QImageData::create(QSize(src->width, src->height), QImage::Format_Mono));
+ dither_to_Mono(mask.data(), src, flags, true);
uchar *dst_data = dst->data;
const uchar *mask_data = mask->data;
for (int y = 0; y < src->height; y++) {
@@ -2870,7 +2860,6 @@ static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::
dst_data += dst->bytes_per_line;
}
dst->has_alpha_clut = true;
- delete mask;
}
#undef MAX_R
@@ -2883,10 +2872,9 @@ static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::
static void convert_ARGB_PM_to_Indexed8(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags)
{
- QImageData *tmp = QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32);
- convert_ARGB_PM_to_ARGB(tmp, src, flags);
- convert_RGB_to_Indexed8(dst, tmp, flags);
- delete tmp;
+ QScopedPointer<QImageData> tmp(QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32));
+ convert_ARGB_PM_to_ARGB(tmp.data(), src, flags);
+ convert_RGB_to_Indexed8(dst, tmp.data(), flags);
}
static void convert_ARGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags)
@@ -3947,10 +3935,8 @@ QImage QImage::scaled(const QSize& s, Qt::AspectRatioMode aspectMode, Qt::Transf
if (newSize == size())
return copy();
- QImage img;
- QTransform wm;
- wm.scale((qreal)newSize.width() / width(), (qreal)newSize.height() / height());
- img = transformed(wm, mode);
+ QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(), (qreal)newSize.height() / height());
+ QImage img = transformed(wm, mode);
return img;
}
@@ -3977,9 +3963,8 @@ QImage QImage::scaledToWidth(int w, Qt::TransformationMode mode) const
if (w <= 0)
return QImage();
- QTransform wm;
qreal factor = (qreal) w / width();
- wm.scale(factor, factor);
+ QTransform wm = QTransform::fromScale(factor, factor);
return transformed(wm, mode);
}
@@ -4006,9 +3991,8 @@ QImage QImage::scaledToHeight(int h, Qt::TransformationMode mode) const
if (h <= 0)
return QImage();
- QTransform wm;
qreal factor = (qreal) h / height();
- wm.scale(factor, factor);
+ QTransform wm = QTransform::fromScale(factor, factor);
return transformed(wm, mode);
}
@@ -4632,12 +4616,19 @@ bool QImage::loadFromData(const uchar *data, int len, const char *format)
binary \a data. The loader attempts to read the image using the
specified \a format. If \a format is not specified (which is the default),
the loader probes the file for a header to guess the file format.
+ binary \a data. The loader attempts to read the image, either using the
+ optional image \a format specified or by determining the image format from
+ the data.
- If the loading of the image failed, this object is a null image.
+ If \a format is not specified (which is the default), the loader probes the
+ file for a header to determine the file format. If \a format is specified,
+ it must be one of the values returned by QImageReader::supportedImageFormats().
+
+ If the loading of the image fails, the image returned will be a null image.
+
+ \sa load(), save(), {QImage#Reading and Writing Image Files}{Reading and Writing Image Files}
+ */
- \sa load(), save(), {QImage#Reading and Writing Image
- Files}{Reading and Writing Image Files}
-*/
QImage QImage::fromData(const uchar *data, int size, const char *format)
{
QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(data), size);
@@ -4764,7 +4755,7 @@ QDataStream &operator>>(QDataStream &s, QImage &image)
image = QImageReader(s.device(), 0).read();
return s;
}
-#endif
+#endif // QT_NO_DATASTREAM
#ifdef QT3_SUPPORT
@@ -4854,8 +4845,6 @@ bool QImage::operator==(const QImage & i) const
return false;
if (d->format != Format_RGB32) {
- if (d->colortable != i.d->colortable)
- return false;
if (d->format >= Format_ARGB32) { // all bits defined
const int n = d->width * d->depth / 8;
if (n == d->bytes_per_line && n == i.d->bytes_per_line) {
@@ -4868,11 +4857,13 @@ bool QImage::operator==(const QImage & i) const
}
}
} else {
- int w = width();
- int h = height();
+ const int w = width();
+ const int h = height();
+ const QVector<QRgb> &colortable = d->colortable;
+ const QVector<QRgb> &icolortable = i.d->colortable;
for (int y=0; y<h; ++y) {
for (int x=0; x<w; ++x) {
- if (pixelIndex(x, y) != i.pixelIndex(x, y))
+ if (colortable[pixelIndex(x, y)] != icolortable[i.pixelIndex(x, y)])
return false;
}
}
@@ -5259,17 +5250,16 @@ QPaintEngine *QImage::paintEngine() const
if (!d)
return 0;
-#ifdef QT_RASTER_IMAGEENGINE
if (!d->paintEngine) {
d->paintEngine = new QRasterPaintEngine(const_cast<QImage *>(this));
}
-#endif
+
return d->paintEngine;
}
/*!
- \reimp
+ \internal
Returns the size for the specified \a metric on the device.
*/
@@ -5587,7 +5577,7 @@ bool QImage::isDetached() const
Note that the image will be converted to the Format_ARGB32_Premultiplied
format if the function succeeds.
- Use one of the composition mods in QPainter::CompositionMode instead.
+ Use one of the composition modes in QPainter::CompositionMode instead.
\warning This function is expensive.
@@ -5665,6 +5655,8 @@ void QImage::setAlphaChannel(const QImage &alphaChannel)
/*!
+ \obsolete
+
Returns the alpha channel of the image as a new grayscale QImage in which
each pixel's red, green, and blue values are given the alpha value of the
original image. The color depth of the returned image is 8-bit.
@@ -5744,7 +5736,7 @@ QImage QImage::alphaChannel() const
Returns true if the image has a format that respects the alpha
channel, otherwise returns false.
- \sa alphaChannel(), {QImage#Image Information}{Image Information}
+ \sa {QImage#Image Information}{Image Information}
*/
bool QImage::hasAlphaChannel() const
{
diff --git a/src/gui/image/qimageiohandler.cpp b/src/gui/image/qimageiohandler.cpp
index d04fa39..8b6c1d9 100644
--- a/src/gui/image/qimageiohandler.cpp
+++ b/src/gui/image/qimageiohandler.cpp
@@ -272,7 +272,6 @@ QImageIOHandler::QImageIOHandler(QImageIOHandlerPrivate &dd)
*/
QImageIOHandler::~QImageIOHandler()
{
- delete d_ptr;
}
/*!
diff --git a/src/gui/image/qimageiohandler.h b/src/gui/image/qimageiohandler.h
index 84f20dc..5f94778 100644
--- a/src/gui/image/qimageiohandler.h
+++ b/src/gui/image/qimageiohandler.h
@@ -44,6 +44,7 @@
#include <QtCore/qplugin.h>
#include <QtCore/qfactoryinterface.h>
+#include <QtCore/qscopedpointer.h>
QT_BEGIN_HEADER
@@ -109,7 +110,7 @@ public:
protected:
QImageIOHandler(QImageIOHandlerPrivate &dd);
- QImageIOHandlerPrivate *d_ptr;
+ QScopedPointer<QImageIOHandlerPrivate> d_ptr;
private:
Q_DISABLE_COPY(QImageIOHandler)
};
diff --git a/src/gui/image/qimagepixmapcleanuphooks.cpp b/src/gui/image/qimagepixmapcleanuphooks.cpp
new file mode 100644
index 0000000..10573fd
--- /dev/null
+++ b/src/gui/image/qimagepixmapcleanuphooks.cpp
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qimagepixmapcleanuphooks_p.h"
+#include "qpixmapdata_p.h"
+
+
+QT_BEGIN_NAMESPACE
+
+// Legacy, single instance hooks: ### Qt 5: remove
+typedef void (*_qt_pixmap_cleanup_hook)(int);
+typedef void (*_qt_pixmap_cleanup_hook_64)(qint64);
+typedef void (*_qt_image_cleanup_hook)(int);
+Q_GUI_EXPORT _qt_pixmap_cleanup_hook qt_pixmap_cleanup_hook = 0;
+Q_GUI_EXPORT _qt_pixmap_cleanup_hook_64 qt_pixmap_cleanup_hook_64 = 0;
+Q_GUI_EXPORT _qt_image_cleanup_hook qt_image_cleanup_hook = 0;
+Q_GUI_EXPORT _qt_image_cleanup_hook_64 qt_image_cleanup_hook_64 = 0;
+
+
+QImagePixmapCleanupHooks* qt_image_and_pixmap_cleanup_hooks = 0;
+
+
+QImagePixmapCleanupHooks::QImagePixmapCleanupHooks()
+{
+ qt_image_and_pixmap_cleanup_hooks = this;
+}
+
+QImagePixmapCleanupHooks *QImagePixmapCleanupHooks::instance()
+{
+ if (!qt_image_and_pixmap_cleanup_hooks)
+ qt_image_and_pixmap_cleanup_hooks = new QImagePixmapCleanupHooks;
+ return qt_image_and_pixmap_cleanup_hooks;
+}
+
+void QImagePixmapCleanupHooks::addPixmapHook(_qt_pixmap_cleanup_hook_pm hook)
+{
+ pixmapHooks.append(hook);
+}
+
+void QImagePixmapCleanupHooks::addImageHook(_qt_image_cleanup_hook_64 hook)
+{
+ imageHooks.append(hook);
+}
+
+void QImagePixmapCleanupHooks::removePixmapHook(_qt_pixmap_cleanup_hook_pm hook)
+{
+ pixmapHooks.removeAll(hook);
+}
+
+void QImagePixmapCleanupHooks::removeImageHook(_qt_image_cleanup_hook_64 hook)
+{
+ imageHooks.removeAll(hook);
+}
+
+
+void QImagePixmapCleanupHooks::executePixmapHooks(QPixmap* pm)
+{
+ for (int i = 0; i < qt_image_and_pixmap_cleanup_hooks->pixmapHooks.count(); ++i)
+ qt_image_and_pixmap_cleanup_hooks->pixmapHooks[i](pm);
+
+ if (qt_pixmap_cleanup_hook_64)
+ qt_pixmap_cleanup_hook_64(pm->cacheKey());
+}
+
+
+void QImagePixmapCleanupHooks::executeImageHooks(qint64 key)
+{
+ for (int i = 0; i < qt_image_and_pixmap_cleanup_hooks->imageHooks.count(); ++i)
+ qt_image_and_pixmap_cleanup_hooks->imageHooks[i](key);
+
+ if (qt_image_cleanup_hook_64)
+ qt_image_cleanup_hook_64(key);
+}
+
+QT_END_NAMESPACE
diff --git a/src/gui/image/qimagepixmapcleanuphooks_p.h b/src/gui/image/qimagepixmapcleanuphooks_p.h
new file mode 100644
index 0000000..f1ac1cb
--- /dev/null
+++ b/src/gui/image/qimagepixmapcleanuphooks_p.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QIMAGEPIXMAP_CLEANUPHOOKS_P_H
+#define QIMAGEPIXMAP_CLEANUPHOOKS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtGui/qpixmap.h>
+
+QT_BEGIN_NAMESPACE
+
+typedef void (*_qt_image_cleanup_hook_64)(qint64);
+typedef void (*_qt_pixmap_cleanup_hook_pm)(QPixmap*);
+
+class QImagePixmapCleanupHooks;
+extern QImagePixmapCleanupHooks* qt_image_and_pixmap_cleanup_hooks;
+
+class Q_GUI_EXPORT QImagePixmapCleanupHooks
+{
+public:
+ QImagePixmapCleanupHooks();
+
+ static QImagePixmapCleanupHooks *instance();
+
+ void addPixmapHook(_qt_pixmap_cleanup_hook_pm);
+ void addImageHook(_qt_image_cleanup_hook_64);
+
+ void removePixmapHook(_qt_pixmap_cleanup_hook_pm);
+ void removeImageHook(_qt_image_cleanup_hook_64);
+
+ static void executePixmapHooks(QPixmap*);
+ static void executeImageHooks(qint64 key);
+
+private:
+ QList<_qt_image_cleanup_hook_64> imageHooks;
+ QList<_qt_pixmap_cleanup_hook_pm> pixmapHooks;
+};
+
+QT_END_NAMESPACE
+
+#endif // QIMAGEPIXMAP_CLEANUPHOOKS_P_H
diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp
index a064937..fb5bed4 100644
--- a/src/gui/image/qimagereader.cpp
+++ b/src/gui/image/qimagereader.cpp
@@ -47,7 +47,7 @@
for reading images from files or other devices.
\reentrant
- \ingroup multimedia
+ \ingroup painting
\ingroup io
The most common way to read images is through QImage and QPixmap's
diff --git a/src/gui/image/qimagewriter.cpp b/src/gui/image/qimagewriter.cpp
index 1dcf4c4..4c121b0 100644
--- a/src/gui/image/qimagewriter.cpp
+++ b/src/gui/image/qimagewriter.cpp
@@ -45,7 +45,7 @@
for writing images to files or other devices.
\reentrant
- \ingroup multimedia
+ \ingroup painting
\ingroup io
QImageWriter supports setting format specific options, such as the
diff --git a/src/gui/image/qmovie.cpp b/src/gui/image/qmovie.cpp
index 0c1c2e1..5c910a8 100644
--- a/src/gui/image/qmovie.cpp
+++ b/src/gui/image/qmovie.cpp
@@ -45,7 +45,7 @@
\brief The QMovie class is a convenience class for playing movies
with QImageReader.
- \ingroup multimedia
+ \ingroup painting
First, create a QMovie object by passing either the name of a file or a
pointer to a QIODevice containing an animated image format to QMovie's
@@ -356,7 +356,7 @@ QFrameInfo QMoviePrivate::infoForFrame(int frameNumber)
reader = new QImageReader(device, format);
else
reader = new QImageReader(absoluteFilePath, format);
- reader->canRead(); // Provoke a device->open() call
+ (void)reader->canRead(); // Provoke a device->open() call
reader->device()->seek(initialDevicePos);
reader->setBackgroundColor(bgColor);
reader->setScaledSize(scaledSize);
diff --git a/src/gui/image/qnativeimage.cpp b/src/gui/image/qnativeimage.cpp
index c0cff24..7de9fe9 100644
--- a/src/gui/image/qnativeimage.cpp
+++ b/src/gui/image/qnativeimage.cpp
@@ -52,6 +52,10 @@
#include <qwidget.h>
#endif
+#ifdef Q_WS_MAC
+#include <private/qpaintengine_mac_p.h>
+#endif
+
QT_BEGIN_NAMESPACE
#ifdef Q_WS_WIN
@@ -65,7 +69,7 @@ typedef struct {
QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool isTextBuffer, QWidget *)
{
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
Q_UNUSED(isTextBuffer);
#endif
BITMAPINFO_MASK bmi;
@@ -78,7 +82,7 @@ QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool is
if (format == QImage::Format_RGB16) {
bmi.bmiHeader.biBitCount = 16;
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
if (isTextBuffer) {
bmi.bmiHeader.biCompression = BI_RGB;
bmi.redMask = 0;
@@ -116,7 +120,7 @@ QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool is
Q_ASSERT(image.paintEngine()->type() == QPaintEngine::Raster);
static_cast<QRasterPaintEngine *>(image.paintEngine())->setDC(hdc);
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
GdiFlush();
#endif
}
@@ -229,18 +233,19 @@ QImage::Format QNativeImage::systemFormat()
#elif defined(Q_WS_MAC)
-QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool /* isTextBuffer */, QWidget *)
+QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool /* isTextBuffer */, QWidget *widget)
: image(width, height, format)
{
- cgColorSpace = CGColorSpaceCreateDeviceRGB();
+
+
uint cgflags = kCGImageAlphaNoneSkipFirst;
#ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
- if(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4)
- cgflags |= kCGBitmapByteOrder32Host;
+ cgflags |= kCGBitmapByteOrder32Host;
#endif
- cg = CGBitmapContextCreate(image.bits(), width, height, 8, image.bytesPerLine(), cgColorSpace, cgflags);
+ cg = CGBitmapContextCreate(image.bits(), width, height, 8, image.bytesPerLine(),
+ QCoreGraphicsPaintEngine::macDisplayColorSpace(widget), cgflags);
CGContextTranslateCTM(cg, 0, height);
CGContextScaleCTM(cg, 1, -1);
@@ -252,7 +257,6 @@ QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool /*
QNativeImage::~QNativeImage()
{
CGContextRelease(cg);
- CGColorSpaceRelease(cgColorSpace);
}
QImage::Format QNativeImage::systemFormat()
diff --git a/src/gui/image/qnativeimage_p.h b/src/gui/image/qnativeimage_p.h
index cfbeb6e..46fa13d 100644
--- a/src/gui/image/qnativeimage_p.h
+++ b/src/gui/image/qnativeimage_p.h
@@ -70,7 +70,7 @@ QT_BEGIN_NAMESPACE
class QWidget;
-class Q_GUI_EXPORT QNativeImage
+class QNativeImage
{
public:
QNativeImage(int width, int height, QImage::Format format, bool isTextBuffer = false, QWidget *widget = 0);
@@ -95,7 +95,6 @@ public:
#elif defined(Q_WS_MAC)
CGContextRef cg;
- CGColorSpaceRef cgColorSpace;
#endif
private:
diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp
index 110a38f..b32861c 100644
--- a/src/gui/image/qpicture.cpp
+++ b/src/gui/image/qpicture.cpp
@@ -69,9 +69,9 @@ void qt_format_text(const QFont &fnt, const QRectF &_r,
\brief The QPicture class is a paint device that records and
replays QPainter commands.
- \ingroup multimedia
+ \ingroup painting
\ingroup shared
- \mainclass
+
A picture serializes painter commands to an IO device in a
platform-independent format. They are sometimes referred to as meta-files.
@@ -131,8 +131,6 @@ QPicture::QPicture(int formatVersion)
d_ptr(new QPicturePrivate)
{
Q_D(QPicture);
- d_ptr->q_ptr = this;
- d->paintEngine = 0;
if (formatVersion == 0)
qWarning("QPicture: invalid format version 0");
@@ -142,8 +140,7 @@ QPicture::QPicture(int formatVersion)
d->formatMajor = formatVersion;
d->formatMinor = 0;
d->formatOk = false;
- }
- else {
+ } else {
d->resetFormat();
}
}
@@ -157,7 +154,6 @@ QPicture::QPicture(int formatVersion)
QPicture::QPicture(const QPicture &pic)
: QPaintDevice(), d_ptr(pic.d_ptr)
{
- d_func()->ref.ref();
}
/*! \internal */
@@ -165,7 +161,6 @@ QPicture::QPicture(QPicturePrivate &dptr)
: QPaintDevice(),
d_ptr(&dptr)
{
- d_ptr->q_ptr = this;
}
/*!
@@ -173,10 +168,6 @@ QPicture::QPicture(QPicturePrivate &dptr)
*/
QPicture::~QPicture()
{
- if (!d_func()->ref.deref()) {
- delete d_func()->paintEngine;
- delete d_func();
- }
}
/*!
@@ -230,8 +221,7 @@ const char* QPicture::data() const
void QPicture::detach()
{
- if (d_func()->ref != 1)
- detach_helper();
+ d_ptr.detach();
}
bool QPicture::isDetached() const
@@ -954,6 +944,8 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords)
}
/*!
+ \internal
+
Internal implementation of the virtual QPaintDevice::metric()
function.
@@ -1015,24 +1007,16 @@ int QPicture::metric(PaintDeviceMetric m) const
/*! \fn bool QPicture::isDetached() const
\internal
*/
+
+/*! \internal
+### Qt 5 - remove me
+ */
void QPicture::detach_helper()
{
- Q_D(QPicture);
- QPicturePrivate *x = new QPicturePrivate;
- int pictsize = size();
- x->pictb.setData(data(), pictsize);
- if (d->pictb.isOpen()) {
- x->pictb.open(d->pictb.openMode());
- x->pictb.seek(d->pictb.pos());
- }
- x->trecs = d->trecs;
- x->formatOk = d->formatOk;
- x->formatMinor = d->formatMinor;
- x->brect = d->brect;
- x->override_rect = d->override_rect;
- if (!d->ref.deref())
- delete d;
- d_ptr = x;
+ // QExplicitelySharedDataPointer takes care of cloning using
+ // QPicturePrivate's copy constructor. Do not call detach_helper() anymore
+ // and remove in Qt 5, please.
+ Q_ASSERT_X(false, "QPicture::detach_helper()", "Do not call this function");
}
/*!
@@ -1041,13 +1025,43 @@ void QPicture::detach_helper()
*/
QPicture& QPicture::operator=(const QPicture &p)
{
- qAtomicAssign<QPicturePrivate>(d_ptr, p.d_ptr);
+ d_ptr = p.d_ptr;
return *this;
}
/*!
\internal
+ Constructs a QPicturePrivate
+*/
+QPicturePrivate::QPicturePrivate()
+ : in_memory_only(false)
+{
+}
+
+/*!
+ \internal
+
+ Copy-Constructs a QPicturePrivate. Needed when detaching.
+*/
+QPicturePrivate::QPicturePrivate(const QPicturePrivate &other)
+ : trecs(other.trecs),
+ formatOk(other.formatOk),
+ formatMinor(other.formatMinor),
+ brect(other.brect),
+ override_rect(other.override_rect),
+ in_memory_only(false)
+{
+ pictb.setData(other.pictb.data(), other.pictb.size());
+ if (other.pictb.isOpen()) {
+ pictb.open(other.pictb.openMode());
+ pictb.seek(other.pictb.pos());
+ }
+}
+
+/*!
+ \internal
+
Sets formatOk to false and resets the format version numbers to default
*/
@@ -1135,14 +1149,15 @@ bool QPicturePrivate::checkFormat()
QPaintEngine *QPicture::paintEngine() const
{
if (!d_func()->paintEngine)
- const_cast<QPicture*>(this)->d_func()->paintEngine = new QPicturePaintEngine;
- return d_func()->paintEngine;
+ const_cast<QPicture*>(this)->d_func()->paintEngine.reset(new QPicturePaintEngine);
+ return d_func()->paintEngine.data();
}
/*****************************************************************************
QPicture stream functions
*****************************************************************************/
+#ifndef QT_NO_DATASTREAM
/*!
\relates QPicture
@@ -1188,6 +1203,7 @@ QDataStream &operator>>(QDataStream &s, QPicture &r)
r.d_func()->resetFormat();
return s;
}
+#endif // QT_NO_DATASTREAM
#ifndef QT_NO_PICTUREIO
@@ -1294,7 +1310,7 @@ QList<QByteArray> QPicture::outputFormats()
\brief The QPictureIO class contains parameters for loading and
saving pictures.
- \ingroup multimedia
+ \ingroup painting
\ingroup io
QPictureIO contains a QIODevice object that is used for picture data
diff --git a/src/gui/image/qpicture.h b/src/gui/image/qpicture.h
index add9f61..30281b7 100644
--- a/src/gui/image/qpicture.h
+++ b/src/gui/image/qpicture.h
@@ -42,8 +42,9 @@
#ifndef QPICTURE_H
#define QPICTURE_H
-#include <QtGui/qpaintdevice.h>
#include <QtCore/qstringlist.h>
+#include <QtCore/qsharedpointer.h>
+#include <QtGui/qpaintdevice.h>
QT_BEGIN_HEADER
@@ -106,14 +107,14 @@ private:
bool exec(QPainter *p, QDataStream &ds, int i);
void detach_helper();
- QPicturePrivate *d_ptr;
+ QExplicitlySharedDataPointer<QPicturePrivate> d_ptr;
friend class QPicturePaintEngine;
friend class Q3Picture;
friend class QAlphaPaintEngine;
friend class QPreviewPaintEngine;
public:
- typedef QPicturePrivate* DataPtr;
+ typedef QExplicitlySharedDataPointer<QPicturePrivate> DataPtr;
inline DataPtr &data_ptr() { return d_ptr; }
};
@@ -184,8 +185,10 @@ private:
QPicture stream functions
*****************************************************************************/
+#ifndef QT_NO_DATASTREAM
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPicture &);
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPicture &);
+#endif
#endif // QT_NO_PICTURE
diff --git a/src/gui/image/qpicture_p.h b/src/gui/image/qpicture_p.h
index 360cf48..27c443c 100644
--- a/src/gui/image/qpicture_p.h
+++ b/src/gui/image/qpicture_p.h
@@ -69,9 +69,8 @@ class QPaintEngine;
extern const char *qt_mfhdr_tag;
-class Q_GUI_EXPORT QPicturePrivate
+class QPicturePrivate
{
- Q_DECLARE_PUBLIC(QPicture)
friend class QPicturePaintEngine;
friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPicture &r);
friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &s, QPicture &r);
@@ -143,7 +142,8 @@ public:
PdcReservedStop = 199 // for Qt
};
- inline QPicturePrivate() : in_memory_only(false), q_ptr(0) { ref = 1; }
+ QPicturePrivate();
+ QPicturePrivate(const QPicturePrivate &other);
QAtomicInt ref;
bool checkFormat();
@@ -156,14 +156,12 @@ public:
int formatMinor;
QRect brect;
QRect override_rect;
- QPaintEngine *paintEngine;
+ QScopedPointer<QPaintEngine> paintEngine;
bool in_memory_only;
QList<QImage> image_list;
QList<QPixmap> pixmap_list;
QList<QBrush> brush_list;
QList<QPen> pen_list;
-
- QPicture *q_ptr;
};
QT_END_NAMESPACE
diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp
index e7fc000..7f5b943 100644
--- a/src/gui/image/qpixmap.cpp
+++ b/src/gui/image/qpixmap.cpp
@@ -43,6 +43,7 @@
#include "qpixmap.h"
#include "qpixmapdata_p.h"
+#include "qimagepixmapcleanuphooks_p.h"
#include "qbitmap.h"
#include "qcolormap.h"
@@ -76,19 +77,15 @@
# include <private/qpixmap_x11_p.h>
#endif
+#if defined(Q_OS_SYMBIAN)
+# include <private/qt_s60_p.h>
+#endif
+
#include "qpixmap_raster_p.h"
QT_BEGIN_NAMESPACE
// ### Qt 5: remove
-typedef void (*_qt_pixmap_cleanup_hook)(int);
-Q_GUI_EXPORT _qt_pixmap_cleanup_hook qt_pixmap_cleanup_hook = 0;
-
-// ### Qt 5: rename
-typedef void (*_qt_pixmap_cleanup_hook_64)(qint64);
-Q_GUI_EXPORT _qt_pixmap_cleanup_hook_64 qt_pixmap_cleanup_hook_64 = 0;
-
-// ### Qt 5: remove
Q_GUI_EXPORT qint64 qt_pixmap_id(const QPixmap &pixmap)
{
return pixmap.cacheKey();
@@ -123,7 +120,6 @@ void QPixmap::init(int w, int h, int type)
data = QGraphicsSystem::createDefaultPixmapData(static_cast<QPixmapData::PixelType>(type));
data->resize(w, h);
- data->ref.ref();
}
/*!
@@ -225,7 +221,6 @@ QPixmap::QPixmap(const QSize &s, int type)
QPixmap::QPixmap(QPixmapData *d)
: QPaintDevice(), data(d)
{
- data->ref.ref();
}
/*!
@@ -281,11 +276,9 @@ QPixmap::QPixmap(const QPixmap &pixmap)
return;
}
if (pixmap.paintingActive()) { // make a deep copy
- data = 0;
operator=(pixmap.copy());
} else {
data = pixmap.data;
- data->ref.ref();
}
}
@@ -329,7 +322,8 @@ QPixmap::QPixmap(const char * const xpm[])
QPixmap::~QPixmap()
{
- deref();
+ if (data->is_cached && data->ref == 1)
+ QImagePixmapCleanupHooks::executePixmapHooks(this);
}
/*!
@@ -374,11 +368,64 @@ QPixmap QPixmap::copy(const QRect &rect) const
else
d = QGraphicsSystem::createDefaultPixmapData(data->pixelType());
- d->copy(data, r);
+ d->copy(data.data(), r);
return QPixmap(d);
}
/*!
+ \fn QPixmap::scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed)
+ \since 4.6
+
+ This convenience function is equivalent to calling QPixmap::scroll(\a dx,
+ \a dy, QRect(\a x, \a y, \a width, \a height), \a exposed).
+
+ \sa QWidget::scroll(), QGraphicsItem::scroll()
+*/
+
+/*!
+ \since 4.6
+
+ Scrolls the area \a rect of this pixmap by (\a dx, \a dy). The exposed
+ region is left unchanged. You can optionally pass a pointer to an empty
+ QRegion to get the region that is \a exposed by the scroll operation.
+
+ \snippet doc/src/snippets/code/src_gui_image_qpixmap.cpp 2
+
+ You cannot scroll while there is an active painter on the pixmap.
+
+ \sa QWidget::scroll(), QGraphicsItem::scroll()
+*/
+void QPixmap::scroll(int dx, int dy, const QRect &rect, QRegion *exposed)
+{
+ if (isNull() || (dx == 0 && dy == 0))
+ return;
+ QRect dest = rect & this->rect();
+ QRect src = dest.translated(-dx, -dy) & dest;
+ if (src.isEmpty()) {
+ if (exposed)
+ *exposed += dest;
+ return;
+ }
+
+ detach();
+
+ if (!data->scroll(dx, dy, src)) {
+ // Fallback
+ QPixmap pix = *this;
+ QPainter painter(&pix);
+ painter.setCompositionMode(QPainter::CompositionMode_Source);
+ painter.drawPixmap(src.translated(dx, dy), *this, src);
+ painter.end();
+ *this = pix;
+ }
+
+ if (exposed) {
+ *exposed += dest;
+ *exposed -= src.translated(dx, dy);
+ }
+}
+
+/*!
Assigns the given \a pixmap to this pixmap and returns a reference
to this pixmap.
@@ -394,8 +441,6 @@ QPixmap &QPixmap::operator=(const QPixmap &pixmap)
if (pixmap.paintingActive()) { // make a deep copy
*this = pixmap.copy();
} else {
- pixmap.data->ref.ref(); // avoid 'x = x'
- deref();
data = pixmap.data;
}
return *this;
@@ -502,7 +547,7 @@ bool QPixmap::isQBitmap() const
*/
bool QPixmap::isNull() const
{
- return data->width() == 0;
+ return data->isNull();
}
/*!
@@ -600,13 +645,13 @@ void QPixmap::resize_helper(const QSize &s)
QPixmap pm(QSize(w, h), data->type);
bool uninit = false;
#if defined(Q_WS_X11)
- QX11PixmapData *x11Data = data->classId() == QPixmapData::X11Class ? static_cast<QX11PixmapData*>(data) : 0;
+ QX11PixmapData *x11Data = data->classId() == QPixmapData::X11Class ? static_cast<QX11PixmapData*>(data.data()) : 0;
if (x11Data) {
pm.x11SetScreen(x11Data->xinfo.screen());
- uninit = x11Data->uninit;
+ uninit = x11Data->flags & QX11PixmapData::Uninitialized;
}
#elif defined(Q_WS_MAC)
- QMacPixmapData *macData = data->classId() == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data) : 0;
+ QMacPixmapData *macData = data->classId() == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0;
if (macData)
uninit = macData->uninit;
#endif
@@ -618,14 +663,9 @@ void QPixmap::resize_helper(const QSize &s)
p.drawPixmap(0, 0, *this, 0, 0, qMin(width(), w), qMin(height(), h));
}
-#if defined(Q_WS_MAC)
-#ifndef QT_MAC_NO_QUICKDRAW
- if(macData && macData->qd_alpha)
- macData->macQDUpdateAlpha();
-#endif
-#elif defined(Q_WS_X11)
+#if defined(Q_WS_X11)
if (x11Data && x11Data->x11_mask) {
- QX11PixmapData *pmData = static_cast<QX11PixmapData*>(pm.data);
+ QX11PixmapData *pmData = static_cast<QX11PixmapData*>(pm.data.data());
pmData->x11_mask = (Qt::HANDLE)XCreatePixmap(X11->display,
RootWindow(x11Data->xinfo.display(),
x11Data->xinfo.screen()),
@@ -794,19 +834,11 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers
if (QPixmapCache::find(key, *this))
return true;
- QImage image = QImageReader(fileName, format).read();
- if (image.isNull())
- return false;
- QPixmap pm;
- if (data->pixelType() == QPixmapData::BitmapType)
- pm = QBitmap::fromImage(image, flags);
- else
- pm = fromImage(image, flags);
- if (!pm.isNull()) {
- *this = pm;
+ if (data->fromFile(fileName, format, flags)) {
QPixmapCache::insert(key, *this);
return true;
}
+
return false;
}
@@ -831,21 +863,7 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers
bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags)
{
- QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buf), len);
- QBuffer b(&a);
- b.open(QIODevice::ReadOnly);
-
- QImage image = QImageReader(&b, format).read();
- QPixmap pm;
- if (data->pixelType() == QPixmapData::BitmapType)
- pm = QBitmap::fromImage(image, flags);
- else
- pm = fromImage(image, flags);
- if (!pm.isNull()) {
- *this = pm;
- return true;
- }
- return false;
+ return data->fromData(buf, len, format, flags);
}
/*!
@@ -1119,7 +1137,7 @@ Qt::HANDLE QPixmap::handle() const
{
#if defined(Q_WS_X11)
if (data->classId() == QPixmapData::X11Class)
- return static_cast<QX11PixmapData*>(data)->handle();
+ return static_cast<const QX11PixmapData*>(data.constData())->handle();
#endif
return 0;
}
@@ -1267,7 +1285,7 @@ QDataStream &operator>>(QDataStream &stream, QPixmap &pixmap)
return stream;
}
-#endif //QT_NO_DATASTREAM
+#endif // QT_NO_DATASTREAM
#ifdef QT3_SUPPORT
Q_GUI_EXPORT void copyBlt(QPixmap *dst, int dx, int dy,
@@ -1306,22 +1324,12 @@ bool QPixmap::isDetached() const
return data->ref == 1;
}
+/*! \internal
+ ### Qt5 - remove me.
+*/
void QPixmap::deref()
{
- if (data && !data->ref.deref()) { // Destroy image if last ref
-#if !defined(QT_NO_DIRECT3D) && defined(Q_WS_WIN)
- if (data->classId() == QPixmapData::RasterClass) {
- QRasterPixmapData *rData = static_cast<QRasterPixmapData*>(data);
- if (rData->texture)
- rData->texture->Release();
- rData->texture = 0;
- }
-#endif
- if (data->is_cached && qt_pixmap_cleanup_hook_64)
- qt_pixmap_cleanup_hook_64(cacheKey());
- delete data;
- data = 0;
- }
+ Q_ASSERT_X(false, "QPixmap::deref()", "Do not call this function anymore!");
}
/*!
@@ -1404,10 +1412,9 @@ QPixmap QPixmap::scaled(const QSize& s, Qt::AspectRatioMode aspectMode, Qt::Tran
if (newSize == size())
return *this;
- QPixmap pix;
- QTransform wm;
- wm.scale((qreal)newSize.width() / width(), (qreal)newSize.height() / height());
- pix = transformed(wm, mode);
+ QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(),
+ (qreal)newSize.height() / height());
+ QPixmap pix = transformed(wm, mode);
return pix;
}
@@ -1434,9 +1441,8 @@ QPixmap QPixmap::scaledToWidth(int w, Qt::TransformationMode mode) const
if (w <= 0)
return QPixmap();
- QTransform wm;
qreal factor = (qreal) w / width();
- wm.scale(factor, factor);
+ QTransform wm = QTransform::fromScale(factor, factor);
return transformed(wm, mode);
}
@@ -1463,9 +1469,8 @@ QPixmap QPixmap::scaledToHeight(int h, Qt::TransformationMode mode) const
if (h <= 0)
return QPixmap();
- QTransform wm;
qreal factor = (qreal) h / height();
- wm.scale(factor, factor);
+ QTransform wm = QTransform::fromScale(factor, factor);
return transformed(wm, mode);
}
@@ -1520,9 +1525,9 @@ QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode)
\brief The QPixmap class is an off-screen image representation
that can be used as a paint device.
- \ingroup multimedia
+ \ingroup painting
\ingroup shared
- \mainclass
+
Qt provides four classes for handling image data: QImage, QPixmap,
QBitmap and QPicture. QImage is designed and optimized for I/O,
@@ -1530,24 +1535,24 @@ QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode)
designed and optimized for showing images on screen. QBitmap is
only a convenience class that inherits QPixmap, ensuring a depth
of 1. The isQBitmap() function returns true if a QPixmap object is
- really a bitmap, otherwise returns false. Finally, the QPicture class is a
- paint device that records and replays QPainter commands.
+ really a bitmap, otherwise returns false. Finally, the QPicture class
+ is a paint device that records and replays QPainter commands.
A QPixmap can easily be displayed on the screen using QLabel or
one of QAbstractButton's subclasses (such as QPushButton and
QToolButton). QLabel has a pixmap property, whereas
- QAbstractButton has an icon property. And because QPixmap is a
- QPaintDevice subclass, QPainter can be used to draw directly onto
- pixmaps.
+ QAbstractButton has an icon property.
In addition to the ordinary constructors, a QPixmap can be
constructed using the static grabWidget() and grabWindow()
functions which creates a QPixmap and paints the given widget, or
- window, in it.
+ window, into it.
+
+ QPixmap objects can be passed around by value since the QPixmap
+ class uses implicit data sharing. For more information, see the \l
+ {Implicit Data Sharing} documentation. QPixmap objects can also be
+ streamed.
- Note that the pixel data in a pixmap is internal and is managed by
- the underlying window system. Pixels can only be accessed through
- QPainter functions or by converting the QPixmap to a QImage.
Depending on the system, QPixmap is stored using a RGB32 or a
premultiplied alpha format. If the image has an alpha channel, and
if the system allows, the preferred format is premultiplied alpha.
@@ -1558,6 +1563,13 @@ QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode)
QPixmap are stored on the client side and don't use any GDI
resources).
+ Note that the pixel data in a pixmap is internal and is managed by
+ the underlying window system. Because QPixmap is a QPaintDevice
+ subclass, QPainter can be used to draw directly onto pixmaps.
+ Pixels can only be accessed through QPainter functions or by
+ converting the QPixmap to a QImage. However, the fill() function
+ is available for initializing the entire pixmap with a given color.
+
There are functions to convert between QImage and
QPixmap. Typically, the QImage class is used to load an image
file, optionally manipulating the image data, before the QImage
@@ -1572,11 +1584,6 @@ QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode)
there are several functions that enables transformation of the
pixmap.
- QPixmap objects can be passed around by value since the QPixmap
- class uses implicit data sharing. For more information, see the \l
- {Implicit Data Sharing} documentation. QPixmap objects can also be
- streamed.
-
\tableofcontents
\section1 Reading and Writing Image Files
@@ -1633,12 +1640,15 @@ QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode)
The hasAlphaChannel() returns true if the pixmap has a format that
respects the alpha channel, otherwise returns false, while the
hasAlpha() function returns true if the pixmap has an alpha
- channel \e or a mask (otherwise false).
+ channel \e or a mask (otherwise false). The mask() function returns
+ the mask as a QBitmap object, which can be set using setMask().
- The alphaChannel() function returns the alpha channel as a new
- QPixmap object, while the mask() function returns the mask as a
- QBitmap object. The alpha channel and mask can be set using the
- setAlphaChannel() and setMask() functions, respectively.
+ The createHeuristicMask() function creates and returns a 1-bpp
+ heuristic mask (i.e. a QBitmap) for this pixmap. It works by
+ selecting a color from one of the corners and then chipping away
+ pixels of that color, starting at all the edges. The
+ createMaskFromColor() function creates and returns a mask (i.e. a
+ QBitmap) for the pixmap based on a given color.
\row
\o Low-level information
@@ -1676,14 +1686,7 @@ QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode)
\section1 Pixmap Transformations
QPixmap supports a number of functions for creating a new pixmap
- that is a transformed version of the original: The
- createHeuristicMask() function creates and returns a 1-bpp
- heuristic mask (i.e. a QBitmap) for this pixmap. It works by
- selecting a color from one of the corners and then chipping away
- pixels of that color, starting at all the edges. The
- createMaskFromColor() function creates and returns a mask (i.e. a
- QBitmap) for the pixmap based on a given color.
-
+ that is a transformed version of the original:
The scaled(), scaledToWidth() and scaledToHeight() functions
return scaled copies of the pixmap, while the copy() function
@@ -1698,11 +1701,6 @@ QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode)
function returns the actual matrix used for transforming the
pixmap.
- There are also functions for changing attributes of a pixmap.
- in-place: The fill() function fills the entire image with the
- given color, the setMask() function sets a mask bitmap, and the
- setAlphaChannel() function sets the pixmap's alpha channel.
-
\sa QBitmap, QImage, QImageReader, QImageWriter
*/
@@ -1721,7 +1719,7 @@ QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode)
Returns true if this pixmap has an alpha channel, \e or has a
mask, otherwise returns false.
- \sa hasAlphaChannel(), alphaChannel(), mask()
+ \sa hasAlphaChannel(), mask()
*/
bool QPixmap::hasAlpha() const
{
@@ -1732,7 +1730,7 @@ bool QPixmap::hasAlpha() const
Returns true if the pixmap has a format that respects the alpha
channel, otherwise returns false.
- \sa alphaChannel(), hasAlpha()
+ \sa hasAlpha()
*/
bool QPixmap::hasAlphaChannel() const
{
@@ -1740,7 +1738,7 @@ bool QPixmap::hasAlphaChannel() const
}
/*!
- \reimp
+ \internal
*/
int QPixmap::metric(PaintDeviceMetric metric) const
{
@@ -1749,6 +1747,7 @@ int QPixmap::metric(PaintDeviceMetric metric) const
/*!
\fn void QPixmap::setAlphaChannel(const QPixmap &alphaChannel)
+ \obsolete
Sets the alpha channel of this pixmap to the given \a alphaChannel
by converting the \a alphaChannel into 32 bit and using the
@@ -1786,6 +1785,8 @@ void QPixmap::setAlphaChannel(const QPixmap &alphaChannel)
}
/*!
+ \obsolete
+
Returns the alpha channel of the pixmap as a new grayscale QPixmap in which
each pixel's red, green, and blue values are given the alpha value of the
original pixmap. The color depth of the returned pixmap is the system depth
@@ -1804,7 +1805,9 @@ void QPixmap::setAlphaChannel(const QPixmap &alphaChannel)
\image alphachannelimage.png The pixmap and channelImage QPixmaps
\warning This is an expensive operation. The alpha channel of the
- pixmap is extracted dynamically from the pixeldata.
+ pixmap is extracted dynamically from the pixeldata. Most usecases of this
+ function are covered by QPainter and compositionModes which will normally
+ execute faster.
\sa setAlphaChannel(), {QPixmap#Pixmap Information}{Pixmap
Information}
@@ -1815,7 +1818,7 @@ QPixmap QPixmap::alphaChannel() const
}
/*!
- \reimp
+ \internal
*/
QPaintEngine *QPixmap::paintEngine() const
{
@@ -1825,7 +1828,7 @@ QPaintEngine *QPixmap::paintEngine() const
/*!
\fn QBitmap QPixmap::mask() const
- Extracts a bitmap mask from the pixmap's alphachannel.
+ Extracts a bitmap mask from the pixmap's alpha channel.
\warning This is potentially an expensive operation. The mask of
the pixmap is extracted dynamically from the pixeldata.
@@ -1853,18 +1856,17 @@ int QPixmap::defaultDepth()
return QScreen::instance()->depth();
#elif defined(Q_WS_X11)
return QX11Info::appDepth();
-#elif defined(Q_OS_WINCE)
+#elif defined(Q_WS_WINCE)
return QColormap::instance().depth();
#elif defined(Q_WS_WIN)
return 32; // XXX
#elif defined(Q_WS_MAC)
return 32;
+#elif defined(Q_OS_SYMBIAN)
+ return S60->screenDepth;
#endif
}
-typedef void (*_qt_pixmap_cleanup_hook_64)(qint64);
-extern _qt_pixmap_cleanup_hook_64 qt_pixmap_cleanup_hook_64;
-
/*!
Detaches the pixmap from shared pixmap data.
@@ -1886,21 +1888,15 @@ void QPixmap::detach()
{
QPixmapData::ClassId id = data->classId();
if (id == QPixmapData::RasterClass) {
- QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data);
+ QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data.data());
rasterData->image.detach();
-#if defined(Q_WS_WIN) && !defined(QT_NO_DIRECT3D)
- if (rasterData->texture) {
- rasterData->texture->Release();
- rasterData->texture = 0;
- }
-#endif
}
- if (data->is_cached && qt_pixmap_cleanup_hook_64 && data->ref == 1)
- qt_pixmap_cleanup_hook_64(cacheKey());
+ if (data->is_cached && data->ref == 1)
+ QImagePixmapCleanupHooks::executePixmapHooks(this);
#if defined(Q_WS_MAC)
- QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data) : 0;
+ QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0;
if (macData) {
if (macData->cg_mask) {
CGImageRelease(macData->cg_mask);
@@ -1911,18 +1907,13 @@ void QPixmap::detach()
if (data->ref != 1) {
*this = copy();
-#if defined(Q_WS_MAC) && !defined(QT_MAC_NO_QUICKDRAW)
- if (id == QPixmapData::MacClass) {
- macData->qd_alpha = 0;
- }
-#endif
}
++data->detach_no;
#if defined(Q_WS_X11)
if (data->classId() == QPixmapData::X11Class) {
- QX11PixmapData *d = static_cast<QX11PixmapData*>(data);
- d->uninit = false;
+ QX11PixmapData *d = static_cast<QX11PixmapData*>(data.data());
+ d->flags &= ~QX11PixmapData::Uninitialized;
// reset the cache data
if (d->hd2) {
@@ -1958,15 +1949,11 @@ QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags)
if (image.isNull())
return QPixmap();
- QPixmapData *data;
QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem();
- if (gs)
- data = gs->createPixmapData(QPixmapData::PixmapType);
- else
- data = QGraphicsSystem::createDefaultPixmapData(QPixmapData::PixmapType);
-
+ QScopedPointer<QPixmapData> data(gs ? gs->createPixmapData(QPixmapData::PixmapType)
+ : QGraphicsSystem::createDefaultPixmapData(QPixmapData::PixmapType));
data->fromImage(image, flags);
- return QPixmap(data);
+ return QPixmap(data.take());
}
/*!
@@ -2011,7 +1998,7 @@ QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags)
*/
QPixmapData* QPixmap::pixmapData() const
{
- return data;
+ return data.data();
}
/*!
diff --git a/src/gui/image/qpixmap.h b/src/gui/image/qpixmap.h
index 08b2643..c2d6d56 100644
--- a/src/gui/image/qpixmap.h
+++ b/src/gui/image/qpixmap.h
@@ -46,11 +46,16 @@
#include <QtGui/qcolor.h>
#include <QtCore/qnamespace.h>
#include <QtCore/qstring.h> // char*->QString conversion
+#include <QtCore/qsharedpointer.h>
#include <QtGui/qimage.h>
#include <QtGui/qtransform.h>
QT_BEGIN_HEADER
+#if defined(Q_OS_SYMBIAN)
+class CFbsBitmap;
+#endif
+
QT_BEGIN_NAMESPACE
QT_MODULE(Gui)
@@ -59,7 +64,6 @@ class QImageWriter;
class QColor;
class QVariant;
class QX11Info;
-
class QPixmapData;
class Q_GUI_EXPORT QPixmap : public QPaintDevice
@@ -79,11 +83,11 @@ public:
QPixmap &operator=(const QPixmap &);
operator QVariant() const;
- bool isNull() const;
+ bool isNull() const; // ### Qt 5: make inline
int devType() const;
- int width() const;
- int height() const;
+ int width() const; // ### Qt 5: make inline
+ int height() const; // ### Qt 5: make inline
QSize size() const;
QRect rect() const;
int depth() const;
@@ -152,9 +156,17 @@ public:
static QPixmap fromMacCGImageRef(CGImageRef image);
#endif
+#if defined(Q_OS_SYMBIAN)
+ CFbsBitmap *toSymbianCFbsBitmap() const;
+ static QPixmap fromSymbianCFbsBitmap(CFbsBitmap *bitmap);
+#endif
+
inline QPixmap copy(int x, int y, int width, int height) const;
QPixmap copy(const QRect &rect = QRect()) const;
+ inline void scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed = 0);
+ void scroll(int dx, int dy, const QRect &rect, QRegion *exposed = 0);
+
int serialNumber() const;
qint64 cacheKey() const;
@@ -216,7 +228,7 @@ public:
#endif
private:
- QPixmapData *data;
+ QExplicitlySharedDataPointer<QPixmapData> data;
bool doImageIO(QImageWriter *io, int quality) const;
@@ -251,8 +263,6 @@ private:
friend class QWidgetPrivate;
friend class QRasterPaintEngine;
friend class QRasterBuffer;
- friend class QDirect3DPaintEngine;
- friend class QDirect3DPaintEnginePrivate;
friend class QDetachedPixmap;
#if !defined(QT_NO_DATASTREAM)
friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
@@ -263,7 +273,7 @@ public:
QPixmapData* pixmapData() const;
public:
- typedef QPixmapData * DataPtr;
+ typedef QExplicitlySharedDataPointer<QPixmapData> DataPtr;
inline DataPtr &data_ptr() { return data; }
};
@@ -274,6 +284,11 @@ inline QPixmap QPixmap::copy(int ax, int ay, int awidth, int aheight) const
return copy(QRect(ax, ay, awidth, aheight));
}
+inline void QPixmap::scroll(int dx, int dy, int ax, int ay, int awidth, int aheight, QRegion *exposed)
+{
+ scroll(dx, dy, QRect(ax, ay, awidth, aheight), exposed);
+}
+
inline bool QPixmap::loadFromData(const QByteArray &buf, const char *format,
Qt::ImageConversionFlags flags)
{
diff --git a/src/gui/image/qpixmap_mac.cpp b/src/gui/image/qpixmap_mac.cpp
index 3a9676d..5cfdba9 100644
--- a/src/gui/image/qpixmap_mac.cpp
+++ b/src/gui/image/qpixmap_mac.cpp
@@ -38,7 +38,6 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-//#define QT_RASTER_PAINTENGINE
#include "qpixmap.h"
#include "qimage.h"
@@ -52,9 +51,6 @@
#include <private/qdrawhelper_p.h>
#include <private/qpixmap_mac_p.h>
#include <private/qpixmap_raster_p.h>
-#ifdef QT_RASTER_PAINTENGINE
-# include <private/qpaintengine_raster_p.h>
-#endif
#include <private/qpaintengine_mac_p.h>
#include <private/qt_mac_p.h>
#include <private/qt_cocoa_helpers_mac_p.h>
@@ -77,12 +73,12 @@ static int qt_pixmap_serial = 0;
Q_GUI_EXPORT quint32 *qt_mac_pixmap_get_base(const QPixmap *pix)
{
- return static_cast<QMacPixmapData*>(pix->data)->pixels;
+ return static_cast<QMacPixmapData*>(pix->data.data())->pixels;
}
Q_GUI_EXPORT int qt_mac_pixmap_get_bytes_per_line(const QPixmap *pix)
{
- return static_cast<QMacPixmapData*>(pix->data)->bytesPerRow;
+ return static_cast<QMacPixmapData*>(pix->data.data())->bytesPerRow;
}
void qt_mac_cgimage_data_free(void *info, const void *memoryToFree, size_t)
@@ -119,14 +115,9 @@ CGImageRef qt_mac_image_to_cgimage(const QImage &image)
CGDataProviderCreateWithData(0, image.bits(), image.bytesPerLine() * image.height(),
0);
-#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
uint cgflags = kCGImageAlphaPremultipliedFirst;
#ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
- if(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4)
- cgflags |= kCGBitmapByteOrder32Host;
-#endif
-#else
- CGImageAlphaInfo cgflags = kCGImageAlphaPremultipliedFirst;
+ cgflags |= kCGBitmapByteOrder32Host;
#endif
CGImageRef cgImage = CGImageCreate(image.width(), image.height(), bitsPerColor, bitsPerPixel,
@@ -168,12 +159,9 @@ static inline QRgb qt_conv16ToRgb(ushort c) {
QSet<QMacPixmapData*> QMacPixmapData::validDataPointers;
QMacPixmapData::QMacPixmapData(PixelType type)
- : QPixmapData(type, MacClass), w(0), h(0), d(0), has_alpha(0), has_mask(0),
+ : QPixmapData(type, MacClass), has_alpha(0), has_mask(0),
uninit(true), pixels(0), pixelsToFree(0), bytesPerRow(0),
cg_data(0), cg_dataBeingReleased(0), cg_mask(0),
-#ifndef QT_MAC_NO_QUICKDRAW
- qd_data(0), qd_alpha(0),
-#endif
pengine(0)
{
}
@@ -188,11 +176,13 @@ void QMacPixmapData::resize(int width, int height)
w = width;
h = height;
+ is_null = (w <= 0 || h <= 0);
d = (pixelType() == BitmapType ? 1 : 32);
bool make_null = w <= 0 || h <= 0; // create null pixmap
if (make_null || d == 0) {
w = 0;
h = 0;
+ is_null = true;
d = 0;
if (!make_null)
qWarning("Qt: QPixmap: Invalid pixmap parameters");
@@ -231,6 +221,7 @@ void QMacPixmapData::fromImage(const QImage &img,
w = img.width();
h = img.height();
+ is_null = (w <= 0 || h <= 0);
d = (pixelType() == BitmapType ? 1 : img.depth());
QImage image = img;
@@ -430,7 +421,7 @@ QPixmap QMacPixmapData::alphaChannel() const
void QMacPixmapData::setAlphaChannel(const QPixmap &alpha)
{
has_mask = true;
- QMacPixmapData *alphaData = static_cast<QMacPixmapData*>(alpha.data);
+ QMacPixmapData *alphaData = static_cast<QMacPixmapData*>(alpha.data.data());
macSetAlphaChannel(alphaData, false);
}
@@ -458,7 +449,7 @@ void QMacPixmapData::setMask(const QBitmap &mask)
has_alpha = false;
has_mask = true;
- QMacPixmapData *maskData = static_cast<QMacPixmapData*>(mask.data);
+ QMacPixmapData *maskData = static_cast<QMacPixmapData*>(mask.data.data());
macSetAlphaChannel(maskData, true);
}
@@ -496,13 +487,6 @@ int QMacPixmapData::metric(QPaintDevice::PaintDeviceMetric theMetric) const
QMacPixmapData::~QMacPixmapData()
{
validDataPointers.remove(this);
-#ifndef QT_MAC_NO_QUICKDRAW
- macQDDisposeAlpha();
- if (qd_data) {
- DisposeGWorld(qd_data);
- qd_data = 0;
- }
-#endif
if (cg_mask) {
CGImageRelease(cg_mask);
cg_mask = 0;
@@ -591,48 +575,9 @@ void QMacPixmapData::macGetAlphaChannel(QMacPixmapData *pix, bool asMask) const
void QMacPixmapData::macSetHasAlpha(bool b)
{
has_alpha = b;
-#ifndef QT_MAC_NO_QUICKDRAW
- macQDDisposeAlpha(); //let it get created lazily
-#endif
macReleaseCGImageRef();
}
-#ifndef QT_MAC_NO_QUICKDRAW
-void QMacPixmapData::macQDDisposeAlpha()
-{
- if (qd_alpha) {
- DisposeGWorld(qd_alpha);
- qd_alpha = 0;
- }
-}
-
-void QMacPixmapData::macQDUpdateAlpha()
-{
- macQDDisposeAlpha(); // get rid of alpha pixmap
- if (!has_alpha && !has_mask)
- return;
-
- //setup
- Rect rect;
- SetRect(&rect, 0, 0, w, h);
- const int params = alignPix | stretchPix | newDepth;
- NewGWorld(&qd_alpha, 32, &rect, 0, 0, params);
- int *dptr = (int *)GetPixBaseAddr(GetGWorldPixMap(qd_alpha)), *drow;
- unsigned short dbpr = GetPixRowBytes(GetGWorldPixMap(qd_alpha));
- const int *sptr = (int*)pixels, *srow;
- const uint sbpr = bytesPerRow;
- uchar clr;
- for (int y = 0; y < h; ++y) {
- drow = (int*)((char *)dptr + (y * dbpr));
- srow = (int*)((char *)sptr + (y * sbpr));
- for (int x=0; x < w; x++) {
- clr = qAlpha(*(srow + x));
- *(drow + x) = qRgba(~clr, ~clr, ~clr, 0);
- }
- }
-}
-#endif
-
void QMacPixmapData::macCreateCGImageRef()
{
Q_ASSERT(cg_data == 0);
@@ -642,14 +587,9 @@ void QMacPixmapData::macCreateCGImageRef()
pixels, bytesPerRow * h,
qt_mac_cgimage_data_free);
validDataPointers.insert(this);
-#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
uint cgflags = kCGImageAlphaPremultipliedFirst;
#ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
- if(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4)
- cgflags |= kCGBitmapByteOrder32Host;
-#endif
-#else
- CGImageAlphaInfo cgflags = kCGImageAlphaPremultipliedFirst;
+ cgflags |= kCGBitmapByteOrder32Host;
#endif
cg_data = CGImageCreate(w, h, 8, 32, bytesPerRow, colorspace,
cgflags, provider, 0, 0, kCGRenderingIntentDefault);
@@ -890,38 +830,6 @@ static void qt_mac_grabDisplayRect(CGDirectDisplayID display, const QRect &displ
ptrCGLDestroyContext(glContextObj); // and destroy the context
}
-static CGImageRef qt_mac_createImageFromBitmapContext(CGContextRef c)
-{
- void *rasterData = CGBitmapContextGetData(c);
- const int width = CGBitmapContextGetBytesPerRow(c),
- height = CGBitmapContextGetHeight(c);
- size_t imageDataSize = width*height;
-
- if(!rasterData)
- return 0;
-
- // Create the data provider from the image data, using
- // the image releaser function releaseBitmapContextImageData.
- CGDataProviderRef dataProvider = CGDataProviderCreateWithData(0, rasterData,
- imageDataSize,
- qt_mac_cgimage_data_free);
-
- if(!dataProvider)
- return 0;
-
- uint bitmapInfo = 0;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if(CGBitmapContextGetBitmapInfo)
- bitmapInfo = CGBitmapContextGetBitmapInfo(c);
- else
-#endif
- bitmapInfo = CGBitmapContextGetAlphaInfo(c);
- return CGImageCreate(width, height, CGBitmapContextGetBitsPerComponent(c),
- CGBitmapContextGetBitsPerPixel(c), CGBitmapContextGetBytesPerRow(c),
- CGBitmapContextGetColorSpace(c), bitmapInfo, dataProvider,
- 0, true, kCGRenderingIntentDefault);
-}
-
// Returns a pixmap containing the screen contents at rect.
static QPixmap qt_mac_grabScreenRect(const QRect &rect)
{
@@ -955,19 +863,8 @@ static QPixmap qt_mac_grabScreenRect(const QRect &rect)
rect.height(), 8, bytewidth,
QCoreGraphicsPaintEngine::macGenericColorSpace(),
kCGImageAlphaNoneSkipFirst);
-
-#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
- if(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
- QCFType<CGImageRef> image = CGBitmapContextCreateImage(bitmap);
- return QPixmap::fromMacCGImageRef(image);
- } else
-#endif
- {
- QCFType<CGImageRef> image = qt_mac_createImageFromBitmapContext(bitmap);
- if (!image)
- return QPixmap();
- return QPixmap::fromMacCGImageRef(image);
- }
+ QCFType<CGImageRef> image = CGBitmapContextCreateImage(bitmap);
+ return QPixmap::fromMacCGImageRef(image);
}
#ifndef QT_MAC_USE_COCOA // no QuickDraw in 64-bit mode
@@ -1029,37 +926,12 @@ QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h)
relocated.
\warning This function is only available on Mac OS X.
+ \warning As of Qt 4.6, this function \e{always} returns zero.
*/
Qt::HANDLE QPixmap::macQDHandle() const
{
-#ifndef QT_MAC_NO_QUICKDRAW
- QMacPixmapData *d = static_cast<QMacPixmapData*>(data);
- if (!d->qd_data) { //create the qd data
- Rect rect;
- SetRect(&rect, 0, 0, d->w, d->h);
- unsigned long qdformat = k32ARGBPixelFormat;
- GWorldFlags qdflags = 0;
-#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
- //we play such games so we can use the same buffer in CG as QD this
- //makes our merge much simpler, at some point the hacks will go away
- //because QD will be removed, but until that day this keeps them coexisting
- if (QSysInfo::ByteOrder == QSysInfo::LittleEndian)
- qdformat = k32BGRAPixelFormat;
-#if 0
- qdflags |= kNativeEndianPixMap;
-#endif
- }
-#endif
- if(NewGWorldFromPtr(&d->qd_data, qdformat, &rect, 0, 0, qdflags,
- (char*)d->pixels, d->bytesPerRow) != noErr)
- qWarning("Qt: internal: QPixmap::init error (%d %d %d %d)", rect.left, rect.top, rect.right, rect.bottom);
- }
- return d->qd_data;
-#else
return 0;
-#endif
}
/*! \internal
@@ -1069,18 +941,11 @@ Qt::HANDLE QPixmap::macQDHandle() const
long as it can be relocated.
\warning This function is only available on Mac OS X.
+ \warning As of Qt 4.6, this function \e{always} returns zero.
*/
Qt::HANDLE QPixmap::macQDAlphaHandle() const
{
-#ifndef QT_MAC_NO_QUICKDRAW
- QMacPixmapData *d = static_cast<QMacPixmapData*>(data);
- if (d->has_alpha || d->has_mask) {
- if (!d->qd_alpha) //lazily created
- d->macQDUpdateAlpha();
- return d->qd_alpha;
- }
-#endif
return 0;
}
@@ -1096,14 +961,14 @@ Qt::HANDLE QPixmap::macQDAlphaHandle() const
Qt::HANDLE QPixmap::macCGHandle() const
{
if (data->classId() == QPixmapData::MacClass) {
- QMacPixmapData *d = static_cast<QMacPixmapData *>(data);
+ QMacPixmapData *d = static_cast<QMacPixmapData *>(data.data());
if (!d->cg_data)
d->macCreateCGImageRef();
CGImageRef ret = d->cg_data;
CGImageRetain(ret);
return ret;
} else if (data->classId() == QPixmapData::RasterClass) {
- return qt_mac_image_to_cgimage(static_cast<QRasterPixmapData *>(data)->image);
+ return qt_mac_image_to_cgimage(static_cast<QRasterPixmapData *>(data.data())->image);
}
return 0;
}
@@ -1115,7 +980,7 @@ bool QMacPixmapData::hasAlphaChannel() const
CGImageRef qt_mac_create_imagemask(const QPixmap &pixmap, const QRectF &sr)
{
- QMacPixmapData *px = static_cast<QMacPixmapData*>(pixmap.data);
+ QMacPixmapData *px = static_cast<QMacPixmapData*>(pixmap.data.data());
if (px->cg_mask) {
if (px->cg_mask_rect == sr) {
CGImageRetain(px->cg_mask); //reference for the caller
@@ -1150,7 +1015,6 @@ IconRef qt_mac_create_iconref(const QPixmap &px)
if (px.isNull())
return 0;
- QMacSavedPortInfo pi; //save the current state
//create icon
IconFamilyHandle iconFamily = reinterpret_cast<IconFamilyHandle>(NewHandle(0));
//create data
@@ -1225,38 +1089,12 @@ IconRef qt_mac_create_iconref(const QPixmap &px)
}
#endif
-QPixmap qt_mac_convert_iconref(const IconRef icon, int width, int height)
-{
- QPixmap ret(width, height);
- ret.fill(QColor(0, 0, 0, 0));
-
- CGRect rect = CGRectMake(0, 0, width, height);
-
- CGContextRef ctx = qt_mac_cg_context(&ret);
- CGAffineTransform old_xform = CGContextGetCTM(ctx);
- CGContextConcatCTM(ctx, CGAffineTransformInvert(old_xform));
- CGContextConcatCTM(ctx, CGAffineTransformIdentity);
-
- ::RGBColor b;
- b.blue = b.green = b.red = 255*255;
- PlotIconRefInContext(ctx, &rect, kAlignNone, kTransformNone, &b, kPlotIconRefNormalFlags, icon);
- CGContextRelease(ctx);
- return ret;
-}
-
/*! \internal */
QPaintEngine* QMacPixmapData::paintEngine() const
{
if (!pengine) {
QMacPixmapData *that = const_cast<QMacPixmapData*>(this);
-#ifdef QT_RASTER_PAINTENGINE
- if (qgetenv("QT_MAC_USE_COREGRAPHICS").isNull())
- that->pengine = new QRasterPaintEngine();
- else
- that->pengine = new QCoreGraphicsPaintEngine();
-#else
that->pengine = new QCoreGraphicsPaintEngine();
-#endif
}
return pengine;
}
@@ -1290,6 +1128,14 @@ void QMacPixmapData::copy(const QPixmapData *data, const QRect &rect)
has_mask = macData->has_mask;
}
+bool QMacPixmapData::scroll(int dx, int dy, const QRect &rect)
+{
+ Q_UNUSED(dx);
+ Q_UNUSED(dy);
+ Q_UNUSED(rect);
+ return false;
+}
+
/*!
\since 4.2
@@ -1321,6 +1167,7 @@ QPixmap QPixmap::fromMacCGImageRef(CGImageRef image)
const size_t w = CGImageGetWidth(image),
h = CGImageGetHeight(image);
QPixmap ret(w, h);
+ ret.fill(Qt::transparent);
CGRect rect = CGRectMake(0, 0, w, h);
CGContextRef ctx = qt_mac_cg_context(&ret);
qt_mac_drawCGImage(ctx, &rect, image);
diff --git a/src/gui/image/qpixmap_mac_p.h b/src/gui/image/qpixmap_mac_p.h
index d0d828f..d32e933 100644
--- a/src/gui/image/qpixmap_mac_p.h
+++ b/src/gui/image/qpixmap_mac_p.h
@@ -68,6 +68,7 @@ public:
void resize(int width, int height);
void fromImage(const QImage &image, Qt::ImageConversionFlags flags);
void copy(const QPixmapData *data, const QRect &rect);
+ bool scroll(int dx, int dy, const QRect &rect);
int metric(QPaintDevice::PaintDeviceMetric metric) const;
void fill(const QColor &color);
@@ -82,7 +83,6 @@ public:
QPaintEngine* paintEngine() const;
private:
- int w, h, d;
uint has_alpha : 1, has_mask : 1, uninit : 1;
@@ -109,11 +109,6 @@ private:
uint bytesPerRow;
QRectF cg_mask_rect;
CGImageRef cg_data, cg_dataBeingReleased, cg_mask;
-#ifndef QT_MAC_NO_QUICKDRAW
- GWorldPtr qd_data, qd_alpha;
- void macQDDisposeAlpha();
- void macQDUpdateAlpha();
-#endif
static QSet<QMacPixmapData*> validDataPointers;
QPaintEngine *pengine;
diff --git a/src/gui/image/qpixmap_qws.cpp b/src/gui/image/qpixmap_qws.cpp
index 55968f1..8966c43 100644
--- a/src/gui/image/qpixmap_qws.cpp
+++ b/src/gui/image/qpixmap_qws.cpp
@@ -48,6 +48,9 @@
#include <private/qdrawhelper_p.h>
#include <private/qpixmap_raster_p.h>
+
+QT_BEGIN_NAMESPACE
+
QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h)
{
QWidget *widget = QWidget::find(window);
@@ -112,7 +115,7 @@ QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h)
QRgb* QPixmap::clut() const
{
if (data->classId() == QPixmapData::RasterClass) {
- const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data);
+ const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
return d->image.colorTable().data();
}
@@ -122,7 +125,7 @@ QRgb* QPixmap::clut() const
int QPixmap::numCols() const
{
if (data->classId() == QPixmapData::RasterClass) {
- const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data);
+ const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
return d->image.numColors();
}
@@ -132,7 +135,7 @@ int QPixmap::numCols() const
const uchar* QPixmap::qwsBits() const
{
if (data->classId() == QPixmapData::RasterClass) {
- const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data);
+ const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
return d->image.bits();
}
@@ -142,9 +145,11 @@ const uchar* QPixmap::qwsBits() const
int QPixmap::qwsBytesPerLine() const
{
if (data->classId() == QPixmapData::RasterClass) {
- const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data);
+ const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
return d->image.bytesPerLine();
}
return 0;
}
+
+QT_END_NAMESPACE
diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp
index 47996ce..da8a33c 100644
--- a/src/gui/image/qpixmap_raster.cpp
+++ b/src/gui/image/qpixmap_raster.cpp
@@ -50,12 +50,6 @@
#include <private/qwidget_p.h>
#include <private/qdrawhelper_p.h>
-#if !defined(QT_NO_DIRECT3D) && defined(Q_WS_WIN)
-#include <private/qpaintengine_d3d_p.h>
-#include <d3d9.h>
-extern QDirect3DPaintEngine *qt_d3dEngine();
-#endif
-
QT_BEGIN_NAMESPACE
const uchar qt_pixmap_bit_mask[] = { 0x01, 0x02, 0x04, 0x08,
@@ -63,9 +57,6 @@ const uchar qt_pixmap_bit_mask[] = { 0x01, 0x02, 0x04, 0x08,
QRasterPixmapData::QRasterPixmapData(PixelType type)
: QPixmapData(type, RasterClass)
-#if defined(Q_WS_WIN) && !defined(QT_NO_DIRECT3D)
- , texture(0)
-#endif
{
}
@@ -94,6 +85,10 @@ void QRasterPixmapData::resize(int width, int height)
#endif
image = QImage(width, height, format);
+ w = width;
+ h = height;
+ d = image.depth();
+ is_null = (w <= 0 || h <= 0);
if (pixelType() == BitmapType && !image.isNull()) {
image.setNumColors(2);
@@ -177,10 +172,28 @@ void QRasterPixmapData::fromImage(const QImage &sourceImage,
}
}
#endif
+ if (image.d) {
+ w = image.d->width;
+ h = image.d->height;
+ d = image.d->depth;
+ } else {
+ w = h = d = 0;
+ }
+ is_null = (w <= 0 || h <= 0);
setSerialNumber(image.serialNumber());
}
+// from qwindowsurface.cpp
+extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset);
+
+bool QRasterPixmapData::scroll(int dx, int dy, const QRect &rect)
+{
+ if (!image.isNull())
+ qt_scrollRectInImage(image, rect, QPoint(dx, dy));
+ return true;
+}
+
void QRasterPixmapData::fill(const QColor &color)
{
uint pixel;
@@ -321,25 +334,36 @@ extern int qt_defaultDpiY();
int QRasterPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const
{
+ QImageData *d = image.d;
+ if (!d)
+ return 0;
+
// override the image dpi with the screen dpi when rendering to a pixmap
- const int dpmX = qRound(qt_defaultDpiX() * 100 / qreal(2.54));
- const int dpmY = qRound(qt_defaultDpiY() * 100 / qreal(2.54));
switch (metric) {
+ case QPaintDevice::PdmWidth:
+ return w;
+ case QPaintDevice::PdmHeight:
+ return h;
case QPaintDevice::PdmWidthMM:
- return qRound(image.width() * 1000 / dpmX);
+ return qRound(d->width * 25.4 / qt_defaultDpiX());
case QPaintDevice::PdmHeightMM:
- return qRound(image.height() * 1000 / dpmY);
- case QPaintDevice::PdmDpiX:
- return qRound(dpmX * qreal(0.0254));
- case QPaintDevice::PdmDpiY:
- return qRound(dpmY * qreal(0.0254));
+ return qRound(d->width * 25.4 / qt_defaultDpiY());
+ case QPaintDevice::PdmNumColors:
+ return d->colortable.size();
+ case QPaintDevice::PdmDepth:
+ return this->d;
+ case QPaintDevice::PdmDpiX: // fall-through
case QPaintDevice::PdmPhysicalDpiX:
- return qRound(dpmX * qreal(0.0254));
+ return qt_defaultDpiX();
+ case QPaintDevice::PdmDpiY: // fall-through
case QPaintDevice::PdmPhysicalDpiY:
- return qRound(dpmY * qreal(0.0254));
+ return qt_defaultDpiY();
default:
- return image.metric(metric);
+ qWarning("QRasterPixmapData::metric(): Unhandled metric type %d", metric);
+ break;
}
+
+ return 0;
}
QImage* QRasterPixmapData::buffer()
diff --git a/src/gui/image/qpixmap_raster_p.h b/src/gui/image/qpixmap_raster_p.h
index 682c84f..8eed2a1 100644
--- a/src/gui/image/qpixmap_raster_p.h
+++ b/src/gui/image/qpixmap_raster_p.h
@@ -58,9 +58,6 @@
#ifdef Q_WS_WIN
# include "qt_windows.h"
-# ifndef QT_NO_DIRECT3D
-# include <d3d9.h>
-# endif
#endif
QT_BEGIN_NAMESPACE
@@ -75,6 +72,7 @@ public:
void fromFile(const QString &filename, Qt::ImageConversionFlags flags);
void fromImage(const QImage &image, Qt::ImageConversionFlags flags);
+ bool scroll(int dx, int dy, const QRect &rect);
void fill(const QColor &color);
void setMask(const QBitmap &mask);
bool hasAlphaChannel() const;
@@ -87,10 +85,6 @@ protected:
int metric(QPaintDevice::PaintDeviceMetric metric) const;
private:
-#if defined(Q_WS_WIN) && !defined(QT_NO_DIRECT3D)
- friend class QDirect3DPaintEnginePrivate;
- IDirect3DTexture9 *texture;
-#endif
friend class QPixmap;
friend class QBitmap;
friend class QDetachedPixmap;
diff --git a/src/gui/image/qpixmap_s60.cpp b/src/gui/image/qpixmap_s60.cpp
new file mode 100644
index 0000000..e00bf26
--- /dev/null
+++ b/src/gui/image/qpixmap_s60.cpp
@@ -0,0 +1,236 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <exception>
+#include <w32std.h>
+#include <fbs.h>
+
+#include <private/qt_s60_p.h>
+#include "qpixmap.h"
+#include "qpixmap_raster_p.h"
+#include <qwidget.h>
+
+QT_BEGIN_NAMESPACE
+
+QPixmap QPixmap::grabWindow(WId winId, int x, int y, int w, int h )
+{
+ CWsScreenDevice* screenDevice = S60->screenDevice();
+ TSize screenSize = screenDevice->SizeInPixels();
+
+ TSize srcSize;
+ // Find out if this is one of our windows.
+ QSymbianControl *sControl;
+ sControl = winId->MopGetObject(sControl);
+ if (sControl && sControl->widget()->windowType() == Qt::Desktop) {
+ // Grabbing desktop widget
+ srcSize = screenSize;
+ } else {
+ TPoint relativePos = winId->PositionRelativeToScreen();
+ x += relativePos.iX;
+ y += relativePos.iY;
+ srcSize = winId->Size();
+ }
+
+ TRect srcRect(TPoint(x, y), srcSize);
+ // Clip to the screen
+ srcRect.Intersection(TRect(screenSize));
+
+ if (w > 0 && h > 0) {
+ TRect subRect(TPoint(x, y), TSize(w, h));
+ // Clip to the subRect
+ srcRect.Intersection(subRect);
+ }
+
+ if (srcRect.IsEmpty())
+ return QPixmap();
+
+ TDisplayMode displayMode = screenDevice->DisplayMode();
+ CFbsBitmap* temporary = q_check_ptr(new CFbsBitmap()); // CBase derived object needs check on new
+ TInt error = temporary->Create(srcRect.Size(), displayMode);
+ if (error == KErrNone)
+ error = screenDevice->CopyScreenToBitmap(temporary, srcRect);
+
+ if (error != KErrNone) {
+ CBase::Delete(temporary);
+ return QPixmap();
+ }
+
+ QPixmap pixmap = QPixmap::fromSymbianCFbsBitmap(temporary);
+ CBase::Delete(temporary);
+ return pixmap;
+}
+
+/*!
+\since 4.6
+
+Returns a \c CFbsBitmap that is equivalent to the QPixmap by copying the data.
+
+It is the caller's responsibility to delete the \c CFbsBitmap after use.
+
+\warning This function is only available on Symbian OS.
+
+\sa fromSymbianCFbsBitmap()
+*/
+
+CFbsBitmap *QPixmap::toSymbianCFbsBitmap() const
+{
+ if (isNull())
+ return 0;
+
+ TDisplayMode mode;
+ const QImage img = toImage();
+ QImage::Format destFormat = img.format();
+ switch (img.format()) {
+ case QImage::Format_Mono:
+ destFormat = QImage::Format_MonoLSB;
+ // Fall through intended
+ case QImage::Format_MonoLSB:
+ mode = EGray2;
+ break;
+ case QImage::Format_Indexed8:
+ if (img.isGrayscale())
+ mode = EGray256;
+ else
+ mode = EColor256;
+ break;
+ case QImage::Format_RGB32:
+ mode = EColor16MU;
+ break;
+ case QImage::Format_ARGB6666_Premultiplied:
+ case QImage::Format_ARGB8565_Premultiplied:
+ case QImage::Format_ARGB8555_Premultiplied:
+ destFormat = QImage::Format_ARGB32_Premultiplied;
+ // Fall through intended
+ case QImage::Format_ARGB32_Premultiplied:
+#if !defined(__SERIES60_31__) && !defined(__S60_32__)
+ // ### TODO: Add runtime detection as well?
+ mode = EColor16MAP;
+ break;
+#endif
+ destFormat = QImage::Format_ARGB32;
+ // Fall through intended
+ case QImage::Format_ARGB32:
+ mode = EColor16MA;
+ break;
+ case QImage::Format_RGB555:
+ destFormat = QImage::Format_RGB16;
+ // Fall through intended
+ case QImage::Format_RGB16:
+ mode = EColor64K;
+ break;
+ case QImage::Format_RGB666:
+ destFormat = QImage::Format_RGB888;
+ // Fall through intended
+ case QImage::Format_RGB888:
+ mode = EColor16M;
+ break;
+ case QImage::Format_RGB444:
+ mode = EColor4K;
+ break;
+ case QImage::Format_Invalid:
+ return 0;
+ default:
+ qWarning("Image format not supported: %d", img.format());
+ return 0;
+ }
+
+ CFbsBitmap* bitmap = q_check_ptr(new CFbsBitmap()); // CBase derived object needs check on new
+ TSize size(width(), height());
+ if (bitmap->Create(size, mode) != KErrNone) {
+ CBase::Delete(bitmap);
+ return 0;
+ }
+
+ const QImage converted = img.convertToFormat(destFormat);
+
+ bitmap->LockHeap();
+ const uchar *sptr = converted.bits();
+ uchar *dptr = (uchar*)bitmap->DataAddress();
+ Mem::Copy(dptr, sptr, converted.numBytes());
+ bitmap->UnlockHeap();
+ return bitmap;
+}
+
+/*!
+ \since 4.6
+
+ Returns a QPixmap that is equivalent to the \c CFbsBitmap \a bitmap
+ by copying the data. If the CFbsBitmap is not valid or is compressed
+ in memory, this function will return a null QPixmap.
+
+ \warning This function is only available on Symbian OS.
+
+ \sa toSymbianCFbsBitmap(), {QPixmap#Pixmap Conversion}{Pixmap Conversion}
+*/
+
+QPixmap QPixmap::fromSymbianCFbsBitmap(CFbsBitmap *bitmap)
+{
+ if (!bitmap)
+ return QPixmap();
+
+ int width = bitmap->SizeInPixels().iWidth;
+ int height = bitmap->SizeInPixels().iHeight;
+
+ if (width <= 0 || height <= 0 || bitmap->IsCompressedInRAM())
+ return QPixmap();
+
+ TDisplayMode displayMode = bitmap->DisplayMode();
+ QImage::Format format = qt_TDisplayMode2Format(displayMode);
+ int bytesPerLine = CFbsBitmap::ScanLineLength(width, displayMode);
+ bitmap->LockHeap();
+ QImage image = QImage((const uchar*)bitmap->DataAddress(), width, height, bytesPerLine, format);
+ if (displayMode == EGray2) {
+ image.setNumColors(2);
+ image.setColor(0, QColor(Qt::color0).rgba());
+ image.setColor(1, QColor(Qt::color1).rgba());
+ } else if (displayMode == EGray256) {
+ for (int i=0; i < 256; ++i)
+ image.setColor(i, qRgb(i, i, i));
+ }else if (displayMode == EColor256) {
+ const TColor256Util *palette = TColor256Util::Default();
+ for (int i=0; i < 256; ++i)
+ image.setColor(i, (QRgb)(palette->Color256(i).Value()));
+ }
+ QPixmap pixmap = QPixmap::fromImage(image.copy());
+ bitmap->UnlockHeap();
+ return pixmap;
+}
+
+QT_END_NAMESPACE
diff --git a/src/gui/image/qpixmap_win.cpp b/src/gui/image/qpixmap_win.cpp
index 9bab0cf..c748adc 100644
--- a/src/gui/image/qpixmap_win.cpp
+++ b/src/gui/image/qpixmap_win.cpp
@@ -59,7 +59,7 @@
#include "qdebug.h"
#include "qt_windows.h"
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
#include <winbase.h>
#include "qguifunctions_wince.h"
extern bool qt_wince_is_high_dpi();
@@ -80,7 +80,7 @@ QPixmap QPixmap::grabWindow(WId winId, int x, int y, int w, int h )
if (w < 0) w = r.right - r.left;
if (h < 0) h = r.bottom - r.top;
-#ifdef Q_OS_WINCE_WM
+#ifdef Q_WS_WINCE_WM
if (qt_wince_is_pocket_pc()) {
QWidget *widget = QWidget::find(winId);
if (qobject_cast<QDesktopWidget *>(widget)) {
@@ -101,7 +101,7 @@ QPixmap QPixmap::grabWindow(WId winId, int x, int y, int w, int h )
// copy data
HDC window_dc = GetDC(winId);
BitBlt(bitmap_dc, 0, 0, w, h, window_dc, x, y, SRCCOPY
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
| CAPTUREBLT
#endif
);
@@ -123,7 +123,7 @@ HBITMAP QPixmap::toWinHBITMAP(HBitmapFormat format) const
{
HBITMAP bitmap = 0;
if (data->classId() == QPixmapData::RasterClass) {
- QRasterPixmapData* d = static_cast<QRasterPixmapData*>(data);
+ QRasterPixmapData* d = static_cast<QRasterPixmapData*>(data.data());
int w = d->image.width();
int h = d->image.height();
@@ -179,13 +179,7 @@ QPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format)
BITMAP bitmap_info;
memset(&bitmap_info, 0, sizeof(BITMAP));
- int res;
- QT_WA({
- res = GetObjectW(bitmap, sizeof(BITMAP), &bitmap_info);
- } , {
- res = GetObjectA(bitmap, sizeof(BITMAP), &bitmap_info);
- });
-
+ int res = GetObject(bitmap, sizeof(BITMAP), &bitmap_info);
if (!res) {
qErrnoWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap info");
return QPixmap();
@@ -243,7 +237,7 @@ QPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format)
}
#ifdef Q_WS_WIN
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
static QImage qt_fromWinHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h)
{
@@ -347,7 +341,7 @@ QPixmap convertHIconToPixmap( const HICON icon)
DeleteDC(hdc);
return QPixmap::fromImage(image);
}
-#else //ifndef Q_OS_WINCE
+#else //ifndef Q_WS_WINCE
QPixmap convertHIconToPixmap( const HICON icon, bool large)
{
HDC screenDevice = GetDC(0);
@@ -412,14 +406,14 @@ QPixmap convertHIconToPixmap( const HICON icon, bool large)
DeleteDC(hdc);
return QPixmap::fromImage(image);
}
-#endif //ifndef Q_OS_WINCE
+#endif //ifndef Q_WS_WINCE
QPixmap loadIconFromShell32( int resourceId, int size )
{
#ifdef Q_OS_WINCE
- HMODULE hmod = LoadLibrary((const wchar_t *) QString::fromLatin1("ceshell.dll").utf16());
+ HMODULE hmod = LoadLibrary(L"ceshell.dll");
#else
- HMODULE hmod = LoadLibraryA("shell32.dll");
+ HMODULE hmod = LoadLibrary(L"shell32.dll");
#endif
if( hmod ) {
HICON iconHandle = (HICON)LoadImage(hmod, MAKEINTRESOURCE(resourceId), IMAGE_ICON, size, size, 0);
diff --git a/src/gui/image/qpixmap_x11.cpp b/src/gui/image/qpixmap_x11.cpp
index 796d88c..aea995a 100644
--- a/src/gui/image/qpixmap_x11.cpp
+++ b/src/gui/image/qpixmap_x11.cpp
@@ -312,8 +312,8 @@ static int qt_pixmap_serial = 0;
int Q_GUI_EXPORT qt_x11_preferred_pixmap_depth = 0;
QX11PixmapData::QX11PixmapData(PixelType type)
- : QPixmapData(type, X11Class), hd(0), w(0), h(0), d(0),
- uninit(true), read_only(false), x11_mask(0), picture(0), mask_picture(0), hd2(0),
+ : QPixmapData(type, X11Class), hd(0),
+ flags(Uninitialized), x11_mask(0), picture(0), mask_picture(0), hd2(0), gl_surface(0),
share_mode(QPixmap::ImplicitlyShared), pengine(0)
{
}
@@ -324,6 +324,7 @@ void QX11PixmapData::resize(int width, int height)
w = width;
h = height;
+ is_null = (w <= 0 || h <= 0);
if (defaultScreen >= 0 && defaultScreen != xinfo.screen()) {
QX11InfoData* xd = xinfo.getX11Data(true);
@@ -347,6 +348,7 @@ void QX11PixmapData::resize(int width, int height)
if (make_null || d == 0) {
w = 0;
h = 0;
+ is_null = true;
hd = 0;
picture = 0;
d = 0;
@@ -375,6 +377,7 @@ void QX11PixmapData::fromImage(const QImage &img,
w = img.width();
h = img.height();
d = img.depth();
+ is_null = (w <= 0 || h <= 0);
if (defaultScreen >= 0 && defaultScreen != xinfo.screen()) {
QX11InfoData* xd = xinfo.getX11Data(true);
@@ -395,6 +398,7 @@ void QX11PixmapData::fromImage(const QImage &img,
if (uint(w) >= 32768 || uint(h) >= 32768) {
w = h = 0;
+ is_null = true;
return;
}
@@ -1109,6 +1113,7 @@ void QX11PixmapData::bitmapFromImage(const QImage &image)
w = img.width();
h = img.height();
d = 1;
+ is_null = (w <= 0 || h <= 0);
int bpl = (w + 7) / 8;
int ibpl = img.bytesPerLine();
if (bpl != ibpl) {
@@ -1212,7 +1217,7 @@ void QX11PixmapData::release()
XFreePixmap(xinfo.display(), hd2);
hd2 = 0;
}
- if (!read_only)
+ if (!(flags & Readonly))
XFreePixmap(xinfo.display(), hd);
hd = 0;
}
@@ -1870,12 +1875,13 @@ QPixmap QX11PixmapData::transformed(const QTransform &transform,
return bm;
} else { // color pixmap
QPixmap pm;
- QX11PixmapData *x11Data = static_cast<QX11PixmapData*>(pm.data);
- x11Data->uninit = false;
+ QX11PixmapData *x11Data = static_cast<QX11PixmapData*>(pm.data.data());
+ x11Data->flags &= ~QX11PixmapData::Uninitialized;
x11Data->xinfo = xinfo;
x11Data->d = d;
x11Data->w = w;
x11Data->h = h;
+ x11Data->is_null = (w <= 0 || h <= 0);
x11Data->hd = (Qt::HANDLE)XCreatePixmap(X11->display,
RootWindow(X11->display, xinfo.screen()),
w, h, d);
@@ -1934,7 +1940,7 @@ void QPixmap::x11SetScreen(int screen)
if (screen < 0)
screen = QX11Info::appScreen();
- QX11PixmapData *x11Data = static_cast<QX11PixmapData*>(data);
+ QX11PixmapData *x11Data = static_cast<QX11PixmapData*>(data.data());
if (screen == x11Data->xinfo.screen())
return; // nothing to do
@@ -2012,7 +2018,7 @@ QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h)
QPixmap pm(data);
- data->uninit = false;
+ data->flags &= ~QX11PixmapData::Uninitialized;
pm.x11SetScreen(scr);
GC gc = XCreateGC(dpy, pm.handle(), 0, 0);
@@ -2031,7 +2037,7 @@ bool QX11PixmapData::hasAlphaChannel() const
const QX11Info &QPixmap::x11Info() const
{
if (data->classId() == QPixmapData::X11Class)
- return static_cast<QX11PixmapData*>(data)->xinfo;
+ return static_cast<QX11PixmapData*>(data.data())->xinfo;
else {
static QX11Info nullX11Info;
return nullX11Info;
@@ -2054,7 +2060,7 @@ QPaintEngine* QX11PixmapData::paintEngine() const
{
QX11PixmapData *that = const_cast<QX11PixmapData*>(this);
- if (read_only && share_mode == QPixmap::ImplicitlyShared) {
+ if ((flags & Readonly) && share_mode == QPixmap::ImplicitlyShared) {
// if someone wants to draw onto us, copy the shared contents
// and turn it into a fully fledged QPixmap
::Pixmap hd_copy = XCreatePixmap(X11->display, RootWindow(X11->display, xinfo.screen()),
@@ -2076,7 +2082,7 @@ QPaintEngine* QX11PixmapData::paintEngine() const
XFreeGC(X11->display, gc);
}
that->hd = hd_copy;
- that->read_only = false;
+ that->flags &= ~QX11PixmapData::Readonly;
}
if (!that->pengine)
@@ -2088,7 +2094,7 @@ Qt::HANDLE QPixmap::x11PictureHandle() const
{
#ifndef QT_NO_XRENDER
if (data->classId() == QPixmapData::X11Class)
- return static_cast<QX11PixmapData*>(data)->picture;
+ return static_cast<const QX11PixmapData*>(data.data())->picture;
else
return 0;
#else
@@ -2127,11 +2133,12 @@ void QX11PixmapData::copy(const QPixmapData *data, const QRect &rect)
setSerialNumber(++qt_pixmap_serial);
- uninit = false;
+ flags &= ~Uninitialized;
xinfo = x11Data->xinfo;
d = x11Data->d;
w = rect.width();
h = rect.height();
+ is_null = (w <= 0 || h <= 0);
hd = (Qt::HANDLE)XCreatePixmap(X11->display,
RootWindow(X11->display, x11Data->xinfo.screen()),
w, h, d);
@@ -2177,6 +2184,16 @@ void QX11PixmapData::copy(const QPixmapData *data, const QRect &rect)
}
}
+bool QX11PixmapData::scroll(int dx, int dy, const QRect &rect)
+{
+ GC gc = XCreateGC(X11->display, hd, 0, 0);
+ XCopyArea(X11->display, hd, hd, gc,
+ rect.left(), rect.top(), rect.width(), rect.height(),
+ rect.left() + dx, rect.top() + dy);
+ XFreeGC(X11->display, gc);
+ return true;
+}
+
#if !defined(QT_NO_XRENDER)
void QX11PixmapData::convertToARGB32(bool preserveContents)
{
@@ -2184,7 +2201,7 @@ void QX11PixmapData::convertToARGB32(bool preserveContents)
return;
// Q_ASSERT(count == 1);
- if (read_only && share_mode == QPixmap::ExplicitlyShared)
+ if ((flags & Readonly) && share_mode == QPixmap::ExplicitlyShared)
return;
Pixmap pm = XCreatePixmap(X11->display, RootWindow(X11->display, xinfo.screen()),
@@ -2194,10 +2211,10 @@ void QX11PixmapData::convertToARGB32(bool preserveContents)
if (picture) {
if (preserveContents)
XRenderComposite(X11->display, PictOpSrc, picture, 0, p, 0, 0, 0, 0, 0, 0, w, h);
- if (!read_only)
+ if (!(flags & Readonly))
XRenderFreePicture(X11->display, picture);
}
- if (hd && !read_only)
+ if (hd && !(flags & Readonly))
XFreePixmap(X11->display, hd);
if (x11_mask) {
XFreePixmap(X11->display, x11_mask);
@@ -2235,11 +2252,11 @@ QPixmap QPixmap::fromX11Pixmap(Qt::HANDLE pixmap, QPixmap::ShareMode mode)
QX11PixmapData *data = new QX11PixmapData(depth == 1 ? QPixmapData::BitmapType : QPixmapData::PixmapType);
data->setSerialNumber(++qt_pixmap_serial);
- data->read_only = true;
+ data->flags = QX11PixmapData::Readonly;
data->share_mode = mode;
- data->uninit = false;
data->w = width;
data->h = height;
+ data->is_null = (width <= 0 || height <= 0);
data->d = depth;
data->hd = pixmap;
diff --git a/src/gui/image/qpixmap_x11_p.h b/src/gui/image/qpixmap_x11_p.h
index ee492f6..fc80186 100644
--- a/src/gui/image/qpixmap_x11_p.h
+++ b/src/gui/image/qpixmap_x11_p.h
@@ -74,6 +74,7 @@ public:
void resize(int width, int height);
void fromImage(const QImage &image, Qt::ImageConversionFlags flags);
void copy(const QPixmapData *data, const QRect &rect);
+ bool scroll(int dx, int dy, const QRect &rect);
void fill(const QColor &color);
QBitmap mask() const;
@@ -98,6 +99,7 @@ private:
friend class QX11PaintEngine;
friend class QX11WindowSurface;
friend class QRasterWindowSurface;
+ friend class QGLContextPrivate; // Needs to access xinfo, gl_surface & flags
void release();
@@ -107,16 +109,21 @@ private:
Qt::HANDLE hd;
- int w, h;
- short d;
- uint uninit : 1;
- uint read_only : 1;
+ enum Flag {
+ NoFlags = 0x0,
+ Uninitialized = 0x1,
+ Readonly = 0x2,
+ InvertedWhenBoundToTexture = 0x4,
+ GlSurfaceCreatedWithAlpha = 0x8
+ };
+ uint flags;
QX11Info xinfo;
Qt::HANDLE x11_mask;
Qt::HANDLE picture;
Qt::HANDLE mask_picture;
Qt::HANDLE hd2; // sorted in the default display depth
+ Qt::HANDLE gl_surface;
#ifndef QT_NO_XRENDER
void convertToARGB32(bool preserveContents = true);
#endif
diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp
index af300a8..6b34898 100644
--- a/src/gui/image/qpixmapcache.cpp
+++ b/src/gui/image/qpixmapcache.cpp
@@ -40,13 +40,9 @@
****************************************************************************/
#include "qpixmapcache.h"
-#include "qcache.h"
#include "qobject.h"
#include "qdebug.h"
-
-#include "qpaintengine.h"
-#include <private/qimage_p.h>
-#include <private/qpixmap_raster_p.h>
+#include "qpixmapcache_p.h"
QT_BEGIN_NAMESPACE
@@ -55,8 +51,7 @@ QT_BEGIN_NAMESPACE
\brief The QPixmapCache class provides an application-wide cache for pixmaps.
- \ingroup environment
- \ingroup multimedia
+ \ingroup painting
This class is a tool for optimized drawing with QPixmap. You can
use it to store temporary pixmaps that are expensive to generate
@@ -68,15 +63,24 @@ QT_BEGIN_NAMESPACE
access the global pixmap cache. It creates an internal QCache
object for caching the pixmaps.
- The cache associates a pixmap with a string (key). If two pixmaps
- are inserted into the cache using equal keys, then the last pixmap
- will hide the first pixmap. The QHash and QCache classes do
- exactly the same.
+ The cache associates a pixmap with a user-provided string as a key,
+ or with a QPixmapCache::Key that the cache generates.
+ Using QPixmapCache::Key for keys is faster than using strings. The string API is
+ very convenient for complex keys but the QPixmapCache::Key API will be very
+ efficient and convenient for a one-to-one object-to-pixmap mapping \mdash in
+ this case, you can store the keys as members of an object.
+
+ If two pixmaps are inserted into the cache using equal keys then the
+ last pixmap will replace the first pixmap in the cache. This follows the
+ behavior of the QHash and QCache classes.
The cache becomes full when the total size of all pixmaps in the
- cache exceeds cacheLimit(). The initial cache limit is 1024 KB (1
- MB); it is changed with setCacheLimit(). A pixmap takes roughly
- (\e{width} * \e{height} * \e{depth})/8 bytes of memory.
+ cache exceeds cacheLimit(). The initial cache limit is
+ 2048 KB (2 MB) on embedded platforms, 10240 KB (10 MB) on desktop
+ platforms; you can change this by calling setCacheLimit() with the
+ required value.
+ A pixmap takes roughly (\e{width} * \e{height} * \e{depth})/8 bytes of
+ memory.
The \e{Qt Quarterly} article
\l{http://qt.nokia.com/doc/qq/qq12-qpixmapcache.html}{Optimizing
@@ -86,58 +90,142 @@ QT_BEGIN_NAMESPACE
\sa QCache, QPixmap
*/
-#if defined(Q_WS_QWS) || defined(Q_OS_WINCE)
+#if defined(Q_OS_SYMBIAN)
+static int cache_limit = 1024; // 1048 KB cache limit for symbian
+#elif defined(Q_WS_QWS) || defined(Q_WS_WINCE)
static int cache_limit = 2048; // 2048 KB cache limit for embedded
#else
static int cache_limit = 10240; // 10 MB cache limit for desktop
#endif
-// XXX: hw: is this a general concept we need to abstract?
-class QDetachedPixmap : public QPixmap
+/*!
+ \class QPixmapCache::Key
+ \brief The QPixmapCache::Key class can be used for efficient access
+ to the QPixmapCache.
+ \since 4.6
+
+ Use QPixmapCache::insert() to receive an instance of Key generated
+ by the pixmap cache. You can store the key in your own objects for
+ a very efficient one-to-one object-to-pixmap mapping.
+*/
+
+/*!
+ Constructs an empty Key object.
+*/
+QPixmapCache::Key::Key() : d(0)
{
-public:
- QDetachedPixmap(const QPixmap &pix) : QPixmap(pix)
- {
- if (data && data->classId() == QPixmapData::RasterClass) {
- QRasterPixmapData *d = static_cast<QRasterPixmapData*>(data);
- if (!d->image.isNull() && d->image.d->paintEngine
- && !d->image.d->paintEngine->isActive())
- {
- delete d->image.d->paintEngine;
- d->image.d->paintEngine = 0;
- }
- }
+}
+
+/*!
+ \internal
+ Constructs a copy of \a other.
+*/
+QPixmapCache::Key::Key(const Key &other)
+{
+ if (other.d)
+ ++(other.d->ref);
+ d = other.d;
+}
+
+/*!
+ Destroys the key.
+*/
+QPixmapCache::Key::~Key()
+{
+ if (d && --(d->ref) == 0)
+ delete d;
+}
+
+/*!
+ \internal
+
+ Returns true if this key is the same as the given \a key; otherwise returns
+ false.
+*/
+bool QPixmapCache::Key::operator ==(const Key &key) const
+{
+ return (d == key.d);
+}
+
+/*!
+ \fn bool QPixmapCache::Key::operator !=(const Key &key) const
+ \internal
+*/
+
+/*!
+ \internal
+*/
+QPixmapCache::Key &QPixmapCache::Key::operator =(const Key &other)
+{
+ if (d != other.d) {
+ if (other.d)
+ ++(other.d->ref);
+ if (d && --(d->ref) == 0)
+ delete d;
+ d = other.d;
}
-};
+ return *this;
+}
-class QPMCache : public QObject, public QCache<qint64, QDetachedPixmap>
+class QPMCache : public QObject, public QCache<QPixmapCache::Key, QDetachedPixmap>
{
Q_OBJECT
public:
- QPMCache()
- : QObject(0),
- QCache<qint64, QDetachedPixmap>(cache_limit * 1024),
- theid(0), ps(0), t(false) { }
- ~QPMCache() { }
+ QPMCache();
+ ~QPMCache();
void timerEvent(QTimerEvent *);
bool insert(const QString& key, const QPixmap &pixmap, int cost);
+ QPixmapCache::Key insert(const QPixmap &pixmap, int cost);
+ bool replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int cost);
bool remove(const QString &key);
+ bool remove(const QPixmapCache::Key &key);
+
+ void resizeKeyArray(int size);
+ QPixmapCache::Key createKey();
+ void releaseKey(const QPixmapCache::Key &key);
+ void clear();
QPixmap *object(const QString &key) const;
+ QPixmap *object(const QPixmapCache::Key &key) const;
+
+ static inline QPixmapCache::KeyData *get(const QPixmapCache::Key &key)
+ {return key.d;}
+
+ static QPixmapCache::KeyData* getKeyData(QPixmapCache::Key *key);
private:
- QHash<QString, qint64> cacheKeys;
+ int *keyArray;
int theid;
int ps;
+ int keyArraySize;
+ int freeKey;
+ QHash<QString, QPixmapCache::Key> cacheKeys;
bool t;
};
+
QT_BEGIN_INCLUDE_NAMESPACE
#include "qpixmapcache.moc"
QT_END_INCLUDE_NAMESPACE
+uint qHash(const QPixmapCache::Key &k)
+{
+ return qHash(QPMCache::get(k)->key);
+}
+
+QPMCache::QPMCache()
+ : QObject(0),
+ QCache<QPixmapCache::Key, QDetachedPixmap>(cache_limit * 1024),
+ keyArray(0), theid(0), ps(0), keyArraySize(0), freeKey(0), t(false)
+{
+}
+QPMCache::~QPMCache()
+{
+ free(keyArray);
+}
+
/*
- This is supposed to cut the cache size down by about 80-90% in a
+ This is supposed to cut the cache size down by about 25% in a
minute once the application becomes idle, to let any inserted pixmap
remain in the cache for some time before it becomes a candidate for
cleaning-up, and to not cut down the size of the cache while the
@@ -146,23 +234,28 @@ QT_END_INCLUDE_NAMESPACE
When the last pixmap has been deleted from the cache, kill the
timer so Qt won't keep the CPU from going into sleep mode.
*/
-
void QPMCache::timerEvent(QTimerEvent *)
{
int mc = maxCost();
bool nt = totalCost() == ps;
+ QList<QPixmapCache::Key> keys = QCache<QPixmapCache::Key, QDetachedPixmap>::keys();
setMaxCost(nt ? totalCost() * 3 / 4 : totalCost() -1);
setMaxCost(mc);
ps = totalCost();
- QHash<QString, qint64>::iterator it = cacheKeys.begin();
+ QHash<QString, QPixmapCache::Key>::iterator it = cacheKeys.begin();
while (it != cacheKeys.end()) {
if (!contains(it.value())) {
+ releaseKey(it.value());
it = cacheKeys.erase(it);
} else {
++it;
}
}
+ for (int i = 0; i < keys.size(); ++i) {
+ if (!contains(keys.at(i)))
+ releaseKey(keys.at(i));
+ }
if (!size()) {
killTimer(theid);
@@ -176,44 +269,163 @@ void QPMCache::timerEvent(QTimerEvent *)
QPixmap *QPMCache::object(const QString &key) const
{
- return QCache<qint64, QDetachedPixmap>::object(cacheKeys.value(key, -1));
+ QPixmapCache::Key cacheKey = cacheKeys.value(key);
+ if (!cacheKey.d || !cacheKey.d->isValid) {
+ const_cast<QPMCache *>(this)->cacheKeys.remove(key);
+ return 0;
+ }
+ QPixmap *ptr = QCache<QPixmapCache::Key, QDetachedPixmap>::object(cacheKey);
+ //We didn't find the pixmap in the cache, the key is not valid anymore
+ if (!ptr) {
+ const_cast<QPMCache *>(this)->cacheKeys.remove(key);
+ const_cast<QPMCache *>(this)->releaseKey(cacheKey);
+ }
+ return ptr;
}
+QPixmap *QPMCache::object(const QPixmapCache::Key &key) const
+{
+ Q_ASSERT(key.d->isValid);
+ QPixmap *ptr = QCache<QPixmapCache::Key, QDetachedPixmap>::object(key);
+ //We didn't find the pixmap in the cache, the key is not valid anymore
+ if (!ptr)
+ const_cast<QPMCache *>(this)->releaseKey(key);
+ return ptr;
+}
bool QPMCache::insert(const QString& key, const QPixmap &pixmap, int cost)
{
- qint64 cacheKey = pixmap.cacheKey();
- if (QCache<qint64, QDetachedPixmap>::object(cacheKey)) {
+ QPixmapCache::Key cacheKey;
+ QPixmapCache::Key oldCacheKey = cacheKeys.value(key);
+ //If for the same key we add already a pixmap we should delete it
+ if (oldCacheKey.d) {
+ QCache<QPixmapCache::Key, QDetachedPixmap>::remove(oldCacheKey);
+ cacheKey = oldCacheKey;
+ } else {
+ cacheKey = createKey();
+ }
+
+ bool success = QCache<QPixmapCache::Key, QDetachedPixmap>::insert(cacheKey, new QDetachedPixmap(pixmap), cost);
+ if (success) {
cacheKeys.insert(key, cacheKey);
- return true;
+ if (!theid) {
+ theid = startTimer(30000);
+ t = false;
+ }
+ } else {
+ //Insertion failed we released the new allocated key
+ releaseKey(cacheKey);
}
- qint64 oldCacheKey = cacheKeys.value(key, -1);
- //If for the same key we add already a pixmap we should delete it
- if (oldCacheKey != -1)
- QCache<qint64, QDetachedPixmap>::remove(oldCacheKey);
+ return success;
+}
- bool success = QCache<qint64, QDetachedPixmap>::insert(cacheKey, new QDetachedPixmap(pixmap), cost);
+QPixmapCache::Key QPMCache::insert(const QPixmap &pixmap, int cost)
+{
+ QPixmapCache::Key cacheKey = createKey();
+ bool success = QCache<QPixmapCache::Key, QDetachedPixmap>::insert(cacheKey, new QDetachedPixmap(pixmap), cost);
if (success) {
- cacheKeys.insert(key, cacheKey);
if (!theid) {
theid = startTimer(30000);
t = false;
}
+ } else {
+ //Insertion failed we released the key and return an invalid one
+ releaseKey(cacheKey);
+ }
+ return cacheKey;
+}
+
+bool QPMCache::replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int cost)
+{
+ Q_ASSERT(key.d->isValid);
+ //If for the same key we add already a pixmap we should delete it
+ QCache<QPixmapCache::Key, QDetachedPixmap>::remove(key);
+
+ bool success = QCache<QPixmapCache::Key, QDetachedPixmap>::insert(key, new QDetachedPixmap(pixmap), cost);
+ if (success && !theid) {
+ theid = startTimer(30000);
+ t = false;
}
return success;
}
bool QPMCache::remove(const QString &key)
{
- qint64 cacheKey = cacheKeys.value(key, -1);
+ QPixmapCache::Key cacheKey = cacheKeys.value(key);
+ //The key was not in the cache
+ if (!cacheKey.d)
+ return false;
cacheKeys.remove(key);
- return QCache<qint64, QDetachedPixmap>::remove(cacheKey);
+ releaseKey(cacheKey);
+ return QCache<QPixmapCache::Key, QDetachedPixmap>::remove(cacheKey);
+}
+
+bool QPMCache::remove(const QPixmapCache::Key &key)
+{
+ bool result = QCache<QPixmapCache::Key, QDetachedPixmap>::remove(key);
+ //We release the key after we removed it from the cache
+ releaseKey(key);
+ return result;
+}
+
+void QPMCache::resizeKeyArray(int size)
+{
+ if (size <= keyArraySize || size == 0)
+ return;
+ keyArray = q_check_ptr(reinterpret_cast<int *>(realloc(keyArray,
+ size * sizeof(int))));
+ for (int i = keyArraySize; i != size; ++i)
+ keyArray[i] = i + 1;
+ keyArraySize = size;
+}
+
+QPixmapCache::Key QPMCache::createKey()
+{
+ if (freeKey == keyArraySize)
+ resizeKeyArray(keyArraySize ? keyArraySize << 1 : 2);
+ int id = freeKey;
+ freeKey = keyArray[id];
+ QPixmapCache::Key key;
+ QPixmapCache::KeyData *d = QPMCache::getKeyData(&key);
+ d->key = ++id;
+ return key;
+}
+
+void QPMCache::releaseKey(const QPixmapCache::Key &key)
+{
+ if (key.d->key > keyArraySize || key.d->key <= 0)
+ return;
+ key.d->key--;
+ keyArray[key.d->key] = freeKey;
+ freeKey = key.d->key;
+ key.d->isValid = false;
+ key.d->key = 0;
+}
+
+void QPMCache::clear()
+{
+ free(keyArray);
+ keyArray = 0;
+ freeKey = 0;
+ keyArraySize = 0;
+ //Mark all keys as invalid
+ QList<QPixmapCache::Key> keys = QCache<QPixmapCache::Key, QDetachedPixmap>::keys();
+ for (int i = 0; i < keys.size(); ++i)
+ keys.at(i).d->isValid = false;
+ QCache<QPixmapCache::Key, QDetachedPixmap>::clear();
+}
+
+QPixmapCache::KeyData* QPMCache::getKeyData(QPixmapCache::Key *key)
+{
+ if (!key->d)
+ key->d = new QPixmapCache::KeyData;
+ return key->d;
}
Q_GLOBAL_STATIC(QPMCache, pm_cache)
/*!
- \obsolete
+ \obsolete
\overload
Returns the pixmap associated with the \a key in the cache, or
@@ -222,7 +434,7 @@ Q_GLOBAL_STATIC(QPMCache, pm_cache)
\warning If valid, you should copy the pixmap immediately (this is
fast). Subsequent insertions into the cache could cause the
pointer to become invalid. For this reason, we recommend you use
- find(const QString&, QPixmap&) instead.
+ bool find(const QString&, QPixmap*) instead.
Example:
\snippet doc/src/snippets/code/src_gui_image_qpixmapcache.cpp 0
@@ -235,25 +447,57 @@ QPixmap *QPixmapCache::find(const QString &key)
/*!
- Looks for a cached pixmap associated with the \a key in the cache.
- If the pixmap is found, the function sets \a pm to that pixmap and
- returns true; otherwise it leaves \a pm alone and returns false.
+ \obsolete
+
+ Use bool find(const QString&, QPixmap*) instead.
+*/
+
+bool QPixmapCache::find(const QString &key, QPixmap& pixmap)
+{
+ return find(key, &pixmap);
+}
+
+/*!
+ Looks for a cached pixmap associated with the given \a key in the cache.
+ If the pixmap is found, the function sets \a pixmap to that pixmap and
+ returns true; otherwise it leaves \a pixmap alone and returns false.
+
+ \since 4.6
Example:
\snippet doc/src/snippets/code/src_gui_image_qpixmapcache.cpp 1
*/
-bool QPixmapCache::find(const QString &key, QPixmap& pm)
+bool QPixmapCache::find(const QString &key, QPixmap* pixmap)
{
QPixmap *ptr = pm_cache()->object(key);
- if (ptr)
- pm = *ptr;
+ if (ptr && pixmap)
+ *pixmap = *ptr;
return ptr != 0;
}
+/*!
+ Looks for a cached pixmap associated with the given \a key in the cache.
+ If the pixmap is found, the function sets \a pixmap to that pixmap and
+ returns true; otherwise it leaves \a pixmap alone and returns false. If
+ the pixmap is not found, it means that the \a key is no longer valid,
+ so it will be released for the next insertion.
+
+ \since 4.6
+*/
+bool QPixmapCache::find(const Key &key, QPixmap* pixmap)
+{
+ //The key is not valid anymore, a flush happened before probably
+ if (!key.d || !key.d->isValid)
+ return false;
+ QPixmap *ptr = pm_cache()->object(key);
+ if (ptr && pixmap)
+ *pixmap = *ptr;
+ return ptr != 0;
+}
/*!
- Inserts a copy of the pixmap \a pm associated with the \a key into
+ Inserts a copy of the pixmap \a pixmap associated with the \a key into
the cache.
All pixmaps inserted by the Qt library have a key starting with
@@ -272,16 +516,53 @@ bool QPixmapCache::find(const QString &key, QPixmap& pm)
\sa setCacheLimit()
*/
-bool QPixmapCache::insert(const QString &key, const QPixmap &pm)
+bool QPixmapCache::insert(const QString &key, const QPixmap &pixmap)
+{
+ return pm_cache()->insert(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
+}
+
+/*!
+ Inserts a copy of the given \a pixmap into the cache and returns a key
+ that can be used to retrieve it.
+
+ When a pixmap is inserted and the cache is about to exceed its
+ limit, it removes pixmaps until there is enough room for the
+ pixmap to be inserted.
+
+ The oldest pixmaps (least recently accessed in the cache) are
+ deleted when more space is needed.
+
+ \sa setCacheLimit(), replace()
+
+ \since 4.6
+*/
+QPixmapCache::Key QPixmapCache::insert(const QPixmap &pixmap)
+{
+ return pm_cache()->insert(pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
+}
+
+/*!
+ Replaces the pixmap associated with the given \a key with the \a pixmap
+ specified. Returns true if the \a pixmap has been correctly inserted into
+ the cache; otherwise returns false.
+
+ \sa setCacheLimit(), insert()
+
+ \since 4.6
+*/
+bool QPixmapCache::replace(const Key &key, const QPixmap &pixmap)
{
- return pm_cache()->insert(key, pm, pm.width() * pm.height() * pm.depth() / 8);
+ //The key is not valid anymore, a flush happened before probably
+ if (!key.d || !key.d->isValid)
+ return false;
+ return pm_cache()->replace(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
}
/*!
Returns the cache limit (in kilobytes).
- The default cache limit is 2048 KB for Embedded, 10240 KB for
- Desktops.
+ The default cache limit is 2048 KB on embedded platforms, 10240 KB on
+ desktop platforms.
\sa setCacheLimit()
*/
@@ -294,8 +575,8 @@ int QPixmapCache::cacheLimit()
/*!
Sets the cache limit to \a n kilobytes.
- The default setting is 2048 KB for Embedded, 10240 KB for
- Desktops.
+ The default setting is 2048 KB on embedded platforms, 10240 KB on
+ desktop platforms.
\sa cacheLimit()
*/
@@ -314,6 +595,19 @@ void QPixmapCache::remove(const QString &key)
pm_cache()->remove(key);
}
+/*!
+ Removes the pixmap associated with \a key from the cache and releases
+ the key for a future insertion.
+
+ \since 4.6
+*/
+void QPixmapCache::remove(const Key &key)
+{
+ //The key is not valid anymore, a flush happened before probably
+ if (!key.d || !key.d->isValid)
+ return;
+ pm_cache()->remove(key);
+}
/*!
Removes all pixmaps from the cache.
@@ -321,7 +615,12 @@ void QPixmapCache::remove(const QString &key)
void QPixmapCache::clear()
{
- pm_cache()->clear();
+ QT_TRY {
+ pm_cache()->clear();
+ } QT_CATCH(const std::bad_alloc &) {
+ // if we ran out of memory during pm_cache(), it's no leak,
+ // so just ignore it.
+ }
}
QT_END_NAMESPACE
diff --git a/src/gui/image/qpixmapcache.h b/src/gui/image/qpixmapcache.h
index 0a8524f..a0b3964 100644
--- a/src/gui/image/qpixmapcache.h
+++ b/src/gui/image/qpixmapcache.h
@@ -53,12 +53,35 @@ QT_MODULE(Gui)
class Q_GUI_EXPORT QPixmapCache
{
public:
+ class KeyData;
+ class Q_GUI_EXPORT Key
+ {
+ public:
+ Key();
+ Key(const Key &other);
+ ~Key();
+ bool operator ==(const Key &key) const;
+ inline bool operator !=(const Key &key) const
+ { return !operator==(key); }
+ Key &operator =(const Key &other);
+
+ private:
+ KeyData *d;
+ friend class QPMCache;
+ friend class QPixmapCache;
+ };
+
static int cacheLimit();
static void setCacheLimit(int);
static QPixmap *find(const QString &key);
- static bool find(const QString &key, QPixmap&);
- static bool insert(const QString &key, const QPixmap&);
+ static bool find(const QString &key, QPixmap &pixmap);
+ static bool find(const QString &key, QPixmap *pixmap);
+ static bool find(const Key &key, QPixmap *pixmap);
+ static bool insert(const QString &key, const QPixmap &pixmap);
+ static Key insert(const QPixmap &pixmap);
+ static bool replace(const Key &key, const QPixmap &pixmap);
static void remove(const QString &key);
+ static void remove(const Key &key);
static void clear();
};
diff --git a/src/gui/image/qpixmapcache_p.h b/src/gui/image/qpixmapcache_p.h
new file mode 100644
index 0000000..511c852
--- /dev/null
+++ b/src/gui/image/qpixmapcache_p.h
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPIXMAPCACHE_P_H
+#define QPIXMAPCACHE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. This header
+// file may change from version to version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qpixmapcache.h"
+#include "qpaintengine.h"
+#include <private/qimage_p.h>
+#include <private/qpixmap_raster_p.h>
+#include "qcache.h"
+
+QT_BEGIN_NAMESPACE
+
+uint qHash(const QPixmapCache::Key &k);
+
+class QPixmapCache::KeyData
+{
+public:
+ KeyData() : isValid(true), key(0), ref(1) {}
+ KeyData(const KeyData &other)
+ : isValid(other.isValid), key(other.key), ref(1) {}
+ ~KeyData() {}
+
+ bool isValid;
+ int key;
+ int ref;
+};
+
+// XXX: hw: is this a general concept we need to abstract?
+class QDetachedPixmap : public QPixmap
+{
+public:
+ QDetachedPixmap(const QPixmap &pix) : QPixmap(pix)
+ {
+ if (data && data->classId() == QPixmapData::RasterClass) {
+ QRasterPixmapData *d = static_cast<QRasterPixmapData*>(data.data());
+ if (!d->image.isNull() && d->image.d->paintEngine
+ && !d->image.d->paintEngine->isActive())
+ {
+ delete d->image.d->paintEngine;
+ d->image.d->paintEngine = 0;
+ }
+ }
+ }
+};
+
+QT_END_NAMESPACE
+
+#endif // QPIXMAPCACHE_P_H
diff --git a/src/gui/image/qpixmapdata.cpp b/src/gui/image/qpixmapdata.cpp
index 6a9a3d0..a52790c 100644
--- a/src/gui/image/qpixmapdata.cpp
+++ b/src/gui/image/qpixmapdata.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include "qpixmapdata_p.h"
+#include <QtCore/qbuffer.h>
#include <QtGui/qbitmap.h>
#include <QtGui/qimagereader.h>
@@ -49,23 +50,61 @@ const uchar qt_pixmap_bit_mask[] = { 0x01, 0x02, 0x04, 0x08,
0x10, 0x20, 0x40, 0x80 };
QPixmapData::QPixmapData(PixelType pixelType, int objectId)
- : ref(0), detach_no(0), type(pixelType), id(objectId), ser_no(0), is_cached(false)
+ : w(0),
+ h(0),
+ d(0),
+ is_null(true),
+ ref(0),
+ detach_no(0),
+ type(pixelType),
+ id(objectId),
+ ser_no(0),
+ is_cached(false)
{
-
}
QPixmapData::~QPixmapData()
{
}
-void QPixmapData::fromFile(const QString &fileName, const char *format,
+static QImage makeBitmapCompliantIfNeeded(QPixmapData *d, const QImage &image, Qt::ImageConversionFlags flags)
+{
+ if (d->pixelType() == QPixmapData::BitmapType) {
+ QImage img = image.convertToFormat(QImage::Format_MonoLSB, flags);
+
+ // make sure image.color(0) == Qt::color0 (white)
+ // and image.color(1) == Qt::color1 (black)
+ const QRgb c0 = QColor(Qt::black).rgb();
+ const QRgb c1 = QColor(Qt::white).rgb();
+ if (img.color(0) == c0 && img.color(1) == c1) {
+ img.invertPixels();
+ img.setColor(0, c1);
+ img.setColor(1, c0);
+ }
+ return img;
+ }
+
+ return image;
+}
+
+bool QPixmapData::fromFile(const QString &fileName, const char *format,
Qt::ImageConversionFlags flags)
{
- const QImage image = QImageReader(fileName, format).read();
+ QImage image = QImageReader(fileName, format).read();
if (image.isNull())
- return;
+ return false;
+ fromImage(makeBitmapCompliantIfNeeded(this, image, flags), flags);
+ return !isNull();
+}
- fromImage(image, flags);
+bool QPixmapData::fromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags)
+{
+ QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buf), len);
+ QBuffer b(&a);
+ b.open(QIODevice::ReadOnly);
+ QImage image = QImageReader(&b, format).read();
+ fromImage(makeBitmapCompliantIfNeeded(this, image, flags), flags);
+ return !isNull();
}
void QPixmapData::copy(const QPixmapData *data, const QRect &rect)
@@ -73,6 +112,14 @@ void QPixmapData::copy(const QPixmapData *data, const QRect &rect)
fromImage(data->toImage().copy(rect), Qt::AutoColor);
}
+bool QPixmapData::scroll(int dx, int dy, const QRect &rect)
+{
+ Q_UNUSED(dx);
+ Q_UNUSED(dy);
+ Q_UNUSED(rect);
+ return false;
+}
+
void QPixmapData::setMask(const QBitmap &mask)
{
if (mask.size().isEmpty()) {
diff --git a/src/gui/image/qpixmapdata_p.h b/src/gui/image/qpixmapdata_p.h
index 3b5cf16..7d462a4 100644
--- a/src/gui/image/qpixmapdata_p.h
+++ b/src/gui/image/qpixmapdata_p.h
@@ -75,9 +75,14 @@ public:
virtual void resize(int width, int height) = 0;
virtual void fromImage(const QImage &image,
Qt::ImageConversionFlags flags) = 0;
- virtual void fromFile(const QString &filename, const char *format,
+
+ virtual bool fromFile(const QString &filename, const char *format,
+ Qt::ImageConversionFlags flags);
+ virtual bool fromData(const uchar *buffer, uint len, const char *format,
Qt::ImageConversionFlags flags);
+
virtual void copy(const QPixmapData *data, const QRect &rect);
+ virtual bool scroll(int dx, int dy, const QRect &rect);
virtual int metric(QPaintDevice::PaintDeviceMetric metric) const = 0;
virtual void fill(const QColor &color) = 0;
@@ -98,18 +103,25 @@ public:
virtual QImage* buffer();
- int width() const { return metric(QPaintDevice::PdmWidth); }
- int height() const { return metric(QPaintDevice::PdmHeight); }
- int numColors() const { return metric(QPaintDevice::PdmNumColors); }
- int depth() const { return metric(QPaintDevice::PdmDepth); }
+ inline int width() const { return w; }
+ inline int height() const { return h; }
+ inline int numColors() const { return metric(QPaintDevice::PdmNumColors); }
+ inline int depth() const { return d; }
+ inline bool isNull() const { return is_null; }
protected:
void setSerialNumber(int serNo);
+ int w;
+ int h;
+ int d;
+ bool is_null;
private:
friend class QPixmap;
friend class QGLContextPrivate;
friend class QX11PixmapData;
+ friend class QGLTextureCache; //Needs to check the reference count
+ friend class QExplicitlySharedDataPointer<QPixmapData>;
QAtomicInt ref;
int detach_no;
@@ -121,7 +133,7 @@ private:
};
#ifdef Q_WS_WIN
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
QPixmap convertHIconToPixmap( const HICON icon);
#else
QPixmap convertHIconToPixmap( const HICON icon, bool large = false);
diff --git a/src/gui/image/qpixmapdatafactory.cpp b/src/gui/image/qpixmapdatafactory.cpp
index 9cad585..53c93ad 100644
--- a/src/gui/image/qpixmapdatafactory.cpp
+++ b/src/gui/image/qpixmapdatafactory.cpp
@@ -47,7 +47,7 @@
#ifdef Q_WS_X11
# include <private/qpixmap_x11_p.h>
#endif
-#ifdef Q_WS_WIN
+#if defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN)
# include <private/qpixmap_raster_p.h>
#endif
#ifdef Q_WS_MAC
@@ -75,7 +75,7 @@ QPixmapData* QSimplePixmapDataFactory::create(QPixmapData::PixelType type)
#if defined(Q_WS_X11)
return new QX11PixmapData(type);
-#elif defined(Q_WS_WIN)
+#elif defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN)
return new QRasterPixmapData(type);
#elif defined(Q_WS_MAC)
return new QMacPixmapData(type);
@@ -84,7 +84,7 @@ QPixmapData* QSimplePixmapDataFactory::create(QPixmapData::PixelType type)
#endif
}
-Q_GLOBAL_STATIC(QSimplePixmapDataFactory, factory);
+Q_GLOBAL_STATIC(QSimplePixmapDataFactory, factory)
#endif // !defined(Q_WS_QWS)
diff --git a/src/gui/image/qpixmapdatafactory_p.h b/src/gui/image/qpixmapdatafactory_p.h
index 134ef2e..2a99e0a 100644
--- a/src/gui/image/qpixmapdatafactory_p.h
+++ b/src/gui/image/qpixmapdatafactory_p.h
@@ -65,7 +65,7 @@ QT_MODULE(Gui)
class QPixmapData;
-class Q_GUI_EXPORT QPixmapDataFactory
+class QPixmapDataFactory
{
public:
static QPixmapDataFactory* instance(int screen = 0);
diff --git a/src/gui/image/qpixmapfilter.cpp b/src/gui/image/qpixmapfilter.cpp
index 3358091..b2d7f0c 100644
--- a/src/gui/image/qpixmapfilter.cpp
+++ b/src/gui/image/qpixmapfilter.cpp
@@ -65,7 +65,7 @@ public:
/*!
\class QPixmapFilter
\since 4.5
- \ingroup multimedia
+ \ingroup painting
\brief The QPixmapFilter class provides the basic functionality for
pixmap filter classes. Pixmap filter can be for example colorize or blur.
@@ -93,6 +93,9 @@ public:
\value DropShadowFilter A filter that is used to add a drop shadow to an
image. See QPixmapDropShadowFilter for more
information.
+ \value BlurFilter A filter that is used to blur an image using
+ a simple blur radius. See QPixmapBlurFilter
+ for more information.
\value UserFilter The first filter type that can be used for
application-specific purposes.
@@ -172,7 +175,7 @@ QRectF QPixmapFilter::boundingRectFor(const QRectF &rect) const
/*!
\class QPixmapConvolutionFilter
\since 4.5
- \ingroup multimedia
+ \ingroup painting
\brief The QPixmapConvolutionFilter class provides convolution
filtering for pixmaps.
@@ -293,8 +296,6 @@ int QPixmapConvolutionFilter::columns() const
/*!
- \reimp
-
\internal
*/
QRectF QPixmapConvolutionFilter::boundingRectFor(const QRectF &rect) const
@@ -401,11 +402,10 @@ static void convolute(
}
yk++;
}
+ delete[] fixedKernel;
}
/*!
- \reimp
-
\internal
*/
void QPixmapConvolutionFilter::draw(QPainter *painter, const QPointF &p, const QPixmap &src, const QRectF& srcRect) const
@@ -478,6 +478,223 @@ void QPixmapConvolutionFilter::draw(QPainter *painter, const QPointF &p, const Q
}
}
+/*!
+ \class QPixmapBlurFilter
+ \since 4.6
+ \ingroup multimedia
+
+ \brief The QPixmapBlurFilter class provides blur filtering
+ for pixmaps.
+
+ QPixmapBlurFilter implements a blur pixmap filter,
+ which is applied when \l{QPixmapFilter::}{draw()} is called.
+
+ The filter lets you specialize the radius of the blur as well
+ as the quality.
+
+ By default, the blur effect is produced by applying an exponential
+ filter generated from the specified blurRadius(). Paint engines
+ may override this with a custom blur that is faster on the
+ underlying hardware.
+
+ \sa {Pixmap Filters Example}, QPixmapConvolutionFilter, QPixmapDropShadowFilter
+
+ \internal
+*/
+
+class QPixmapBlurFilterPrivate : public QPixmapFilterPrivate
+{
+public:
+ QPixmapBlurFilterPrivate() : radius(5), quality(Qt::FastTransformation) {}
+
+ int radius;
+ Qt::TransformationMode quality;
+};
+
+
+/*!
+ Constructs a pixmap blur filter.
+
+ \internal
+*/
+QPixmapBlurFilter::QPixmapBlurFilter(QObject *parent)
+ : QPixmapFilter(*new QPixmapBlurFilterPrivate, BlurFilter, parent)
+{
+}
+
+/*!
+ Destructor of pixmap blur filter.
+
+ \internal
+*/
+QPixmapBlurFilter::~QPixmapBlurFilter()
+{
+}
+
+/*!
+ Sets the radius of the blur filter. Higher radius produces increased blurriness.
+
+ \internal
+*/
+void QPixmapBlurFilter::setRadius(int radius)
+{
+ Q_D(QPixmapBlurFilter);
+ d->radius = radius;
+}
+
+/*!
+ Gets the radius of the blur filter.
+
+ \internal
+*/
+int QPixmapBlurFilter::radius() const
+{
+ Q_D(const QPixmapBlurFilter);
+ return d->radius;
+}
+
+/*!
+ Setting the quality to FastTransformation causes the implementation
+ to trade off visual quality to blur the image faster. Setting the
+ quality to SmoothTransformation causes the implementation to improve
+ visual quality at the expense of speed. The implementation is free
+ to ignore this value if it only has a single blur algorithm.
+
+ \internal
+*/
+void QPixmapBlurFilter::setQuality(Qt::TransformationMode quality)
+{
+ Q_D(QPixmapBlurFilter);
+ d->quality = quality;
+}
+
+/*!
+ Gets the quality of the blur filter.
+
+ \internal
+*/
+Qt::TransformationMode QPixmapBlurFilter::quality() const
+{
+ Q_D(const QPixmapBlurFilter);
+ return d->quality;
+}
+
+/*!
+ \internal
+*/
+QRectF QPixmapBlurFilter::boundingRectFor(const QRectF &rect) const
+{
+ Q_D(const QPixmapBlurFilter);
+ const qreal delta = d->radius * 2;
+ return rect.adjusted(-delta, -delta, delta, delta);
+}
+
+// Blur the image according to the blur radius
+// Based on exponential blur algorithm by Jani Huhtanen
+// (maximum radius is set to 16)
+static QImage blurred(const QImage& image, const QRect& rect, int radius)
+{
+ int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
+ int alpha = (radius < 1) ? 16 : (radius > 17) ? 1 : tab[radius-1];
+
+ QImage result = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
+ int r1 = rect.top();
+ int r2 = rect.bottom();
+ int c1 = rect.left();
+ int c2 = rect.right();
+
+ int bpl = result.bytesPerLine();
+ int rgba[4];
+ unsigned char* p;
+
+ for (int col = c1; col <= c2; col++) {
+ p = result.scanLine(r1) + col * 4;
+ for (int i = 0; i < 4; i++)
+ rgba[i] = p[i] << 4;
+
+ p += bpl;
+ for (int j = r1; j < r2; j++, p += bpl)
+ for (int i = 0; i < 4; i++)
+ p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
+ }
+
+ for (int row = r1; row <= r2; row++) {
+ p = result.scanLine(row) + c1 * 4;
+ for (int i = 0; i < 4; i++)
+ rgba[i] = p[i] << 4;
+
+ p += 4;
+ for (int j = c1; j < c2; j++, p += 4)
+ for (int i = 0; i < 4; i++)
+ p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
+ }
+
+ for (int col = c1; col <= c2; col++) {
+ p = result.scanLine(r2) + col * 4;
+ for (int i = 0; i < 4; i++)
+ rgba[i] = p[i] << 4;
+
+ p -= bpl;
+ for (int j = r1; j < r2; j++, p -= bpl)
+ for (int i = 0; i < 4; i++)
+ p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
+ }
+
+ for (int row = r1; row <= r2; row++) {
+ p = result.scanLine(row) + c2 * 4;
+ for (int i = 0; i < 4; i++)
+ rgba[i] = p[i] << 4;
+
+ p -= 4;
+ for (int j = c1; j < c2; j++, p -= 4)
+ for (int i = 0; i < 4; i++)
+ p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
+ }
+
+ return result;
+}
+
+/*!
+ \internal
+*/
+void QPixmapBlurFilter::draw(QPainter *painter, const QPointF &p, const QPixmap &src, const QRectF &srcRect) const
+{
+ Q_D(const QPixmapBlurFilter);
+ if (!painter->isActive())
+ return;
+
+ if (d->radius == 0) {
+ painter->drawPixmap(srcRect.translated(p), src, srcRect);
+ return;
+ }
+
+ QPixmapFilter *filter = painter->paintEngine() && painter->paintEngine()->isExtended() ?
+ static_cast<QPaintEngineEx *>(painter->paintEngine())->createPixmapFilter(type()) : 0;
+ QPixmapBlurFilter *blurFilter = static_cast<QPixmapBlurFilter*>(filter);
+ if (blurFilter) {
+ blurFilter->setRadius(d->radius);
+ blurFilter->setQuality(d->quality);
+ blurFilter->draw(painter, p, src, srcRect);
+ delete blurFilter;
+ return;
+ }
+
+ QImage srcImage;
+ QImage destImage;
+
+ if (srcRect.isNull()) {
+ srcImage = src.toImage();
+ destImage = blurred(srcImage, srcImage.rect(), d->radius);
+ } else {
+ QRect rect = srcRect.toAlignedRect().intersected(src.rect());
+
+ srcImage = src.copy(rect).toImage();
+ destImage = blurred(srcImage, srcImage.rect(), d->radius);
+ }
+
+ painter->drawImage(p, destImage);
+}
+
// grayscales the image to dest (could be same). If rect isn't defined
// destination image size is used to determine the dimension of grayscaling
// process.
@@ -520,7 +737,7 @@ static void grayscale(const QImage &image, QImage &dest, const QRect& rect = QRe
/*!
\class QPixmapColorizeFilter
\since 4.5
- \ingroup multimedia
+ \ingroup painting
\brief The QPixmapColorizeFilter class provides colorizing
filtering for pixmaps.
@@ -580,8 +797,6 @@ void QPixmapColorizeFilter::setColor(const QColor &color)
}
/*!
- \reimp
-
\internal
*/
void QPixmapColorizeFilter::draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect) const
@@ -631,22 +846,17 @@ class QPixmapDropShadowFilterPrivate : public QPixmapFilterPrivate
{
public:
QPixmapDropShadowFilterPrivate()
- : offset(8, 8),
- radius(1),
- color(63, 63, 63, 255) {
- }
+ : offset(8, 8), color(63, 63, 63, 180), blurFilter(new QPixmapBlurFilter) {}
QPointF offset;
- qreal radius;
QColor color;
-
- QPixmapConvolutionFilter *convolution;
+ QPixmapBlurFilter *blurFilter;
};
/*!
\class QPixmapDropShadowFilter
\since 4.5
- \ingroup multimedia
+ \ingroup painting
\brief The QPixmapDropShadowFilter class is a convenience class
for drawing pixmaps with drop shadows.
@@ -685,9 +895,7 @@ QPixmapDropShadowFilter::QPixmapDropShadowFilter(QObject *parent)
: QPixmapFilter(*new QPixmapDropShadowFilterPrivate, DropShadowFilter, parent)
{
Q_D(QPixmapDropShadowFilter);
- d->convolution = new QPixmapConvolutionFilter;
-
- setBlurRadius(1);
+ d->blurFilter->setRadius(1);
}
/*!
@@ -698,7 +906,7 @@ QPixmapDropShadowFilter::QPixmapDropShadowFilter(QObject *parent)
QPixmapDropShadowFilter::~QPixmapDropShadowFilter()
{
Q_D(QPixmapDropShadowFilter);
- delete d->convolution;
+ delete d->blurFilter;
}
/*!
@@ -710,10 +918,10 @@ QPixmapDropShadowFilter::~QPixmapDropShadowFilter()
\internal
*/
-qreal QPixmapDropShadowFilter::blurRadius() const
+int QPixmapDropShadowFilter::blurRadius() const
{
Q_D(const QPixmapDropShadowFilter);
- return d->radius;
+ return d->blurFilter->radius();
}
/*!
@@ -725,18 +933,10 @@ qreal QPixmapDropShadowFilter::blurRadius() const
\internal
*/
-void QPixmapDropShadowFilter::setBlurRadius(qreal radius)
+void QPixmapDropShadowFilter::setBlurRadius(int radius)
{
Q_D(QPixmapDropShadowFilter);
-
- d->radius = radius;
-
- int dim = 2 * qRound(radius) + 1;
- QVarLengthArray<qreal> arr(dim * dim);
- qreal f = 1 / qreal(dim * dim);
- for (int i = 0; i < dim * dim; ++i)
- arr[i] = f;
- d->convolution->setConvolutionKernel(arr.data(), dim, dim);
+ d->blurFilter->setRadius(radius);
}
/*!
@@ -804,25 +1004,22 @@ void QPixmapDropShadowFilter::setOffset(const QPointF &offset)
*/
/*!
- \reimp
-
\internal
*/
QRectF QPixmapDropShadowFilter::boundingRectFor(const QRectF &rect) const
{
Q_D(const QPixmapDropShadowFilter);
- qreal x1 = qMin(rect.left(), rect.left() + d->offset.x() - d->radius);
- qreal y1 = qMin(rect.top(), rect.top() + d->offset.y() - d->radius);
- qreal x2 = qMax(rect.right(), rect.right() + d->offset.x() + d->radius);
- qreal y2 = qMax(rect.bottom(), rect.bottom() + d->offset.y() + d->radius);
+ const qreal delta = qreal(d->blurFilter->radius() * 2);
+ qreal x1 = qMin(rect.left(), rect.left() + d->offset.x() - delta);
+ qreal y1 = qMin(rect.top(), rect.top() + d->offset.y() - delta);
+ qreal x2 = qMax(rect.right(), rect.right() + d->offset.x() + delta);
+ qreal y2 = qMax(rect.bottom(), rect.bottom() + d->offset.y() + delta);
return QRectF(x1, y1, x2 - x1, y2 - y1);
}
/*!
- \reimp
-
\internal
*/
void QPixmapDropShadowFilter::draw(QPainter *p,
@@ -832,7 +1029,7 @@ void QPixmapDropShadowFilter::draw(QPainter *p,
{
Q_D(const QPixmapDropShadowFilter);
- QPixmap tmp = src.isNull() ? px : px.copy(src.toRect());
+ QImage tmp = src.isNull() ? px.toImage() : px.copy(src.toRect()).toImage();
QPainter tmpPainter(&tmp);
// blacken the image...
@@ -840,10 +1037,13 @@ void QPixmapDropShadowFilter::draw(QPainter *p,
tmpPainter.fillRect(0, 0, tmp.width(), tmp.height(), d->color);
tmpPainter.end();
+ const QPixmap pixTmp = QPixmap::fromImage(tmp);
+
// draw the blurred drop shadow...
- d->convolution->draw(p, pos + d->offset, tmp);
+ d->blurFilter->draw(p, pos + d->offset, pixTmp);
// Draw the actual pixmap...
p->drawPixmap(pos, px, src);
}
+
QT_END_NAMESPACE
diff --git a/src/gui/image/qpixmapfilter_p.h b/src/gui/image/qpixmapfilter_p.h
index 351aaf6..4489344 100644
--- a/src/gui/image/qpixmapfilter_p.h
+++ b/src/gui/image/qpixmapfilter_p.h
@@ -78,6 +78,7 @@ public:
ConvolutionFilter,
ColorizeFilter,
DropShadowFilter,
+ BlurFilter,
UserFilter = 1024
};
@@ -117,6 +118,30 @@ private:
int columns() const;
};
+class QPixmapBlurFilterPrivate;
+
+class Q_GUI_EXPORT QPixmapBlurFilter : public QPixmapFilter
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QPixmapBlurFilter)
+
+public:
+ QPixmapBlurFilter(QObject *parent = 0);
+ ~QPixmapBlurFilter();
+
+ void setRadius(int radius);
+ void setQuality(Qt::TransformationMode mode);
+
+ int radius() const;
+ Qt::TransformationMode quality() const;
+
+ QRectF boundingRectFor(const QRectF &rect) const;
+ void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect = QRectF()) const;
+
+private:
+ friend class QGLPixmapBlurFilter;
+};
+
class QPixmapColorizeFilterPrivate;
class Q_GUI_EXPORT QPixmapColorizeFilter : public QPixmapFilter
@@ -147,8 +172,8 @@ public:
QRectF boundingRectFor(const QRectF &rect) const;
void draw(QPainter *p, const QPointF &pos, const QPixmap &px, const QRectF &src = QRectF()) const;
- qreal blurRadius() const;
- void setBlurRadius(qreal radius);
+ int blurRadius() const;
+ void setBlurRadius(int radius);
QColor color() const;
void setColor(const QColor &color);
diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp
index 449e179..3f3a55c 100644
--- a/src/gui/image/qpnghandler.cpp
+++ b/src/gui/image/qpnghandler.cpp
@@ -956,7 +956,7 @@ QVariant QPngHandler::option(ImageOption option) const
void QPngHandler::setOption(ImageOption option, const QVariant &value)
{
if (option == Gamma)
- d->gamma = value.toDouble();
+ d->gamma = value.toFloat();
else if (option == Quality)
d->quality = value.toInt();
else if (option == Description)
diff --git a/src/gui/image/qppmhandler.cpp b/src/gui/image/qppmhandler.cpp
index 4e037ae..a97aef4 100644
--- a/src/gui/image/qppmhandler.cpp
+++ b/src/gui/image/qppmhandler.cpp
@@ -80,7 +80,7 @@ static int read_pbm_int(QIODevice *d)
else if (isspace((uchar) c))
continue;
else if (c == '#')
- d->readLine(buf, buflen);
+ (void)d->readLine(buf, buflen);
else
break;
}
diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp
index 433bd90..9a96762 100644
--- a/src/gui/image/qxpmhandler.cpp
+++ b/src/gui/image/qxpmhandler.cpp
@@ -1146,7 +1146,7 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const
QTextStream s(device);
s << "/* XPM */" << endl
<< "static char *" << fbname(fileName) << "[]={" << endl
- << "\"" << w << " " << h << " " << ncolors << " " << cpp << "\"";
+ << '\"' << w << ' ' << h << ' ' << ncolors << ' ' << cpp << '\"';
// write palette
QMap<QRgb, int>::Iterator c = colorMap.begin();
@@ -1162,7 +1162,7 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const
qGreen(color),
qBlue(color));
++c;
- s << "," << endl << line;
+ s << ',' << endl << line;
}
// write pixels, limit to 4 characters per pixel
@@ -1184,7 +1184,7 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const
}
}
}
- s << "," << endl << "\"" << line << "\"";
+ s << ',' << endl << '\"' << line << '\"';
}
s << "};" << endl;
return (s.status() == QTextStream::Ok);