Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
Zone.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
7#include <phosphorzones_export.h>
8#include <QObject>
9#include <QRect>
10#include <QUuid>
11#include <QString>
12#include <QColor>
13#include <QJsonObject>
14
15namespace PhosphorZones {
16
28enum class ZoneGeometryMode {
29 Relative = 0,
30 Fixed = 1
31};
32
43class PHOSPHORZONES_EXPORT Zone : public QObject
44{
45 Q_OBJECT
46
47 Q_PROPERTY(QUuid id READ id CONSTANT)
48 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
49 Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry NOTIFY geometryChanged)
50 Q_PROPERTY(QRectF relativeGeometry READ relativeGeometry WRITE setRelativeGeometry NOTIFY relativeGeometryChanged)
51 Q_PROPERTY(int zoneNumber READ zoneNumber WRITE setZoneNumber NOTIFY zoneNumberChanged)
52 Q_PROPERTY(QColor highlightColor READ highlightColor WRITE setHighlightColor NOTIFY highlightColorChanged)
53 Q_PROPERTY(QColor inactiveColor READ inactiveColor WRITE setInactiveColor NOTIFY inactiveColorChanged)
54 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
55 Q_PROPERTY(qreal activeOpacity READ activeOpacity WRITE setActiveOpacity NOTIFY activeOpacityChanged)
56 Q_PROPERTY(qreal inactiveOpacity READ inactiveOpacity WRITE setInactiveOpacity NOTIFY inactiveOpacityChanged)
57 Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged)
58 Q_PROPERTY(int borderRadius READ borderRadius WRITE setBorderRadius NOTIFY borderRadiusChanged)
59 Q_PROPERTY(bool isHighlighted READ isHighlighted WRITE setHighlighted NOTIFY highlightedChanged)
60 Q_PROPERTY(bool useCustomColors READ useCustomColors WRITE setUseCustomColors NOTIFY useCustomColorsChanged)
61 Q_PROPERTY(
62 int overlayDisplayMode READ overlayDisplayMode WRITE setOverlayDisplayMode NOTIFY overlayDisplayModeChanged)
63 Q_PROPERTY(int geometryMode READ geometryModeInt WRITE setGeometryModeInt NOTIFY geometryModeChanged)
64 Q_PROPERTY(QRectF fixedGeometry READ fixedGeometry WRITE setFixedGeometry NOTIFY fixedGeometryChanged)
65
66public:
67 explicit Zone(QObject* parent = nullptr);
68 explicit Zone(const QRectF& geometry, QObject* parent = nullptr);
69 ~Zone() override = default;
70
71 // QObjects should not be copied - use clone() instead
72 Zone(const Zone&) = delete;
73 Zone& operator=(const Zone&) = delete;
74
80 Q_INVOKABLE Zone* clone(QObject* parent = nullptr) const;
81
86 void copyPropertiesFrom(const Zone& other);
87
88 // Identification
89 QUuid id() const
90 {
91 return m_id;
92 }
93 QString name() const
94 {
95 return m_name;
96 }
97 void setName(const QString& name);
98
99 // Geometry (absolute pixel coordinates)
100 QRectF geometry() const
101 {
102 return m_geometry;
103 }
104 void setGeometry(const QRectF& geometry);
105
106 // Relative geometry (0.0-1.0 normalized coordinates for resolution independence)
107 QRectF relativeGeometry() const
108 {
109 return m_relativeGeometry;
110 }
111 void setRelativeGeometry(const QRectF& relativeGeometry);
112
113 // Zone numbering for keyboard navigation
114 int zoneNumber() const
115 {
116 return m_zoneNumber;
117 }
118 void setZoneNumber(int number);
119
120 // Ricer-friendly appearance customization
121 QColor highlightColor() const
122 {
123 return m_highlightColor;
124 }
125 void setHighlightColor(const QColor& color);
126
127 QColor inactiveColor() const
128 {
129 return m_inactiveColor;
130 }
131 void setInactiveColor(const QColor& color);
132
133 QColor borderColor() const
134 {
135 return m_borderColor;
136 }
137 void setBorderColor(const QColor& color);
138
139 qreal activeOpacity() const
140 {
141 return m_activeOpacity;
142 }
143 void setActiveOpacity(qreal opacity);
144
145 qreal inactiveOpacity() const
146 {
147 return m_inactiveOpacity;
148 }
149 void setInactiveOpacity(qreal opacity);
150
151 int borderWidth() const
152 {
153 return m_borderWidth;
154 }
155 void setBorderWidth(int width);
156
157 int borderRadius() const
158 {
159 return m_borderRadius;
160 }
161 void setBorderRadius(int radius);
162
163 bool isHighlighted() const
164 {
165 return m_isHighlighted;
166 }
167 void setHighlighted(bool highlighted);
168
169 bool useCustomColors() const
170 {
171 return m_useCustomColors;
172 }
173 void setUseCustomColors(bool useCustom);
174
176 {
177 return m_overlayDisplayMode;
178 }
179 void setOverlayDisplayMode(int mode);
180
181 // Per-zone geometry mode
183 {
184 return m_geometryMode;
185 }
186 int geometryModeInt() const
187 {
188 return static_cast<int>(m_geometryMode);
189 }
190 bool isFixedGeometry() const
191 {
192 return m_geometryMode == ZoneGeometryMode::Fixed;
193 }
195 void setGeometryModeInt(int mode);
196
197 QRectF fixedGeometry() const
198 {
199 return m_fixedGeometry;
200 }
201 void setFixedGeometry(const QRectF& geometry);
202
211 Q_INVOKABLE QRectF normalizedGeometry(const QRectF& referenceGeometry) const;
212
213 // Geometry calculations
214 Q_INVOKABLE bool containsPoint(const QPointF& point) const;
215 Q_INVOKABLE qreal distanceToPoint(const QPointF& point) const;
216 Q_INVOKABLE QRectF calculateAbsoluteGeometry(const QRectF& screenGeometry) const;
217 Q_INVOKABLE QRectF applyPadding(int padding) const;
218
226 static QRectF computeAbsoluteGeometry(ZoneGeometryMode mode, const QRectF& relativeGeometry,
227 const QRectF& fixedGeometry, const QRectF& screenGeometry);
228
229 // Serialization
230 QJsonObject toJson(const QRectF& referenceGeometry = QRectF()) const;
231 static Zone* fromJson(const QJsonObject& json, QObject* parent = nullptr);
232
233Q_SIGNALS:
250
251private:
252 QUuid m_id;
253 QString m_name;
254 QRectF m_geometry;
255 QRectF m_relativeGeometry;
256 int m_zoneNumber = 0;
257
258 // Appearance (ricer-friendly) — defaults sourced from PhosphorZones::ZoneDefaults.
259 QColor m_highlightColor = ::PhosphorZones::ZoneDefaults::HighlightColor;
260 QColor m_inactiveColor = ::PhosphorZones::ZoneDefaults::InactiveColor;
261 QColor m_borderColor = ::PhosphorZones::ZoneDefaults::BorderColor;
262 qreal m_activeOpacity = ::PhosphorZones::ZoneDefaults::Opacity;
263 qreal m_inactiveOpacity = ::PhosphorZones::ZoneDefaults::InactiveOpacity;
266 bool m_isHighlighted = false;
267 bool m_useCustomColors = false;
268 int m_overlayDisplayMode = -1; // -1 = use layout/global setting
269
270 // Per-zone geometry mode
271 ZoneGeometryMode m_geometryMode = ZoneGeometryMode::Relative;
272 QRectF m_fixedGeometry; // Absolute pixel coords relative to screen origin
273};
274
275} // namespace PhosphorZones
Represents a single zone within a layout.
Definition Zone.h:44
~Zone() override=default
QRectF fixedGeometry() const
Definition Zone.h:197
void setRelativeGeometry(const QRectF &relativeGeometry)
bool useCustomColors() const
Definition Zone.h:169
void setGeometry(const QRectF &geometry)
void setActiveOpacity(qreal opacity)
QColor highlightColor() const
Definition Zone.h:121
QColor inactiveColor() const
Definition Zone.h:127
void setInactiveColor(const QColor &color)
Zone(const QRectF &geometry, QObject *parent=nullptr)
void inactiveOpacityChanged()
static QRectF computeAbsoluteGeometry(ZoneGeometryMode mode, const QRectF &relativeGeometry, const QRectF &fixedGeometry, const QRectF &screenGeometry)
Pure helper shared between Zone::calculateAbsoluteGeometry and LayoutWorker (which runs off-thread an...
ZoneGeometryMode geometryMode() const
Definition Zone.h:182
int overlayDisplayMode() const
Definition Zone.h:175
qreal distanceToPoint(const QPointF &point) const
int zoneNumber() const
Definition Zone.h:114
QRectF calculateAbsoluteGeometry(const QRectF &screenGeometry) const
void setGeometryMode(ZoneGeometryMode mode)
QRectF relativeGeometry() const
Definition Zone.h:107
QRectF normalizedGeometry(const QRectF &referenceGeometry) const
Returns normalized 0-1 coordinates regardless of geometry mode.
void setBorderColor(const QColor &color)
int geometryModeInt() const
Definition Zone.h:186
int borderRadius() const
Definition Zone.h:157
QString name() const
Definition Zone.h:93
Zone(const Zone &)=delete
void relativeGeometryChanged()
void setZoneNumber(int number)
void useCustomColorsChanged()
bool isHighlighted() const
Definition Zone.h:163
int borderWidth() const
Definition Zone.h:151
Zone & operator=(const Zone &)=delete
void copyPropertiesFrom(const Zone &other)
Copies properties from another zone (excluding ID)
void setName(const QString &name)
QRectF applyPadding(int padding) const
bool containsPoint(const QPointF &point) const
void setHighlightColor(const QColor &color)
Zone(QObject *parent=nullptr)
void setGeometryModeInt(int mode)
static Zone * fromJson(const QJsonObject &json, QObject *parent=nullptr)
void setBorderWidth(int width)
void overlayDisplayModeChanged()
void setFixedGeometry(const QRectF &geometry)
void highlightColorChanged()
bool isFixedGeometry() const
Definition Zone.h:190
QColor borderColor() const
Definition Zone.h:133
void setHighlighted(bool highlighted)
void setBorderRadius(int radius)
QUuid id() const
Definition Zone.h:89
QRectF geometry() const
Definition Zone.h:100
QJsonObject toJson(const QRectF &referenceGeometry=QRectF()) const
void setOverlayDisplayMode(int mode)
void setUseCustomColors(bool useCustom)
Zone * clone(QObject *parent=nullptr) const
Creates a copy of this zone with a new unique ID.
qreal activeOpacity() const
Definition Zone.h:139
void setInactiveOpacity(qreal opacity)
qreal inactiveOpacity() const
Definition Zone.h:145
const QColor HighlightColor
Windows blue.
Definition ZoneDefaults.h:29
constexpr int BorderRadius
Definition ZoneDefaults.h:38
const QColor InactiveColor
Definition ZoneDefaults.h:30
constexpr qreal Opacity
Definition ZoneDefaults.h:35
constexpr int BorderWidth
Definition ZoneDefaults.h:37
constexpr qreal InactiveOpacity
Definition ZoneDefaults.h:36
const QColor BorderColor
Definition ZoneDefaults.h:31
Definition IWindowTrackingService.h:22
ZoneGeometryMode
Geometry mode for individual zones.
Definition Zone.h:28