Qt 4.8
Classes | Public Types | Public Functions | Private Functions | Static Private Functions | Properties | Static Private Attributes | Friends | List of all members
QRegion Class Reference

The QRegion class specifies a clip region for a painter. More...

#include <qregion.h>

Classes

struct  QRegionData
 

Public Types

enum  RegionType { Rectangle, Ellipse }
 Specifies the shape of the region to be created. More...
 

Public Functions

QRect boundingRect () const
 Returns the bounding rectangle of this region. More...
 
bool contains (const QPoint &p) const
 Returns true if the region contains the point p; otherwise returns false. More...
 
bool contains (const QRect &r) const
 Returns true if the region overlaps the rectangle r; otherwise returns false. More...
 
QRegion eor (const QRegion &r) const
 Use xored(r) instead. More...
 
Handle handle () const
 Returns a platform-specific region handle. More...
 
QRegion intersect (const QRegion &r) const
 Use intersected(r) instead. More...
 
QRegion intersect (const QRect &r) const
 Use intersected(rect) instead. More...
 
QRegion intersected (const QRegion &r) const
 Returns a region which is the intersection of this region and r. More...
 
QRegion intersected (const QRect &r) const
 Returns a region which is the intersection of this region and the given rect. More...
 
bool intersects (const QRegion &r) const
 Returns true if this region intersects with region, otherwise returns false. More...
 
bool intersects (const QRect &r) const
 Returns true if this region intersects with rect, otherwise returns false. More...
 
bool isEmpty () const
 Returns true if the region is empty; otherwise returns false. More...
 
QT_DEPRECATED int numRects () const
 Returns the number of rectangles that will be returned in rects(). More...
 
const QRegion operator & (const QRegion &r) const
 
const QRegion operator & (const QRect &r) const
 
QRegionoperator &= (const QRegion &r)
 
QRegionoperator &= (const QRect &r)
 
 operator QVariant () const
 Returns the region as a QVariant. More...
 
bool operator!= (const QRegion &r) const
 Returns true if this region is different from the other region; otherwise returns false. More...
 
const QRegion operator+ (const QRegion &r) const
 Applies the united() function to this region and r. More...
 
const QRegion operator+ (const QRect &r) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
QRegionoperator+= (const QRegion &r)
 Applies the united() function to this region and r and assigns the result to this region. More...
 
QRegionoperator+= (const QRect &r)
 Returns a region that is the union of this region with the specified rect. More...
 
const QRegion operator- (const QRegion &r) const
 Applies the subtracted() function to this region and r. More...
 
QRegionoperator-= (const QRegion &r)
 Applies the subtracted() function to this region and r and assigns the result to this region. More...
 
QRegionoperator= (const QRegion &)
 Assigns r to this region and returns a reference to the region. More...
 
bool operator== (const QRegion &r) const
 Returns true if the region is equal to r; otherwise returns false. More...
 
const QRegion operator^ (const QRegion &r) const
 Applies the xored() function to this region and r. More...
 
QRegionoperator^= (const QRegion &r)
 Applies the xored() function to this region and r and assigns the result to this region. More...
 
const QRegion operator| (const QRegion &r) const
 Applies the united() function to this region and r. More...
 
QRegionoperator|= (const QRegion &r)
 Applies the united() function to this region and r and assigns the result to this region. More...
 
 QRegion ()
 Constructs an empty region. More...
 
 QRegion (int x, int y, int w, int h, RegionType t=Rectangle)
 Constructs a rectangular or elliptic region. More...
 
 QRegion (const QRect &r, RegionType t=Rectangle)
 Create a region based on the rectange r with region type t. More...
 
 QRegion (const QPolygon &pa, Qt::FillRule fillRule=Qt::OddEvenFill)
 Constructs a polygon region from the point array a with the fill rule specified by fillRule. More...
 
 QRegion (const QRegion &region)
 Constructs a new region which is equal to region r. More...
 
 QRegion (const QBitmap &bitmap)
 Constructs a region from the bitmap bm. More...
 
int rectCount () const
 Returns the number of rectangles that will be returned in rects(). More...
 
QVector< QRectrects () const
 Returns an array of non-overlapping rectangles that make up the region. More...
 
void setRects (const QRect *rect, int num)
 Sets the region using the array of rectangles specified by rects and number. More...
 
QRegion subtract (const QRegion &r) const
 Use subtracted(r) instead. More...
 
QRegion subtracted (const QRegion &r) const
 Returns a region which is r subtracted from this region. More...
 
void swap (QRegion &other)
 Swaps region other with this region. More...
 
void translate (int dx, int dy)
 Translates (moves) the region dx along the X axis and dy along the Y axis. More...
 
void translate (const QPoint &p)
 Translates the region {point}. More...
 
QRegion translated (int dx, int dy) const
 Returns a copy of the region that is translated dx along the x axis and dy along the y axis, relative to the current position. More...
 
QRegion translated (const QPoint &p) const
 Returns a copy of the regtion that is translated {p}. More...
 
QRegion unite (const QRegion &r) const
 Use united(r) instead. More...
 
QRegion unite (const QRect &r) const
 Use united(rect) instead. More...
 
QRegion united (const QRegion &r) const
 Returns a region which is the union of this region and r. More...
 
QRegion united (const QRect &r) const
 Returns a region which is the union of this region and the given rect. More...
 
QRegion xored (const QRegion &r) const
 Returns a region which is the exclusive or (XOR) of this region and r. More...
 
 ~QRegion ()
 Destroys the region. More...
 

Private Functions

QRegion copy () const
 
void detach ()
 
void ensureHandle () const
 
void exec (const QByteArray &ba, int ver=0, QDataStream::ByteOrder byteOrder=QDataStream::BigEndian)
 
QRegion winCombine (const QRegion &r, int num) const
 

Static Private Functions

static void cleanUp (QRegionData *x)
 

Properties

struct QRegionDatad
 

Static Private Attributes

static struct QRegionData shared_empty = { Q_BASIC_ATOMIC_INITIALIZER(1), 0 }
 

Friends

Q_GUI_EXPORT QDataStreamoperator<< (QDataStream &, const QRegion &)
 Writes the region r to the stream s and returns a reference to the stream. More...
 
Q_GUI_EXPORT QDataStreamoperator>> (QDataStream &, QRegion &)
 Reads a region from the stream s into r and returns a reference to the stream. More...
 
class QETWidget
 
struct QRegionPrivate
 
bool qt_region_strictContains (const QRegion &region, const QRect &rect)
 Returns true if rect is guaranteed to be fully contained in region. More...
 

Detailed Description

The QRegion class specifies a clip region for a painter.

QRegion is used with QPainter::setClipRegion() to limit the paint area to what needs to be painted. There is also a QWidget::repaint() function that takes a QRegion parameter. QRegion is the best tool for minimizing the amount of screen area to be updated by a repaint.

This class is not suitable for constructing shapes for rendering, especially as outlines. Use QPainterPath to create paths and shapes for use with QPainter.

QRegion is an implicitly shared class.

Creating and Using Regions

A region can be created from a rectangle, an ellipse, a polygon or a bitmap. Complex regions may be created by combining simple regions using united(), intersected(), subtracted(), or xored() (exclusive or). You can move a region using translate().

You can test whether a region isEmpty() or if it contains() a QPoint or QRect. The bounding rectangle can be found with boundingRect().

The function rects() gives a decomposition of the region into rectangles.

Example of using complex regions:

