src/gui/image/qpixmap.cpp
branchRCL_3
changeset 8 3f74d0d4af4c
parent 4 3b1da2848fc7
equal deleted inserted replaced
6:dee5afe5301f 8:3f74d0d4af4c
   318 */
   318 */
   319 
   319 
   320 QPixmap::~QPixmap()
   320 QPixmap::~QPixmap()
   321 {
   321 {
   322     Q_ASSERT(!data || data->ref >= 1); // Catch if ref-counting changes again
   322     Q_ASSERT(!data || data->ref >= 1); // Catch if ref-counting changes again
   323     if (data && data->is_cached && data->ref == 1) // ref will be decrememnted after destructor returns
       
   324         QImagePixmapCleanupHooks::executePixmapDestructionHooks(this);
       
   325 }
   323 }
   326 
   324 
   327 /*!
   325 /*!
   328   \internal
   326   \internal
   329 */
   327 */
   831         QString::number(info.size()) + QLatin1Char('_') + QString::number(data ? data->pixelType() : QPixmapData::PixmapType);
   829         QString::number(info.size()) + QLatin1Char('_') + QString::number(data ? data->pixelType() : QPixmapData::PixmapType);
   832 
   830 
   833     if (QPixmapCache::find(key, *this))
   831     if (QPixmapCache::find(key, *this))
   834         return true;
   832         return true;
   835 
   833 
   836     bool ok;
   834     QScopedPointer<QPixmapData> tmp(QPixmapData::create(0, 0, data ? data->type : QPixmapData::PixmapType));
   837 
   835     if (tmp->fromFile(fileName, format, flags)) {
   838     if (data) {
   836         data = tmp.take();
   839         ok = data->fromFile(fileName, format, flags);
       
   840     } else {
       
   841         QScopedPointer<QPixmapData> tmp(QPixmapData::create(0, 0, QPixmapData::PixmapType));
       
   842         ok = tmp->fromFile(fileName, format, flags);
       
   843         if (ok)
       
   844             data = tmp.take();
       
   845     }
       
   846 
       
   847     if (ok)
       
   848         QPixmapCache::insert(key, *this);
   837         QPixmapCache::insert(key, *this);
   849 
   838         return true;
   850     return ok;
   839     }
       
   840 
       
   841     return false;
   851 }
   842 }
   852 
   843 
   853 /*!
   844 /*!
   854     \fn bool QPixmap::loadFromData(const uchar *data, uint len, const char *format, Qt::ImageConversionFlags flags)
   845     \fn bool QPixmap::loadFromData(const uchar *data, uint len, const char *format, Qt::ImageConversionFlags flags)
   855 
   846 
  1023 qint64 QPixmap::cacheKey() const
  1014 qint64 QPixmap::cacheKey() const
  1024 {
  1015 {
  1025     if (isNull())
  1016     if (isNull())
  1026         return 0;
  1017         return 0;
  1027 
  1018 
  1028     int classKey = data->classId();
  1019     Q_ASSERT(data);
  1029     if (classKey >= 1024)
  1020     return data->cacheKey();
  1030         classKey = -(classKey >> 10);
       
  1031     return ((((qint64) classKey) << 56)
       
  1032             | (((qint64) data->serialNumber()) << 32)
       
  1033             | ((qint64) (data->detach_no)));
       
  1034 }
  1021 }
  1035 
  1022 
  1036 static void sendResizeEvents(QWidget *target)
  1023 static void sendResizeEvents(QWidget *target)
  1037 {
  1024 {
  1038     QResizeEvent e(target->size(), QSize());
  1025     QResizeEvent e(target->size(), QSize());
  1674     \row
  1661     \row
  1675     \o Alpha component
  1662     \o Alpha component
  1676     \o
  1663     \o
  1677 
  1664 
  1678     The hasAlphaChannel() returns true if the pixmap has a format that
  1665     The hasAlphaChannel() returns true if the pixmap has a format that
  1679     respects the alpha channel, otherwise returns false, while the
  1666     respects the alpha channel, otherwise returns false. The hasAlpha(),
  1680     hasAlpha() function returns true if the pixmap has an alpha
  1667     setMask() and mask() functions are legacy and should not be used.
  1681     channel \e or a mask (otherwise false). The mask() function returns
  1668     They are potentially very slow.
  1682     the mask as a QBitmap object, which can be set using setMask().
       
  1683 
  1669 
  1684     The createHeuristicMask() function creates and returns a 1-bpp
  1670     The createHeuristicMask() function creates and returns a 1-bpp
  1685     heuristic mask (i.e. a QBitmap) for this pixmap. It works by
  1671     heuristic mask (i.e. a QBitmap) for this pixmap. It works by
  1686     selecting a color from one of the corners and then chipping away
  1672     selecting a color from one of the corners and then chipping away
  1687     pixels of that color, starting at all the edges. The
  1673     pixels of that color, starting at all the edges. The
  1763 */
  1749 */
  1764 
  1750 
  1765 /*!
  1751 /*!
  1766     Returns true if this pixmap has an alpha channel, \e or has a
  1752     Returns true if this pixmap has an alpha channel, \e or has a
  1767     mask, otherwise returns false.
  1753     mask, otherwise returns false.
       
  1754 
       
  1755     \warning This is potentially an expensive operation.
  1768 
  1756 
  1769     \sa hasAlphaChannel(), mask()
  1757     \sa hasAlphaChannel(), mask()
  1770 */
  1758 */
  1771 bool QPixmap::hasAlpha() const
  1759 bool QPixmap::hasAlpha() const
  1772 {
  1760 {
  1941         QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data.data());
  1929         QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data.data());
  1942         rasterData->image.detach();
  1930         rasterData->image.detach();
  1943     }
  1931     }
  1944 
  1932 
  1945     if (data->is_cached && data->ref == 1)
  1933     if (data->is_cached && data->ref == 1)
  1946         QImagePixmapCleanupHooks::executePixmapModificationHooks(this);
  1934         QImagePixmapCleanupHooks::executePixmapDataModificationHooks(data.data());
  1947 
  1935 
  1948 #if defined(Q_WS_MAC)
  1936 #if defined(Q_WS_MAC)
  1949     QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0;
  1937     QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0;
  1950     if (macData) {
  1938     if (macData) {
  1951         if (macData->cg_mask) {
  1939         if (macData->cg_mask) {
  2029     The grabWindow() function grabs pixels from the screen, not from
  2017     The grabWindow() function grabs pixels from the screen, not from
  2030     the window, i.e. if there is another window partially or entirely
  2018     the window, i.e. if there is another window partially or entirely
  2031     over the one you grab, you get pixels from the overlying window,
  2019     over the one you grab, you get pixels from the overlying window,
  2032     too. The mouse cursor is generally not grabbed.
  2020     too. The mouse cursor is generally not grabbed.
  2033 
  2021 
  2034     Note on X11that if the given \a window doesn't have the same depth
  2022     Note on X11 that if the given \a window doesn't have the same depth
  2035     as the root window, and another window partially or entirely
  2023     as the root window, and another window partially or entirely
  2036     obscures the one you grab, you will \e not get pixels from the
  2024     obscures the one you grab, you will \e not get pixels from the
  2037     overlying window.  The contents of the obscured areas in the
  2025     overlying window.  The contents of the obscured areas in the
  2038     pixmap will be undefined and uninitialized.
  2026     pixmap will be undefined and uninitialized.
  2039 
  2027 
       
  2028     On Windows Vista and above grabbing a layered window, which is
       
  2029     created by setting the Qt::WA_TranslucentBackground attribute, will
       
  2030     not work. Instead grabbing the desktop widget should work.
       
  2031 
  2040     \warning In general, grabbing an area outside the screen is not
  2032     \warning In general, grabbing an area outside the screen is not
  2041     safe. This depends on the underlying window system.
  2033     safe. This depends on the underlying window system.
  2042 
  2034 
  2043     \sa grabWidget(), {Screenshot Example}
  2035     \sa grabWidget(), {Screenshot Example}
  2044 */
  2036 */