diff options
author | Gunnar Sletta <gunnar.sletta@nokia.com> | 2010-08-04 07:14:30 (GMT) |
---|---|---|
committer | Gunnar Sletta <gunnar.sletta@nokia.com> | 2010-08-04 08:43:34 (GMT) |
commit | 5683a6f6f30e65c272c1194f31395161bde229e4 (patch) | |
tree | a4432011ade11e353a4da732dd2ea3e83f58c05e /src/gui | |
parent | 0d6a0f1371d899c4105bc4383550ca1cb6b132b2 (diff) | |
download | Qt-5683a6f6f30e65c272c1194f31395161bde229e4.zip Qt-5683a6f6f30e65c272c1194f31395161bde229e4.tar.gz Qt-5683a6f6f30e65c272c1194f31395161bde229e4.tar.bz2 |
QImage::fill() overloads that take QColor and Qt::GlobalColor
This will break source compatibility in some cases, but only
when the user has a bug in the first place, so this is preferable
Reviewed-by: Eskil
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/image/qimage.cpp | 82 | ||||
-rw-r--r-- | src/gui/image/qimage.h | 3 |
2 files changed, 85 insertions, 0 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 30cf758..0e7ced83 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -2022,6 +2022,88 @@ void QImage::fill(uint pixel) 0, 0, d->width, d->height, d->bytes_per_line); } + +/*! + \fn void QImage::fill(Qt::GlobalColor color) + + \overload + + \since 4.8 + */ + +void QImage::fill(Qt::GlobalColor color) +{ + fill(QColor(color)); +} + + + +/*! + \fn void QImage::fill(Qt::GlobalColor color) + + \overload + + Fills the entire image with the given \a color. + + If the depth of the image is 1, the image will be filled with 1 if + \a color equals Qt::color0; it will otherwise be filled with 0. + + If the depth of the image is 8, the image will be filled with the + index corresponding the \a color in the color table if present; it + will otherwise be filled with 0.| + + \since 4.8 +*/ + +void QImage::fill(const QColor &color) +{ + if (!d) + return; + detach(); + + // In case we run out of memory + if (!d) + return; + + if (d->depth == 32) { + uint pixel = color.rgba(); + if (d->format == QImage::Format_ARGB32_Premultiplied) + pixel = PREMUL(pixel); + fill((uint) pixel); + + } else if (d->depth == 16 && d->format == QImage::Format_RGB16) { + qrgb565 p(color.rgba()); + fill((uint) p.rawValue()); + + } else if (d->depth == 1) { + if (color == Qt::color1) + fill((uint) 1); + else + fill((uint) 0); + + } else if (d->depth == 8) { + uint pixel = 0; + for (int i=0; i<d->colortable.size(); ++i) { + if (color.rgba() == d->colortable.at(i)) { + pixel = i; + break; + } + } + fill(pixel); + + } else { + QPainter p(this); + p.setCompositionMode(QPainter::CompositionMode_Source); + p.fillRect(rect(), color); + } + +} + + + + + + /*! Inverts all pixel values in the image. diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h index 896061f..f37dcf2 100644 --- a/src/gui/image/qimage.h +++ b/src/gui/image/qimage.h @@ -210,6 +210,9 @@ public: void setColorTable(const QVector<QRgb> colors); void fill(uint pixel); + void fill(const QColor &color); + void fill(Qt::GlobalColor color); + bool hasAlphaChannel() const; void setAlphaChannel(const QImage &alphaChannel); |