void MyWidget::paintEvent(QPaintEvent *)
{
QRegion r1(QRect(100, 100, 200, 80), // r1: elliptic region
QRegion r2(QRect(100, 120, 90, 30)); // r2: rectangular region
QRegion r3 = r1.intersected(r2); // r3: intersection
QPainter painter(this);
painter.setClipRegion(r3);
... // paint clipped graphics
}

Additional License Information

On Embedded Linux, Windows CE and X11 platforms, parts of this class rely on code obtained under the following licenses:

Copyright (c) 1987 X Consortium

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of the X Consortium shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the X Consortium.

Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.

                    All Rights Reserved

Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Digital not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission.

DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

See also
QPainter::setClipRegion(), QPainter::setClipRect(), QPainterPath

Definition at line 68 of file qregion.h.

Enumerations

◆ RegionType

Specifies the shape of the region to be created.

  • Rectangle the region covers the entire rectangle.
  • Ellipse the region is an ellipse inside the rectangle.
Enumerator
Rectangle 
Ellipse 

Definition at line 71 of file qregion.h.

Constructors and Destructors

◆ QRegion() [1/6]

QRegion::QRegion ( )

Constructs an empty region.

See also
isEmpty()

Definition at line 3961 of file qregion.cpp.

Referenced by eor(), exec(), intersect(), intersects(), operator|=(), QRegion(), qt_bitmapToRegion(), setRects(), and subtract().

3962  : d(&shared_empty)
3963 {
3964  d->ref.ref();
3965 }
static struct QRegionData shared_empty
Definition: qregion.h:218
struct QRegionData * d
Definition: qregion.h:217
QBasicAtomicInt ref
Definition: qregion.h:201

◆ QRegion() [2/6]

QRegion::QRegion ( int  x,
int  y,
int  w,
int  h,
RegionType  t = Rectangle 
)

Constructs a rectangular or elliptic region.

If t is Rectangle, the region is the filled rectangle (x, y, w, h). If t is Ellipse, the region is the filled ellipse with center at (x + w / 2, y + h / 2) and size (w ,h).

Definition at line 272 of file qregion.cpp.

273 {
274  QRegion tmp(QRect(x, y, w, h), t);
275  tmp.d->ref.ref();
276  d = tmp.d;
277 }
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
struct QRegionData * d
Definition: qregion.h:217

◆ QRegion() [3/6]

QRegion::QRegion ( const QRect r,
RegionType  t = Rectangle 
)

Create a region based on the rectange r with region type t.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

If the rectangle is invalid a null region will be created.

See also
QRegion::RegionType

Definition at line 3967 of file qregion.cpp.

3968 {
3969  if (r.isEmpty()) {
3970  d = &shared_empty;
3971  d->ref.ref();
3972  } else {
3973  d = new QRegionData;
3974  d->ref = 1;
3975 #if defined(Q_WS_X11)
3976  d->rgn = 0;
3977  d->xrectangles = 0;
3978 #elif defined(Q_WS_WIN)
3979  d->rgn = 0;
3980 #endif
3981  if (t == Rectangle) {
3982  d->qt_rgn = new QRegionPrivate(r);
3983  } else if (t == Ellipse) {
3984  QPainterPath path;
3985  path.addEllipse(r.x(), r.y(), r.width(), r.height());
3986  QPolygon a = path.toSubpathPolygons().at(0).toPolygon();
3988  }
3989  }
3990 }
friend struct QRegionPrivate
Definition: qregion.h:195
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define EvenOddRule
Definition: qregion.cpp:1782
static QRegionPrivate * PolygonRegion(const QPoint *Pts, int Count, int rule)
Definition: qregion.cpp:3689
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QRegionPrivate * qt_rgn
Definition: qregion.h:211
long ASN1_INTEGER_get ASN1_INTEGER * a
The QPolygon class provides a vector of points using integer precision.
Definition: qpolygon.h:60
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
static struct QRegionData shared_empty
Definition: qregion.h:218
The Rectangle item provides a filled rectangle with an optional border.
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QList< QPolygonF > toSubpathPolygons(const QMatrix &matrix=QMatrix()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
struct QRegionData * d
Definition: qregion.h:217
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QBasicAtomicInt ref
Definition: qregion.h:201
void addEllipse(const QRectF &rect)
Creates an ellipse within the specified boundingRectangle and adds it to the painter path as a closed...

◆ QRegion() [4/6]

QRegion::QRegion ( const QPolygon a,
Qt::FillRule  fillRule = Qt::OddEvenFill 
)

Constructs a polygon region from the point array a with the fill rule specified by fillRule.

If fillRule is Qt::WindingFill, the polygon region is defined using the winding algorithm; if it is Qt::OddEvenFill, the odd-even fill algorithm is used.

Warning
This constructor can be used to create complex regions that will slow down painting when used.

Definition at line 3992 of file qregion.cpp.

3993 {
3994  if (a.count() > 2) {
3995  QRegionPrivate *qt_rgn = PolygonRegion(a.constData(), a.size(),
3996  fillRule == Qt::WindingFill ? WindingRule : EvenOddRule);
3997  if (qt_rgn) {
3998  d = new QRegionData;
3999  d->ref = 1;
4000 #if defined(Q_WS_X11)
4001  d->rgn = 0;
4002  d->xrectangles = 0;
4003 #elif defined(Q_WS_WIN)
4004  d->rgn = 0;
4005 #endif
4006  d->qt_rgn = qt_rgn;
4007  } else {
4008  d = &shared_empty;
4009  d->ref.ref();
4010  }
4011  } else {
4012  d = &shared_empty;
4013  d->ref.ref();
4014  }
4015 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
#define EvenOddRule
Definition: qregion.cpp:1782
static QRegionPrivate * PolygonRegion(const QPoint *Pts, int Count, int rule)
Definition: qregion.cpp:3689
QRegionPrivate * qt_rgn
Definition: qregion.h:211
static struct QRegionData shared_empty
Definition: qregion.h:218
#define WindingRule
Definition: qregion.cpp:1783
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
struct QRegionData * d
Definition: qregion.h:217
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QBasicAtomicInt ref
Definition: qregion.h:201

◆ QRegion() [5/6]

QRegion::QRegion ( const QRegion region)

Constructs a new region which is equal to region r.

Definition at line 4017 of file qregion.cpp.

4018 {
4019  d = r.d;
4020  d->ref.ref();
4021 }
struct QRegionData * d
Definition: qregion.h:217
QBasicAtomicInt ref
Definition: qregion.h:201

◆ QRegion() [6/6]

QRegion::QRegion ( const QBitmap bm)

Constructs a region from the bitmap bm.

The resulting region consists of the pixels in bitmap bm that are Qt::color1, as if each pixel was a 1 by 1 rectangle.

This constructor may create complex regions that will slow down painting when used. Note that drawing masked pixmaps can be done much faster using QPixmap::setMask().

Definition at line 4024 of file qregion.cpp.

4025 {
4026  if (bm.isNull()) {
4027  d = &shared_empty;
4028  d->ref.ref();
4029  } else {
4030  d = new QRegionData;
4031  d->ref = 1;
4032 #if defined(Q_WS_X11)
4033  d->rgn = 0;
4034  d->xrectangles = 0;
4035 #elif defined(Q_WS_WIN)
4036  d->rgn = 0;
4037 #endif
4038  d->qt_rgn = qt_bitmapToRegion(bm);
4039  }
4040 }
QRegionPrivate * qt_rgn
Definition: qregion.h:211
static struct QRegionData shared_empty
Definition: qregion.h:218
QRegionPrivate * qt_bitmapToRegion(const QBitmap &bitmap)
Definition: qregion.cpp:3886
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
struct QRegionData * d
Definition: qregion.h:217
QBasicAtomicInt ref
Definition: qregion.h:201

◆ ~QRegion()

QRegion::~QRegion ( )

Destroys the region.

Warning
This function is not part of the public interface.

Definition at line 4057 of file qregion.cpp.

Referenced by qt_bitmapToRegion().

4058 {
4059  if (!d->ref.deref())
4060  cleanUp(d);
4061 }
static void cleanUp(QRegionData *x)
Definition: qregion.cpp:4042
struct QRegionData * d
Definition: qregion.h:217
QBasicAtomicInt ref
Definition: qregion.h:201

Functions

◆ boundingRect()

QRect QRegion::boundingRect ( ) const

Returns the bounding rectangle of this region.

An empty region gives a rectangle that is QRect::isNull().

Definition at line 4363 of file qregion.cpp.

Referenced by _q_paintIntoCache(), QWidgetBackingStore::addDirtyWidget(), QOnScreenRasterPaintEngine::begin(), QScreen::blit(), blit_template(), QVGPaintEngine::clip(), QPaintEngineEx::clip(), QRasterPaintEngine::clip(), QPaintBufferEngine::clip(), QPainter::clipBoundingRect(), QPaintBuffer::commandDescription(), QScreen::compose(), QMultiScreen::connect(), QWindowsXPStylePrivate::drawBackgroundDirectly(), QMacStyle::drawComplexControl(), QGraphicsScenePrivate::drawItems(), QTreeView::drawTree(), effectiveState(), QDirectFBScreen::exposeRegion(), QScreen::exposeRegion(), QVGCompositionHelper::fillBackground(), QVGPaintEngine::fillRegion(), fillRegion(), QOpenGLPaintEnginePrivate::fillVertexArray(), QGraphicsViewPrivate::findItems(), QDirectFBScreen::flipSurface(), QVFbWindowSurface::flush(), QXcbWindowSurface::flush(), QCocoaWindowSurface::flush(), QX11GLWindowSurface::flush(), QX11WindowSurface::flush(), QWSWindowSurface::flush(), QGLWindowSurface::flush(), QRasterWindowSurface::flush(), QWSYellowSurface::flush(), intersects(), QVGPaintEngine::isDefaultClipRegion(), isFullUpdate(), isServerProcess(), make_widget_eventUPP(), QTransform::map(), QTransformedScreen::mapFromDevice(), QWidgetBackingStore::markDirty(), QWidgetPrivate::moveRect(), operator<<(), QDecorationStyled::paint(), QDecorationWindows::paint(), QDecorationDefault::paint(), QDeclarativePaintedItem::paint(), QScreen::paintBackground(), QWSMemorySurface::painterOffset(), QSystemTrayIconSys::paintEvent(), QWidgetPrivate::paintSiblingsRecursive(), QBBWindow::post(), QPainterReplayer::process(), QPaintEngineExReplayer::process(), qt_bitmapToRegion(), qt_mac_fill_background(), qt_mac_unregister_widget(), qt_regionToPath(), QWidgetPrivate::render(), QWidgetPrivate::render_helper(), QFbWindow::repaint(), QWSServerPrivate::request_region(), QDirectFbWindowSurface::scroll(), QMacWindowSurface::scroll(), QX11WindowSurface::scroll(), QDirectFBWindowSurface::scroll(), QGLWindowSurface::scroll(), QRasterWindowSurface::scroll(), QVGEGLWindowSurfaceDirect::scroll(), QWidgetPrivate::scrollRect(), QPainter::setClipRegion(), QClipData::setClipRegion(), PvrEglWindowSurface::setDirectRegion(), QVFbScreen::setDirty(), QMultiScreen::setDirty(), QDirectFBWindowSurface::setGeometry(), QX11WindowSurface::setGeometry(), QWSLocalMemSurface::setGeometry(), QMacStyle::sizeFromContents(), QTransformedScreen::solidFill(), QDirectFBScreen::solidFill(), QWidgetPrivate::subtractOpaqueSiblings(), QWidgetBackingStore::sync(), QGL2PaintEngineExPrivate::systemStateChanged(), QRasterPaintEnginePrivate::systemStateChanged(), QPaintEnginePrivate::transformSystemClip(), QETWidget::translateEmbedEvent(), QWidget::update(), QPicturePaintEngine::updateClipRegion(), QGL2PaintEngineExPrivate::updateClipScissorTest(), QETWidget::updateRegion(), QDesktopWidgetPrivate::updateScreenList(), QVGEGLWindowSurfacePrivate::windowSurfaceSize(), and QPicturePaintEngine::writeCmdLength().

4364 {
4365  if (isEmpty())
4366  return QRect();
4367  return d->qt_rgn->extents;
4368 }
QRegionPrivate * qt_rgn
Definition: qregion.h:211
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
struct QRegionData * d
Definition: qregion.h:217

◆ cleanUp()

void QRegion::cleanUp ( QRegion::QRegionData x)
staticprivate

Definition at line 4042 of file qregion.cpp.

Referenced by copy(), operator=(), qt_bitmapToRegion(), and ~QRegion().

4043 {
4044  delete x->qt_rgn;
4045 #if defined(Q_WS_X11)
4046  if (x->rgn)
4047  XDestroyRegion(x->rgn);
4048  if (x->xrectangles)
4049  free(x->xrectangles);
4050 #elif defined(Q_WS_WIN)
4051  if (x->rgn)
4052  qt_win_dispose_rgn(x->rgn);
4053 #endif
4054  delete x;
4055 }
void qt_win_dispose_rgn(HRGN r)
QRegionPrivate * qt_rgn
Definition: qregion.h:211

◆ contains() [1/2]

bool QRegion::contains ( const QPoint p) const

Returns true if the region contains the point p; otherwise returns false.

Definition at line 4104 of file qregion.cpp.

Referenced by QRegionPrivate::contains(), QWSServerPrivate::invokeSelectCursor(), QMultiScreenCursor::move(), QDeclarativePaintedItem::paint(), QDockAreaLayoutInfo::paintSeparators(), QDockAreaLayout::paintSeparators(), parseGeometry(), QWidgetPrivate::pointInsideRectAndMask(), qt_bitmapToRegion(), QDecoration::regionAt(), setMaxWindowRect(), QScreen::subScreenIndexAt(), QApplication::topLevelAt(), and QWSServer::windowAt().

4105 {
4106  return PointInRegion(d->qt_rgn, p.x(), p.y());
4107 }
QRegionPrivate * qt_rgn
Definition: qregion.h:211
static bool PointInRegion(QRegionPrivate *pRegion, int x, int y)
Definition: qregion.cpp:2832
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
struct QRegionData * d
Definition: qregion.h:217

◆ contains() [2/2]

bool QRegion::contains ( const QRect r) const

Returns true if the region overlaps the rectangle r; otherwise returns false.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 4109 of file qregion.cpp.

4110 {
4111  return RectInRegion(d->qt_rgn, r.left(), r.top(), r.width(), r.height()) != RectangleOut;
4112 }
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QRegionPrivate * qt_rgn
Definition: qregion.h:211
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define RectangleOut
Definition: qregion.cpp:1779
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
static bool RectInRegion(register QRegionPrivate *region, int rx, int ry, uint rwidth, uint rheight)
Definition: qregion.cpp:2851
struct QRegionData * d
Definition: qregion.h:217

◆ copy()

QRegion QRegion::copy ( ) const
private
Warning
This function is not part of the public interface.

Definition at line 4077 of file qregion.cpp.

Referenced by detach(), exec(), qt_bitmapToRegion(), and QVector< QPoint >::replace().

4078 {
4079  QRegion r;
4080  QScopedPointer<QRegionData> x(new QRegionData);
4081  x->ref = 1;
4082 #if defined(Q_WS_X11)
4083  x->rgn = 0;
4084  x->xrectangles = 0;
4085 #elif defined(Q_WS_WIN)
4086  x->rgn = 0;
4087 #endif
4088  if (d->qt_rgn)
4089  x->qt_rgn = new QRegionPrivate(*d->qt_rgn);
4090  else
4091  x->qt_rgn = new QRegionPrivate;
4092  if (!r.d->ref.deref())
4093  cleanUp(r.d);
4094  r.d = x.take();
4095  return r;
4096 }
friend struct QRegionPrivate
Definition: qregion.h:195
QRegionPrivate * qt_rgn
Definition: qregion.h:211
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
static void cleanUp(QRegionData *x)
Definition: qregion.cpp:4042
struct QRegionData * d
Definition: qregion.h:217
QBasicAtomicInt ref
Definition: qregion.h:201

◆ detach()

void QRegion::detach ( )
private

Definition at line 300 of file qregion.cpp.

Referenced by eor(), intersect(), operator+=(), qt_bitmapToRegion(), setRects(), subtract(), translate(), and unite().

301 {
302  if (d->ref != 1)
303  *this = copy();
304 #if defined(Q_WS_X11)
305  else if (d->xrectangles) {
306  free(d->xrectangles);
307  d->xrectangles = 0;
308  }
309 #endif
310 }
QRegion copy() const
Definition: qregion.cpp:4077
struct QRegionData * d
Definition: qregion.h:217
QBasicAtomicInt ref
Definition: qregion.h:201

◆ ensureHandle()

void QRegion::ensureHandle ( ) const
private

Definition at line 130 of file qregion_win.cpp.

131 {
132  if (d->rgn)
133  DeleteObject(d->rgn);
134  d->rgn = CreateRectRgn(0,0,0,0);
135  if (d->qt_rgn) {
136  if (d->qt_rgn->numRects == 1) {
137  QRect r = d->qt_rgn->extents;
138  qt_add_rect(d->rgn, r);
139  return;
140  }
141  for (int i = 0;i < d->qt_rgn->numRects;i++) {
142  QRect r = d->qt_rgn->rects.at(i);
143  qt_add_rect(d->rgn, r);
144  }
145  }
146 }
QRegionPrivate * qt_rgn
Definition: qregion.h:211
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QVector< QRect > rects
Definition: qregion.cpp:1227
static void qt_add_rect(HRGN &winRegion, QRect r)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
struct QRegionData * d
Definition: qregion.h:217

◆ eor()

QRegion QRegion::eor ( const QRegion r) const

Use xored(r) instead.

Definition at line 4345 of file qregion.cpp.

Referenced by qt_bitmapToRegion().

4346 {
4347  if (isEmptyHelper(d->qt_rgn)) {
4348  return r;
4349  } else if (isEmptyHelper(r.d->qt_rgn)) {
4350  return *this;
4351  } else if (!EXTENTCHECK(&d->qt_rgn->extents, &r.d->qt_rgn->extents)) {
4352  return (*this + r);
4353  } else if (d == r.d || EqualRegion(d->qt_rgn, r.d->qt_rgn)) {
4354  return QRegion();
4355  } else {
4356  QRegion result;
4357  result.detach();
4358  XorRegion(d->qt_rgn, r.d->qt_rgn, *result.d->qt_rgn);
4359  return result;
4360  }
4361 }
void detach()
Definition: qregion.cpp:300
static void XorRegion(QRegionPrivate *sra, QRegionPrivate *srb, QRegionPrivate &dest)
Definition: qregion.cpp:2776
QRegionPrivate * qt_rgn
Definition: qregion.h:211
QRegion()
Constructs an empty region.
Definition: qregion.cpp:3961
#define EXTENTCHECK(r1, r2)
Definition: qregion.cpp:1846
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
static bool EqualRegion(const QRegionPrivate *r1, const QRegionPrivate *r2)
Definition: qregion.cpp:2810
struct QRegionData * d
Definition: qregion.h:217
static bool isEmptyHelper(const QRegionPrivate *preg)
Definition: qregion.cpp:1321

◆ exec()

void QRegion::exec ( const QByteArray ba,
int  ver = 0,
QDataStream::ByteOrder  byteOrder = QDataStream::BigEndian 
)
private

Definition at line 336 of file qregion.cpp.

Referenced by exec().

337 {
338  QByteArray copy = buffer;
340  if (ver)
341  s.setVersion(ver);
342  s.setByteOrder(byteOrder);
343  QRegion rgn;
344 #ifndef QT_NO_DEBUG
345  int test_cnt = 0;
346 #endif
347  while (!s.atEnd()) {
348  qint32 id;
349  if (s.version() == 1) {
350  int id_int;
351  s >> id_int;
352  id = id_int;
353  } else {
354  s >> id;
355  }
356 #ifndef QT_NO_DEBUG
357  if (test_cnt > 0 && id != QRGN_TRANSLATE)
358  qWarning("QRegion::exec: Internal error");
359  test_cnt++;
360 #endif
361  if (id == QRGN_SETRECT || id == QRGN_SETELLIPSE) {
362  QRect r;
363  s >> r;
364  rgn = QRegion(r, id == QRGN_SETRECT ? Rectangle : Ellipse);
365  } else if (id == QRGN_SETPTARRAY_ALT || id == QRGN_SETPTARRAY_WIND) {
366  QPolygon a;
367  s >> a;
369  } else if (id == QRGN_TRANSLATE) {
370  QPoint p;
371  s >> p;
372  rgn.translate(p.x(), p.y());
373  } else if (id >= QRGN_OR && id <= QRGN_XOR) {
374  QByteArray bop1, bop2;
375  QRegion r1, r2;
376  s >> bop1;
377  r1.exec(bop1);
378  s >> bop2;
379  r2.exec(bop2);
380 
381  switch (id) {
382  case QRGN_OR:
383  rgn = r1.united(r2);
384  break;
385  case QRGN_AND:
386  rgn = r1.intersected(r2);
387  break;
388  case QRGN_SUB:
389  rgn = r1.subtracted(r2);
390  break;
391  case QRGN_XOR:
392  rgn = r1.xored(r2);
393  break;
394  }
395  } else if (id == QRGN_RECTS) {
396  // (This is the only form used in Qt 2.0)
397  quint32 n;
398  s >> n;
399  QRect r;
400  for (int i=0; i<(int)n; i++) {
401  s >> r;
402  rgn = rgn.united(QRegion(r));
403  }
404  }
405  }
406  *this = rgn;
407 }
#define QRGN_SETPTARRAY_ALT
Definition: qregion.cpp:315
QRegion intersected(const QRegion &r) const
Returns a region which is the intersection of this region and r.
Definition: qregion.h:112
#define QRGN_TRANSLATE
Definition: qregion.cpp:317
int qint32
Definition: qglobal.h:937
#define QRGN_SETPTARRAY_WIND
Definition: qregion.cpp:316
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
long ASN1_INTEGER_get ASN1_INTEGER * a
The QPolygon class provides a vector of points using integer precision.
Definition: qpolygon.h:60
QRegion()
Constructs an empty region.
Definition: qregion.cpp:3961
#define QRGN_RECTS
Definition: qregion.cpp:322
QRegion copy() const
Definition: qregion.cpp:4077
#define QRGN_OR
Definition: qregion.cpp:318
The Rectangle item provides a filled rectangle with an optional border.
#define QRGN_AND
Definition: qregion.cpp:319
Q_CORE_EXPORT void qWarning(const char *,...)
#define QRGN_SUB
Definition: qregion.cpp:320
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QRegion united(const QRegion &r) const
Returns a region which is the union of this region and r.
Definition: qregion.h:110
#define QRGN_SETRECT
Definition: qregion.cpp:313
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
unsigned int quint32
Definition: qglobal.h:938
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void translate(int dx, int dy)
Translates (moves) the region dx along the X axis and dy along the Y axis.
Definition: qregion.cpp:4116
void exec(const QByteArray &ba, int ver=0, QDataStream::ByteOrder byteOrder=QDataStream::BigEndian)
Definition: qregion.cpp:336
#define QRGN_XOR
Definition: qregion.cpp:321
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
QRegion subtracted(const QRegion &r) const
Returns a region which is r subtracted from this region.
Definition: qregion.h:114
QRegion xored(const QRegion &r) const
Returns a region which is the exclusive or (XOR) of this region and r.
Definition: qregion.h:115
#define QRGN_SETELLIPSE
Definition: qregion.cpp:314

◆ handle()

Handle QRegion::handle ( ) const

Returns a platform-specific region handle.

The Handle type is HRGN on Windows, Region on X11, and RgnHandle on Mac OS X. On Qt for Embedded Linux it is {void *}.

Warning
This function is not portable.

Referenced by do_size_hints(), QWindowsXPStylePrivate::drawBackgroundDirectly(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), qt_grab_cursor(), QETWidget::translatePaintEvent(), QWin32PrintEngine::updateClipPath(), QAxServerBase::updateMask(), and QGLContext::updatePaintDevice().

◆ intersect() [1/2]

QRegion QRegion::intersect ( const QRegion r) const

Use intersected(r) instead.

Definition at line 4249 of file qregion.cpp.

Referenced by QVGPaintEngine::clip(), clipTransformIsSimple(), intersects(), QRegionPrivate::operator=(), qt_bitmapToRegion(), PvrEglWindowSurface::setDirectRegion(), and QVGPaintEngine::updateScissor().

4250 {
4252  || !EXTENTCHECK(&d->qt_rgn->extents, &r.d->qt_rgn->extents))
4253  return QRegion();
4254 
4255  /* this is fully contained in r */
4256  if (r.d->qt_rgn->contains(*d->qt_rgn))
4257  return *this;
4258 
4259  /* r is fully contained in this */
4260  if (d->qt_rgn->contains(*r.d->qt_rgn))
4261  return r;
4262 
4263  if (r.d->qt_rgn->numRects == 1 && d->qt_rgn->numRects == 1) {
4265  d->qt_rgn->extents);
4266  return QRegion(rect);
4267  } else if (r.d->qt_rgn->numRects == 1) {
4268  QRegion result(*this);
4269  result.detach();
4270  result.d->qt_rgn->intersect(r.d->qt_rgn->extents);
4271  return result;
4272  } else if (d->qt_rgn->numRects == 1) {
4273  QRegion result(r);
4274  result.detach();
4275  result.d->qt_rgn->intersect(d->qt_rgn->extents);
4276  return result;
4277  }
4278 
4279  QRegion result;
4280  result.detach();
4281  miRegionOp(*result.d->qt_rgn, d->qt_rgn, r.d->qt_rgn, miIntersectO, 0, 0);
4282 
4283  /*
4284  * Can't alter dest's extents before we call miRegionOp because
4285  * it might be one of the source regions and miRegionOp depends
4286  * on the extents of those regions being the same. Besides, this
4287  * way there's no checking against rectangles that will be nuked
4288  * due to coalescing, so we have to examine fewer rectangles.
4289  */
4290  miSetExtents(*result.d->qt_rgn);
4291  return result;
4292 }
void detach()
Definition: qregion.cpp:300
static QRect qt_rect_intersect_normalized(const QRect &r1, const QRect &r2)
Definition: qregion.cpp:1396
QRegionPrivate * qt_rgn
Definition: qregion.h:211
QRegion()
Constructs an empty region.
Definition: qregion.cpp:3961
#define EXTENTCHECK(r1, r2)
Definition: qregion.cpp:1846
static void miSetExtents(QRegionPrivate &dest)
Definition: qregion.cpp:2005
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
static void miRegionOp(register QRegionPrivate &dest, const QRegionPrivate *reg1, const QRegionPrivate *reg2, OverlapFunc overlapFunc, NonOverlapFunc nonOverlap1Func, NonOverlapFunc nonOverlap2Func)
Definition: qregion.cpp:2279
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
struct QRegionData * d
Definition: qregion.h:217
static void miIntersectO(register QRegionPrivate &dest, register const QRect *r1, const QRect *r1End, register const QRect *r2, const QRect *r2End, int y1, int y2)
Definition: qregion.cpp:2085
static bool isEmptyHelper(const QRegionPrivate *preg)
Definition: qregion.cpp:1321
bool contains(const QRegionPrivate &r) const
Definition: qregion.cpp:1263

◆ intersect() [2/2]

QRegion QRegion::intersect ( const QRect rect) const

Use intersected(rect) instead.

Since
4.4

Definition at line 4294 of file qregion.cpp.

4295 {
4296  if (isEmptyHelper(d->qt_rgn) || r.isEmpty()
4297  || !EXTENTCHECK(&d->qt_rgn->extents, &r))
4298  return QRegion();
4299 
4300  /* this is fully contained in r */
4301  if (d->qt_rgn->within(r))
4302  return *this;
4303 
4304  /* r is fully contained in this */
4305  if (d->qt_rgn->contains(r))
4306  return r;
4307 
4308  if (d->qt_rgn->numRects == 1) {
4310  r.normalized());
4311  return QRegion(rect);
4312  }
4313 
4314  QRegion result(*this);
4315  result.detach();
4316  result.d->qt_rgn->intersect(r);
4317  return result;
4318 }
static QRect qt_rect_intersect_normalized(const QRect &r1, const QRect &r2)
Definition: qregion.cpp:1396
bool within(const QRect &r1) const
Definition: qregion.cpp:1276
QRect normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
Definition: qrect.cpp:322
QRegionPrivate * qt_rgn
Definition: qregion.h:211
QRegion()
Constructs an empty region.
Definition: qregion.cpp:3961
#define EXTENTCHECK(r1, r2)
Definition: qregion.cpp:1846
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
struct QRegionData * d
Definition: qregion.h:217
static bool isEmptyHelper(const QRegionPrivate *preg)
Definition: qregion.cpp:1321
bool contains(const QRegionPrivate &r) const
Definition: qregion.cpp:1263

