Loading...
Searching...
No Matches
OngoingState.hpp
1#pragma once
2#include <Curve/Palette/CurvePaletteBaseTransitions.hpp>
3#include <Curve/Palette/CurvePoint.hpp>
4
5#include <score/statemachine/StateMachineTools.hpp>
6#include <score/statemachine/StateMachineUtils.hpp>
7
8#include <QFinalState>
9#include <QState>
10
11namespace Curve
12{
13class OngoingState final : public Curve::StateBase
14{
15public:
16 template <typename CommandObject>
17 OngoingState(CommandObject& obj, QState* parent)
18 : Curve::StateBase{parent}
19 {
20 using namespace Curve;
21
22 obj.setCurveState(this);
23
24 auto mainState = new QState{this};
25 auto finalState = new QFinalState{this};
26
27 setInitialState(mainState);
28 {
29 auto pressed = new QState{mainState};
30 pressed->setObjectName("Pressed");
31 auto moving = new QState{mainState};
32 moving->setObjectName("Moving");
33 auto released = new QFinalState{mainState};
34 released->setObjectName("Released");
35
36 // General setup
37 mainState->setInitialState(pressed);
38
39 // Also try with pressed, released
40 score::make_transition<MoveOnAnything_Transition>(pressed, moving, *this);
41 score::make_transition<ReleaseOnAnything_Transition>(pressed, released);
42
43 score::make_transition<MoveOnAnything_Transition>(moving, moving, *this);
44 score::make_transition<ReleaseOnAnything_Transition>(moving, released);
45
46 connect(pressed, &QAbstractState::entered, this, [&]() { obj.press(); });
47 connect(moving, &QAbstractState::entered, this, [&]() { obj.move(); });
48 connect(released, &QAbstractState::entered, this, [&]() { obj.release(); });
49 }
50
51 mainState->addTransition(mainState, finishedState(), finalState);
52
53 auto cancelled = new QState{this};
54 score::make_transition<score::Cancel_Transition>(mainState, cancelled);
55 cancelled->addTransition(finalState);
56
57 connect(cancelled, &QAbstractState::entered, this, [&]() { obj.cancel(); });
58 }
59};
60}
Definition OngoingState.hpp:14
Definition CurvePaletteBaseStates.hpp:20
Utilities and base classes for 1D curves.
Definition FocusDispatcher.hpp:12