KWayland

region.cpp
1 /*
2  SPDX-FileCopyrightText: 2014 Martin Gräßlin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "region.h"
7 #include "wayland_pointer_p.h"
8 // Qt
9 #include <QRegion>
10 #include <QVector>
11 // Wayland
12 #include <wayland-client-protocol.h>
13 
14 namespace KWayland
15 {
16 namespace Client
17 {
18 
19 class Q_DECL_HIDDEN Region::Private
20 {
21 public:
22  Private(const QRegion &region);
23  void installRegion(const QRect &rect);
24  void installRegion(const QRegion &region);
25  void uninstallRegion(const QRect &rect);
26  void uninstallRegion(const QRegion &region);
27 
28  WaylandPointer<wl_region, wl_region_destroy> region;
29  QRegion qtRegion;
30 };
31 
32 Region::Private::Private(const QRegion &region)
33  : qtRegion(region)
34 {
35 }
36 
37 void Region::Private::installRegion(const QRect &rect)
38 {
39  if (!region.isValid()) {
40  return;
41  }
42  wl_region_add(region, rect.x(), rect.y(), rect.width(), rect.height());
43 }
44 
45 void Region::Private::installRegion(const QRegion &region)
46 {
47  for (const QRect &rect : region) {
48  installRegion(rect);
49  }
50 }
51 
52 void Region::Private::uninstallRegion(const QRect &rect)
53 {
54  if (!region.isValid()) {
55  return;
56  }
57  wl_region_subtract(region, rect.x(), rect.y(), rect.width(), rect.height());
58 }
59 
60 void Region::Private::uninstallRegion(const QRegion &region)
61 {
62  for (const QRect &rect : region) {
63  uninstallRegion(rect);
64  }
65 }
66 
67 Region::Region(const QRegion &region, QObject *parent)
68  : QObject(parent)
69  , d(new Private(region))
70 {
71 }
72 
73 Region::~Region()
74 {
75  release();
76 }
77 
78 void Region::release()
79 {
80  d->region.release();
81 }
82 
83 void Region::destroy()
84 {
85  d->region.destroy();
86 }
87 
88 void Region::setup(wl_region *region)
89 {
90  Q_ASSERT(region);
91  d->region.setup(region);
92  d->installRegion(d->qtRegion);
93 }
94 
95 bool Region::isValid() const
96 {
97  return d->region.isValid();
98 }
99 
100 void Region::add(const QRect &rect)
101 {
102  d->qtRegion = d->qtRegion.united(rect);
103  d->installRegion(rect);
104 }
105 
106 void Region::add(const QRegion &region)
107 {
108  d->qtRegion = d->qtRegion.united(region);
109  d->installRegion(region);
110 }
111 
112 void Region::subtract(const QRect &rect)
113 {
114  d->qtRegion = d->qtRegion.subtracted(rect);
115  d->uninstallRegion(rect);
116 }
117 
118 void Region::subtract(const QRegion &region)
119 {
120  d->qtRegion = d->qtRegion.subtracted(region);
121  d->uninstallRegion(region);
122 }
123 
124 QRegion Region::region() const
125 {
126  return d->qtRegion;
127 }
128 
129 Region::operator wl_region*() const
130 {
131  return d->region;
132 }
133 
134 Region::operator wl_region*()
135 {
136  return d->region;
137 }
138 
139 }
140 }
int height() const const
int x() const const
int y() const const
int width() const const
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 7 2020 22:48:19 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.