diff options
author | Gunnar Sletta <gunnar.sletta@nokia.com> | 2010-08-09 12:03:45 (GMT) |
---|---|---|
committer | Gunnar Sletta <gunnar.sletta@nokia.com> | 2010-08-09 12:04:54 (GMT) |
commit | cfc1658c68ee3b7227277a4549b60de545ec5f6f (patch) | |
tree | a633469d3c29868818e16b3e2fe63231eef1709f /src/gui/painting | |
parent | 8bf7fbcc4f4e2cc5d9d9f0dc38a6e336d2fcc143 (diff) | |
download | Qt-cfc1658c68ee3b7227277a4549b60de545ec5f6f.zip Qt-cfc1658c68ee3b7227277a4549b60de545ec5f6f.tar.gz Qt-cfc1658c68ee3b7227277a4549b60de545ec5f6f.tar.bz2 |
Added QPainter::clipBoundingRect() which is significantly faster
than QPainter::clipRegion().boundingRect().
Task: http://bugreports.qt.nokia.com/browse/QTBUG-12618
Reviewed-by: Kim
Diffstat (limited to 'src/gui/painting')
-rw-r--r-- | src/gui/painting/qpainter.cpp | 55 | ||||
-rw-r--r-- | src/gui/painting/qpainter.h | 2 |
2 files changed, 57 insertions, 0 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index f24eafd..c4de7f0 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -2702,6 +2702,61 @@ QPainterPath QPainter::clipPath() const } /*! + Returns the bounding rectangle of the current clip if there is a clip; + otherwise returns an empty rectangle. Note that the clip region is + given in logical coordinates. + + The bounding rectangle is not guaranteed to be tight. + + \sa setClipRect(), setClipPath(), setClipRegion() + + \since 4.8 + */ + +QRectF QPainter::clipBoundingRect() const +{ + Q_D(const QPainter); + + if (!d->engine) { + qWarning("QPainter::clipBoundingRect: Painter not active"); + return QRectF(); + } + + // Accumulate the bounding box in device space. This is not 100% + // precise, but it fits within the guarantee and it is resonably + // fast. + QRectF bounds; + for (int i=0; i<d->state->clipInfo.size(); ++i) { + QRectF r; + const QPainterClipInfo &info = d->state->clipInfo.at(i); + + if (info.clipType == QPainterClipInfo::RectClip) + r = info.rect; + else if (info.clipType == QPainterClipInfo::RegionClip) + r = info.region.boundingRect(); + else + r = info.path.boundingRect(); + + r = info.matrix.mapRect(r); + + if (i == 0) + bounds = r; + else if (info.operation == Qt::IntersectClip) + bounds &= r; + else if (info.operation == Qt::UniteClip) + bounds |= r; + } + + + // Map the rectangle back into logical space using the inverse + // matrix. + if (!d->txinv) + const_cast<QPainter *>(this)->d_ptr->updateInvMatrix(); + + return d->invMatrix.mapRect(bounds); +} + +/*! \fn void QPainter::setClipRect(const QRectF &rectangle, Qt::ClipOperation operation) Enables clipping, and sets the clip region to the given \a diff --git a/src/gui/painting/qpainter.h b/src/gui/painting/qpainter.h index 85751a9..96305e3 100644 --- a/src/gui/painting/qpainter.h +++ b/src/gui/painting/qpainter.h @@ -222,6 +222,8 @@ public: void setClipping(bool enable); bool hasClipping() const; + QRectF clipBoundingRect() const; + void save(); void restore(); |