diff options
Diffstat (limited to 'src/gui/image/qpixmap.cpp')
-rw-r--r-- | src/gui/image/qpixmap.cpp | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 4b2334ae52..5b4d218603 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -714,8 +714,8 @@ QBitmap QPixmap::createMaskFromColor(const QColor &maskColor, Qt::MaskMode mode) control the conversion. Note that QPixmaps are automatically added to the QPixmapCache - when loaded from a file; the key used is internal and can not - be acquired. + when loaded from a file in main thread; the key used is internal + and cannot be acquired. \sa loadFromData(), {QPixmap#Reading and Writing Image Files}{Reading and Writing Image Files} @@ -729,6 +729,7 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers // Note: If no extension is provided, we try to match the // file against known plugin extensions if (info.completeSuffix().isEmpty() || info.exists()) { + const bool inGuiThread = qApp->thread() == QThread::currentThread(); QString key = QLatin1String("qt_pixmap") % info.absoluteFilePath() @@ -736,13 +737,14 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers % HexString<quint64>(info.size()) % HexString<uint>(data ? data->pixelType() : QPlatformPixmap::PixmapType); - if (QPixmapCache::find(key, this)) + if (inGuiThread && QPixmapCache::find(key, this)) return true; data = QPlatformPixmap::create(0, 0, data ? data->pixelType() : QPlatformPixmap::PixmapType); if (data->fromFile(fileName, format, flags)) { - QPixmapCache::insert(key, *this); + if (inGuiThread) + QPixmapCache::insert(key, *this); return true; } } @@ -856,6 +858,7 @@ bool QPixmap::doImageIO(QImageWriter *writer, int quality) const } +#if QT_DEPRECATED_SINCE(5, 13) /*! \obsolete @@ -876,6 +879,14 @@ void QPixmap::fill(const QPaintDevice *device, const QPoint &p) Use QPainter or the fill(QColor) overload instead. */ +void QPixmap::fill(const QPaintDevice *device, int xofs, int yofs) +{ + Q_UNUSED(device) + Q_UNUSED(xofs) + Q_UNUSED(yofs) + qWarning("this function is deprecated, ignored"); +} +#endif /*! @@ -959,6 +970,7 @@ static void sendResizeEvents(QWidget *target) } #endif +#if QT_DEPRECATED_SINCE(5, 13) /*! \obsolete @@ -982,6 +994,14 @@ QPixmap QPixmap::grabWidget(QObject *widget, const QRect &rectangle) Use QWidget::grab() instead. */ +QPixmap QPixmap::grabWidget(QObject *widget, int x, int y, int w, int h) +{ +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + return grabWidget(widget, QRect(x, y, w, h)); +QT_WARNING_POP +} +#endif /***************************************************************************** QPixmap stream functions @@ -1356,12 +1376,6 @@ QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode) The cacheKey() function returns a number that uniquely identifies the contents of the QPixmap object. - The x11Info() function returns information about the configuration - of the X display used by the screen to which the pixmap currently - belongs. The x11PictureHandle() function returns the X11 Picture - handle of the pixmap for XRender support. Note that the two latter - functions are only available on x11. - \endtable \section1 Pixmap Conversion @@ -1392,9 +1406,6 @@ QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode) function returns the actual matrix used for transforming the pixmap. - \note When using the native X11 graphics system, the pixmap - becomes invalid when the QApplication instance is destroyed. - \sa QBitmap, QImage, QImageReader, QImageWriter */ @@ -1541,6 +1552,11 @@ QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags) if (image.isNull()) return QPixmap(); + if (Q_UNLIKELY(!qobject_cast<QGuiApplication *>(QCoreApplication::instance()))) { + qWarning("QPixmap::fromImage: QPixmap cannot be created without a QGuiApplication"); + return QPixmap(); + } + QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); data->fromImage(image, flags); return QPixmap(data.take()); @@ -1563,6 +1579,11 @@ QPixmap QPixmap::fromImageInPlace(QImage &image, Qt::ImageConversionFlags flags) if (image.isNull()) return QPixmap(); + if (Q_UNLIKELY(!qobject_cast<QGuiApplication *>(QCoreApplication::instance()))) { + qWarning("QPixmap::fromImageInPlace: QPixmap cannot be created without a QGuiApplication"); + return QPixmap(); + } + QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); data->fromImageInPlace(image, flags); return QPixmap(data.take()); @@ -1582,11 +1603,17 @@ QPixmap QPixmap::fromImageInPlace(QImage &image, Qt::ImageConversionFlags flags) */ QPixmap QPixmap::fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags) { + if (Q_UNLIKELY(!qobject_cast<QGuiApplication *>(QCoreApplication::instance()))) { + qWarning("QPixmap::fromImageReader: QPixmap cannot be created without a QGuiApplication"); + return QPixmap(); + } + QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); data->fromImageReader(imageReader, flags); return QPixmap(data.take()); } +#if QT_DEPRECATED_SINCE(5, 13) /*! \fn QPixmap QPixmap::grabWindow(WId window, int x, int y, int width, int height) @@ -1640,6 +1667,7 @@ QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h) " Defaulting to primary screen."); return QGuiApplication::primaryScreen()->grabWindow(window, x, y, w, h); } +#endif /*! \internal |