Loading...
Searching...
No Matches
OutputMapping.hpp
1#pragma once
2#include <Gfx/Window/WindowSettings.hpp>
3
4#include <QGraphicsRectItem>
5#include <QGraphicsScene>
6#include <QGraphicsView>
7
8namespace Gfx
9{
10
11class OutputMappingCanvas;
12
13// Graphics item for draggable/resizable output mapping quads
14class OutputMappingItem final : public QGraphicsRectItem
15{
16public:
17 explicit OutputMappingItem(
18 int index, const QRectF& rect, OutputMappingCanvas* canvas,
19 QGraphicsItem* parent = nullptr);
20
21 int outputIndex() const noexcept { return m_index; }
22 void setOutputIndex(int idx);
23
24 // Per-output window properties stored on the item
25 int screenIndex{-1};
26 QPoint windowPosition{0, 0};
27 QSize windowSize{1280, 720};
28 bool fullscreen{false};
29
30 // Soft-edge blending
31 EdgeBlend blendLeft;
32 EdgeBlend blendRight;
33 EdgeBlend blendTop;
34 EdgeBlend blendBottom;
35
36 // 4-corner perspective warp
37 CornerWarp cornerWarp;
38
39 OutputLockMode lockMode{OutputLockMode::Free};
40
41 void applyLockedState();
42
43 // Called when item is moved or resized in the canvas
44 std::function<void()> onChanged;
45
46 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
47 override;
48
49protected:
50 QVariant itemChange(GraphicsItemChange change, const QVariant& value) override;
51 void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
52 void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
53 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
54 void hoverMoveEvent(QGraphicsSceneHoverEvent* event) override;
55
56private:
57 enum ResizeEdge
58 {
59 None = 0,
60 Left = 1,
61 Right = 2,
62 Top = 4,
63 Bottom = 8
64 };
65 int hitTestEdges(const QPointF& pos) const;
66
67 enum BlendHandle
68 {
69 BlendNone = 0,
70 BlendLeft,
71 BlendRight,
72 BlendTop,
73 BlendBottom
74 };
75 BlendHandle hitTestBlendHandles(const QPointF& pos) const;
76
77 int m_index{};
78 int m_resizeEdges{None};
79 BlendHandle m_blendHandle{BlendNone};
80 QPointF m_dragStart{};
81 QRectF m_rectStart{};
82 QPointF m_moveAnchorScene{}; // scene pos at press for precision move
83 QPointF m_posAtPress{}; // item pos() at press
84 OutputMappingCanvas* m_canvas{};
85};
86
87class OutputMappingCanvas final : public QGraphicsView
88{
89public:
90 explicit OutputMappingCanvas(QWidget* parent = nullptr);
92
93 void setMappings(const std::vector<OutputMapping>& mappings);
94 std::vector<OutputMapping> getMappings() const;
95
96 void addOutput();
97 void removeSelectedOutput();
98
99 void updateAspectRatio(int inputWidth, int inputHeight);
100
101 double canvasWidth() const noexcept { return m_canvasWidth; }
102 double canvasHeight() const noexcept { return m_canvasHeight; }
103
104 bool snapEnabled() const noexcept { return m_snapEnabled; }
105 void setSnapEnabled(bool enabled);
106 QPointF snapPosition(const OutputMappingItem* item, QPointF proposedPos) const;
107
108 // Warp mode: double-click an item to enter/exit
109 void enterWarpMode(int outputIndex);
110 void exitWarpMode();
111 bool inWarpMode() const noexcept { return m_warpItemIndex >= 0; }
112 void resetWarp();
113
114 std::function<void(int)> onSelectionChanged;
115 std::function<void(int)> onItemGeometryChanged;
116 std::function<void()> onWarpChanged;
117
118protected:
119 void resizeEvent(QResizeEvent* event) override;
120 void mouseDoubleClickEvent(QMouseEvent* event) override;
121 void mousePressEvent(QMouseEvent* event) override;
122 void mouseMoveEvent(QMouseEvent* event) override;
123 void mouseReleaseEvent(QMouseEvent* event) override;
124 void keyPressEvent(QKeyEvent* event) override;
125
126private:
127 void setupItemCallbacks(OutputMappingItem* item);
128 void updateWarpVisuals();
129 OutputMappingItem* findItemByIndex(int index) const;
130
131 QGraphicsScene m_scene;
132 QGraphicsRectItem* m_border{};
133 double m_canvasWidth{400.0};
134 double m_canvasHeight{300.0};
135 bool m_snapEnabled{true};
136
137 // Warp mode state
138 int m_warpItemIndex{-1};
139 QGraphicsEllipseItem* m_warpHandles[4]{};
140 QGraphicsPolygonItem* m_warpQuad{};
141 std::vector<QGraphicsLineItem*> m_warpGrid;
142 bool m_warpDragging{false};
143 int m_warpDragHandle{-1};
144 QPointF m_warpHandleAnchor{};
145 QPointF m_warpMouseAnchor{};
146};
147}
Definition OutputMapping.hpp:88
Definition OutputMapping.hpp:15
Binds the rendering pipeline to ossia processes.
Definition CameraDevice.cpp:30
Definition WindowSettings.hpp:33
Definition WindowSettings.hpp:27