diff options
Diffstat (limited to 'src/gui/image/qimagereader.cpp')
-rw-r--r-- | src/gui/image/qimagereader.cpp | 86 |
1 files changed, 62 insertions, 24 deletions
diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp index a10198a006..3bf002373c 100644 --- a/src/gui/image/qimagereader.cpp +++ b/src/gui/image/qimagereader.cpp @@ -74,17 +74,32 @@ that occurred, or errorString() to get a human readable description of what went wrong. + \section1 Formats + Call supportedImageFormats() for a list of formats that QImageReader can read. QImageReader supports all built-in image formats, in addition to any image format plugins that support - reading. + reading. Call supportedMimeTypes() to obtain a list of supported MIME + types, which for example can be passed to QFileDialog::setMimeTypeFilters(). QImageReader autodetects the image format by default, by looking at the provided (optional) format string, the file name suffix, and the data stream contents. You can enable or disable this feature, by calling setAutoDetectImageFormat(). - \sa QImageWriter, QImageIOHandler, QImageIOPlugin + \section1 High Resolution Versions of Images + + It is possible to provide high resolution versions of images should a scaling + between \e{device pixels} and \e{device independent pixels} be in effect. + + The high resolution version is marked by the suffix \c @2x on the base name. + The image read will have its \e{device pixel ratio} set to a value of 2. + + This can be disabled by setting the environment variable + \c QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING. + + \sa QImageWriter, QImageIOHandler, QImageIOPlugin, QMimeDatabase + \sa QImage::devicePixelRatio(), QPixmap::devicePixelRatio(), QIcon, QPainter::drawPixmap(), QPainter::drawImage(), Qt::AA_UseHighDpiPixmaps */ /*! @@ -125,7 +140,6 @@ #include <qimageiohandler.h> #include <qlist.h> #include <qrect.h> -#include <qset.h> #include <qsize.h> #include <qcolor.h> #include <qvariant.h> @@ -568,7 +582,7 @@ bool QImageReaderPrivate::initHandler() // check some preconditions if (!device || (!deleteDevice && !device->isOpen() && !device->open(QIODevice::ReadOnly))) { imageReaderError = QImageReader::DeviceError; - errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Invalid device")); + errorString = QImageReader::tr("Invalid device"); return false; } @@ -595,7 +609,7 @@ bool QImageReaderPrivate::initHandler() if (!device->isOpen()) { imageReaderError = QImageReader::FileNotFoundError; - errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "File not found")); + errorString = QImageReader::tr("File not found"); file->setFileName(fileName); // restore the old file name return false; } @@ -604,7 +618,7 @@ bool QImageReaderPrivate::initHandler() // assign a handler if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat, ignoresFormatAndExtension)) == 0) { imageReaderError = QImageReader::UnsupportedFormatError; - errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unsupported image format")); + errorString = QImageReader::tr("Unsupported image format"); return false; } return true; @@ -1101,6 +1115,36 @@ bool QImageReader::supportsAnimation() const } /*! + \since 5.4 + + Returns the subtype of the image. +*/ +QByteArray QImageReader::subType() const +{ + if (!d->initHandler()) + return QByteArray(); + + if (d->handler->supportsOption(QImageIOHandler::SubType)) + return d->handler->option(QImageIOHandler::SubType).toByteArray(); + return QByteArray(); +} + +/*! + \since 5.4 + + Returns the list of subtypes supported by an image. +*/ +QList<QByteArray> QImageReader::supportedSubTypes() const +{ + if (!d->initHandler()) + return QList<QByteArray>(); + + if (!d->handler->supportsOption(QImageIOHandler::SupportedSubTypes)) + return d->handler->option(QImageIOHandler::SupportedSubTypes).value< QList<QByteArray> >(); + return QList<QByteArray>(); +} + +/*! Returns \c true if an image can be read for the device (i.e., the image format is supported, and the device seems to contain valid data); otherwise returns \c false. @@ -1191,7 +1235,7 @@ bool QImageReader::read(QImage *image) // read the image if (!d->handler->read(image)) { d->imageReaderError = InvalidDataError; - d->errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unable to read image data")); + d->errorString = QImageReader::tr("Unable to read image data"); return false; } @@ -1384,7 +1428,7 @@ QImageReader::ImageReaderError QImageReader::error() const QString QImageReader::errorString() const { if (d->errorString.isEmpty()) - return QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unknown error")); + return QImageReader::tr("Unknown error"); return d->errorString; } @@ -1445,11 +1489,11 @@ QByteArray QImageReader::imageFormat(QIODevice *device) #ifndef QT_NO_IMAGEFORMATPLUGIN void supportedImageHandlerFormats(QFactoryLoader *loader, QImageIOPlugin::Capability cap, - QSet<QByteArray> *result); + QList<QByteArray> *result); void supportedImageHandlerMimeTypes(QFactoryLoader *loader, QImageIOPlugin::Capability cap, - QSet<QByteArray> *result); + QList<QByteArray> *result); #endif /*! @@ -1482,7 +1526,7 @@ void supportedImageHandlerMimeTypes(QFactoryLoader *loader, QList<QByteArray> QImageReader::supportedImageFormats() { - QSet<QByteArray> formats; + QList<QByteArray> formats; for (int i = 0; i < _qt_NumFormats; ++i) formats << _qt_BuiltInFormats[i].extension; @@ -1490,12 +1534,9 @@ QList<QByteArray> QImageReader::supportedImageFormats() supportedImageHandlerFormats(loader(), QImageIOPlugin::CanRead, &formats); #endif // QT_NO_IMAGEFORMATPLUGIN - QList<QByteArray> sortedFormats; - for (QSet<QByteArray>::ConstIterator it = formats.constBegin(); it != formats.constEnd(); ++it) - sortedFormats << *it; - - std::sort(sortedFormats.begin(), sortedFormats.end()); - return sortedFormats; + std::sort(formats.begin(), formats.end()); + formats.erase(std::unique(formats.begin(), formats.end()), formats.end()); + return formats; } /*! @@ -1509,7 +1550,7 @@ QList<QByteArray> QImageReader::supportedImageFormats() QList<QByteArray> QImageReader::supportedMimeTypes() { - QSet<QByteArray> mimeTypes; + QList<QByteArray> mimeTypes; for (int i = 0; i < _qt_NumFormats; ++i) mimeTypes << _qt_BuiltInFormats[i].mimeType; @@ -1517,12 +1558,9 @@ QList<QByteArray> QImageReader::supportedMimeTypes() supportedImageHandlerMimeTypes(loader(), QImageIOPlugin::CanRead, &mimeTypes); #endif // QT_NO_IMAGEFORMATPLUGIN - QList<QByteArray> sortedMimeTypes; - for (QSet<QByteArray>::ConstIterator it = mimeTypes.constBegin(); it != mimeTypes.constEnd(); ++it) - sortedMimeTypes << *it; - - std::sort(sortedMimeTypes.begin(), sortedMimeTypes.end()); - return sortedMimeTypes; + std::sort(mimeTypes.begin(), mimeTypes.end()); + mimeTypes.erase(std::unique(mimeTypes.begin(), mimeTypes.end()), mimeTypes.end()); + return mimeTypes; } QT_END_NAMESPACE |