pub struct Region<'a> { /* private fields */ }
Expand description
Notice these docs are heavy WIP and not very relevent yet
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().
Iteration over the region (with begin(), end(), or C++11 ranged-for loops) gives a decomposition of the region into rectangles.
Example of using complex regions:
Additional License Information
On Embedded Linux 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.
r
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: Painter::set_clip_region
Painter::set_clip_rect
[PainterPath
]
Licence
The documentation is an adoption of the original Qt Documentation and provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Implementations
sourceimpl<'a> Region<'a>
impl<'a> Region<'a>
pub fn new() -> Region<'a>
sourcepub fn swap<R: RegionTrait<'a>>(&self, other: &R) -> &Self
pub fn swap<R: RegionTrait<'a>>(&self, other: &R) -> &Self
Swaps region other with this region. This operation is very fast and never fails.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the region is empty; otherwise returns false.
An
empty region is a region that contains no points.
Example:
sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
Returns true
if the region is empty; otherwise returns false.
An
empty region is a region that contains no points. This function is
the same as isEmpty
See also: [is_empty()
]
sourcepub fn contains<P: PointTrait<'a>>(&self, p: &P) -> bool
pub fn contains<P: PointTrait<'a>>(&self, p: &P) -> bool
Returns true
if the region contains the point p; otherwise
returns false.
Overloads
Returns true
if the region overlaps the rectangle r; otherwise
returns false.
sourcepub fn contains_2<R: RectTrait<'a>>(&self, r: &R) -> bool
pub fn contains_2<R: RectTrait<'a>>(&self, r: &R) -> bool
Returns true
if the region contains the point p; otherwise
returns false.
Overloads
Returns true
if the region overlaps the rectangle r; otherwise
returns false.
sourcepub fn united<R: RegionTrait<'a>>(&self, r: &R) -> Region<'_>
pub fn united<R: RegionTrait<'a>>(&self, r: &R) -> Region<'_>
Returns a region which is the union of this region and the given rect.
See also: [intersected()
]
[subtracted()
]
[xored()
]
Returns a region which is the union of this region and r.
The figure shows the union of two elliptical regions.
See also: [intersected()
]
[subtracted()
]
[xored()
]
sourcepub fn united_2<R: RectTrait<'a>>(&self, r: &R) -> Region<'_>
pub fn united_2<R: RectTrait<'a>>(&self, r: &R) -> Region<'_>
Returns a region which is the union of this region and the given rect.
See also: [intersected()
]
[subtracted()
]
[xored()
]
Returns a region which is the union of this region and r.
The figure shows the union of two elliptical regions.
See also: [intersected()
]
[subtracted()
]
[xored()
]
sourcepub fn intersected<R: RegionTrait<'a>>(&self, r: &R) -> Region<'_>
pub fn intersected<R: RegionTrait<'a>>(&self, r: &R) -> Region<'_>
Returns a region which is the intersection of this region and the given rect.
See also: [subtracted()
]
[united()
]
[xored()
]
Returns a region which is the intersection of this region and r.
The figure shows the intersection of two elliptical regions.
See also: [subtracted()
]
[united()
]
[xored()
]
sourcepub fn intersected_2<R: RectTrait<'a>>(&self, r: &R) -> Region<'_>
pub fn intersected_2<R: RectTrait<'a>>(&self, r: &R) -> Region<'_>
Returns a region which is the intersection of this region and the given rect.
See also: [subtracted()
]
[united()
]
[xored()
]
Returns a region which is the intersection of this region and r.
The figure shows the intersection of two elliptical regions.
See also: [subtracted()
]
[united()
]
[xored()
]
sourcepub fn xored<R: RegionTrait<'a>>(&self, r: &R) -> Region<'_>
pub fn xored<R: RegionTrait<'a>>(&self, r: &R) -> Region<'_>
Returns a region which is the exclusive or (XOR) of this region and r.
The figure shows the exclusive or of two elliptical regions.
See also: [intersected()
]
[united()
]
[subtracted()
]
sourcepub fn intersects<R: RegionTrait<'a>>(&self, r: &R) -> bool
pub fn intersects<R: RegionTrait<'a>>(&self, r: &R) -> bool
Returns true
if this region intersects with region, otherwise
returns false.
Returns true
if this region intersects with rect, otherwise
returns false.
sourcepub fn intersects_2<R: RectTrait<'a>>(&self, r: &R) -> bool
pub fn intersects_2<R: RectTrait<'a>>(&self, r: &R) -> bool
Returns true
if this region intersects with region, otherwise
returns false.
Returns true
if this region intersects with rect, otherwise
returns false.
sourcepub fn bounding_rect(&self) -> Rect<'_>
pub fn bounding_rect(&self) -> Rect<'_>
Returns the bounding rectangle of this region. An empty region gives a rectangle that is QRect::isNull().
sourcepub fn set_rects<R: RectTrait<'a>>(&self, rect: &R, num: i32) -> &Self
pub fn set_rects<R: RectTrait<'a>>(&self, rect: &R, num: i32) -> &Self
Use begin() and end() instead.
Returns an array of non-overlapping rectangles that make up the region.
The union of all the rectangles is equal to the original region.
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.
sourcepub fn rect_count(&self) -> i32
pub fn rect_count(&self) -> i32
Returns the number of rectangles that this region is composed of.
Same as end() - begin()
.