Changeset 846 for trunk/src/gui/image/qpixmap.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/image/qpixmap.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 83 83 84 84 #include "qpixmap_raster_p.h" 85 #include "private/qstylehelper_p.h" 85 86 86 87 QT_BEGIN_NAMESPACE … … 579 580 QSize QPixmap::size() const 580 581 { 581 return data ? QSize(data->width(), data->height()) : QSize( );582 return data ? QSize(data->width(), data->height()) : QSize(0, 0); 582 583 } 583 584 … … 636 637 return; 637 638 639 // QPixmap.data member may be QRuntimePixmapData so use pixmapData() function to get 640 // the actual underlaying runtime pixmap data. 641 QPixmapData *pd = pixmapData(); 642 638 643 // Create new pixmap 639 QPixmap pm(QSize(w, h), data ? data->type : QPixmapData::PixmapType);644 QPixmap pm(QSize(w, h), pd ? pd->type : QPixmapData::PixmapType); 640 645 bool uninit = false; 641 646 #if defined(Q_WS_X11) 642 QX11PixmapData *x11Data = data && data->classId() == QPixmapData::X11Class ? static_cast<QX11PixmapData*>(data.data()) : 0;647 QX11PixmapData *x11Data = pd && pd->classId() == QPixmapData::X11Class ? static_cast<QX11PixmapData*>(pd) : 0; 643 648 if (x11Data) { 644 649 pm.x11SetScreen(x11Data->xinfo.screen()); … … 646 651 } 647 652 #elif defined(Q_WS_MAC) 648 QMacPixmapData *macData = data && data->classId() == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0;653 QMacPixmapData *macData = pd && pd->classId() == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(pd) : 0; 649 654 if (macData) 650 655 uninit = macData->uninit; … … 660 665 #if defined(Q_WS_X11) 661 666 if (x11Data && x11Data->x11_mask) { 662 QX11PixmapData *pmData = static_cast<QX11PixmapData*>(pm.data.data()); 663 pmData->x11_mask = (Qt::HANDLE)XCreatePixmap(X11->display, 664 RootWindow(x11Data->xinfo.display(), 665 x11Data->xinfo.screen()), 666 w, h, 1); 667 GC gc = XCreateGC(X11->display, pmData->x11_mask, 0, 0); 668 XCopyArea(X11->display, x11Data->x11_mask, pmData->x11_mask, gc, 0, 0, qMin(width(), w), qMin(height(), h), 0, 0); 669 XFreeGC(X11->display, gc); 667 QPixmapData *newPd = pm.pixmapData(); 668 QX11PixmapData *pmData = (newPd && newPd->classId() == QPixmapData::X11Class) 669 ? static_cast<QX11PixmapData*>(newPd) : 0; 670 if (pmData) { 671 pmData->x11_mask = (Qt::HANDLE)XCreatePixmap(X11->display, 672 RootWindow(x11Data->xinfo.display(), 673 x11Data->xinfo.screen()), 674 w, h, 1); 675 GC gc = XCreateGC(X11->display, pmData->x11_mask, 0, 0); 676 XCopyArea(X11->display, x11Data->x11_mask, pmData->x11_mask, gc, 0, 0, 677 qMin(width(), w), qMin(height(), h), 0, 0); 678 XFreeGC(X11->display, gc); 679 } 670 680 } 671 681 #endif … … 766 776 Creates and returns a mask for this pixmap based on the given \a 767 777 maskColor. If the \a mode is Qt::MaskInColor, all pixels matching the 768 maskColor will be opaque. If \a mode is Qt::MaskOutColor, all pixels769 matching the maskColor will be transparent.778 maskColor will be transparent. If \a mode is Qt::MaskOutColor, all pixels 779 matching the maskColor will be opaque. 770 780 771 781 This function is slow because it involves converting to/from a … … 826 836 827 837 QFileInfo info(fileName); 828 QString key = QLatin1String("qt_pixmap_") + info.absoluteFilePath() + QLatin1Char('_') + QString::number(info.lastModified().toTime_t()) + QLatin1Char('_') + 829 QString::number(info.size()) + QLatin1Char('_') + QString::number(data ? data->pixelType() : QPixmapData::PixmapType); 838 QString key = QLatin1Literal("qt_pixmap") 839 % info.absoluteFilePath() 840 % HexString<uint>(info.lastModified().toTime_t()) 841 % HexString<quint64>(info.size()) 842 % HexString<uint>(data ? data->pixelType() : QPixmapData::PixmapType); 843 844 // Note: If no extension is provided, we try to match the 845 // file against known plugin extensions 846 if (!info.completeSuffix().isEmpty() && !info.exists()) 847 return false; 830 848 831 849 if (QPixmapCache::find(key, *this)) … … 1072 1090 sendResizeEvents(widget); 1073 1091 1092 widget->d_func()->prepareToRender(QRegion(), 1093 QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask); 1094 1074 1095 QRect r(rect); 1075 1096 if (r.width() < 0) … … 1082 1103 1083 1104 QPixmap res(r.size()); 1084 widget->render(&res, QPoint(), r, 1085 QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask); 1105 if (!qt_widget_private(widget)->isOpaque) 1106 res.fill(Qt::transparent); 1107 1108 widget->d_func()->render(&res, QPoint(), r, QWidget::DrawWindowBackground 1109 | QWidget::DrawChildren | QWidget::IgnoreMask, true); 1086 1110 return res; 1087 1111 } … … 1161 1185 { 1162 1186 #if defined(Q_WS_X11) 1163 if (data && data->classId() == QPixmapData::X11Class) 1164 return static_cast<const QX11PixmapData*>(data.constData())->handle(); 1187 const QPixmapData *pd = pixmapData(); 1188 if (pd) { 1189 if (pd->classId() == QPixmapData::X11Class) 1190 return static_cast<const QX11PixmapData*>(pd)->handle(); 1191 else 1192 qWarning("QPixmap::handle(): Pixmap is not an X11 class pixmap"); 1193 } 1165 1194 #endif 1166 1195 return 0; … … 1279 1308 valid image file. 1280 1309 1281 \sa QPixmap::save(), { Format of the QDataStream Operators}1310 \sa QPixmap::save(), {Serializing Qt Data Types} 1282 1311 */ 1283 1312 … … 1292 1321 Reads an image from the given \a stream into the given \a pixmap. 1293 1322 1294 \sa QPixmap::load(), { Format of the QDataStream Operators}1323 \sa QPixmap::load(), {Serializing Qt Data Types} 1295 1324 */ 1296 1325 … … 1364 1393 1365 1394 /*! 1366 \fn bool QPixmap::convertFromImage(const QImage &image, Qt::ImageConversionFlags flags) 1367 1368 Use the static fromImage() function instead. 1369 */ 1395 Replaces this pixmap's data with the given \a image using the 1396 specified \a flags to control the conversion. The \a flags 1397 argument is a bitwise-OR of the \l{Qt::ImageConversionFlags}. 1398 Passing 0 for \a flags sets all the default options. Returns true 1399 if the result is that this pixmap is not null. 1400 1401 Note: this function was part of Qt 3 support in Qt 4.6 and earlier. 1402 It has been promoted to official API status in 4.7 to support updating 1403 the pixmap's image without creating a new QPixmap as fromImage() would. 1404 1405 \sa fromImage() 1406 \since 4.7 1407 */ 1408 bool QPixmap::convertFromImage(const QImage &image, Qt::ImageConversionFlags flags) 1409 { 1410 if (image.isNull() || !data) 1411 *this = QPixmap::fromImage(image, flags); 1412 else 1413 data->fromImage(image, flags); 1414 return !isNull(); 1415 } 1370 1416 1371 1417 /*! … … 1735 1781 pixmap. 1736 1782 1783 \note When using the native X11 graphics system, the pixmap 1784 becomes invalid when the QApplication instance is destroyed. 1785 1737 1786 \sa QBitmap, QImage, QImageReader, QImageWriter 1738 1787 */ … … 1753 1802 mask, otherwise returns false. 1754 1803 1755 \warning This is potentially an expensive operation.1756 1757 1804 \sa hasAlphaChannel(), mask() 1758 1805 */ 1759 1806 bool QPixmap::hasAlpha() const 1760 1807 { 1761 return data && (data->hasAlphaChannel() || !data->mask().isNull()); 1808 #if defined(Q_WS_X11) 1809 if (data && data->hasAlphaChannel()) 1810 return true; 1811 QPixmapData *pd = pixmapData(); 1812 if (pd && pd->classId() == QPixmapData::X11Class) { 1813 QX11PixmapData *x11Data = static_cast<QX11PixmapData*>(pd); 1814 #ifndef QT_NO_XRENDER 1815 if (x11Data->picture && x11Data->d == 32) 1816 return true; 1817 #endif 1818 if (x11Data->d == 1 || x11Data->x11_mask) 1819 return true; 1820 } 1821 return false; 1822 #else 1823 return data && data->hasAlphaChannel(); 1824 #endif 1762 1825 } 1763 1826 … … 1927 1990 return; 1928 1991 1929 QPixmapData::ClassId id = data->classId(); 1992 // QPixmap.data member may be QRuntimePixmapData so use pixmapData() function to get 1993 // the actual underlaying runtime pixmap data. 1994 QPixmapData *pd = pixmapData(); 1995 QPixmapData::ClassId id = pd->classId(); 1930 1996 if (id == QPixmapData::RasterClass) { 1931 QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>( data.data());1997 QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(pd); 1932 1998 rasterData->image.detach(); 1933 1999 } 1934 2000 1935 2001 if (data->is_cached && data->ref == 1) 1936 QImagePixmapCleanupHooks::executePixmapDataModificationHooks( data.data());2002 QImagePixmapCleanupHooks::executePixmapDataModificationHooks(pd); 1937 2003 1938 2004 #if defined(Q_WS_MAC) 1939 QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>( data.data()) : 0;2005 QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(pd) : 0; 1940 2006 if (macData) { 1941 2007 if (macData->cg_mask) { … … 1952 2018 1953 2019 #if defined(Q_WS_X11) 1954 if ( data->classId() == QPixmapData::X11Class) {1955 QX11PixmapData *d = static_cast<QX11PixmapData*>( data.data());2020 if (pd->classId() == QPixmapData::X11Class) { 2021 QX11PixmapData *d = static_cast<QX11PixmapData*>(pd); 1956 2022 d->flags &= ~QX11PixmapData::Uninitialized; 1957 2023 … … 1983 2049 use QBitmap::fromImage() instead. 1984 2050 1985 \sa toImage(), {QPixmap#Pixmap Conversion}{Pixmap Conversion}2051 \sa fromImageReader(), toImage(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} 1986 2052 */ 1987 2053 QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags) … … 1998 2064 1999 2065 /*! 2066 \fn QPixmap QPixmap::fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags) 2067 2068 Create a QPixmap from an image read directly from an \a imageReader. 2069 The \a flags argument is a bitwise-OR of the \l{Qt::ImageConversionFlags}. 2070 Passing 0 for \a flags sets all the default options. 2071 2072 On some systems, reading an image directly to QPixmap can use less memory than 2073 reading a QImage to convert it to QPixmap. 2074 2075 \sa fromImage(), toImage(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} 2076 */ 2077 QPixmap QPixmap::fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags) 2078 { 2079 QGraphicsSystem *gs = QApplicationPrivate::graphicsSystem(); 2080 QScopedPointer<QPixmapData> data(gs ? gs->createPixmapData(QPixmapData::PixmapType) 2081 : QGraphicsSystem::createDefaultPixmapData(QPixmapData::PixmapType)); 2082 data->fromImageReader(imageReader, flags); 2083 return QPixmap(data.take()); 2084 } 2085 2086 /*! 2000 2087 \fn QPixmap QPixmap::grabWindow(WId window, int x, int y, int 2001 2088 width, int height) … … 2043 2130 QPixmapData* QPixmap::pixmapData() const 2044 2131 { 2045 return data.data(); 2046 } 2132 if (data) { 2133 QPixmapData* pm = data.data(); 2134 return pm->runtimeData() ? pm->runtimeData() : pm; 2135 } 2136 2137 return 0; 2138 } 2139 2047 2140 2048 2141 /*!
Note:
See TracChangeset
for help on using the changeset viewer.