Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
ZoneDetector.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
10#include <QPointF>
11#include <QRectF>
12#include <QVector>
13#include <memory>
14
15namespace PhosphorZones {
16class ZoneHighlighter;
17} // namespace PhosphorZones
18
19namespace PhosphorZones {
20
21// ZoneDetectionResult is defined in IZoneDetector.h
22
37class PHOSPHORZONES_EXPORT ZoneDetector : public IZoneDetector
38{
39 Q_OBJECT
40
41 // Fully-qualified property type so moc's NOTIFY-signal validity check
42 // (a global-namespace namespace block that references the property
43 // type by its textual spelling) can resolve the type.
44 Q_PROPERTY(PhosphorZones::Layout* layout READ layout WRITE setLayout NOTIFY layoutChanged)
45
46public:
47 explicit ZoneDetector(QObject* parent = nullptr);
48 ~ZoneDetector() override; // Defined in .cpp to allow unique_ptr with forward declaration
49
50 // IZoneDetector interface implementation
51 Layout* layout() const override
52 {
53 return m_layout;
54 }
55 void setLayout(Layout* layout) override;
56
70 {
71 m_adjacentThreshold = px;
72 }
74 {
75 return m_adjacentThreshold;
76 }
77
78 Q_INVOKABLE ZoneDetectionResult detectZone(const QPointF& cursorPos) const override;
79 Q_INVOKABLE ZoneDetectionResult detectMultiZone(const QPointF& cursorPos) const override;
86 Q_INVOKABLE QVector<Zone*> expandPaintedZonesToRect(const QVector<Zone*>& seedZones) const override;
87 Q_INVOKABLE Zone* zoneAtPoint(const QPointF& point) const override;
88 Q_INVOKABLE Zone* nearestZone(const QPointF& point) const override;
89
90 // Note: Highlighting methods removed - use ZoneHighlighter instead
91 // These methods are kept for backward compatibility but delegate to ZoneHighlighter
92 Q_INVOKABLE void highlightZone(Zone* zone) override;
93 Q_INVOKABLE void highlightZones(const QVector<Zone*>& zones) override;
94 Q_INVOKABLE void clearHighlights() override;
95
96 // Signals (layoutChanged, zoneHighlighted, highlightsCleared) are
97 // inherited from IZoneDetector. Redeclaring them here would make moc
98 // generate a second metaObject entry for each, causing connections
99 // established through IZoneDetector* to fire a different slot from
100 // connections made through ZoneDetector* — exactly the "signal
101 // shadowing" pitfall that ILayoutManager.h warns against.
102
103private:
104 QRectF combineZoneGeometries(const QVector<Zone*>& zones) const;
105 bool areZonesAdjacent(Zone* zone1, Zone* zone2) const;
106 qreal distanceToZoneEdge(const QPointF& point, Zone* zone) const;
107 Zone* resolveOverlappingZone(const QPointF& point) const;
108
109 Layout* m_layout = nullptr;
110 int m_adjacentThreshold = ::PhosphorZones::ZoneDefaults::AdjacentThreshold;
111
112 // UI state management
113 std::unique_ptr<class ZoneHighlighter> m_highlighter;
114};
115
116} // namespace PhosphorZones
117
118// Q_DECLARE_METATYPE is in IZoneDetector.h
Abstract interface for zone detection + highlight lifecycle.
Definition IZoneDetector.h:84
Represents a collection of zones that form a layout.
Definition Layout.h:74
Efficient zone detection for window snapping.
Definition ZoneDetector.h:38
void highlightZone(Zone *zone) override
Layout * layout() const override
Definition ZoneDetector.h:51
Zone * nearestZone(const QPointF &point) const override
ZoneDetector(QObject *parent=nullptr)
void setLayout(Layout *layout) override
void highlightZones(const QVector< Zone * > &zones) override
int adjacentThreshold() const
Definition ZoneDetector.h:73
Zone * zoneAtPoint(const QPointF &point) const override
QVector< Zone * > expandPaintedZonesToRect(const QVector< Zone * > &seedZones) const override
Expand painted zones to include all zones that intersect the bounding rect.
void clearHighlights() override
ZoneDetectionResult detectMultiZone(const QPointF &cursorPos) const override
void setAdjacentThreshold(int px)
Set the adjacency threshold used by detectMultiZone / areZonesAdjacent.
Definition ZoneDetector.h:69
ZoneDetectionResult detectZone(const QPointF &cursorPos) const override
Represents a single zone within a layout.
Definition Zone.h:44
constexpr int AdjacentThreshold
Pixel distance considered "adjacent" for multi-zone span detection.
Definition ZoneDefaults.h:41
Definition IWindowTrackingService.h:22
Result of zone detection.
Definition IZoneDetector.h:32