summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qregion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/painting/qregion.cpp')
-rw-r--r--src/gui/painting/qregion.cpp142
1 files changed, 87 insertions, 55 deletions
diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp
index 8021b17c6b..8b712ee46d 100644
--- a/src/gui/painting/qregion.cpp
+++ b/src/gui/painting/qregion.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qregion.h"
#include "qpainterpath.h"
@@ -48,8 +12,13 @@
#include "qbitmap.h"
#include "qtransform.h"
+#include <memory>
#include <private/qdebug_p.h>
+#ifdef Q_OS_WIN
+# include <qt_windows.h>
+#endif
+
QT_BEGIN_NAMESPACE
/*!
@@ -82,7 +51,7 @@ QT_BEGIN_NAMESPACE
contains() a QPoint or QRect. The bounding rectangle can be found
with boundingRect().
- Iteration over the region (with begin(), end(), or C++11
+ Iteration over the region (with begin(), end(), or
ranged-for loops) gives a decomposition of the region into
rectangles.
@@ -130,7 +99,7 @@ QT_BEGIN_NAMESPACE
\fn QRegion::QRegion(const QRect &r, RegionType t)
\overload
- Create a region based on the rectange \a r with region type \a t.
+ Create a region based on the rectangle \a r with region type \a t.
If the rectangle is invalid a null region will be created.
@@ -296,7 +265,7 @@ void QRegion::exec(const QByteArray &buffer, int ver, QDataStream::ByteOrder byt
quint32 n;
s >> n;
QRect r;
- for (int i=0; i<(int)n; i++) {
+ for (int i=0; i < static_cast<int>(n); i++) {
s >> r;
rgn = rgn.united(QRegion(r));
}
@@ -345,19 +314,19 @@ QDataStream &operator<<(QDataStream &s, const QRegion &r)
{
auto b = r.begin(), e = r.end();
if (b == e) {
- s << (quint32)0;
+ s << static_cast<quint32>(0);
} else {
const auto size = e - b;
if (s.version() == 1) {
for (auto i = size - 1; i > 0; --i) {
- s << (quint32)(12 + i * 24);
- s << (int)QRGN_OR;
+ s << static_cast<quint32>(12 + i * 24);
+ s << static_cast<int>(QRGN_OR);
}
for (auto it = b; it != e; ++it)
- s << (quint32)(4+8) << (int)QRGN_SETRECT << *it;
+ s << static_cast<quint32>(4+8) << static_cast<int>(QRGN_SETRECT) << *it;
} else {
s << quint32(4 + 4 + 16 * size); // 16: storage size of QRect
- s << (qint32)QRGN_RECTS;
+ s << static_cast<qint32>(QRGN_RECTS);
s << quint32(size);
for (auto it = b; it != e; ++it)
s << *it;
@@ -579,7 +548,7 @@ QRegion& QRegion::operator^=(const QRegion &r)
*/
QRegion::operator QVariant() const
{
- return QVariant(QMetaType::QRegion, this);
+ return QVariant::fromValue(*this);
}
/*!
@@ -667,7 +636,7 @@ bool QRegion::intersects(const QRegion &region) const
*/
-#if !defined (Q_OS_UNIX) && !defined (Q_OS_WIN) || defined(Q_CLANG_QDOC)
+#if !defined (Q_OS_UNIX) && !defined (Q_OS_WIN) || defined(Q_QDOC)
/*
\overload
\since 4.4
@@ -1101,7 +1070,7 @@ Q_GUI_EXPORT QPainterPath qt_regionToPath(const QRegion &region)
struct QRegionPrivate {
int numRects;
int innerArea;
- QVector<QRect> rects;
+ QList<QRect> rects;
QRect extents;
QRect innerRect;
@@ -2173,7 +2142,7 @@ static void miRegionOp(QRegionPrivate &dest,
* reg1->rects and reg2->rects (if the regions have more than 1 rectangle),
* take a copy of dest.rects to keep those iteractors valid.
*/
- const QVector<QRect> destRectsCopy = dest.rects;
+ const QList<QRect> destRectsCopy = dest.rects;
Q_UNUSED(destRectsCopy);
dest.numRects = 0;
@@ -3222,8 +3191,7 @@ static void CreateETandAET(int count, const QPoint *pts,
int iSLLBlock = 0;
int dy;
- if (count < 2)
- return;
+ Q_ASSERT(count > 1);
/*
* initialize the Active Edge Table
@@ -3565,9 +3533,12 @@ static QRegionPrivate *PolygonRegion(const QPoint *Pts, int Count, int rule)
int fixWAET = false;
POINTBLOCK FirstPtBlock, *curPtBlock; /* PtBlock buffers */
FirstPtBlock.pts = reinterpret_cast<QPoint *>(FirstPtBlock.data);
+ FirstPtBlock.next = nullptr;
POINTBLOCK *tmpPtBlock;
int numFullPtBlocks = 0;
+ Q_ASSERT(Count > 1);
+
region = new QRegionPrivate;
/* special case a rectangle */
@@ -3846,7 +3817,7 @@ QRegion::QRegion(const QRect &r, RegionType t)
QRegion::QRegion(const QPolygon &a, Qt::FillRule fillRule)
{
- if (a.count() > 2) {
+ if (a.size() > 2) {
QRegionPrivate *qt_rgn = PolygonRegion(a.constData(), a.size(),
fillRule == Qt::WindingFill ? WindingRule : EvenOddRule);
if (qt_rgn) {
@@ -3908,7 +3879,7 @@ QRegion &QRegion::operator=(const QRegion &r)
QRegion QRegion::copy() const
{
QRegion r;
- QScopedPointer<QRegionData> x(new QRegionData);
+ auto x = std::make_unique<QRegionData>();
x->ref.initializeOwned();
if (d->qt_rgn)
x->qt_rgn = new QRegionPrivate(*d->qt_rgn);
@@ -3916,7 +3887,7 @@ QRegion QRegion::copy() const
x->qt_rgn = new QRegionPrivate;
if (!r.d->ref.deref())
cleanUp(r.d);
- r.d = x.take();
+ r.d = x.release();
return r;
}
@@ -4314,4 +4285,65 @@ bool QRegion::intersects(const QRect &rect) const
#endif
+
+#if defined(Q_OS_WIN) || defined(Q_QDOC)
+
+static inline HRGN qt_RectToHRGN(const QRect &rc)
+{
+ return CreateRectRgn(rc.left(), rc.top(), rc.right() + 1, rc.bottom() + 1);
+}
+
+/*!
+ \since 6.0
+
+ Returns a HRGN that is equivalent to the given region.
+*/
+HRGN QRegion::toHRGN() const
+{
+ const int size = rectCount();
+ if (size == 0)
+ return nullptr;
+
+ HRGN resultRgn = nullptr;
+ const auto rects = begin();
+ resultRgn = qt_RectToHRGN(rects[0]);
+ for (int i = 1; i < size; ++i) {
+ HRGN tmpRgn = qt_RectToHRGN(rects[i]);
+ int err = CombineRgn(resultRgn, resultRgn, tmpRgn, RGN_OR);
+ if (err == ERROR)
+ qWarning("Error combining HRGNs.");
+ DeleteObject(tmpRgn);
+ }
+ return resultRgn;
+}
+
+/*!
+ \since 6.0
+
+ Returns a QRegion that is equivalent to the given \a hrgn.
+ */
+QRegion QRegion::fromHRGN(HRGN hrgn)
+{
+ DWORD regionDataSize = GetRegionData(hrgn, 0, nullptr);
+ if (regionDataSize == 0)
+ return QRegion();
+
+ auto regionData = reinterpret_cast<LPRGNDATA>(malloc(regionDataSize));
+ if (!regionData)
+ return QRegion();
+
+ QRegion region;
+ if (GetRegionData(hrgn, regionDataSize, regionData) == regionDataSize) {
+ auto pRect = reinterpret_cast<LPRECT>(regionData->Buffer);
+ for (DWORD i = 0; i < regionData->rdh.nCount; ++i)
+ region += QRect(pRect[i].left, pRect[i].top,
+ pRect[i].right - pRect[i].left,
+ pRect[i].bottom - pRect[i].top);
+ }
+
+ free(regionData);
+ return region;
+}
+#endif // Q_OS_WIN || Q_QDOC
+
QT_END_NAMESPACE