Loading...
Searching...
No Matches
CurveProcessPresenter.hpp
1#pragma once
2#include <Process/Focus/FocusDispatcher.hpp>
3#include <Process/LayerPresenter.hpp>
4#include <Process/LayerView.hpp>
5
6#include <Curve/CurveModel.hpp>
7#include <Curve/CurvePresenter.hpp>
8#include <Curve/CurveView.hpp>
9#include <Curve/Palette/CurvePalette.hpp>
10#include <Curve/Process/CurveProcessModel.hpp>
11#include <Curve/Segment/CurveSegmentList.hpp>
12
13#include <score/command/Dispatchers/CommandDispatcher.hpp>
14#include <score/document/DocumentInterface.hpp>
15#include <score/graphics/GraphicsItem.hpp>
16#include <score/tools/Bind.hpp>
17
18#include <score_plugin_curve_export.h>
19
20class CurvePresenter;
21class LayerView;
22class CurveProcessView;
23
24namespace Curve
25{
26template <typename Model_T, typename LayerView_T>
28{
29public:
31 const Curve::Style& style, const Model_T& lm, LayerView_T* view,
32 const Process::Context& ctx, QObject* parent)
33 : LayerPresenter{lm, view, ctx, parent}
34 , m_view{static_cast<LayerView_T*>(view)}
35 , m_curve{ctx, style, lm.curve(), new View{m_view}, this}
36 , m_commandDispatcher{ctx.commandStack}
37 , m_sm{m_context, m_curve}
38 {
39 con(lm, &CurveProcessModel::curveChanged, this,
40 &CurveProcessPresenter::parentGeometryChanged);
41
42 con(m_curve, &Presenter::contextMenuRequested, this,
43 &LayerPresenter::contextMenuRequested);
44
45 connect(&m_curve.view(), &View::doubleClick, this, [this](QPointF pt) {
46 m_sm.createPoint(pt);
47 });
48
49 parentGeometryChanged();
50 m_view->setCurveView(&m_curve.view());
51 }
52
53 virtual ~CurveProcessPresenter() { }
54
55 void on_focusChanged() final override
56 {
57 bool b = focused();
58 if(b)
59 m_view->setFocus();
60
61 // TODO Same for Scenario please.
62 m_curve.enableActions(b);
63
64 m_curve.editionSettings().setTool(Curve::Tool::Select);
65 }
66
67 void setWidth(qreal width, qreal defaultWidth) final override
68 {
69 m_view->setWidth(width);
70 m_curve.view().setRect(m_view->boundingRect());
71 m_curve.view().setDefaultWidth(defaultWidth);
72 }
73
74 void setHeight(qreal height) final override
75 {
76 m_view->setHeight(height);
77 m_curve.view().setRect(m_view->boundingRect());
78 }
79
80 void putToFront() final override
81 {
82 // m_view->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
83 m_curve.enable();
84 }
85
86 void putBehind() final override
87 {
88 // m_view->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
89 m_curve.disable();
90 }
91
92 void on_zoomRatioChanged(ZoomRatio val) final override
93 {
94 m_zoomRatio = val;
95 parentGeometryChanged();
96 }
97
98 void parentGeometryChanged() override
99 {
100 // Compute the rect with the duration of the process.
101 QRectF rect = m_view->boundingRect(); // for the height
102 m_curve.view().setRect(rect); // wtf
103
104 const auto dw = m_process.duration().toPixels(m_zoomRatio);
105 m_curve.view().setDefaultWidth(dw);
106 rect.setWidth(dw);
107 m_curve.setRect(rect);
108 }
109
110 void fillContextMenu(
111 QMenu& menu, QPoint pos, QPointF scenepos,
112 const Process::LayerContextMenuManager&) final override
113 {
114 m_curve.fillContextMenu(menu, pos, scenepos);
115 }
116
117 LayerView_T* view() { return m_view.impl; }
118 const Model_T& model() const { return static_cast<const Model_T&>(m_process); }
119
120protected:
122
123 Presenter m_curve;
124 CommandDispatcher<> m_commandDispatcher;
125
127 ZoomRatio m_zoomRatio{};
128};
129}
The CommandDispatcher class.
Definition CommandDispatcher.hpp:13
Definition CurveProcessPresenter.hpp:28
Definition CurvePresenter.hpp:32
Definition CurveView.hpp:25
Definition LayerContextMenu.hpp:38
Definition LayerPresenter.hpp:34
Utilities and base classes for 1D curves.
Definition FocusDispatcher.hpp:12
Definition CurveStyle.hpp:13
Definition CurvePalette.hpp:71
Definition ProcessContext.hpp:12
Definition GraphicsItem.hpp:47