◆ intersected() [1/2]

QRegion QRegion::intersected ( const QRegion r) const
inline

Returns a region which is the intersection of this region and r.

Since
4.2
rintersect.png
Region Intersection

The figure shows the intersection of two elliptical regions.

See also
subtracted(), united(), xored()

Definition at line 112 of file qregion.h.

Referenced by QFbScreen::doRedraw(), exec(), QBlitterPaintEngine::fillRect(), QGL2PaintEngineExPrivate::fillStencilWithVertexArray(), QBBRasterWindowSurface::flush(), QAlphaPaintEnginePrivate::fullyContained(), operator+(), QWidgetPrivate::scrollRect(), and QX11PaintEngine::updateClipRegion_dev().

112 { return intersect(r); }
QRegion intersect(const QRegion &r) const
Use intersected(r) instead.
Definition: qregion.cpp:4249

◆ intersected() [2/2]

QRegion QRegion::intersected ( const QRect rect) const
inline

Returns a region which is the intersection of this region and the given rect.

Since
4.4
See also
subtracted(), united(), xored()

Definition at line 113 of file qregion.h.

113 { return intersect(r); }
QRegion intersect(const QRegion &r) const
Use intersected(r) instead.
Definition: qregion.cpp:4249

◆ intersects() [1/2]

