diff options
Diffstat (limited to 'src/gui/image/qpixmap.cpp')
-rw-r--r-- | src/gui/image/qpixmap.cpp | 254 |
1 files changed, 28 insertions, 226 deletions
diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 70715793a7..4c7e5dec81 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -48,14 +48,10 @@ #include "qbitmap.h" #include "qcolormap.h" #include "qimage.h" -#include "qwidget.h" #include "qpainter.h" #include "qdatastream.h" #include "qbuffer.h" -#include "qapplication.h" -#include <private/qapplication_p.h> -#include <private/qgraphicssystem_p.h> -#include <private/qwidget_p.h> +#include <private/qguiapplication_p.h> #include "qevent.h" #include "qfile.h" #include "qfileinfo.h" @@ -65,6 +61,7 @@ #include "qimagewriter.h" #include "qpaintengine.h" #include "qthread.h" +#include "qdebug.h" #ifdef Q_WS_MAC # include "private/qt_mac_p.h" @@ -86,7 +83,7 @@ #endif #include "qpixmap_raster_p.h" -#include "private/qstylehelper_p.h" +#include "private/qhexstring_p.h" QT_BEGIN_NAMESPACE @@ -98,25 +95,17 @@ Q_GUI_EXPORT qint64 qt_pixmap_id(const QPixmap &pixmap) static bool qt_pixmap_thread_test() { - if (!qApp) { + if (!QCoreApplication::instance()) { qFatal("QPixmap: Must construct a QApplication before a QPaintDevice"); return false; } if (qApp->thread() != QThread::currentThread()) { bool fail = false; -#if defined (Q_WS_X11) - if (!QApplication::testAttribute(Qt::AA_X11InitThreads)) - fail = true; -#elif defined (Q_WS_QPA) - if (!QApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedPixmaps)) { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedPixmaps)) { printf("Lighthouse plugin does not support threaded pixmaps!\n"); fail = true; } -#else - if (QApplicationPrivate::graphics_system_name != QLatin1String("raster")) - fail = true; -#endif if (fail) { qWarning("QPixmap: It is not safe to use pixmaps outside the GUI thread"); return false; @@ -130,16 +119,8 @@ void QPixmap::init(int w, int h, Type type) init(w, h, int(type)); } -extern QApplication::Type qt_appType; - void QPixmap::init(int w, int h, int type) { - if (qt_appType == QApplication::Tty) { - qWarning("QPixmap: Cannot create a QPixmap when no GUI is being used"); - data = 0; - return; - } - if ((w > 0 && h > 0) || type == QPixmapData::BitmapType) data = QPixmapData::create(w, h, (QPixmapData::PixelType) type); else @@ -657,65 +638,6 @@ int QPixmap::depth() const pixmap = pixmap.copy(QRect(QPoint(0, 0), size)); \endcode */ -#ifdef QT3_SUPPORT -void QPixmap::resize_helper(const QSize &s) -{ - int w = s.width(); - int h = s.height(); - if (w < 1 || h < 1) { - *this = QPixmap(); - return; - } - - if (size() == s) - return; - - // QPixmap.data member may be QRuntimePixmapData so use pixmapData() function to get - // the actual underlaying runtime pixmap data. - QPixmapData *pd = pixmapData(); - - // Create new pixmap - QPixmap pm(QSize(w, h), pd ? pd->type : QPixmapData::PixmapType); - bool uninit = false; -#if defined(Q_WS_X11) - QX11PixmapData *x11Data = pd && pd->classId() == QPixmapData::X11Class ? static_cast<QX11PixmapData*>(pd) : 0; - if (x11Data) { - pm.x11SetScreen(x11Data->xinfo.screen()); - uninit = x11Data->flags & QX11PixmapData::Uninitialized; - } -#elif defined(Q_WS_MAC) - QMacPixmapData *macData = pd && pd->classId() == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(pd) : 0; - if (macData) - uninit = macData->uninit; -#endif - if (!uninit && !isNull()) { - // Copy old pixmap - if (hasAlphaChannel()) - pm.fill(Qt::transparent); - QPainter p(&pm); - p.drawPixmap(0, 0, *this, 0, 0, qMin(width(), w), qMin(height(), h)); - } - -#if defined(Q_WS_X11) - if (x11Data && x11Data->x11_mask) { - QPixmapData *newPd = pm.pixmapData(); - QX11PixmapData *pmData = (newPd && newPd->classId() == QPixmapData::X11Class) - ? static_cast<QX11PixmapData*>(newPd) : 0; - if (pmData) { - pmData->x11_mask = (Qt::HANDLE)XCreatePixmap(X11->display, - RootWindow(x11Data->xinfo.display(), - x11Data->xinfo.screen()), - w, h, 1); - GC gc = XCreateGC(X11->display, pmData->x11_mask, 0, 0); - XCopyArea(X11->display, x11Data->x11_mask, pmData->x11_mask, gc, 0, 0, - qMin(width(), w), qMin(height(), h), 0, 0); - XFreeGC(X11->display, gc); - } - } -#endif - *this = pm; -} -#endif /*! \fn void QPixmap::resize(int width, int height) @@ -986,21 +908,24 @@ bool QPixmap::doImageIO(QImageWriter *writer, int quality) const return writer->write(toImage()); } - -// The implementation (and documentation) of -// QPixmap::fill(const QWidget *, const QPoint &) -// is in qwidget.cpp - /*! - \fn void QPixmap::fill(const QWidget *widget, int x, int y) + \fn void QPixmap::fill(const QPaintDevice *device, int x, int y) \overload - Fills the pixmap with the \a widget's background color or pixmap. + \obsolete + + Fills the pixmap with the \a device's background color or pixmap. The given point, (\a x, \a y), defines an offset in widget coordinates to which the pixmap's top-left pixel will be mapped to. */ +void QPixmap::fill(const QPaintDevice *, const QPoint &) +{ + qWarning() << "QPixmap::fill(const QPaintDevice *device, const QPoint &offset) is deprecated, ignored"; +} + + /*! Fills the pixmap with the given \a color. @@ -1072,6 +997,7 @@ qint64 QPixmap::cacheKey() const return data->cacheKey(); } +#if 0 static void sendResizeEvents(QWidget *target) { QResizeEvent e(target->size(), QSize()); @@ -1084,9 +1010,10 @@ static void sendResizeEvents(QWidget *target) sendResizeEvents(child); } } +#endif /*! - \fn QPixmap QPixmap::grabWidget(QWidget * widget, const QRect &rectangle) + \fn QPixmap QPixmap::grabWidget(QPaintDevice * widget, const QRect &rectangle) Creates a pixmap and paints the given \a widget, restricted by the given \a rectangle, in it. If the \a widget has any children, then @@ -1115,8 +1042,13 @@ static void sendResizeEvents(QWidget *target) \sa grabWindow() */ -QPixmap QPixmap::grabWidget(QWidget * widget, const QRect &rect) +QPixmap QPixmap::grabWidget(QPaintDevice *, const QRect &) { + // ### Qt5: should we keep or remove this method? + // SC solution would be to install a callback form QtWidgets, but ugly. + qWarning() << "QPixmap::grabWidget is deprecated, use QWidget::render() instead"; + return QPixmap(); +#if 0 if (!widget) return QPixmap(); @@ -1142,6 +1074,7 @@ QPixmap QPixmap::grabWidget(QWidget * widget, const QRect &rect) widget->d_func()->render(&res, QPoint(), r, QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask, true); return res; +#endif } /*! @@ -1217,7 +1150,6 @@ QPixmap QPixmap::grabWidget(QWidget * widget, const QRect &rect) graphics system is explicitly enabled. \sa detach() - \sa QApplication::setGraphicsSystem() */ Qt::HANDLE QPixmap::handle() const @@ -1232,104 +1164,6 @@ Qt::HANDLE QPixmap::handle() const #endif -#ifdef QT3_SUPPORT -static Qt::ImageConversionFlags colorModeToFlags(QPixmap::ColorMode mode) -{ - Qt::ImageConversionFlags flags = Qt::AutoColor; - switch (mode) { - case QPixmap::Color: - flags |= Qt::ColorOnly; - break; - case QPixmap::Mono: - flags |= Qt::MonoOnly; - break; - default: - break;// Nothing. - } - return flags; -} - -/*! - Use the constructor that takes a Qt::ImageConversionFlag instead. -*/ - -QPixmap::QPixmap(const QString& fileName, const char *format, ColorMode mode) - : QPaintDevice() -{ - init(0, 0, QPixmapData::PixmapType); - if (!qt_pixmap_thread_test()) - return; - - load(fileName, format, colorModeToFlags(mode)); -} - -/*! - Constructs a pixmap from the QImage \a image. - - Use the static fromImage() function instead. -*/ -QPixmap::QPixmap(const QImage& image) - : QPaintDevice() -{ - init(0, 0, QPixmapData::PixmapType); - if (!qt_pixmap_thread_test()) - return; - - if (data && data->pixelType() == QPixmapData::BitmapType) - *this = QBitmap::fromImage(image); - else - *this = fromImage(image); -} - -/*! - \overload - - Converts the given \a image to a pixmap that is assigned to this - pixmap. - - Use the static fromImage() function instead. -*/ - -QPixmap &QPixmap::operator=(const QImage &image) -{ - if (data && data->pixelType() == QPixmapData::BitmapType) - *this = QBitmap::fromImage(image); - else - *this = fromImage(image); - return *this; -} - -/*! - Use the load() function that takes a Qt::ImageConversionFlag instead. -*/ - -bool QPixmap::load(const QString &fileName, const char *format, ColorMode mode) -{ - return load(fileName, format, colorModeToFlags(mode)); -} - -/*! - Use the loadFromData() function that takes a Qt::ImageConversionFlag instead. -*/ - -bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, ColorMode mode) -{ - return loadFromData(buf, len, format, colorModeToFlags(mode)); -} - -/*! - Use the static fromImage() function instead. -*/ -bool QPixmap::convertFromImage(const QImage &image, ColorMode mode) -{ - if (data && data->pixelType() == QPixmapData::BitmapType) - *this = QBitmap::fromImage(image, colorModeToFlags(mode)); - else - *this = fromImage(image, colorModeToFlags(mode)); - return !isNull(); -} - -#endif /***************************************************************************** QPixmap stream functions @@ -1375,34 +1209,6 @@ QDataStream &operator>>(QDataStream &stream, QPixmap &pixmap) #endif // QT_NO_DATASTREAM -#ifdef QT3_SUPPORT -Q_GUI_EXPORT void copyBlt(QPixmap *dst, int dx, int dy, - const QPixmap *src, int sx, int sy, int sw, int sh) -{ - Q_ASSERT_X(dst, "::copyBlt", "Destination pixmap must be non-null"); - Q_ASSERT_X(src, "::copyBlt", "Source pixmap must be non-null"); - - if (src->hasAlphaChannel()) { - if (dst->paintEngine()->hasFeature(QPaintEngine::PorterDuff)) { - QPainter p(dst); - p.setCompositionMode(QPainter::CompositionMode_Source); - p.drawPixmap(dx, dy, *src, sx, sy, sw, sh); - } else { - QImage image = dst->toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied); - QPainter p(&image); - p.setCompositionMode(QPainter::CompositionMode_Source); - p.drawPixmap(dx, dy, *src, sx, sy, sw, sh); - p.end(); - *dst = QPixmap::fromImage(image); - } - } else { - QPainter p(dst); - p.drawPixmap(dx, dy, *src, sx, sy, sw, sh); - } - -} -#endif - /*! \internal */ @@ -1990,7 +1796,7 @@ int QPixmap::defaultDepth() #elif defined(Q_OS_SYMBIAN) return S60->screenDepth; #elif defined(Q_WS_QPA) - return 32; //LITE: use graphicssystem (we should do that in general) + return 32; //LITE: ### use graphicssystem (we should do that in general) #endif } @@ -2082,9 +1888,7 @@ QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags) if (image.isNull()) return QPixmap(); - QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem(); - QScopedPointer<QPixmapData> data(gs ? gs->createPixmapData(QPixmapData::PixmapType) - : QGraphicsSystem::createDefaultPixmapData(QPixmapData::PixmapType)); + QScopedPointer<QPixmapData> data(QGuiApplicationPrivate::platformIntegration()->createPixmapData(QPixmapData::PixmapType)); data->fromImage(image, flags); return QPixmap(data.take()); } @@ -2103,9 +1907,7 @@ QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags) */ QPixmap QPixmap::fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags) { - QGraphicsSystem *gs = QApplicationPrivate::graphicsSystem(); - QScopedPointer<QPixmapData> data(gs ? gs->createPixmapData(QPixmapData::PixmapType) - : QGraphicsSystem::createDefaultPixmapData(QPixmapData::PixmapType)); + QScopedPointer<QPixmapData> data(QGuiApplicationPrivate::platformIntegration()->createPixmapData(QPixmapData::PixmapType)); data->fromImageReader(imageReader, flags); return QPixmap(data.take()); } |