CurvePaletteBaseTransitions.hpp
1 #pragma once
2 #include "CurvePaletteBaseEvents.hpp"
3 #include "CurvePaletteBaseStates.hpp"
4 
5 #include <Curve/Point/CurvePointModel.hpp>
6 #include <Curve/Point/CurvePointView.hpp>
7 #include <Curve/Segment/CurveSegmentModel.hpp>
8 #include <Curve/Segment/CurveSegmentView.hpp>
9 
10 namespace Curve
11 {
12 // TODO cleanup this file
13 
14 template <typename T>
15 using GenericTransition = score::StateAwareTransition<StateBase, T>;
16 
17 template <typename Event>
18 class MatchedCurveTransition : public GenericTransition<score::MatchedTransition<Event>>
19 {
20 public:
22 };
23 
24 template <typename Element_T, typename Modifier_T>
26  : public MatchedCurveTransition<CurveEvent<Element_T, Modifier_T>>
27 {
28 public:
31 
32 protected:
33  void onTransition(QEvent* ev) override
34  {
35  auto qev = safe_cast<CurveEvent<Element_T, Modifier_T>*>(ev);
36  this->state().currentPoint = qev->point;
37 
38  impl(qev);
39  }
40 
41 private:
44  {
45  auto& model = safe_cast<const PointView*>(ev->item)->model();
46  this->state().clickedPointId = {model.previous(), model.following()};
47  }
49  {
50  this->state().clickedSegmentId
51  = safe_cast<const SegmentView*>(ev->item)->model().id();
52  }
53 
56  {
57  auto& model = safe_cast<const PointView*>(ev->item)->model();
58  this->state().hoveredPointId = {model.previous(), model.following()};
59  }
61  {
62  this->state().hoveredSegmentId
63  = safe_cast<const SegmentView*>(ev->item)->model().id();
64  }
65 
68  {
69  auto& model = safe_cast<const PointView*>(ev->item)->model();
70  this->state().hoveredPointId = {model.previous(), model.following()};
71  }
73  {
74  this->state().hoveredSegmentId
75  = safe_cast<const SegmentView*>(ev->item)->model().id();
76  }
77 };
78 
85 
92 
99 
100 class ClickOnAnything_Transition final : public GenericTransition<QAbstractTransition>
101 {
102 public:
104 
105 protected:
106  bool eventTest(QEvent* e) override
107  {
108  using namespace std;
109  static const constexpr QEvent::Type types[]
110  = {QEvent::Type(QEvent::User + ClickOnNothing_Event::user_type),
111  QEvent::Type(QEvent::User + ClickOnPoint_Event::user_type),
112  QEvent::Type(QEvent::User + ClickOnSegment_Event::user_type)};
113 
114  return find(begin(types), end(types), e->type()) != end(types);
115  }
116 
117  void onTransition(QEvent* e) override
118  {
119  auto qev = safe_cast<score::PositionedEvent<Curve::Point>*>(e);
120 
121  this->state().currentPoint = qev->point;
122  }
123 };
124 
125 class MoveOnAnything_Transition final : public GenericTransition<QAbstractTransition>
126 {
127 public:
129 
130 protected:
131  bool eventTest(QEvent* e) override
132  {
133  using namespace std;
134  static const constexpr QEvent::Type types[]
135  = {QEvent::Type(QEvent::User + MoveOnNothing_Event::user_type),
136  QEvent::Type(QEvent::User + MoveOnPoint_Event::user_type),
137  QEvent::Type(QEvent::User + MoveOnSegment_Event::user_type)};
138 
139  return find(begin(types), end(types), e->type()) != end(types);
140  }
141 
142  void onTransition(QEvent* e) override
143  {
144  auto qev = safe_cast<score::PositionedEvent<Curve::Point>*>(e);
145 
146  this->state().currentPoint = qev->point;
147  }
148 };
149 
150 class ReleaseOnAnything_Transition final : public QAbstractTransition
151 {
152 protected:
153  bool eventTest(QEvent* e) override
154  {
155  using namespace std;
156  static const constexpr QEvent::Type types[]
157  = {QEvent::Type(QEvent::User + ReleaseOnNothing_Event::user_type),
158  QEvent::Type(QEvent::User + ReleaseOnPoint_Event::user_type),
159  QEvent::Type(QEvent::User + ReleaseOnSegment_Event::user_type)};
160 
161  return find(begin(types), end(types), e->type()) != end(types);
162  }
163 
164  void onTransition(QEvent* e) override { }
165 };
166 }
Definition: CurvePaletteBaseTransitions.hpp:101
Definition: CurvePaletteBaseTransitions.hpp:19
Definition: CurvePaletteBaseTransitions.hpp:126
Definition: CurvePaletteBaseTransitions.hpp:27
Definition: CurvePaletteBaseTransitions.hpp:151
Definition: StateMachineUtils.hpp:76
Utilities and base classes for 1D curves.
Definition: FocusDispatcher.hpp:12
Definition: CurvePaletteBaseEvents.hpp:29