From ea27ea003d826261c5ec8363cf04b464d04b202e Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Mon, 15 Aug 2016 14:08:07 +0000 Subject: [PATCH] bring back QPixmap::setAlphaChannel() and QPixmap::alphaChannel() as non-deprecated Signed-off-by: Ivailo Monev --- src/gui/image/qpixmap.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++ src/gui/image/qpixmap.h | 3 ++ 2 files changed, 74 insertions(+) diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 23dafcf1b..99a60f751 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -1610,6 +1610,77 @@ int QPixmap::metric(PaintDeviceMetric metric) const return data ? data->metric(metric) : 0; } + +/*! + \fn void QPixmap::setAlphaChannel(const QPixmap &alphaChannel) + + Sets the alpha channel of this pixmap to the given \a alphaChannel + by converting the \a alphaChannel into 32 bit and using the + intensity of the RGB pixel values. + + The effect of this function is undefined when the pixmap is being + painted on. + + \warning This is potentially an expensive operation. Most usecases + for this function are covered by QPainter and compositionModes + which will normally execute faster. + + \sa alphaChannel(), {QPixmap#Pixmap Transformations}{Pixmap + Transformations} + */ +void QPixmap::setAlphaChannel(const QPixmap &alphaChannel) +{ + if (alphaChannel.isNull()) + return; + + if (paintingActive()) { + qWarning("QPixmap::setAlphaChannel: " + "Cannot set alpha channel while pixmap is being painted on"); + return; + } + + if (width() != alphaChannel.width() && height() != alphaChannel.height()) { + qWarning("QPixmap::setAlphaChannel: " + "The pixmap and the alpha channel pixmap must have the same size"); + return; + } + + detach(); + data->setAlphaChannel(alphaChannel); +} + +/*! + + Returns the alpha channel of the pixmap as a new grayscale QPixmap in which + each pixel's red, green, and blue values are given the alpha value of the + original pixmap. The color depth of the returned pixmap is the system depth + on X11 and 8-bit on Windows and Mac OS X. + + You can use this function while debugging + to get a visible image of the alpha channel. If the pixmap doesn't have an + alpha channel, i.e., the alpha channel's value for all pixels equals + 0xff), a null pixmap is returned. You can check this with the \c isNull() + function. + + We show an example: + + \snippet doc/src/snippets/alphachannel.cpp 0 + + \image alphachannelimage.png The pixmap and channelImage QPixmaps + + \warning This is an expensive operation. The alpha channel of the + pixmap is extracted dynamically from the pixeldata. Most usecases of this + function are covered by QPainter and compositionModes which will normally + execute faster. + + \sa setAlphaChannel(), {QPixmap#Pixmap Information}{Pixmap + Information} +*/ +QPixmap QPixmap::alphaChannel() const +{ + return data ? data->alphaChannel() : QPixmap(); +} + /*! \internal */ diff --git a/src/gui/image/qpixmap.h b/src/gui/image/qpixmap.h index 29de9c6fe..d599c99d9 100644 --- a/src/gui/image/qpixmap.h +++ b/src/gui/image/qpixmap.h @@ -104,6 +104,9 @@ public: QBitmap mask() const; void setMask(const QBitmap &); + QPixmap alphaChannel() const; + void setAlphaChannel(const QPixmap &); + bool hasAlpha() const; bool hasAlphaChannel() const; -- 2.11.0