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 <score_plugin_curve_export.h>
19 
20 #include <verdigris>
21 
22 class QActionGroup;
23 class QMenu;
24 namespace Curve
25 {
26 class SegmentList;
27 struct Style;
28 class View;
29 class Model;
30 
31 class SCORE_PLUGIN_CURVE_EXPORT Presenter final : public QObject
32 {
33  friend class View;
34  W_OBJECT(Presenter)
35 public:
36  Presenter(
37  const score::DocumentContext& lst, const Curve::Style&, const Model&, View*,
38  QObject* parent);
39  virtual ~Presenter();
40 
41  const score::DocumentContext& context() const noexcept
42  {
43  return m_commandDispatcher.stack().context();
44  }
45 
46  const auto& points() const noexcept { return m_points; }
47  const auto& segments() const noexcept { return m_segments; }
48 
49  // Removes all the points & segments
50  void clear();
51 
52  const Model& model() const noexcept { return m_model; }
53  View& view() const noexcept { return *m_view; }
54 
55  void setRect(const QRectF& rect);
56 
57  void enableActions(bool);
58 
59  // Changes the colors
60  void enable();
61  void disable();
62 
63  Curve::EditionSettings& editionSettings() noexcept { return m_editionSettings; }
64 
65  void fillContextMenu(QMenu&, const QPoint&, const QPointF&);
66 
67  void removeSelection();
68 
69  // Used to allow moving outside [0; 1] when in the panel view.
70  bool boundedMove() const noexcept { return m_boundedMove; }
71  void setBoundedMove(bool b) noexcept { m_boundedMove = b; }
72 
73  QRectF rect() const noexcept { return m_localRect; }
74 
75 public:
76  void contextMenuRequested(const QPoint& arg_1, const QPointF& arg_2)
77  E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, contextMenuRequested, arg_1, arg_2)
78 
79 private:
80  // Context menu actions
81  void updateSegmentsType(const UuidKey<Curve::SegmentFactory>& segment);
82 
83  // Setup utilities
84  void setPos(PointView&);
85  void setPos(SegmentView&);
86  void setupSignals();
87  void setupView();
88  void setupStateMachine();
89 
90  // Adding
91  void addPoint(PointView*);
92  void addSegment(SegmentView*);
93 
94  void addPoint_impl(PointView*);
95  void addSegment_impl(SegmentView*);
96 
97  void setupPointConnections(PointView*);
98  void setupSegmentConnections(SegmentView*);
99  void modelReset();
100 
101  const SegmentList& m_curveSegments;
102  QRectF m_localRect;
103 
104  const Model& m_model;
106 
109 
110  // Required dispatchers
111  CommandDispatcher<> m_commandDispatcher;
112 
113  const Curve::Style& m_style;
114  Curve::EditionSettings& m_editionSettings;
115 
116  QMenu* m_contextMenu{};
117 
118  bool m_enabled = true;
119  bool m_boundedMove = true;
120 };
121 }
The CommandDispatcher class.
Definition: CommandDispatcher.hpp:13
Definition: CurveEditionSettings.hpp:34
Definition: CurveModel.hpp:25
Definition: CurvePointView.hpp:24
Definition: CurvePresenter.hpp:32
Definition: CurveSegmentList.hpp:12
Definition: CurveSegmentView.hpp:26
Definition: CurveView.hpp:25
A map to access child objects through their id.
Definition: IdentifiedObjectMap.hpp:16
Utilities and base classes for 1D curves.
Definition: FocusDispatcher.hpp:12
Definition: CurveStyle.hpp:13
Definition: GraphicsItem.hpp:41
Definition: DocumentContext.hpp:18