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  W_OBJECT(Presenter)
34 public:
35  Presenter(
36  const score::DocumentContext& lst, const Curve::Style&, const Model&, View*,
37  QObject* parent);
38  virtual ~Presenter();
39 
40  const score::DocumentContext& context() const noexcept
41  {
42  return m_commandDispatcher.stack().context();
43  }
44 
45  const auto& points() const noexcept { return m_points; }
46  const auto& segments() const noexcept { return m_segments; }
47 
48  // Removes all the points & segments
49  void clear();
50 
51  const Model& model() const noexcept { return m_model; }
52  View& view() const noexcept { return *m_view; }
53 
54  void setRect(const QRectF& rect);
55 
56  void enableActions(bool);
57 
58  // Changes the colors
59  void enable();
60  void disable();
61 
62  Curve::EditionSettings& editionSettings() noexcept { return m_editionSettings; }
63 
64  void fillContextMenu(QMenu&, const QPoint&, const QPointF&);
65 
66  void removeSelection();
67 
68  // Used to allow moving outside [0; 1] when in the panel view.
69  bool boundedMove() const noexcept { return m_boundedMove; }
70  void setBoundedMove(bool b) noexcept { m_boundedMove = b; }
71 
72  QRectF rect() const noexcept { return m_localRect; }
73 
74 public:
75  void contextMenuRequested(const QPoint& arg_1, const QPointF& arg_2)
76  E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, contextMenuRequested, arg_1, arg_2)
77 
78 private:
79  // Context menu actions
80  void updateSegmentsType(const UuidKey<Curve::SegmentFactory>& segment);
81 
82  // Setup utilities
83  void setPos(PointView&);
84  void setPos(SegmentView&);
85  void setupSignals();
86  void setupView();
87  void setupStateMachine();
88 
89  // Adding
90  void addPoint(PointView*);
91  void addSegment(SegmentView*);
92 
93  void addPoint_impl(PointView*);
94  void addSegment_impl(SegmentView*);
95 
96  void setupPointConnections(PointView*);
97  void setupSegmentConnections(SegmentView*);
98  void modelReset();
99 
100  const SegmentList& m_curveSegments;
101  QRectF m_localRect;
102 
103  const Model& m_model;
105 
108 
109  // Required dispatchers
110  CommandDispatcher<> m_commandDispatcher;
111 
112  const Curve::Style& m_style;
113  Curve::EditionSettings& m_editionSettings;
114 
115  QMenu* m_contextMenu{};
116 
117  bool m_enabled = true;
118  bool m_boundedMove = true;
119 };
120 }
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:23
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