1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the QtGui module of the Qt Toolkit. |
7 ** This file is part of the QtGui module of the Qt Toolkit. |
8 ** |
8 ** |
355 QPixmap QPixmap::copy(const QRect &rect) const |
353 QPixmap QPixmap::copy(const QRect &rect) const |
356 { |
354 { |
357 if (isNull()) |
355 if (isNull()) |
358 return QPixmap(); |
356 return QPixmap(); |
359 |
357 |
360 const QRect r = rect.isEmpty() ? QRect(0, 0, width(), height()) : rect; |
358 QRect r(0, 0, width(), height()); |
|
359 if (!rect.isEmpty()) |
|
360 r = r.intersected(rect); |
361 |
361 |
362 QPixmapData *d = data->createCompatiblePixmapData(); |
362 QPixmapData *d = data->createCompatiblePixmapData(); |
363 d->copy(data.data(), r); |
363 d->copy(data.data(), r); |
364 return QPixmap(d); |
364 return QPixmap(d); |
365 } |
365 } |
829 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); |
830 |
830 |
831 if (QPixmapCache::find(key, *this)) |
831 if (QPixmapCache::find(key, *this)) |
832 return true; |
832 return true; |
833 |
833 |
834 QPixmapData *tmp = QPixmapData::create(0, 0, QPixmapData::PixmapType); |
834 QScopedPointer<QPixmapData> tmp(QPixmapData::create(0, 0, data ? data->type : QPixmapData::PixmapType)); |
835 if (tmp->fromFile(fileName, format, flags)) { |
835 if (tmp->fromFile(fileName, format, flags)) { |
836 data = tmp; |
836 data = tmp.take(); |
837 QPixmapCache::insert(key, *this); |
837 QPixmapCache::insert(key, *this); |
838 return true; |
838 return true; |
839 } |
839 } |
840 delete tmp; |
840 |
841 return false; |
841 return false; |
842 } |
842 } |
843 |
843 |
844 /*! |
844 /*! |
845 \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) |
1014 qint64 QPixmap::cacheKey() const |
1014 qint64 QPixmap::cacheKey() const |
1015 { |
1015 { |
1016 if (isNull()) |
1016 if (isNull()) |
1017 return 0; |
1017 return 0; |
1018 |
1018 |
1019 int classKey = data->classId(); |
1019 Q_ASSERT(data); |
1020 if (classKey >= 1024) |
1020 return data->cacheKey(); |
1021 classKey = -(classKey >> 10); |
|
1022 return ((((qint64) classKey) << 56) |
|
1023 | (((qint64) data->serialNumber()) << 32) |
|
1024 | ((qint64) (data->detach_no))); |
|
1025 } |
1021 } |
1026 |
1022 |
1027 static void sendResizeEvents(QWidget *target) |
1023 static void sendResizeEvents(QWidget *target) |
1028 { |
1024 { |
1029 QResizeEvent e(target->size(), QSize()); |
1025 QResizeEvent e(target->size(), QSize()); |
1665 \row |
1661 \row |
1666 \o Alpha component |
1662 \o Alpha component |
1667 \o |
1663 \o |
1668 |
1664 |
1669 The hasAlphaChannel() returns true if the pixmap has a format that |
1665 The hasAlphaChannel() returns true if the pixmap has a format that |
1670 respects the alpha channel, otherwise returns false, while the |
1666 respects the alpha channel, otherwise returns false. The hasAlpha(), |
1671 hasAlpha() function returns true if the pixmap has an alpha |
1667 setMask() and mask() functions are legacy and should not be used. |
1672 channel \e or a mask (otherwise false). The mask() function returns |
1668 They are potentially very slow. |
1673 the mask as a QBitmap object, which can be set using setMask(). |
|
1674 |
1669 |
1675 The createHeuristicMask() function creates and returns a 1-bpp |
1670 The createHeuristicMask() function creates and returns a 1-bpp |
1676 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 |
1677 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 |
1678 pixels of that color, starting at all the edges. The |
1673 pixels of that color, starting at all the edges. The |
1754 */ |
1749 */ |
1755 |
1750 |
1756 /*! |
1751 /*! |
1757 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 |
1758 mask, otherwise returns false. |
1753 mask, otherwise returns false. |
|
1754 |
|
1755 \warning This is potentially an expensive operation. |
1759 |
1756 |
1760 \sa hasAlphaChannel(), mask() |
1757 \sa hasAlphaChannel(), mask() |
1761 */ |
1758 */ |
1762 bool QPixmap::hasAlpha() const |
1759 bool QPixmap::hasAlpha() const |
1763 { |
1760 { |
1932 QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data.data()); |
1929 QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data.data()); |
1933 rasterData->image.detach(); |
1930 rasterData->image.detach(); |
1934 } |
1931 } |
1935 |
1932 |
1936 if (data->is_cached && data->ref == 1) |
1933 if (data->is_cached && data->ref == 1) |
1937 QImagePixmapCleanupHooks::executePixmapModificationHooks(this); |
1934 QImagePixmapCleanupHooks::executePixmapDataModificationHooks(data.data()); |
1938 |
1935 |
1939 #if defined(Q_WS_MAC) |
1936 #if defined(Q_WS_MAC) |
1940 QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0; |
1937 QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0; |
1941 if (macData) { |
1938 if (macData) { |
1942 if (macData->cg_mask) { |
1939 if (macData->cg_mask) { |
2020 The grabWindow() function grabs pixels from the screen, not from |
2017 The grabWindow() function grabs pixels from the screen, not from |
2021 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 |
2022 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, |
2023 too. The mouse cursor is generally not grabbed. |
2020 too. The mouse cursor is generally not grabbed. |
2024 |
2021 |
2025 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 |
2026 as the root window, and another window partially or entirely |
2023 as the root window, and another window partially or entirely |
2027 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 |
2028 overlying window. The contents of the obscured areas in the |
2025 overlying window. The contents of the obscured areas in the |
2029 pixmap will be undefined and uninitialized. |
2026 pixmap will be undefined and uninitialized. |
2030 |
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 |
2031 \warning In general, grabbing an area outside the screen is not |
2032 \warning In general, grabbing an area outside the screen is not |
2032 safe. This depends on the underlying window system. |
2033 safe. This depends on the underlying window system. |
2033 |
2034 |
2034 \sa grabWidget(), {Screenshot Example} |
2035 \sa grabWidget(), {Screenshot Example} |
2035 */ |
2036 */ |