bool QRegion::intersects ( const QRegion region) const

Returns true if this region intersects with region, otherwise returns false.

Since
4.2

Definition at line 766 of file qregion.cpp.

Referenced by QWidgetBackingStore::bltRect(), QFbScreen::doRedraw(), QTableViewPrivate::drawAndClipSpans(), QGraphicsScenePrivate::drawSubtreeRecursive(), QDirectFBScreen::exposeRegion(), QScreen::exposeRegion(), QGL2PaintEngineExPrivate::fillStencilWithVertexArray(), QXcbShmImage::preparePaint(), QBBRasterWindowSurface::scroll(), and QWidgetBackingStore::sync().

767 {
768  if (isEmpty() || region.isEmpty())
769  return false;
770 
771  if (!rect_intersects(boundingRect(), region.boundingRect()))
772  return false;
773  if (rectCount() == 1 && region.rectCount() == 1)
774  return true;
775 
776  const QVector<QRect> myRects = rects();
777  const QVector<QRect> otherRects = region.rects();
778 
779  for (QVector<QRect>::const_iterator i1 = myRects.constBegin(); i1 < myRects.constEnd(); ++i1)
780  for (QVector<QRect>::const_iterator i2 = otherRects.constBegin(); i2 < otherRects.constEnd(); ++i2)
781  if (rect_intersects(*i1, *i2))
782  return true;
783  return false;
784 }
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
int rectCount() const
Returns the number of rectangles that will be returned in rects().
Definition: qregion.cpp:4461
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
bool rect_intersects(const QRect &r1, const QRect &r2)
Definition: qregion.cpp:751

◆ intersects() [2/2]

bool QRegion::intersects ( const QRect rect) const

