SelectionState.hpp
1 #pragma once
2 #include <Curve/CurveModel.hpp>
3 #include <Curve/CurvePresenter.hpp>
4 #include <Curve/CurveView.hpp>
5 #include <Curve/Palette/CurvePalette.hpp>
6 
7 #include <score/statemachine/CommonSelectionState.hpp>
8 
9 namespace Curve
10 {
11 class ToolPalette;
13 {
14 private:
15  QPointF m_initialPoint;
16  QPointF m_movePoint;
17 
18  const Curve::ToolPalette& m_parentSM;
19  View& m_view;
20 
21 public:
23  score::SelectionStack& stack, const Curve::ToolPalette& parentSM, View& view,
24  QState* parent)
25  : CommonSelectionState{stack, &view, parent}
26  , m_parentSM{parentSM}
27  , m_view{view}
28  {
29  }
30 
31  const QPointF& initialPoint() const { return m_initialPoint; }
32  const QPointF& movePoint() const { return m_movePoint; }
33 
34  void on_pressAreaSelection() override { m_initialPoint = m_parentSM.scenePoint; }
35 
36  void on_moveAreaSelection() override
37  {
38  m_movePoint = m_parentSM.scenePoint;
39  auto rect
40  = QRectF{m_view.mapFromScene(m_initialPoint), m_view.mapFromScene(m_movePoint)}
41  .normalized();
42 
43  m_view.setSelectionArea(rect);
44  setSelectionArea(rect);
45  }
46 
47  void on_releaseAreaSelection() override
48  {
49  if(m_parentSM.scenePoint == m_initialPoint)
50  {
51  dispatcher.deselect();
52  auto proc = (IdentifiedObjectAbstract*)m_parentSM.model().parent();
53  dispatcher.select(Selection{proc});
54  }
55  m_view.setSelectionArea(QRectF{});
56  }
57 
58  void on_deselect() override
59  {
60  dispatcher.deselect();
61  m_view.setSelectionArea(QRectF{});
62  }
63 
64 private:
65  void setSelectionArea(QRectF scene_area)
66  {
67  using namespace std;
68  Selection sel;
69 
70  for(const auto& point : m_parentSM.presenter().points())
71  {
72  if(point.shape().translated(point.pos()).intersects(scene_area))
73  {
74  sel.append(point.model());
75  }
76  }
77 
78  for(const auto& segment : m_parentSM.presenter().segments())
79  {
80  if(segment.shape().translated(segment.pos()).intersects(scene_area))
81  {
82  sel.append(segment.model());
83  }
84  }
85 
86  dispatcher.select(
87  filterSelections(sel, m_parentSM.model().selectedChildren(), multiSelection()));
88  }
89 };
90 }
The CommonSelectionState class.
Definition: CommonSelectionState.hpp:27
Definition: SelectionState.hpp:13
Definition: CurvePalette.hpp:33
Definition: CurveView.hpp:25
Base class for IdentifiedObject.
Definition: IdentifiedObjectAbstract.hpp:16
Definition: Selection.hpp:12
The SelectionStack class.
Definition: SelectionStack.hpp:24
Utilities and base classes for 1D curves.
Definition: FocusDispatcher.hpp:12