diff options
Diffstat (limited to 'src/gui/image')
26 files changed, 289 insertions, 111 deletions
diff --git a/src/gui/image/qbitmap.h b/src/gui/image/qbitmap.h index 1f062a0758..f8bd2feed7 100644 --- a/src/gui/image/qbitmap.h +++ b/src/gui/image/qbitmap.h @@ -44,8 +44,6 @@ #include <QtGui/qpixmap.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -80,6 +78,4 @@ Q_DECLARE_SHARED(QBitmap) QT_END_NAMESPACE -QT_END_HEADER - #endif // QBITMAP_H diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index dce902301c..d73cd0aa57 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -60,6 +60,7 @@ #include "private/qhexstring_p.h" #include "private/qguiapplication_p.h" +#include "qpa/qplatformtheme.h" #ifndef QT_NO_ICON QT_BEGIN_NAMESPACE @@ -118,6 +119,25 @@ static void qt_cleanup_icon_cache() qtIconCache()->clear(); } +/*! \internal + + Returns the effective device pixel ratio, using + the provided window pointer if possible. + + if Qt::AA_UseHighDpiPixmaps is not set this function + returns 1.0 to keep non-hihdpi aware code working. +*/ +static qreal qt_effective_device_pixel_ratio(QWindow *window = 0) +{ + if (!qApp->testAttribute(Qt::AA_UseHighDpiPixmaps)) + return qreal(1.0); + + if (window) + return window->devicePixelRatio(); + + return qApp->devicePixelRatio(); // Don't know which window to target. +} + QIconPrivate::QIconPrivate() : engine(0), ref(1), serialNum(serialNumCounter.fetchAndAddRelaxed(1)), @@ -125,6 +145,25 @@ QIconPrivate::QIconPrivate() { } +/*! \internal + Computes the displayDevicePixelRatio for a pixmap. + + If displayDevicePixelRatio is 1.0 the reurned value is 1.0, always. + + For a displayDevicePixelRatio of 2.0 the returned value will be between + 1.0 and 2.0, depending on requestedSize and actualsize: + * If actualsize < requestedSize : 1.0 (not enough pixels for a normal-dpi pixmap) + * If actualsize == requestedSize * 2.0 : 2.0 (enough pixels for a high-dpi pixmap) + * else : a scaled value between 1.0 and 2.0. (pixel count is between normal-dpi and high-dpi) +*/ +qreal QIconPrivate::pixmapDevicePixelRatio(qreal displayDevicePixelRatio, const QSize &requestedSize, const QSize &actualSize) +{ + QSize targetSize = requestedSize * displayDevicePixelRatio; + qreal scale = 0.5 * (qreal(actualSize.width()) / qreal(targetSize.width()) + + qreal(actualSize.height() / qreal(targetSize.height()))); + return qMax(qreal(1.0), displayDevicePixelRatio *scale); +} + QPixmapIconEngine::QPixmapIconEngine() { } @@ -140,10 +179,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) - pixmapSize *= qt_mac_get_scalefactor(); -#endif + QSize pixmapSize = rect.size() * qt_effective_device_pixel_ratio(0); + QPixmap px = pixmap(pixmapSize, mode, state); painter->drawPixmap(rect, pixmap(pixmapSize, mode, state)); } @@ -344,6 +381,9 @@ void QPixmapIconEngine::addFile(const QString &fileName, const QSize &_size, QIc } if (pe->size == QSize() && pe->pixmap.isNull()) { pe->pixmap = QPixmap(pe->fileName); + // Reset the devicePixelRatio. The pixmap may be loaded from a @2x file, + // but be used as a 1x pixmap by QIcon. + pe->pixmap.setDevicePixelRatio(1.0); pe->size = pe->pixmap.size(); } if(pe->size == size) { @@ -657,13 +697,17 @@ qint64 QIcon::cacheKey() const state, generating one if necessary. The pixmap might be smaller than requested, but never larger. + Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this + function to return pixmaps that are larger than the requested size. Such + images will have a devicePixelRatio larger than 1. + \sa actualSize(), paint() */ QPixmap QIcon::pixmap(const QSize &size, Mode mode, State state) const { if (!d) return QPixmap(); - return d->engine->pixmap(size, mode, state); + return pixmap(0, size, mode, state); } /*! @@ -673,6 +717,10 @@ QPixmap QIcon::pixmap(const QSize &size, Mode mode, State state) const Returns a pixmap of size QSize(\a w, \a h). The pixmap might be smaller than requested, but never larger. + + Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this + function to return pixmaps that are larger than the requested size. Such + images will have a devicePixelRatio larger than 1. */ /*! @@ -682,11 +730,16 @@ QPixmap QIcon::pixmap(const QSize &size, Mode mode, State state) const Returns a pixmap of size QSize(\a extent, \a extent). The pixmap might be smaller than requested, but never larger. + + Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this + function to return pixmaps that are larger than the requested size. Such + images will have a devicePixelRatio larger than 1. */ /*! Returns the actual size of the icon for the requested \a size, \a mode, and \a state. The result might be smaller than requested, but - never larger. + never larger. The returned size is in device-independent pixels (This + is relevant for high-dpi pixmaps.) \sa pixmap(), paint() */ @@ -694,9 +747,63 @@ QSize QIcon::actualSize(const QSize &size, Mode mode, State state) const { if (!d) return QSize(); - return d->engine->actualSize(size, mode, state); + return actualSize(0, size, mode, state); +} + +/*! + \since 5.1 + + Returns a pixmap with the requested \a window \a size, \a mode, and \a + state, generating one if necessary. + + The pixmap can be smaller than the requested size. If \a window is on + a high-dpi display the pixmap can be larger. In that case it will have + a devicePixelRatio larger than 1. + + \sa actualSize(), paint() +*/ +QPixmap QIcon::pixmap(QWindow *window, const QSize &size, Mode mode, State state) const +{ + if (!d) + return QPixmap(); + + qreal devicePixelRatio = qt_effective_device_pixel_ratio(window); + + // Handle the simple normal-dpi case: + if (!(devicePixelRatio > 1.0)) + return d->engine->pixmap(size, mode, state); + + // Try get a pixmap that is big enough to be displayed at device pixel resolution. + QPixmap pixmap = d->engine->pixmap(size * devicePixelRatio, mode, state); + pixmap.setDevicePixelRatio(d->pixmapDevicePixelRatio(devicePixelRatio, size, pixmap.size())); + return pixmap; } +/*! + \since 5.1 + + Returns the actual size of the icon for the requested \a window \a size, \a + mode, and \a state. + + The pixmap can be smaller than the requested size. The returned size + is in device-independent pixels (This is relevant for high-dpi pixmaps.) + + \sa actualSize(), pixmap(), paint() +*/ +QSize QIcon::actualSize(QWindow *window, const QSize &size, Mode mode, State state) const +{ + if (!d) + return QSize(); + + qreal devicePixelRatio = qt_effective_device_pixel_ratio(window); + + // Handle the simple normal-dpi case: + if (!(devicePixelRatio > 1.0)) + return d->engine->actualSize(size, mode, state); + + QSize actualSize = d->engine->actualSize(size * devicePixelRatio, mode, state); + return actualSize / d->pixmapDevicePixelRatio(devicePixelRatio, size, actualSize); +} /*! Uses the \a painter to paint the icon with specified \a alignment, @@ -851,6 +958,17 @@ void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State detach(); } d->engine->addFile(fileName, size, mode, state); + + // Check if a "@2x" file exists and add it. + if (qApp->devicePixelRatio() > 1.0) { + int dotIndex = fileName.lastIndexOf(QLatin1Char('.')); + if (dotIndex != -1) { + QString at2xfileName = fileName; + at2xfileName.insert(dotIndex, QStringLiteral("@2x")); + if (QFile::exists(at2xfileName)) + d->engine->addFile(at2xfileName, size, mode, state); + } + } } /*! @@ -945,6 +1063,7 @@ void QIcon::setThemeName(const QString &name) */ QString QIcon::themeName() { + QIconLoader::instance()->ensureInitialized(); return QIconLoader::instance()->themeName(); } @@ -986,7 +1105,10 @@ QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback) if (qtIconCache()->contains(name)) { icon = *qtIconCache()->object(name); } else { - QIcon *cachedIcon = new QIcon(new QIconLoaderEngine(name)); + QPlatformTheme * const platformTheme = QGuiApplicationPrivate::platformTheme(); + QIconEngine * const engine = platformTheme ? platformTheme->createIconEngine(name) + : new QIconLoaderEngine(name); + QIcon *cachedIcon = new QIcon(engine); qtIconCache()->insert(name, cachedIcon); icon = *cachedIcon; } diff --git a/src/gui/image/qicon.h b/src/gui/image/qicon.h index ad459005f5..e81bea69d6 100644 --- a/src/gui/image/qicon.h +++ b/src/gui/image/qicon.h @@ -47,8 +47,6 @@ #include <QtCore/qlist.h> #include <QtGui/qpixmap.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -81,8 +79,10 @@ public: { return pixmap(QSize(w, h), mode, state); } inline QPixmap pixmap(int extent, Mode mode = Normal, State state = Off) const { return pixmap(QSize(extent, extent), mode, state); } + QPixmap pixmap(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const; QSize actualSize(const QSize &size, Mode mode = Normal, State state = Off) const; + QSize actualSize(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const; QString name() const; @@ -140,6 +140,4 @@ Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QIcon &); QT_END_NAMESPACE -QT_END_HEADER - #endif // QICON_H diff --git a/src/gui/image/qicon_p.h b/src/gui/image/qicon_p.h index 2ddb5872e1..a46cc310ad 100644 --- a/src/gui/image/qicon_p.h +++ b/src/gui/image/qicon_p.h @@ -72,6 +72,8 @@ public: delete engine; } + qreal pixmapDevicePixelRatio(qreal displayDevicePixelRatio, const QSize &requestedSize, const QSize &actualSize); + QIconEngine *engine; QAtomicInt ref; diff --git a/src/gui/image/qiconengine.h b/src/gui/image/qiconengine.h index 1d296b9f66..9fb21adf97 100644 --- a/src/gui/image/qiconengine.h +++ b/src/gui/image/qiconengine.h @@ -46,8 +46,6 @@ #include <QtCore/qlist.h> #include <QtGui/qicon.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -90,6 +88,4 @@ typedef QIconEngine QIconEngineV2; QT_END_NAMESPACE -QT_END_HEADER - #endif // QICONENGINE_H diff --git a/src/gui/image/qiconengineplugin.h b/src/gui/image/qiconengineplugin.h index 58bade1d09..a62659f8cb 100644 --- a/src/gui/image/qiconengineplugin.h +++ b/src/gui/image/qiconengineplugin.h @@ -45,8 +45,6 @@ #include <QtCore/qplugin.h> #include <QtCore/qfactoryinterface.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -66,6 +64,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QICONENGINEPLUGIN_H diff --git a/src/gui/image/qiconloader_p.h b/src/gui/image/qiconloader_p.h index ea144ec299..419d93d576 100644 --- a/src/gui/image/qiconloader_p.h +++ b/src/gui/image/qiconloader_p.h @@ -42,6 +42,8 @@ #ifndef QICONLOADER_P_H #define QICONLOADER_P_H +#include <QtCore/qglobal.h> + #ifndef QT_NO_ICON // // W A R N I N G diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 481cb37c8c..7287f54e74 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -1126,6 +1126,7 @@ QImage QImage::copy(const QRect& r) const image.d->colortable = d->colortable; image.d->dpmx = d->dpmx; image.d->dpmy = d->dpmy; + image.d->devicePixelRatio = d->devicePixelRatio; image.d->offset = d->offset; image.d->has_alpha_clut = d->has_alpha_clut; image.d->text = d->text; diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h index bce25c49ea..50d4bc7666 100644 --- a/src/gui/image/qimage.h +++ b/src/gui/image/qimage.h @@ -53,8 +53,6 @@ #include <QtCore/qstringlist.h> #endif -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -430,6 +428,4 @@ Q_GUI_EXPORT QDebug operator<<(QDebug, const QImage &); QT_END_NAMESPACE -QT_END_HEADER - #endif // QIMAGE_H diff --git a/src/gui/image/qimageiohandler.cpp b/src/gui/image/qimageiohandler.cpp index f770458127..055ace9985 100644 --- a/src/gui/image/qimageiohandler.cpp +++ b/src/gui/image/qimageiohandler.cpp @@ -433,7 +433,7 @@ bool QImageIOHandler::supportsOption(ImageOption option) const the sequence number of the current image in the animation. If this function is called before any image is read(), -1 is returned. The number of the first image in the sequence is 0. - + If the image format does not support animation, 0 is returned. \sa read() diff --git a/src/gui/image/qimageiohandler.h b/src/gui/image/qimageiohandler.h index f6d905bc6b..2ba99beab3 100644 --- a/src/gui/image/qimageiohandler.h +++ b/src/gui/image/qimageiohandler.h @@ -46,8 +46,6 @@ #include <QtCore/qfactoryinterface.h> #include <QtCore/qscopedpointer.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -142,6 +140,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QImageIOPlugin::Capabilities) QT_END_NAMESPACE -QT_END_HEADER - #endif // QIMAGEIOHANDLER_H diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp index 684778694e..e612a2c374 100644 --- a/src/gui/image/qimagereader.cpp +++ b/src/gui/image/qimagereader.cpp @@ -190,34 +190,35 @@ struct _qt_BuiltInFormatStruct { _qt_BuiltInFormatType type; const char *extension; + const char *mimeType; }; static const _qt_BuiltInFormatStruct _qt_BuiltInFormats[] = { #ifndef QT_NO_IMAGEFORMAT_PNG - {_qt_PngFormat, "png"}, + {_qt_PngFormat, "png", "image/png"}, #endif #ifndef QT_NO_IMAGEFORMAT_JPEG - {_qt_JpgFormat, "jpg"}, + {_qt_JpgFormat, "jpg", "image/jpeg"}, {_qt_JpegFormat, "jpeg"}, #endif #ifdef QT_BUILTIN_GIF_READER - {_qt_GifFormat, "gif"}, + {_qt_GifFormat, "gif", "image/gif"}, #endif #ifndef QT_NO_IMAGEFORMAT_BMP - {_qt_BmpFormat, "bmp"}, + {_qt_BmpFormat, "bmp", "image/bmp"}, #endif #ifndef QT_NO_IMAGEFORMAT_PPM - {_qt_PpmFormat, "ppm"}, - {_qt_PgmFormat, "pgm"}, - {_qt_PbmFormat, "pbm"}, + {_qt_PpmFormat, "ppm", "image/x-portable-pixmap"}, + {_qt_PgmFormat, "pgm", "image/x-portable-graymap"}, + {_qt_PbmFormat, "pbm", "image/x-portable-bitmap"}, #endif #ifndef QT_NO_IMAGEFORMAT_XBM - {_qt_XbmFormat, "xbm"}, + {_qt_XbmFormat, "xbm", "image/x-xbitmap"}, #endif #ifndef QT_NO_IMAGEFORMAT_XPM - {_qt_XpmFormat, "xpm"}, + {_qt_XpmFormat, "xpm", "image/x-xpixmap"}, #endif - {_qt_NoFormat, ""} + {_qt_NoFormat, "", ""} }; static QImageIOHandler *createReadHandlerHelper(QIODevice *device, @@ -1445,6 +1446,10 @@ QByteArray QImageReader::imageFormat(QIODevice *device) void supportedImageHandlerFormats(QFactoryLoader *loader, QImageIOPlugin::Capability cap, QSet<QByteArray> *result); + +void supportedImageHandlerMimeTypes(QFactoryLoader *loader, + QImageIOPlugin::Capability cap, + QSet<QByteArray> *result); #endif /*! @@ -1453,18 +1458,17 @@ void supportedImageHandlerFormats(QFactoryLoader *loader, By default, Qt can read the following formats: \table - \header \li Format \li Description - \row \li BMP \li Windows Bitmap - \row \li GIF \li Graphic Interchange Format (optional) - \row \li JPG \li Joint Photographic Experts Group - \row \li JPEG \li Joint Photographic Experts Group - \row \li PNG \li Portable Network Graphics - \row \li PBM \li Portable Bitmap - \row \li PGM \li Portable Graymap - \row \li PPM \li Portable Pixmap - \row \li XBM \li X11 Bitmap - \row \li XPM \li X11 Pixmap - \row \li SVG \li Scalable Vector Graphics + \header \li Format \li MIME type \li Description + \row \li BMP \li image/bmp \li Windows Bitmap + \row \li GIF \li image/gif \li Graphic Interchange Format (optional) + \row \li JPG \li image/jpeg \li Joint Photographic Experts Group + \row \li PNG \li image/png \li Portable Network Graphics + \row \li PBM \li image/x-portable-bitmap \li Portable Bitmap + \row \li PGM \li image/x-portable-graymap \li Portable Graymap + \row \li PPM \li image/x-portable-pixmap \li Portable Pixmap + \row \li XBM \li image/x-xbitmap \li X11 Bitmap + \row \li XPM \li image/x-xpixmap \li X11 Pixmap + \row \li SVG \li image/svg+xml \li Scalable Vector Graphics \endtable Reading and writing SVG files is supported through the \l{Qt SVG} module. @@ -1494,4 +1498,31 @@ QList<QByteArray> QImageReader::supportedImageFormats() return sortedFormats; } +/*! + Returns the list of MIME types supported by QImageReader. + + Note that the QApplication instance must be created before this function is + called. + + \sa supportedImageFormats(), QImageWriter::supportedMimeTypes() +*/ + +QList<QByteArray> QImageReader::supportedMimeTypes() +{ + QSet<QByteArray> mimeTypes; + for (int i = 0; i < _qt_NumFormats; ++i) + mimeTypes << _qt_BuiltInFormats[i].mimeType; + +#ifndef QT_NO_LIBRARY + supportedImageHandlerMimeTypes(loader(), QImageIOPlugin::CanRead, &mimeTypes); +#endif // QT_NO_LIBRARY + + QList<QByteArray> sortedMimeTypes; + for (QSet<QByteArray>::ConstIterator it = mimeTypes.constBegin(); it != mimeTypes.constEnd(); ++it) + sortedMimeTypes << *it; + + qSort(sortedMimeTypes); + return sortedMimeTypes; +} + QT_END_NAMESPACE diff --git a/src/gui/image/qimagereader.h b/src/gui/image/qimagereader.h index 11c925b142..4f3c93af7d 100644 --- a/src/gui/image/qimagereader.h +++ b/src/gui/image/qimagereader.h @@ -46,8 +46,6 @@ #include <QtGui/qimage.h> #include <QtGui/qimageiohandler.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -133,6 +131,7 @@ public: static QByteArray imageFormat(const QString &fileName); static QByteArray imageFormat(QIODevice *device); static QList<QByteArray> supportedImageFormats(); + static QList<QByteArray> supportedMimeTypes(); private: Q_DISABLE_COPY(QImageReader) @@ -141,6 +140,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QIMAGEREADER_H diff --git a/src/gui/image/qimagewriter.cpp b/src/gui/image/qimagewriter.cpp index 20e601be03..8823f9293d 100644 --- a/src/gui/image/qimagewriter.cpp +++ b/src/gui/image/qimagewriter.cpp @@ -100,6 +100,7 @@ #include <qfile.h> #include <qfileinfo.h> #include <qimageiohandler.h> +#include <qjsonarray.h> #include <qset.h> #include <qvariant.h> @@ -677,6 +678,26 @@ void supportedImageHandlerFormats(QFactoryLoader *loader, result->insert(key); } } + +void supportedImageHandlerMimeTypes(QFactoryLoader *loader, + QImageIOPlugin::Capability cap, + QSet<QByteArray> *result) +{ + QList<QJsonObject> metaDataList = loader->metaData(); + + const int pluginCount = metaDataList.size(); + for (int i = 0; i < pluginCount; ++i) { + const QJsonObject metaData = metaDataList.at(i).value(QStringLiteral("MetaData")).toObject(); + const QJsonArray keys = metaData.value(QStringLiteral("Keys")).toArray(); + const QJsonArray mimeTypes = metaData.value(QStringLiteral("MimeTypes")).toArray(); + QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(loader->instance(i)); + const int keyCount = keys.size(); + for (int k = 0; k < keyCount; ++k) { + if (plugin && (plugin->capabilities(0, keys.at(k).toString().toLatin1()) & cap) != 0) + result->insert(mimeTypes.at(k).toString().toLatin1()); + } + } +} #endif // QT_NO_IMAGEFORMATPLUGIN /*! @@ -685,16 +706,15 @@ void supportedImageHandlerFormats(QFactoryLoader *loader, By default, Qt can write the following formats: \table - \header \li Format \li Description - \row \li BMP \li Windows Bitmap - \row \li JPG \li Joint Photographic Experts Group - \row \li JPEG \li Joint Photographic Experts Group - \row \li PNG \li Portable Network Graphics - \row \li PBM \li Portable Bitmap - \row \li PGM \li Portable Graymap - \row \li PPM \li Portable Pixmap - \row \li XBM \li X11 Bitmap - \row \li XPM \li X11 Pixmap + \header \li Format \li MIME type \li Description + \row \li BMP \li image/bmp \li Windows Bitmap + \row \li JPG \li image/jpeg \li Joint Photographic Experts Group + \row \li PNG \li image/png \li Portable Network Graphics + \row \li PBM \li image/x-portable-bitmap \li Portable Bitmap + \row \li PGM \li image/x-portable-graymap \li Portable Graymap + \row \li PPM \li image/x-portable-pixmap \li Portable Pixmap + \row \li XBM \li image/x-xbitmap \li X11 Bitmap + \row \li XPM \li image/x-xpixmap \li X11 Pixmap \endtable Reading and writing SVG files is supported through the \l{Qt SVG} module. @@ -726,9 +746,6 @@ QList<QByteArray> QImageWriter::supportedImageFormats() #ifndef QT_NO_IMAGEFORMAT_JPEG formats << "jpg" << "jpeg"; #endif -#ifdef QT_BUILTIN_GIF_READER - formats << "gif"; -#endif #ifndef QT_NO_IMAGEFORMATPLUGIN supportedImageHandlerFormats(loader(), QImageIOPlugin::CanWrite, &formats); @@ -742,4 +759,46 @@ QList<QByteArray> QImageWriter::supportedImageFormats() return sortedFormats; } +/*! + Returns the list of MIME types supported by QImageWriter. + + Note that the QApplication instance must be created before this function is + called. + + \sa supportedImageFormats(), QImageReader::supportedMimeTypes() +*/ +QList<QByteArray> QImageWriter::supportedMimeTypes() +{ + QSet<QByteArray> mimeTypes; + mimeTypes << "image/bmp"; +#ifndef QT_NO_IMAGEFORMAT_PPM + mimeTypes << "image/x-portable-bitmap"; + mimeTypes << "image/x-portable-graymap"; + mimeTypes << "image/x-portable-pixmap"; +#endif +#ifndef QT_NO_IMAGEFORMAT_XBM + mimeTypes << "image/x-xbitmap"; +#endif +#ifndef QT_NO_IMAGEFORMAT_XPM + mimeTypes << "image/x-xpixmap"; +#endif +#ifndef QT_NO_IMAGEFORMAT_PNG + mimeTypes << "image/png"; +#endif +#ifndef QT_NO_IMAGEFORMAT_JPEG + mimeTypes << "image/jpeg"; +#endif + +#ifndef QT_NO_LIBRARY + supportedImageHandlerMimeTypes(loader(), QImageIOPlugin::CanWrite, &mimeTypes); +#endif // QT_NO_LIBRARY + + QList<QByteArray> sortedMimeTypes; + for (QSet<QByteArray>::ConstIterator it = mimeTypes.constBegin(); it != mimeTypes.constEnd(); ++it) + sortedMimeTypes << *it; + + qSort(sortedMimeTypes); + return sortedMimeTypes; +} + QT_END_NAMESPACE diff --git a/src/gui/image/qimagewriter.h b/src/gui/image/qimagewriter.h index 7d05cd5236..3f5cf9c454 100644 --- a/src/gui/image/qimagewriter.h +++ b/src/gui/image/qimagewriter.h @@ -46,8 +46,6 @@ #include <QtCore/qlist.h> #include <QtGui/qimageiohandler.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -102,6 +100,7 @@ public: bool supportsOption(QImageIOHandler::ImageOption option) const; static QList<QByteArray> supportedImageFormats(); + static QList<QByteArray> supportedMimeTypes(); private: Q_DISABLE_COPY(QImageWriter) @@ -110,6 +109,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QIMAGEWRITER_H diff --git a/src/gui/image/qmovie.cpp b/src/gui/image/qmovie.cpp index e137af2231..ae526f5ba7 100644 --- a/src/gui/image/qmovie.cpp +++ b/src/gui/image/qmovie.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -/*! +/*! \class QMovie \inmodule QtGui @@ -150,7 +150,7 @@ copy of the frame. */ -/*! +/*! \fn void QMovie::stateChanged(QMovie::MovieState state) This signal is emitted every time the state of the movie changes. The new @@ -203,23 +203,23 @@ public: inline QFrameInfo(bool endMark) : pixmap(QPixmap()), delay(QMOVIE_INVALID_DELAY), endMark(endMark) { } - + inline QFrameInfo() : pixmap(QPixmap()), delay(QMOVIE_INVALID_DELAY), endMark(false) { } - + inline QFrameInfo(const QPixmap &pixmap, int delay) : pixmap(pixmap), delay(delay), endMark(false) { } - + inline bool isValid() { return endMark || !(pixmap.isNull() && (delay == QMOVIE_INVALID_DELAY)); } - + inline bool isEndMarker() { return endMark; } - + static inline QFrameInfo endMarker() { return QFrameInfo(true); } }; diff --git a/src/gui/image/qmovie.h b/src/gui/image/qmovie.h index 60df9199c4..94d7c79e7b 100644 --- a/src/gui/image/qmovie.h +++ b/src/gui/image/qmovie.h @@ -50,8 +50,6 @@ #include <QtCore/qlist.h> #include <QtGui/qimagereader.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -146,8 +144,6 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_MOVIE #endif // QMOVIE_H diff --git a/src/gui/image/qpicture.h b/src/gui/image/qpicture.h index f0abb50764..08445a3143 100644 --- a/src/gui/image/qpicture.h +++ b/src/gui/image/qpicture.h @@ -46,8 +46,6 @@ #include <QtCore/qsharedpointer.h> #include <QtGui/qpaintdevice.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -193,6 +191,4 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPicture &); QT_END_NAMESPACE -QT_END_HEADER - #endif // QPICTURE_H diff --git a/src/gui/image/qpictureformatplugin.h b/src/gui/image/qpictureformatplugin.h index 16e7feaffe..30989c084c 100644 --- a/src/gui/image/qpictureformatplugin.h +++ b/src/gui/image/qpictureformatplugin.h @@ -45,8 +45,6 @@ #include <QtCore/qplugin.h> #include <QtCore/qfactoryinterface.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -76,6 +74,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QPICTUREFORMATPLUGIN_H diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index b6a21f588e..85f0dc2d92 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -678,6 +678,9 @@ qreal QPixmap::devicePixelRatio() const */ void QPixmap::setDevicePixelRatio(qreal scaleFactor) { + if (isNull()) + return; + detach(); data->setDevicePixelRatio(scaleFactor); } diff --git a/src/gui/image/qpixmap.h b/src/gui/image/qpixmap.h index a25ecb21e4..f1fce03c80 100644 --- a/src/gui/image/qpixmap.h +++ b/src/gui/image/qpixmap.h @@ -50,8 +50,6 @@ #include <QtGui/qimage.h> #include <QtGui/qtransform.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -245,6 +243,4 @@ Q_GUI_EXPORT QDebug operator<<(QDebug, const QPixmap &); QT_END_NAMESPACE -QT_END_HEADER - #endif // QPIXMAP_H diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp index f8fef9cada..302945dbf8 100644 --- a/src/gui/image/qpixmap_raster.cpp +++ b/src/gui/image/qpixmap_raster.cpp @@ -240,12 +240,14 @@ QImage QRasterPlatformPixmap::toImage(const QRect &rect) const QRect clipped = rect.intersected(QRect(0, 0, w, h)); const uint du = uint(d); - if ((du % 8 == 0) && (((uint(clipped.x()) * du)) % 32 == 0)) - return QImage(image.scanLine(clipped.y()) + clipped.x() * (du / 8), + if ((du % 8 == 0) && (((uint(clipped.x()) * du)) % 32 == 0)) { + QImage newImage(image.scanLine(clipped.y()) + clipped.x() * (du / 8), clipped.width(), clipped.height(), image.bytesPerLine(), image.format()); - else + return newImage; + } else { return image.copy(clipped); + } } QPaintEngine* QRasterPlatformPixmap::paintEngine() const @@ -354,7 +356,9 @@ void QRasterPlatformPixmap::createPixmapForImage(QImage &sourceImage, Qt::ImageC is_null = (w <= 0 || h <= 0); image.d->devicePixelRatio = sourceImage.devicePixelRatio(); + //ensure the pixmap and the image resulting from toImage() have the same cacheKey(); setSerialNumber(image.cacheKey() >> 32); + setDetachNumber(image.d->detach_no); } QImage* QRasterPlatformPixmap::buffer() diff --git a/src/gui/image/qpixmapcache.h b/src/gui/image/qpixmapcache.h index 7f7db7dc35..83e6610f2a 100644 --- a/src/gui/image/qpixmapcache.h +++ b/src/gui/image/qpixmapcache.h @@ -48,8 +48,6 @@ #include <QtCore/qpair.h> #endif -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -96,6 +94,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QPIXMAPCACHE_H diff --git a/src/gui/image/qplatformpixmap.cpp b/src/gui/image/qplatformpixmap.cpp index ce66972dc3..54f0087bc2 100644 --- a/src/gui/image/qplatformpixmap.cpp +++ b/src/gui/image/qplatformpixmap.cpp @@ -173,6 +173,11 @@ void QPlatformPixmap::setSerialNumber(int serNo) ser_no = serNo; } +void QPlatformPixmap::setDetachNumber(int detNo) +{ + detach_no = detNo; +} + QImage QPlatformPixmap::toImage(const QRect &rect) const { if (rect.contains(QRect(0, 0, w, h))) diff --git a/src/gui/image/qplatformpixmap.h b/src/gui/image/qplatformpixmap.h index ded4bd30a9..08e03f10bd 100644 --- a/src/gui/image/qplatformpixmap.h +++ b/src/gui/image/qplatformpixmap.h @@ -54,8 +54,6 @@ #include <QtGui/qpixmap.h> #include <QtCore/qatomic.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -132,6 +130,7 @@ public: protected: void setSerialNumber(int serNo); + void setDetachNumber(int detNo); int w; int h; int d; @@ -158,6 +157,4 @@ extern bool qt_xForm_helper(const QTransform&, int, int, int, uchar*, int, int, QT_END_NAMESPACE -QT_END_HEADER - #endif // QPLATFORMPIXMAP_H diff --git a/src/gui/image/qxbmhandler.cpp b/src/gui/image/qxbmhandler.cpp index 0e1ecfa299..498f6ce767 100644 --- a/src/gui/image/qxbmhandler.cpp +++ b/src/gui/image/qxbmhandler.cpp @@ -302,7 +302,7 @@ bool QXbmHandler::read(QImage *image) { if (state == Error) return false; - + if (state == Ready && !readHeader()) { state = Error; return false; |