Returns true if this region intersects with rect, otherwise returns false.

Since
4.2

Definition at line 4480 of file qregion.cpp.

4481 {
4482  if (isEmptyHelper(d->qt_rgn) || rect.isNull())
4483  return false;
4484 
4485  const QRect r = rect.normalized();
4486  if (!rect_intersects(d->qt_rgn->extents, r))
4487  return false;
4488  if (d->qt_rgn->numRects == 1)
4489  return true;
4490 
4491  const QVector<QRect> myRects = rects();
4492  for (QVector<QRect>::const_iterator it = myRects.constBegin(); it < myRects.constEnd(); ++it)
4493  if (rect_intersects(r, *it))
4494  return true;
4495  return false;
4496 }
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:231
#define it(className, varName)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
QRect normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
Definition: qrect.cpp:322
QRegionPrivate * qt_rgn
Definition: qregion.h:211
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool rect_intersects(const QRect &r1, const QRect &r2)
Definition: qregion.cpp:751
struct QRegionData * d
Definition: qregion.h:217
static bool isEmptyHelper(const QRegionPrivate *preg)
Definition: qregion.cpp:1321

◆ isEmpty()

bool QRegion::isEmpty ( ) const

Returns true if the region is empty; otherwise returns false.

An empty region is a region that contains no points.

Example:

QRegion r1(10, 10, 20, 20);
r1.isEmpty(); // false
r3.isEmpty(); // true
QRegion r2(40, 40, 20, 20);
r3 = r1.intersected(r2); // r3: intersection of r1 and r2
r3.isEmpty(); // true
r3 = r1.united(r2); // r3: union of r1 and r2
r3.isEmpty(); // false

Definition at line 4098 of file qregion.cpp.

