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 int rotation{0};
42 bool mirrorX{false};
43 bool mirrorY{false};
44
45 void applyLockedState();
46
47 // Called when item is moved or resized in the canvas
48 std::function<void()> onChanged;
49
50 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
51 override;
52
53protected:
54 QVariant itemChange(GraphicsItemChange change, const QVariant& value) override;
55 void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
56 void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
57 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
58 void hoverMoveEvent(QGraphicsSceneHoverEvent* event) override;
59
60private:
61 enum ResizeEdge
62 {
63 None = 0,
64 Left = 1,
65 Right = 2,
66 Top = 4,
67 Bottom = 8
68 };
69 int hitTestEdges(const QPointF& pos) const;
70
71 enum BlendHandle
72 {
73 BlendNone = 0,
74 BlendLeft,
75 BlendRight,
76 BlendTop,
77 BlendBottom
78 };
79 BlendHandle hitTestBlendHandles(const QPointF& pos) const;
80
81 int m_index{};
82 int m_resizeEdges{None};
83 BlendHandle m_blendHandle{BlendNone};
84 QPointF m_dragStart{};
85 QRectF m_rectStart{};
86 QPointF m_moveAnchorScene{}; // scene pos at press for precision move
87 QPointF m_posAtPress{}; // item pos() at press
88 OutputMappingCanvas* m_canvas{};
89};
90
91class OutputMappingCanvas final : public QGraphicsView
92{
93public:
94 explicit OutputMappingCanvas(QWidget* parent = nullptr);
96
97 void setMappings(const std::vector<OutputMapping>& mappings);
98 std::vector<OutputMapping> getMappings() const;
99
100 void addOutput();
101 void removeSelectedOutput();
102
103 void updateAspectRatio(int inputWidth, int inputHeight);
104
105 double canvasWidth() const noexcept { return m_canvasWidth; }
106 double canvasHeight() const noexcept { return m_canvasHeight; }
107
108 bool snapEnabled() const noexcept { return m_snapEnabled; }
109 void setSnapEnabled(bool enabled);
110 QPointF snapPosition(const OutputMappingItem* item, QPointF proposedPos) const;
111
112 // Warp mode: double-click an item to enter/exit
113 void enterWarpMode(int outputIndex);
114 void exitWarpMode();
115 bool inWarpMode() const noexcept { return m_warpItemIndex >= 0; }
116 void resetWarp();
117
118 std::function<void(int)> onSelectionChanged;
119 std::function<void(int)> onItemGeometryChanged;
120 std::function<void()> onWarpChanged;
121
122protected:
123 void resizeEvent(QResizeEvent* event) override;
124 void mouseDoubleClickEvent(QMouseEvent* event) override;
125 void mousePressEvent(QMouseEvent* event) override;
126 void mouseMoveEvent(QMouseEvent* event) override;
127 void mouseReleaseEvent(QMouseEvent* event) override;
128 void keyPressEvent(QKeyEvent* event) override;
129
130private:
131 void setupItemCallbacks(OutputMappingItem* item);
132 void updateWarpVisuals();
133 OutputMappingItem* findItemByIndex(int index) const;
134
135 QGraphicsScene m_scene;
136 QGraphicsRectItem* m_border{};
137 double m_canvasWidth{400.0};
138 double m_canvasHeight{300.0};
139 bool m_snapEnabled{true};
140
141 // Warp mode state
142 int m_warpItemIndex{-1};
143 QGraphicsEllipseItem* m_warpHandles[4]{};
144 QGraphicsPolygonItem* m_warpQuad{};
145 std::vector<QGraphicsLineItem*> m_warpGrid;
146 bool m_warpDragging{false};
147 int m_warpDragHandle{-1};
148 QPointF m_warpHandleAnchor{};
149 QPointF m_warpMouseAnchor{};
150};
151}
Definition OutputMapping.hpp:92
Definition OutputMapping.hpp:15
Binds the rendering pipeline to ossia processes.
Definition CameraDevice.cpp:30
Definition WindowSettings.hpp:49
Definition WindowSettings.hpp:43