Loading...
Searching...
No Matches
ScenarioDocumentView.hpp
1#pragma once
2#include <Process/Dataflow/AutoScrollableView.hpp>
3
4#include <Scenario/Document/Minimap/Minimap.hpp>
5#include <Scenario/Document/ScenarioDocument/ScenarioScene.hpp>
6#include <Scenario/Document/TimeRuler/TimeRuler.hpp>
7#include <Scenario/Document/TimeRuler/TimeRulerGraphicsView.hpp>
8
9#include <score/graphics/ArrowDialog.hpp>
10#include <score/graphics/GraphicsProxyObject.hpp>
11#include <score/plugins/documentdelegate/DocumentDelegateView.hpp>
12#include <score/tools/Events.hpp>
13#include <score/widgets/MimeData.hpp>
14
15#include <ossia/detail/flat_set.hpp>
16
17#include <QGraphicsView>
18#include <QMimeData>
19#include <QPoint>
20#include <QPointer>
21
22#include <score_plugin_scenario_export.h>
23
24#include <verdigris>
25
26#include <functional>
27
28class QGraphicsView;
29class QObject;
30class QWidget;
31class QFocusEvent;
32class QGraphicsScene;
33class QKeyEvent;
34class QPainterPath;
35class QResizeEvent;
36class QSize;
37class QWheelEvent;
38class SceneGraduations;
39
40namespace score
41{
42struct DocumentContext;
43struct GUIApplicationContext;
44
45class BackgroundRenderer;
46}
47
48namespace Scenario
49{
50class AddressBarWidget;
51class Minimap;
52class ScenarioScene;
53class IntervalDurations;
54class IntervalView;
55class TimeRuler;
56class ScenarioDocumentView;
57class SCORE_PLUGIN_SCENARIO_EXPORT ProcessGraphicsView final
58 : public QGraphicsView
60{
61 W_OBJECT(ProcessGraphicsView)
62public:
64 const score::GUIApplicationContext& ctx, QGraphicsScene* scene, QWidget* parent);
65 ~ProcessGraphicsView() override;
66
67 void scrollHorizontal(double dx);
68 QRectF visibleRect() const noexcept;
69
78 std::function<bool(QPoint)> autoScrollHandler;
79 bool autoScrollBy(QPoint delta) override;
80
81 QPointer<score::ArrowDialog> currentPopup{};
82
83 IntervalDurations* currentTimebar{};
84 IntervalView* currentView{};
85
86 score::BackgroundRenderer* currentBackground{};
87 bool timebarPlaying{};
88 bool timebarVisible{};
89
90public:
91 void drawForeground(QPainter* painter, const QRectF& rect) override;
92 void sizeChanged(const QSize& arg_1)
93 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, sizeChanged, arg_1)
94 void scrolled(int arg_1) E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, scrolled, arg_1)
95 void focusedOut() E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, focusedOut)
96 void horizontalZoom(QPointF pixDelta, QPointF pos)
97 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, horizontalZoom, pixDelta, pos)
98 void verticalZoom(QPointF pixDelta, QPointF pos)
99 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, verticalZoom, pixDelta, pos)
100
101 void visibleRectChanged(QRectF r)
102 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, visibleRectChanged, r)
103 void dropRequested(QPoint pos, const QMimeData* mime)
104 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, dropRequested, pos, mime)
105 void emptyContextMenuRequested(QPoint pos)
106 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, emptyContextMenuRequested, pos)
107
108 void dropFinished() W_SIGNAL(dropFinished);
109
110 void mousePress(QMouseEvent* p) E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, mousePress, p);
111 void mouseMove(QMouseEvent* p) E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, mouseMove, p);
112 void mouseRelease(QMouseEvent* p)
113 E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, mouseRelease, p);
114 void hoverEnter(QHoverEvent* p) E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, hoverEnter, p);
115 void hoverMove(QHoverEvent* p) E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, hoverMove, p);
116 void hoverLeave(QHoverEvent* p) E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, hoverLeave, p);
117 void keyPress(QKeyEvent* e) E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, keyPress, e);
118 void keyRelease(QKeyEvent* e) E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, keyRelease, e);
119 void tabletMove(QTabletEvent* e) E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, tabletMove, e);
120
121private:
122 void resizeEvent(QResizeEvent* ev) override;
123 void scrollContentsBy(int dx, int dy) override;
124 void wheelEvent(QWheelEvent* event) override;
125 void keyPressEvent(QKeyEvent* event) override;
126 void keyReleaseEvent(QKeyEvent* event) override;
127 void focusOutEvent(QFocusEvent* event) override;
128 void leaveEvent(QEvent* event) override;
129 void mousePressEvent(QMouseEvent* event) override;
130 void mouseMoveEvent(QMouseEvent* event) override;
131 void mouseReleaseEvent(QMouseEvent* event) override;
132 void dragEnterEvent(QDragEnterEvent* event) override;
133 void dragMoveEvent(QDragMoveEvent* event) override;
134 void dragLeaveEvent(QDragLeaveEvent* event) override;
135 void dropEvent(QDropEvent* event) override;
136 void contextMenuEvent(QContextMenuEvent* event) override;
137 bool event(QEvent*) override;
138
139 void hoverEnterEvent(QHoverEvent* event);
140 void hoverMoveEvent(QHoverEvent* event);
141 void hoverLeaveEvent(QHoverEvent* event);
142
143 void checkAndRemoveCurrentDialog(QPoint pos);
144 void drawBackground(QPainter* painter, const QRectF& rect) override;
145 const score::GUIApplicationContext& m_app;
146
147 std::chrono::steady_clock::time_point m_lastwheel;
148 ossia::flat_set<Qt::MouseButton> m_press_release_chain{};
149 std::vector<score::BackgroundRenderer*> m_globalRenderers;
150 bool m_opengl{false};
151
152 friend class ScenarioDocumentView;
153};
154
155class SCORE_PLUGIN_SCENARIO_EXPORT ScenarioDocumentView final
157{
158 W_OBJECT(ScenarioDocumentView)
159
160public:
161 ScenarioDocumentView(const score::DocumentContext& ctx, QObject* parent);
162 ~ScenarioDocumentView() override;
163
164 QWidget* getWidget() override;
165
166 BaseGraphicsObject& baseItem() { return *m_baseObject; }
167
168 ScenarioScene& scene() { return m_scene; }
169
170 ProcessGraphicsView& view() { return *m_view; }
171
172 qreal viewWidth() const;
173
174 QGraphicsView& rulerView() { return *m_timeRulerView; }
175
176 TimeRulerBase& timeRuler() { return *m_timeRuler; }
177
178 Minimap& minimap() { return *m_minimap; }
179
181 AddressBarWidget& addressBar() { return *m_addressBar; }
182
183 QRectF viewportRect() const;
184 QRectF visibleSceneRect() const;
185
186 void showRulers(bool);
187 void ready() override;
188
189 void zoom(double zx, double zy);
190 void scroll(double dx, double dy);
191
192 void addBackgroundRenderer(score::BackgroundRenderer*);
193 void removeBackgroundRenderer(score::BackgroundRenderer*);
194 score::BackgroundRenderer* activeBackgroundRenderer() const noexcept override;
195 void updateBackgroundMode();
196
197 void elementsScaleChanged(double arg_1) W_SIGNAL(elementsScaleChanged, arg_1);
198 void setLargeView() W_SIGNAL(setLargeView);
199 void timeRulerChanged() W_SIGNAL(timeRulerChanged);
200 void requestTransport(QPointF pt) W_SIGNAL(requestTransport, pt);
201
202private:
203 void timerEvent(QTimerEvent* event) override;
204 QWidget* m_widget{};
205 const score::DocumentContext& m_context;
206 ScenarioScene m_scene;
207
208 // The three views below are put into m_widget's layout, which REPARENTS
209 // them: Qt then deletes them through ~QWidget's deleteChildren(). As
210 // by-value members that would be `delete` on an address inside this object,
211 // which is not a heap allocation -- the same defect the scenes and the base
212 // item have to avoid.
213 //
214 // Heap-allocated, they are Qt's to delete, and QPointer means we can also
215 // delete them ourselves in ~ScenarioDocumentView for the OTHER teardown
216 // order (a document closed with removeTab orphans the widget, so nothing
217 // Qt-side ever deletes it) without risking a double free. Deleting them in
218 // the destructor BODY also keeps the original ordering guarantee: a view
219 // dies before the by-value scene it renders.
220 QPointer<ProcessGraphicsView> m_view;
221 // Owned by the scene, not by value. m_scene is a QObject child of m_widget,
222 // so ~QWidget destroys it -- and QGraphicsScene::clear() deletes its
223 // top-level items -- before ScenarioDocumentView's own members are destroyed.
224 // As a by-value member that would be `delete` on a non-heap address.
225 BaseGraphicsObject* m_baseObject{};
226
227 QGraphicsScene m_timeRulerScene;
228 QPointer<TimeRulerGraphicsView> m_timeRulerView;
229 TimeRulerBase* m_timeRuler{};
230 QGraphicsScene m_minimapScene;
231 QPointer<MinimapGraphicsView> m_minimapView;
232 // Same treatment as m_baseObject: a QGraphicsItem added to a scene that
233 // deletes its top-level items, so it must be heap-allocated and left to
234 // that scene. Never deleted here.
235 Minimap* m_minimap{};
236
237 AddressBarWidget* m_addressBar{};
238
239 int m_timer{-1};
240 bool m_transport{};
241};
242}
Definition GraphicsProxyObject.hpp:8
A QGraphicsView that knows how to move its content for auto-scroll.
Definition AutoScrollableView.hpp:17
Clickable path of the interval shown in the central view.
Definition AddressBarWidget.hpp:27
Definition IntervalDurations.hpp:23
Definition Minimap.hpp:15
Definition ScenarioDocumentView.hpp:60
std::function< bool(QPoint)> autoScrollHandler
How the content is moved when something (a cable being dragged against the edge) asks to reveal more ...
Definition ScenarioDocumentView.hpp:78
Definition ScenarioDocumentView.hpp:157
AddressBarWidget & addressBar()
Path of the displayed interval, shown in the document's navigation bar.
Definition ScenarioDocumentView.hpp:181
Definition ScenarioScene.hpp:9
Definition TimeRuler.hpp:36
Definition BackgroundRenderer.hpp:13
Definition DocumentDelegateView.hpp:11
Main plug-in of score.
Definition score-plugin-dataflow/Dataflow/PortItem.hpp:13
Base toolkit upon which the software is built.
Definition Application.cpp:117
STL namespace.
Definition DocumentContext.hpp:18
Specializes ApplicationContext with the QMainWindow.
Definition GUIApplicationContext.hpp:15