Loading...
Searching...
No Matches
CurvePresenter.hpp
1#pragma once
2#include <Curve/Palette/CurveEditionSettings.hpp>
3#include <Curve/Point/CurvePointModel.hpp>
4#include <Curve/Point/CurvePointView.hpp>
5#include <Curve/Segment/CurveSegmentModel.hpp>
6#include <Curve/Segment/CurveSegmentView.hpp>
7
8#include <score/command/Dispatchers/CommandDispatcher.hpp>
9#include <score/document/DocumentContext.hpp>
10#include <score/graphics/GraphicsItem.hpp>
11#include <score/model/IdentifiedObjectMap.hpp>
12#include <score/selection/SelectionDispatcher.hpp>
13
14#include <QObject>
15#include <QPoint>
16#include <QRect>
17
18#include <functional>
19
20#include <score_plugin_curve_export.h>
21
22#include <verdigris>
23
24class QActionGroup;
25class QMenu;
26namespace Curve
27{
28class SegmentList;
29struct Style;
30class View;
31class Model;
32
33class SCORE_PLUGIN_CURVE_EXPORT Presenter final : public QObject
34{
35 friend class View;
36 W_OBJECT(Presenter)
37public:
39 const score::DocumentContext& lst, const Curve::Style&, const Model&, View*,
40 QObject* parent);
41 virtual ~Presenter();
42
43 const score::DocumentContext& context() const noexcept
44 {
45 return m_commandDispatcher.stack().context();
46 }
47
48 const auto& points() const noexcept { return m_points; }
49 const auto& segments() const noexcept { return m_segments; }
50
51 // Removes all the points & segments
52 void clear();
53
54 const Model& model() const noexcept { return m_model; }
55 View& view() const noexcept { return *m_view; }
56
57 void setRect(const QRectF& rect);
58
59 void enableActions(bool);
60
61 // Changes the colors
62 void enable();
63 void disable();
64
65 Curve::EditionSettings& editionSettings() noexcept { return m_editionSettings; }
66
67 void fillContextMenu(QMenu&, const QPoint&, const QPointF&);
68
69 void removeSelection();
70
73 void convertSamplesToPoints();
74
75 // Used to allow moving outside [0; 1] when in the panel view.
76 bool boundedMove() const noexcept { return m_boundedMove; }
77 void setBoundedMove(bool b) noexcept { m_boundedMove = b; }
78
79 QRectF rect() const noexcept { return m_localRect; }
80
83 void setMagnetism(std::function<double(double)> f) noexcept
84 {
85 m_magnetism = std::move(f);
86 }
87 double magnetic(double x) const { return m_magnetism ? m_magnetism(x) : x; }
88
89public:
90 void contextMenuRequested(const QPoint& arg_1, const QPointF& arg_2)
91 E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, contextMenuRequested, arg_1, arg_2)
92
93private:
94 // Context menu actions
95 void updateSegmentsType(const UuidKey<Curve::SegmentFactory>& segment);
96
97 // Setup utilities
98 void setPos(PointView&);
99 void setPos(SegmentView&);
100 void setupSignals();
101 void setupView();
102 void setupStateMachine();
103
104 // Adding
105 void addPoint(PointView*);
106 void addSegment(SegmentView*);
107
108 void addPoint_impl(PointView*);
109 void addSegment_impl(SegmentView*);
110
111 void setupPointConnections(PointView*);
112 void setupSegmentConnections(SegmentView*);
113 void modelReset();
114
115 const SegmentList& m_curveSegments;
116 QRectF m_localRect;
117 std::function<double(double)> m_magnetism;
118
119 const Model& m_model;
121
124
125 // Required dispatchers
126 CommandDispatcher<> m_commandDispatcher;
127
128 const Curve::Style& m_style;
129 Curve::EditionSettings& m_editionSettings;
130
131 QMenu* m_contextMenu{};
132
133 bool m_enabled = true;
134 bool m_boundedMove = true;
135};
136}
The CommandDispatcher class.
Definition CommandDispatcher.hpp:13
Definition CurveEditionSettings.hpp:34
Definition CurveModel.hpp:26
Definition CurvePresenter.hpp:34
void setMagnetism(std::function< double(double)> f) noexcept
Definition CurvePresenter.hpp:83
Definition CurveView.hpp:28
A map to access child objects through their id.
Definition IdentifiedObjectMap.hpp:17
Definition UuidKey.hpp:345
Utilities and base classes for 1D curves.
Definition FocusDispatcher.hpp:12
Definition CurveStyle.hpp:14
Definition GraphicsItem.hpp:73
Definition DocumentContext.hpp:18