Loading...
Searching...
No Matches
ResizeSlotState.hpp
1#pragma once
2#include <Scenario/Commands/Interval/Rack/Slot/ResizeSlotVertically.hpp>
3#include <Scenario/Commands/Interval/Rack/SwapSlots.hpp>
4#include <Scenario/Document/Interval/IntervalModel.hpp>
5#include <Scenario/Document/Interval/Slot.hpp>
6#include <Scenario/Palette/ScenarioPaletteBaseStates.hpp>
7#include <Scenario/Palette/ScenarioPaletteBaseTransitions.hpp>
8#include <Scenario/Palette/Transitions/AnythingTransitions.hpp>
9
10#include <score/command/Dispatchers/SingleOngoingCommandDispatcher.hpp>
11#include <score/document/DocumentInterface.hpp>
12
13#include <QFinalState>
14
15namespace Scenario
16{
17
18class MoveOnAnything_SlotTransition final : public QAbstractTransition
19{
20protected:
21 bool eventTest(QEvent* e) override
22 {
23 using namespace std;
24 using namespace Scenario;
25 static const constexpr QEvent::Type types[] = {
26 QEvent::Type(QEvent::User + MoveOnNothing_Event::user_type),
27 QEvent::Type(QEvent::User + MoveOnState_Event::user_type),
28 QEvent::Type(QEvent::User + MoveOnEvent_Event::user_type),
29 QEvent::Type(QEvent::User + MoveOnTimeSync_Event::user_type),
30 QEvent::Type(QEvent::User + MoveOnInterval_Event::user_type),
31 QEvent::Type(QEvent::User + MoveOnLeftBrace_Event::user_type),
32 QEvent::Type(QEvent::User + MoveOnRightBrace_Event::user_type),
33 QEvent::Type(QEvent::User + MoveOnSlotHandle_Event::user_type),
34 };
35
36 return find(begin(types), end(types), e->type()) != end(types);
37 }
38 void onTransition(QEvent* event) override { }
39};
40
41class ReleaseOnAnything_SlotTransition final : public QAbstractTransition
42{
43protected:
44 bool eventTest(QEvent* e) override
45 {
46 using namespace std;
47 using namespace Scenario;
48 static const constexpr QEvent::Type types[] = {
49 QEvent::Type(QEvent::User + ReleaseOnNothing_Event::user_type),
50 QEvent::Type(QEvent::User + ReleaseOnState_Event::user_type),
51 QEvent::Type(QEvent::User + ReleaseOnEvent_Event::user_type),
52 QEvent::Type(QEvent::User + ReleaseOnTimeSync_Event::user_type),
53 QEvent::Type(QEvent::User + ReleaseOnInterval_Event::user_type),
54 QEvent::Type(QEvent::User + ReleaseOnLeftBrace_Event::user_type),
55 QEvent::Type(QEvent::User + ReleaseOnRightBrace_Event::user_type),
56 QEvent::Type(QEvent::User + ReleaseOnSlotHandle_Event::user_type),
57 };
58
59 return find(begin(types), end(types), e->type()) != end(types);
60 }
61 void onTransition(QEvent* event) override { }
62};
63
64template <typename Scenario_T, typename ToolPalette_T>
65class ResizeSlotState final : public SlotState
66{
67public:
69 const score::CommandStackFacade& stack, const ToolPalette_T& sm, QState* parent)
70 : SlotState{parent}
71 , m_ongoingDispatcher{stack}
72 , m_sm{sm}
73 {
74 auto press = new QState{this};
75 this->setInitialState(press);
76 auto move = new QState{this};
77 auto release = new QFinalState{this};
78
79 score::make_transition<Scenario::MoveOnAnything_SlotTransition>(press, move);
80 score::make_transition<Scenario::MoveOnAnything_SlotTransition>(move, move);
81 score::make_transition<Scenario::ReleaseOnAnything_SlotTransition>(press, release);
82 score::make_transition<Scenario::ReleaseOnAnything_SlotTransition>(move, release);
83
84 connect(press, &QAbstractState::entered, [this, &ctx = stack.context()] {
85 m_originalPoint = m_sm.scenePoint;
86
87 const IntervalModel& cst = this->currentSlot.interval.find(ctx);
88 m_originalHeight = cst.getSlotHeight(this->currentSlot);
89 });
90
91 connect(move, &QAbstractState::entered, [this, &ctx = stack.context()] {
92 auto val = std::max(
93 20.0, m_originalHeight + (m_sm.scenePoint.y() - m_originalPoint.y()));
94
95 const IntervalModel& cst = this->currentSlot.interval.find(ctx);
96 m_ongoingDispatcher.submit(cst, this->currentSlot, val);
97 });
98
99 connect(release, &QAbstractState::entered, [this, &ctx = stack.context()] {
100 m_ongoingDispatcher.commit();
101
102 IntervalModel& cst = this->currentSlot.interval.find(ctx);
103 cst.heightFinishedChanging();
104 });
105 }
106
107private:
109 m_ongoingDispatcher;
110 const ToolPalette_T& m_sm;
111};
112}
Definition ResizeSlotState.hpp:19
Definition ResizeSlotState.hpp:42
Definition ResizeSlotState.hpp:66
Definition ScenarioPaletteBaseStates.hpp:60
The SingleOngoingCommandDispatcher class.
Definition SingleOngoingCommandDispatcher.hpp:17
A small abstraction layer over the score::CommandStack.
Definition CommandStackFacade.hpp:20
Main plug-in of score.
Definition score-plugin-dataflow/Dataflow/PortItem.hpp:13
STL namespace.