src/gui/image/qpixmap.cpp
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
--- a/src/gui/image/qpixmap.cpp	Tue Feb 02 00:43:10 2010 +0200
+++ b/src/gui/image/qpixmap.cpp	Wed Mar 31 11:06:36 2010 +0300
@@ -1,6 +1,6 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
 **
@@ -320,8 +320,6 @@
 QPixmap::~QPixmap()
 {
     Q_ASSERT(!data || data->ref >= 1); // Catch if ref-counting changes again
-    if (data && data->is_cached && data->ref == 1) // ref will be decrememnted after destructor returns
-        QImagePixmapCleanupHooks::executePixmapDestructionHooks(this);
 }
 
 /*!
@@ -357,7 +355,9 @@
     if (isNull())
         return QPixmap();
 
-    const QRect r = rect.isEmpty() ? QRect(0, 0, width(), height()) : rect;
+    QRect r(0, 0, width(), height());
+    if (!rect.isEmpty())
+        r = r.intersected(rect);
 
     QPixmapData *d = data->createCompatiblePixmapData();
     d->copy(data.data(), r);
@@ -831,13 +831,13 @@
     if (QPixmapCache::find(key, *this))
         return true;
 
-    QPixmapData *tmp = QPixmapData::create(0, 0, QPixmapData::PixmapType);
+    QScopedPointer<QPixmapData> tmp(QPixmapData::create(0, 0, data ? data->type : QPixmapData::PixmapType));
     if (tmp->fromFile(fileName, format, flags)) {
-        data = tmp;
+        data = tmp.take();
         QPixmapCache::insert(key, *this);
         return true;
     }
-    delete tmp;
+
     return false;
 }
 
@@ -1016,12 +1016,8 @@
     if (isNull())
         return 0;
 
-    int classKey = data->classId();
-    if (classKey >= 1024)
-        classKey = -(classKey >> 10);
-    return ((((qint64) classKey) << 56)
-            | (((qint64) data->serialNumber()) << 32)
-            | ((qint64) (data->detach_no)));
+    Q_ASSERT(data);
+    return data->cacheKey();
 }
 
 static void sendResizeEvents(QWidget *target)
@@ -1667,10 +1663,9 @@
     \o
 
     The hasAlphaChannel() returns true if the pixmap has a format that
-    respects the alpha channel, otherwise returns false, while the
-    hasAlpha() function returns true if the pixmap has an alpha
-    channel \e or a mask (otherwise false). The mask() function returns
-    the mask as a QBitmap object, which can be set using setMask().
+    respects the alpha channel, otherwise returns false. The hasAlpha(),
+    setMask() and mask() functions are legacy and should not be used.
+    They are potentially very slow.
 
     The createHeuristicMask() function creates and returns a 1-bpp
     heuristic mask (i.e. a QBitmap) for this pixmap. It works by
@@ -1757,6 +1752,8 @@
     Returns true if this pixmap has an alpha channel, \e or has a
     mask, otherwise returns false.
 
+    \warning This is potentially an expensive operation.
+
     \sa hasAlphaChannel(), mask()
 */
 bool QPixmap::hasAlpha() const
@@ -1934,7 +1931,7 @@
     }
 
     if (data->is_cached && data->ref == 1)
-        QImagePixmapCleanupHooks::executePixmapModificationHooks(this);
+        QImagePixmapCleanupHooks::executePixmapDataModificationHooks(data.data());
 
 #if defined(Q_WS_MAC)
     QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0;
@@ -2022,12 +2019,16 @@
     over the one you grab, you get pixels from the overlying window,
     too. The mouse cursor is generally not grabbed.
 
-    Note on X11that if the given \a window doesn't have the same depth
+    Note on X11 that if the given \a window doesn't have the same depth
     as the root window, and another window partially or entirely
     obscures the one you grab, you will \e not get pixels from the
     overlying window.  The contents of the obscured areas in the
     pixmap will be undefined and uninitialized.
 
+    On Windows Vista and above grabbing a layered window, which is
+    created by setting the Qt::WA_TranslucentBackground attribute, will
+    not work. Instead grabbing the desktop widget should work.
+
     \warning In general, grabbing an area outside the screen is not
     safe. This depends on the underlying window system.