Referenced by _q_paintIntoCache(), QGL2PaintEngineEx::begin(), QWidgetBackingStore::beginPaint(), QMultiScreen::blit(), QScreen::blit(), boundingRect(), QVGPaintEngine::clip(), QGL2PaintEngineEx::clip(), QScreen::compose(), QBBWindow::copyBack(), do_size_hints(), QFbScreen::doRedraw(), QWindowsXPStylePrivate::drawBackgroundDirectly(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QGraphicsScenePrivate::drawItemHelper(), QWidgetPrivate::drawWidget(), effectiveState(), QMultiScreen::exposeRegion(), QDirectFBScreen::exposeRegion(), QScreen::exposeRegion(), QWSServerPrivate::exposeRegion(), QWSWindowSurface::flush(), QWidgetBackingStore::flush(), QGLWindowSurface::flush(), QWidgetPrivate::getOpaqueChildren(), QWSTtyKbPrivate::handleConsoleSwitch(), QWindowSurface::hasStaticContents(), intersects(), QWidgetPrivate::invalidateBuffer(), QWidgetPrivate::invalidateBuffer_resizeHelper(), QWSWindow::isFullyObscured(), isServerProcess(), QWSServerPrivate::lowerWindow(), make_widget_eventUPP(), QTransformedScreen::mapFromDevice(), QWidgetBackingStore::markDirty(), QWidgetBackingStore::markDirtyOnScreen(), QMdiSubWindow::mouseMoveEvent(), QWidgetPrivate::moveRect(), QWSServerPrivate::moveWindowRegion(), operator==(), QDecorationStyled::paint(), QDeclarativePaintedItem::paint(), QScreen::paintBackground(), QWSMemorySurface::painterOffset(), QGraphicsWidget::paintWindowFrame(), parseGeometry(), QBBWindow::post(), QMacCGContext::QMacCGContext(), qt_bitmapToRegion(), qt_flush(), qt_grab_cursor(), qt_mac_clip_cg(), qt_mac_post_retranslateAppMenu(), qt_mac_unregister_widget(), qt_region_strictContains(), qt_tablet_cleanup_wce(), QWSServerPrivate::raiseWindow(), QWidgetBackingStore::removeDirtyWidget(), QWidget::render(), QWidgetPrivate::render(), QWidgetPrivate::render_helper(), QWidget::repaint(), QETWidget::repaintDecoration(), QWSServerPrivate::request_region(), QDirectFbWindowSurface::scroll(), QWidgetPrivate::scrollRect(), QCoreGraphicsPaintEnginePrivate::setClip(), QRasterPaintEngine::setClipRectInDeviceCoords(), QWSWindowSurface::setClipRegion(), QMenuPrivate::setCurrentAction(), PvrEglWindowSurface::setDirectRegion(), QMultiScreen::setDirty(), QWidget::setDisabled(), QWSWindowSurface::setGeometry(), QWSLocalMemSurface::setGeometry(), QWidget::setMask(), QWidgetPrivate::setMask_sys(), QPaintEnginePrivate::setSystemViewport(), QMultiScreen::solidFill(), QDirectFBScreen::solidFill(), QWidgetBackingStore::staticContents(), QWidgetPrivate::subtractOpaqueChildren(), QWidgetPrivate::subtractOpaqueSiblings(), QWidgetBackingStore::sync(), QGL2PaintEngineExPrivate::systemStateChanged(), QApplication::topLevelAt(), QPaintEnginePrivate::transformSystemClip(), QETWidget::translateEmbedEvent(), QETWidget::translatePaintEvent(), QWidgetBackingStore::unflushPaint(), QWidget::update(), QX11PaintEngine::updateBrush(), QOpenGLPaintEngine::updateClipRegion(), QX11PaintEngine::updateClipRegion_dev(), QMdiSubWindowPrivate::updateMask(), QWorkspaceChild::updateMask(), QGLContext::updatePaintDevice(), QX11PaintEngine::updatePen(), updateRedirectedToGraphicsProxyWidget(), QVGPaintEngine::updateScissor(), QApplication::widgetAt(), and QVGEGLWindowSurfacePrivate::windowSurfaceSize().

4099 {
4100  return d == &shared_empty || d->qt_rgn->numRects == 0;
4101 }
QRegionPrivate * qt_rgn
Definition: qregion.h:211
static struct QRegionData shared_empty
Definition: qregion.h:218
struct QRegionData * d
Definition: qregion.h:217

◆ numRects()

int QRegion::numRects ( ) const

Returns the number of rectangles that will be returned in rects().

Since
4.4

Definition at line 4456 of file qregion.cpp.

Referenced by QRegionPrivate::append(), QRegionPrivate::canAppend(), QRegionPrivate::canPrepend(), clipTransformIsSimple(), QFbScreen::doRedraw(), QRegionPrivate::intersect(), QDeclarativePaintedItem::paint(), and QRegionPrivate::prepend().

4457 {
4458  return (d->qt_rgn ? d->qt_rgn->numRects : 0);
4459 }
QRegionPrivate * qt_rgn
Definition: qregion.h:211
struct QRegionData * d
Definition: qregion.h:217

◆ operator &() [1/2]

const QRegion QRegion::operator& ( const QRegion r) const

Referenced by operator+(), and qt_bitmapToRegion().

◆ operator &() [2/2]

const QRegion QRegion::operator& ( const QRect r) const

◆ operator &=() [1/2]

QRegion& QRegion::operator&= ( const QRegion r)

Referenced by operator|=(), and qt_bitmapToRegion().

◆ operator &=() [2/2]

QRegion& QRegion::operator&= ( const QRect r)

◆ operator QVariant()

QRegion::operator QVariant ( ) const

Returns the region as a QVariant.

Definition at line 677 of file qregion.cpp.

678 {
679  return QVariant(QVariant::Region, this);
680 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92

◆ operator!=()

bool QRegion::operator!= ( const QRegion r) const
inline

Returns true if this region is different from the other region; otherwise returns false.

Definition at line 144 of file qregion.h.

144 { return !(operator==(r)); }
bool operator==(const QRegion &r) const
Returns true if the region is equal to r; otherwise returns false.
Definition: qregion.cpp:4467

◆ operator+() [1/2]

const QRegion QRegion::operator+ ( const QRegion r) const

Applies the united() function to this region and r.

r1+r2 is equivalent to r1.united(r2).

See also
united(), operator|()

Definition at line 523 of file qregion.cpp.

524  { return united(r); }
QRegion united(const QRegion &r) const
Returns a region which is the union of this region and r.
Definition: qregion.h:110

◆ operator+() [2/2]

const QRegion QRegion::operator+ ( const QRect r) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.4

Definition at line 530 of file qregion.cpp.

531  { return united(r); }
QRegion united(const QRegion &r) const
Returns a region which is the union of this region and r.
Definition: qregion.h:110

◆ operator+=() [1/2]

QRegion & QRegion::operator+= ( const QRegion r)

Applies the united() function to this region and r and assigns the result to this region.

r1+=r2 is equivalent to {r1 = r1.united(r2)}.

See also
intersected()

Definition at line 4158 of file qregion.cpp.

Referenced by operator|=(), and qt_bitmapToRegion().

4159 {
4160  if (isEmptyHelper(d->qt_rgn))
4161  return *this = r;
4162  if (isEmptyHelper(r.d->qt_rgn))
4163  return *this;
4164  if (d == r.d)
4165  return *this;
4166 
4167  if (d->qt_rgn->contains(*r.d->qt_rgn)) {
4168  return *this;
4169  } else if (r.d->qt_rgn->contains(*d->qt_rgn)) {
4170  return *this = r;
4171  } else if (d->qt_rgn->canAppend(r.d->qt_rgn)) {
4172  detach();
4173  d->qt_rgn->append(r.d->qt_rgn);
4174  return *this;
4175  } else if (d->qt_rgn->canPrepend(r.d->qt_rgn)) {
4176  detach();
4177  d->qt_rgn->prepend(r.d->qt_rgn);
4178  return *this;
4179  } else if (EqualRegion(d->qt_rgn, r.d->qt_rgn)) {
4180  return *this;
4181  } else {
4182  detach();
4183  UnionRegion(d->qt_rgn, r.d->qt_rgn, *d->qt_rgn);
4184  return *this;
4185  }
4186 }
void detach()
Definition: qregion.cpp:300
void append(const QRect *r)
Definition: qregion.cpp:1460
QRegionPrivate * qt_rgn
Definition: qregion.h:211
static void UnionRegion(const QRegionPrivate *reg1, const QRegionPrivate *reg2, QRegionPrivate &dest)
Definition: qregion.cpp:2577
bool canPrepend(const QRect *r) const
Definition: qregion.cpp:1691
static bool EqualRegion(const QRegionPrivate *r1, const QRegionPrivate *r2)
Definition: qregion.cpp:2810
bool canAppend(const QRect *r) const
Definition: qregion.cpp:1669
struct QRegionData * d
Definition: qregion.h:217
static bool isEmptyHelper(const QRegionPrivate *preg)
Definition: qregion.cpp:1321
void prepend(const QRect *r)
Definition: qregion.cpp:1637
bool contains(const QRegionPrivate &r) const
Definition: qregion.cpp:1263

◆ operator+=() [2/2]

QRegion & QRegion::operator+= ( const QRect rect)

Returns a region that is the union of this region with the specified rect.

See also
united()

Definition at line 4220 of file qregion.cpp.

4221 {
4222  if (isEmptyHelper(d->qt_rgn))
4223  return *this = r;
4224  if (r.isEmpty())
4225  return *this;
4226 
4227  if (d->qt_rgn->contains(r)) {
4228  return *this;
4229  } else if (d->qt_rgn->within(r)) {
4230  return *this = r;
4231  } else if (d->qt_rgn->canAppend(&r)) {
4232  detach();
4233  d->qt_rgn->append(&r);
4234  return *this;
4235  } else if (d->qt_rgn->canPrepend(&r)) {
4236  detach();
4237  d->qt_rgn->prepend(&r);
4238  return *this;
4239  } else if (d->qt_rgn->numRects == 1 && d->qt_rgn->extents == r) {
4240  return *this;
4241  } else {
4242  detach();
4243  QRegionPrivate p(r);
4244  UnionRegion(d->qt_rgn, &p, *d->qt_rgn);
4245  return *this;
4246  }
4247 }
void detach()
Definition: qregion.cpp:300
void append(const QRect *r)
Definition: qregion.cpp:1460
bool within(const QRect &r1) const
Definition: qregion.cpp:1276
QRegionPrivate * qt_rgn
Definition: qregion.h:211
static void UnionRegion(const QRegionPrivate *reg1, const QRegionPrivate *reg2, QRegionPrivate &dest)
Definition: qregion.cpp:2577
bool canPrepend(const QRect *r) const
Definition: qregion.cpp:1691
bool canAppend(const QRect *r) const
Definition: qregion.cpp:1669
struct QRegionData * d
Definition: qregion.h:217
static bool isEmptyHelper(const QRegionPrivate *preg)
Definition: qregion.cpp:1321
void prepend(const QRect *r)
Definition: qregion.cpp:1637
bool contains(const QRegionPrivate &r) const
Definition: qregion.cpp:1263

◆ operator-()

const QRegion QRegion::operator- ( const QRegion r) const

Applies the subtracted() function to this region and r.

r1-r2 is equivalent to r1.subtracted(r2).

See also
subtracted()

Definition at line 557 of file qregion.cpp.

558  { return subtracted(r); }
QRegion subtracted(const QRegion &r) const
Returns a region which is r subtracted from this region.
Definition: qregion.h:114

◆ operator-=()

QRegion & QRegion::operator-= ( const QRegion r)

Applies the subtracted() function to this region and r and assigns the result to this region.

r1-=r2 is equivalent to {r1 = r1.subtracted(r2)}.

See also
subtracted()

Definition at line 651 of file qregion.cpp.

652  { return *this = *this - r; }

◆ operator=()

QRegion & QRegion::operator= ( const QRegion r)

Assigns r to this region and returns a reference to the region.

Definition at line 4064 of file qregion.cpp.

Referenced by qt_bitmapToRegion().

4065 {
4066  r.d->ref.ref();
4067  if (!d->ref.deref())
4068  cleanUp(d);
4069  d = r.d;
4070  return *this;
4071 }
static void cleanUp(QRegionData *x)
Definition: qregion.cpp:4042
struct QRegionData * d
Definition: qregion.h:217
QBasicAtomicInt ref
Definition: qregion.h:201

◆ operator==()

bool QRegion::operator== ( const QRegion r) const

Returns true if the region is equal to r; otherwise returns false.

Definition at line 4467 of file qregion.cpp.

Referenced by qt_region_strictContains().

4468 {
4469  if (!d->qt_rgn)
4470  return r.isEmpty();
4471  if (!r.d->qt_rgn)
4472  return isEmpty();
4473 
4474  if (d == r.d)
4475  return true;
4476  else
4477  return EqualRegion(d->qt_rgn, r.d->qt_rgn);
4478 }
QRegionPrivate * qt_rgn
Definition: qregion.h:211
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
static bool EqualRegion(const QRegionPrivate *r1, const QRegionPrivate *r2)
Definition: qregion.cpp:2810
struct QRegionData * d
Definition: qregion.h:217

◆ operator^()

const QRegion QRegion::operator^ ( const QRegion r) const

Applies the xored() function to this region and r.

r1^r2 is equivalent to r1.xored(r2).

See also
xored()

Definition at line 566 of file qregion.cpp.

567  { return xored(r); }
QRegion xored(const QRegion &r) const
Returns a region which is the exclusive or (XOR) of this region and r.
Definition: qregion.h:115

◆ operator^=()

QRegion & QRegion::operator^= ( const QRegion r)

Applies the xored() function to this region and r and assigns the result to this region.

r1^=r2 is equivalent to {r1 = r1.xored(r2)}.

See also
xored()

Definition at line 661 of file qregion.cpp.

662  { return *this = *this ^ r; }

◆ operator|()

const QRegion QRegion::operator| ( const QRegion r) const

Applies the united() function to this region and r.

r1|r2 is equivalent to r1.united(r2).

See also
united(), operator+()

Definition at line 514 of file qregion.cpp.

515  { return united(r); }
QRegion united(const QRegion &r) const
Returns a region which is the union of this region and r.
Definition: qregion.h:110

◆ operator|=()

QRegion & QRegion::operator|= ( const QRegion r)

Applies the united() function to this region and r and assigns the result to this region.

r1|=r2 is equivalent to {r1 = r1.united(r2)}.

See also
united()

Definition at line 576 of file qregion.cpp.

577  { return *this = *this | r; }

◆ rectCount()

int QRegion::rectCount ( ) const

◆ rects()

QVector< QRect > QRegion::rects ( ) const

Returns an array of non-overlapping rectangles that make up the region.

The union of all the rectangles is equal to the original region.

Definition at line 4412 of file qregion.cpp.

Referenced by QPainterPath::addRegion(), QRegionPrivate::append(), QXcbWindowSurface::beginPaint(), QXlibWindowSurface::beginPaint(), QX11WindowSurface::beginPaint(), QRasterWindowSurface::beginPaint(), QWSMemorySurface::beginPaint(), QTransformedScreen::blit(), blit_template(), QGraphicsItem::boundingRegion(), QRegionPrivate::canAppend(), QRegionPrivate::canPrepend(), QPaintEngineEx::clip(), QScreen::compose(), QBBWindow::copyBack(), QLinuxFbScreen::doRedraw(), QVNCScreen::doRedraw(), QFbScreen::doRedraw(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QGraphicsScenePrivate::drawItemHelper(), QBlitterPaintEngine::drawPixmap(), QTreeView::drawTree(), QQnxScreen::exposeRegion(), QProxyScreen::exposeRegion(), QDirectFBScreen::exposeRegion(), QScreen::exposeRegion(), QVGCompositionHelper::fillBackground(), QBlitterPaintEngine::fillRect(), QBlitterPaintEnginePrivate::fillRect(), QVGPaintEngine::fillRegion(), fillRegion(), QGL2PaintEngineExPrivate::fillStencilWithVertexArray(), QGraphicsViewPrivate::findItems(), QDirectFBScreen::flipSurface(), QDirectFbWindowSurface::flush(), QXcbWindowSurface::flush(), QWaylandShmWindowSurface::flush(), QMacWindowSurface::flush(), QGLWindowSurface::flush(), QRasterWindowSurface::flush(), QFbScreen::generateRects(), QClipData::initialize(), QGraphicsItemPrivate::initStyleOption(), QRegionPrivate::intersect(), intersects(), make_widget_eventUPP(), QTransformedScreen::mapFromDevice(), QVGPaintEnginePrivate::modifyMask(), QVNCCursor::move(), operator<<(), QDeclarativePaintedItem::paint(), QScreen::paintBackground(), QBlittablePixmapData::paintEngine(), QTableView::paintEvent(), QMdiArea::paintEvent(), QRasterWindowSurface::prepareBuffer(), QRegionPrivate::prepend(), qt_mac_clip_cg(), qt_mac_fill_background(), qt_mac_post_retranslateAppMenu(), qt_region_strictContains(), qt_regionToPath(), QVNCDirtyMap::QVNCDirtyMap(), QmlJSDebugger::regionToPolygon(), QWSDisplay::repaintRegion(), QDirectFbWindowSurface::scroll(), QXcbWindowSurface::scroll(), QXlibWindowSurface::scroll(), QX11GLWindowSurface::scroll(), QRasterWindowSurface::scroll(), QWSMemorySurface::scroll(), QGraphicsItem::scroll(), QVNCCursor::set(), QPainter::setClipRegion(), QClipData::setClipRegion(), QWSRegionEvent::setData(), QWSRegionCommand::setData(), PvrEglWindowSurface::setDirectRegion(), setRects(), QVGCompositionHelper::setScissor(), QWidgetPrivate::setWindowOpacity_sys(), showYellowThing_win(), QDirectFBScreen::solidFill(), solidFill_template(), QEglContext::swapBuffersRegion2NOK(), QWidgetBackingStore::sync(), QOpenGLPaintEngine::updateClipRegion(), QGLContext::updatePaintDevice(), updateRedirectedToGraphicsProxyWidget(), QVGPaintEngine::updateScissor(), QPdfBaseEngine::updateState(), and QRfbRawEncoder::write().

4413 {
4414  if (d->qt_rgn) {
4415  d->qt_rgn->vectorize();
4416  // hw: modify the vector size directly to avoid reallocation
4417  d->qt_rgn->rects.d->size = d->qt_rgn->numRects;
4418  return d->qt_rgn->rects;
4419  } else {
4420  return QVector<QRect>();
4421  }
4422 }
QRegionPrivate * qt_rgn
Definition: qregion.h:211
QVectorData * d
Definition: qvector.h:109
QVector< QRect > rects
Definition: qregion.cpp:1227
int size
Definition: qvector.h:70
struct QRegionData * d
Definition: qregion.h:217
void vectorize()
Definition: qregion.cpp:1290

◆ setRects()

void QRegion::setRects ( const QRect rects,
int  number 
)

Sets the region using the array of rectangles specified by rects and number.

The rectangles must be optimally Y-X sorted and follow these restrictions:

  • The rectangles must not intersect.
  • All rectangles with a given top coordinate must have the same height.
  • No two rectangles may abut horizontally (they should be combined into a single wider rectangle in that case).
  • The rectangles must be sorted in ascending order, with Y as the major sort key and X as the minor sort key.
Warning
This function is not part of the public interface. Only some platforms have these restrictions (Qt for Embedded Linux, X11 and Mac OS X).

Definition at line 4424 of file qregion.cpp.

Referenced by QWSServerPrivate::invokeRepaintRegion(), qt_region_strictContains(), QApplication::qwsProcessEvent(), and QETWidget::translateRegionEvent().

4425 {
4426  *this = QRegion();
4427  if (!rects || num == 0 || (num == 1 && rects->isEmpty()))
4428  return;
4429 
4430  detach();
4431 
4432  d->qt_rgn->numRects = num;
4433  if (num == 1) {
4434  d->qt_rgn->extents = *rects;
4435  d->qt_rgn->innerRect = *rects;
4436  } else {
4437  d->qt_rgn->rects.resize(num);
4438 
4439  int left = INT_MAX,
4440  right = INT_MIN,
4441  top = INT_MAX,
4442  bottom = INT_MIN;
4443  for (int i = 0; i < num; ++i) {
4444  const QRect &rect = rects[i];
4445  d->qt_rgn->rects[i] = rect;
4446  left = qMin(rect.left(), left);
4447  right = qMax(rect.right(), right);
4448  top = qMin(rect.top(), top);
4449  bottom = qMax(rect.bottom(), bottom);
4450  d->qt_rgn->updateInnerRect(rect);
4451  }
4452  d->qt_rgn->extents = QRect(QPoint(left, top), QPoint(right, bottom));
4453  }
4454 }
void detach()
Definition: qregion.cpp:300
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
QRegionPrivate * qt_rgn
Definition: qregion.h:211
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
QRegion()
Constructs an empty region.
Definition: qregion.cpp:3961
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
void updateInnerRect(const QRect &rect)
Definition: qregion.cpp:1282
QVector< QRect > rects
Definition: qregion.cpp:1227
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
struct QRegionData * d
Definition: qregion.h:217
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
#define INT_MAX

◆ subtract()

QRegion QRegion::subtract ( const QRegion r) const

Use subtracted(r) instead.

Definition at line 4320 of file qregion.cpp.

Referenced by qt_bitmapToRegion().

4321 {
4322  if (isEmptyHelper(d->qt_rgn) || isEmptyHelper(r.d->qt_rgn))
4323  return *this;
4324  if (r.d->qt_rgn->contains(*d->qt_rgn))
4325  return QRegion();
4326  if (!EXTENTCHECK(&d->qt_rgn->extents, &r.d->qt_rgn->extents))
4327  return *this;
4328  if (d == r.d || EqualRegion(d->qt_rgn, r.d->qt_rgn))
4329  return QRegion();
4330 
4331 #ifdef QT_REGION_DEBUG
4332  d->qt_rgn->selfTest();
4333  r.d->qt_rgn->selfTest();
4334 #endif
4335 
4336  QRegion result;
4337  result.detach();
4338  SubtractRegion(d->qt_rgn, r.d->qt_rgn, *result.d->qt_rgn);
4339 #ifdef QT_REGION_DEBUG
4340  result.d->qt_rgn->selfTest();
4341 #endif
4342  return result;
4343 }
void detach()
Definition: qregion.cpp:300
static void SubtractRegion(QRegionPrivate *regM, QRegionPrivate *regS, register QRegionPrivate &dest)
Definition: qregion.cpp:2755
QRegionPrivate * qt_rgn
Definition: qregion.h:211
QRegion()
Constructs an empty region.
Definition: qregion.cpp:3961
#define EXTENTCHECK(r1, r2)
Definition: qregion.cpp:1846
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
static bool EqualRegion(const QRegionPrivate *r1, const QRegionPrivate *r2)
Definition: qregion.cpp:2810
struct QRegionData * d
Definition: qregion.h:217
static bool isEmptyHelper(const QRegionPrivate *preg)
Definition: qregion.cpp:1321
bool contains(const QRegionPrivate &r) const
Definition: qregion.cpp:1263

◆ subtracted()

QRegion QRegion::subtracted ( const QRegion r) const
inline

Returns a region which is r subtracted from this region.

Since
4.2
rsubtract.png
Region Subtraction

The figure shows the result when the ellipse on the right is subtracted from the ellipse on the left ({left - right}).

See also
intersected(), united(), xored()

Definition at line 114 of file qregion.h.

Referenced by QPlastiqueStyle::drawControl(), QGtkStyle::drawControl(), exec(), operator-(), and QmlJSDebugger::SubcomponentMaskLayerItem::setCurrentItem().

114 { return subtract(r); }
QRegion subtract(const QRegion &r) const
Use subtracted(r) instead.
Definition: qregion.cpp:4320

◆ swap()

void QRegion::swap ( QRegion other)
inline

Swaps region other with this region.

Since
4.8

This operation is very fast and never fails.

Definition at line 88 of file qregion.h.

88 { qSwap(d, other.d); }
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
struct QRegionData * d
Definition: qregion.h:217

◆ translate() [1/2]

void QRegion::translate ( int  dx,
int  dy 
)

Translates (moves) the region dx along the X axis and dy along the Y axis.

Definition at line 4116 of file qregion.cpp.

Referenced by QOnScreenRasterPaintEngine::begin(), QWidgetBackingStore::beginPaint(), effectiveState(), exec(), QX11WindowSurface::flush(), QWSWindowSurface::flush(), QWSYellowSurface::flush(), QWidgetPrivate::getOpaqueChildren(), isServerProcess(), make_widget_eventUPP(), QMatrix::map(), QTransform::map(), QWidgetPrivate::moveRect(), QWSServerPrivate::moveWindowRegion(), QWidgetPrivate::paintSiblingsRecursive(), QMacCGContext::QMacCGContext(), qt_bitmapToRegion(), qt_mac_unregister_widget(), QGraphicsItem::scroll(), QWidgetPrivate::scrollRect(), QWSWindowSurface::setClipRegion(), QWidget::setMask(), QWidgetBackingStore::showYellowThing(), QWidgetBackingStore::staticContents(), QWidgetPrivate::subtractOpaqueSiblings(), QWidgetBackingStore::sync(), QPaintEnginePrivate::transformSystemClip(), translated(), QETWidget::translateRegionEvent(), and QETWidget::updateRegion().

4117 {
4118  if ((dx == 0 && dy == 0) || isEmptyHelper(d->qt_rgn))
4119  return;
4120 
4121  detach();
4122  OffsetRegion(*d->qt_rgn, dx, dy);
4123 }
void detach()
Definition: qregion.cpp:300
QRegionPrivate * qt_rgn
Definition: qregion.h:211
struct QRegionData * d
Definition: qregion.h:217
static bool isEmptyHelper(const QRegionPrivate *preg)
Definition: qregion.cpp:1321
static void OffsetRegion(register QRegionPrivate &region, register int x, register int y)
Definition: qregion.cpp:2054

◆ translate() [2/2]

void QRegion::translate ( const QPoint point)
inline

Translates the region {point}.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

x() along the x axis and {point}.y() along the y axis, relative to the current position. Positive values move the region to the right and down.

Translates to the given point.

Definition at line 98 of file qregion.h.

Referenced by translate().

98 { translate(p.x(), p.y()); }
void translate(int dx, int dy)
Translates (moves) the region dx along the X axis and dy along the Y axis.
Definition: qregion.cpp:4116

◆ translated() [1/2]

QRegion QRegion::translated ( int  dx,
int  dy 
) const

◆ translated() [2/2]

QRegion QRegion::translated ( const QPoint p) const
inline

Returns a copy of the regtion that is translated {p}.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.1

x() along the x axis and {p}.y() along the y axis, relative to the current position. Positive values move the rectangle to the right and down.

See also
translate()

Definition at line 100 of file qregion.h.

Referenced by translated().

100 { return translated(p.x(), p.y()); }
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
QRegion translated(int dx, int dy) const
Returns a copy of the region that is translated dx along the x axis and dy along the y axis...
Definition: qregion.cpp:743
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128

◆ unite() [1/2]

QRegion QRegion::unite ( const QRegion r) const

Use united(r) instead.

Definition at line 4125 of file qregion.cpp.

Referenced by clipTransformIsSimple(), qt_bitmapToRegion(), and QColumnView::visualRegionForSelection().

4126 {
4127  if (isEmptyHelper(d->qt_rgn))
4128  return r;
4129  if (isEmptyHelper(r.d->qt_rgn))
4130  return *this;
4131  if (d == r.d)
4132  return *this;
4133 
4134  if (d->qt_rgn->contains(*r.d->qt_rgn)) {
4135  return *this;
4136  } else if (r.d->qt_rgn->contains(*d->qt_rgn)) {
4137  return r;
4138  } else if (d->qt_rgn->canAppend(r.d->qt_rgn)) {
4139  QRegion result(*this);
4140  result.detach();
4141  result.d->qt_rgn->append(r.d->qt_rgn);
4142  return result;
4143  } else if (d->qt_rgn->canPrepend(r.d->qt_rgn)) {
4144  QRegion result(*this);
4145  result.detach();
4146  result.d->qt_rgn->prepend(r.d->qt_rgn);
4147  return result;
4148  } else if (EqualRegion(d->qt_rgn, r.d->qt_rgn)) {
4149  return *this;
4150  } else {
4151  QRegion result;
4152  result.detach();
4153  UnionRegion(d->qt_rgn, r.d->qt_rgn, *result.d->qt_rgn);
4154  return result;
4155  }
4156 }
void detach()
Definition: qregion.cpp:300
QRegionPrivate * qt_rgn
Definition: qregion.h:211
static void UnionRegion(const QRegionPrivate *reg1, const QRegionPrivate *reg2, QRegionPrivate &dest)
Definition: qregion.cpp:2577
bool canPrepend(const QRect *r) const
Definition: qregion.cpp:1691
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
static bool EqualRegion(const QRegionPrivate *r1, const QRegionPrivate *r2)
Definition: qregion.cpp:2810
bool canAppend(const QRect *r) const
Definition: qregion.cpp:1669
struct QRegionData * d
Definition: qregion.h:217
static bool isEmptyHelper(const QRegionPrivate *preg)
Definition: qregion.cpp:1321
bool contains(const QRegionPrivate &r) const
Definition: qregion.cpp:1263

◆ unite() [2/2]

QRegion QRegion::unite ( const QRect rect) const

Use united(rect) instead.

Since
4.4

Definition at line 4188 of file qregion.cpp.

4189 {
4190  if (isEmptyHelper(d->qt_rgn))
4191  return r;
4192  if (r.isEmpty())
4193  return *this;
4194 
4195  if (d->qt_rgn->contains(r)) {
4196  return *this;
4197  } else if (d->qt_rgn->within(r)) {
4198  return r;
4199  } else if (d->qt_rgn->numRects == 1 && d->qt_rgn->extents == r) {
4200  return *this;
4201  } else if (d->qt_rgn->canAppend(&r)) {
4202  QRegion result(*this);
4203  result.detach();
4204  result.d->qt_rgn->append(&r);
4205  return result;
4206  } else if (d->qt_rgn->canPrepend(&r)) {
4207  QRegion result(*this);
4208  result.detach();
4209  result.d->qt_rgn->prepend(&r);
4210  return result;
4211  } else {
4212  QRegion result;
4213  result.detach();
4214  QRegionPrivate rp(r);
4215  UnionRegion(d->qt_rgn, &rp, *result.d->qt_rgn);
4216  return result;
4217  }
4218 }
void detach()
Definition: qregion.cpp:300
bool within(const QRect &r1) const
Definition: qregion.cpp:1276
QRegionPrivate * qt_rgn
Definition: qregion.h:211
static void UnionRegion(const QRegionPrivate *reg1, const QRegionPrivate *reg2, QRegionPrivate &dest)
Definition: qregion.cpp:2577
bool canPrepend(const QRect *r) const
Definition: qregion.cpp:1691
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
bool canAppend(const QRect *r) const
Definition: qregion.cpp:1669
struct QRegionData * d
Definition: qregion.h:217
static bool isEmptyHelper(const QRegionPrivate *preg)
Definition: qregion.cpp:1321
bool contains(const QRegionPrivate &r) const
Definition: qregion.cpp:1263

◆ united() [1/2]

QRegion QRegion::united ( const QRegion r) const
inline

Returns a region which is the union of this region and r.

Since
4.2
runion.png
Region Union

The figure shows the union of two elliptical regions.

See also
intersected(), subtracted(), xored()

Definition at line 110 of file qregion.h.

Referenced by exec(), operator+(), and operator|().

110 { return unite(r); }
QRegion unite(const QRegion &r) const
Use united(r) instead.
Definition: qregion.cpp:4125

◆ united() [2/2]

QRegion QRegion::united ( const QRect rect) const
inline

Returns a region which is the union of this region and the given rect.

Since
4.4
See also
intersected(), subtracted(), xored()

Definition at line 111 of file qregion.h.

111 { return unite(r); }
QRegion unite(const QRegion &r) const
Use united(r) instead.
Definition: qregion.cpp:4125

◆ winCombine()

QRegion QRegion::winCombine ( const QRegion r,
int  num 
) const
private

◆ xored()

QRegion QRegion::xored ( const QRegion r) const
inline

Returns a region which is the exclusive or (XOR) of this region and r.

Since
4.2
rxor.png
Region XORed

The figure shows the exclusive or of two elliptical regions.

See also
intersected(), united(), subtracted()

Definition at line 115 of file qregion.h.

Referenced by exec(), and operator^().

115 { return eor(r); }
QRegion eor(const QRegion &r) const
Use xored(r) instead.
Definition: qregion.cpp:4345

Friends and Related Functions

◆ operator<<

QDataStream & operator<< ( QDataStream s,
const QRegion r 
)
friend

Writes the region r to the stream s and returns a reference to the stream.

See also
Format of the QDataStream operators

Definition at line 446 of file qregion.cpp.

447 {
448  QVector<QRect> a = r.rects();
449  if (a.isEmpty()) {
450  s << (quint32)0;
451  } else {
452  if (s.version() == 1) {
453  int i;
454  for (i = a.size() - 1; i > 0; --i) {
455  s << (quint32)(12 + i * 24);
456  s << (int)QRGN_OR;
457  }
458  for (i = 0; i < a.size(); ++i) {
459  s << (quint32)(4+8) << (int)QRGN_SETRECT << a[i];
460  }
461  } else {
462  s << (quint32)(4 + 4 + 16 * a.size()); // 16: storage size of QRect
463  s << (qint32)QRGN_RECTS;
464  s << a;
465  }
466  }
467  return s;
468 }
int qint32
Definition: qglobal.h:937
long ASN1_INTEGER_get ASN1_INTEGER * a
#define QRGN_RECTS
Definition: qregion.cpp:322
#define QRGN_OR
Definition: qregion.cpp:318
#define QRGN_SETRECT
Definition: qregion.cpp:313
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
unsigned int quint32
Definition: qglobal.h:938
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ operator>>

QDataStream & operator>> ( QDataStream s,
QRegion r 
)
friend

Reads a region from the stream s into r and returns a reference to the stream.

See also
Format of the QDataStream operators

Definition at line 482 of file qregion.cpp.

483 {
484  QByteArray b;
485  s >> b;
486  r.exec(b, s.version(), s.byteOrder());
487  return s;
488 }
ByteOrder byteOrder() const
Returns the current byte order setting – either BigEndian or LittleEndian.
Definition: qdatastream.h:209
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
void exec(const QByteArray &ba, int ver=0, QDataStream::ByteOrder byteOrder=QDataStream::BigEndian)
Definition: qregion.cpp:336

◆ QETWidget

friend class QETWidget
friend

Definition at line 215 of file qregion.h.

◆ QRegionPrivate

friend struct QRegionPrivate
friend

Definition at line 195 of file qregion.h.

Referenced by copy(), QRegion(), qt_bitmapToRegion(), and UnionRectWithRegion().

◆ qt_region_strictContains

bool qt_region_strictContains ( const QRegion region,
const QRect rect 
)
friend

Returns true if rect is guaranteed to be fully contained in region.

Warning
This function is not part of the public interface.

A false return value does not guarantee the opposite.

Definition at line 4380 of file qregion.cpp.

4381 {
4382  if (isEmptyHelper(region.d->qt_rgn) || !rect.isValid())
4383  return false;
4384 
4385 #if 0 // TEST_INNERRECT
4386  static bool guard = false;
4387  if (guard)
4388  return false;
4389  guard = true;
4390  QRegion inner = region.d->qt_rgn->innerRect;
4391  Q_ASSERT((inner - region).isEmpty());
4392  guard = false;
4393 
4394  int maxArea = 0;
4395  for (int i = 0; i < region.d->qt_rgn->numRects; ++i) {
4396  const QRect r = region.d->qt_rgn->rects.at(i);
4397  if (r.width() * r.height() > maxArea)
4398  maxArea = r.width() * r.height();
4399  }
4400 
4401  if (maxArea > region.d->qt_rgn->innerArea) {
4402  qDebug() << "not largest rectangle" << region << region.d->qt_rgn->innerRect;
4403  }
4404  Q_ASSERT(maxArea <= region.d->qt_rgn->innerArea);
4405 #endif
4406 
4407  const QRect r1 = region.d->qt_rgn->innerRect;
4408  return (rect.left() >= r1.left() && rect.right() <= r1.right()
4409  && rect.top() >= r1.top() && rect.bottom() <= r1.bottom());
4410 }
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QRegionPrivate * qt_rgn
Definition: qregion.h:211
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_CORE_EXPORT void qDebug(const char *,...)
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QVector< QRect > rects
Definition: qregion.cpp:1227
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
struct QRegionData * d
Definition: qregion.h:217
static bool isEmptyHelper(const QRegionPrivate *preg)
Definition: qregion.cpp:1321

Properties

◆ d

struct QRegionData* QRegion::d
private

◆ shared_empty

QRegion::QRegionData QRegion::shared_empty = { Q_BASIC_ATOMIC_INITIALIZER(1), 0 }
staticprivate

Definition at line 218 of file qregion.h.

Referenced by QRegionPrivate::canPrepend(), isEmpty(), isEmptyHelper(), and QRegion().


The documentation for this class was generated from the following files: