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 class Q_DECL_HIDDEN Region::Private
19 {
20 public:
21  Private(const QRegion &region);
22  void installRegion(const QRect &rect);
23  void installRegion(const QRegion &region);
24  void uninstallRegion(const QRect &rect);
25  void uninstallRegion(const QRegion &region);
26 
27  WaylandPointer<wl_region, wl_region_destroy> region;
28  QRegion qtRegion;
29 };
30 
31 Region::Private::Private(const QRegion &region)
32  : qtRegion(region)
33 {
34 }
35 
36 void Region::Private::installRegion(const QRect &rect)
37 {
38  if (!region.isValid()) {
39  return;
40  }
41  wl_region_add(region, rect.x(), rect.y(), rect.width(), rect.height());
42 }
43 
44 void Region::Private::installRegion(const QRegion &region)
45 {
46  for (const QRect &rect : region) {
47  installRegion(rect);
48  }
49 }
50 
51 void Region::Private::uninstallRegion(const QRect &rect)
52 {
53  if (!region.isValid()) {
54  return;
55  }
56  wl_region_subtract(region, rect.x(), rect.y(), rect.width(), rect.height());
57 }
58 
59 void Region::Private::uninstallRegion(const QRegion &region)
60 {
61  for (const QRect &rect : region) {
62  uninstallRegion(rect);
63  }
64 }
65 
66 Region::Region(const QRegion &region, QObject *parent)
67  : QObject(parent)
68  , d(new Private(region))
69 {
70 }
71 
72 Region::~Region()
73 {
74  release();
75 }
76 
78 {
79  d->region.release();
80 }
81 
82 void Region::destroy()
83 {
84  d->region.destroy();
85 }
86 
87 void Region::setup(wl_region *region)
88 {
89  Q_ASSERT(region);
90  d->region.setup(region);
91  d->installRegion(d->qtRegion);
92 }
93 
94 bool Region::isValid() const
95 {
96  return d->region.isValid();
97 }
98 
99 void Region::add(const QRect &rect)
100 {
101  d->qtRegion = d->qtRegion.united(rect);
102  d->installRegion(rect);
103 }
104 
105 void Region::add(const QRegion &region)
106 {
107  d->qtRegion = d->qtRegion.united(region);
108  d->installRegion(region);
109 }
110 
111 void Region::subtract(const QRect &rect)
112 {
113  d->qtRegion = d->qtRegion.subtracted(rect);
114  d->uninstallRegion(rect);
115 }
116 
117 void Region::subtract(const QRegion &region)
118 {
119  d->qtRegion = d->qtRegion.subtracted(region);
120  d->uninstallRegion(region);
121 }
122 
123 QRegion Region::region() const
124 {
125  return d->qtRegion;
126 }
127 
128 Region::operator wl_region *() const
129 {
130  return d->region;
131 }
132 
133 Region::operator wl_region *()
134 {
135  return d->region;
136 }
137 
138 }
139 }
virtual void release(quint64 objid)
int width() const const
int x() const const
int y() const const
int height() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Jan 30 2023 03:56:24 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.