CurveTool.hpp
1 #pragma once
2 #include <Curve/Palette/CurvePoint.hpp>
3 #include <Curve/Point/CurvePointView.hpp>
4 #include <Curve/Segment/CurveSegmentView.hpp>
5 
6 #include <score/document/DocumentContext.hpp>
7 #include <score/selection/SelectionDispatcher.hpp>
8 #include <score/statemachine/CommonSelectionState.hpp>
9 #include <score/statemachine/GraphicsSceneTool.hpp>
10 
11 #include <QGraphicsItem>
12 #include <QPoint>
13 
14 namespace Curve
15 {
16 class ToolPalette;
17 
18 class CurveTool : public GraphicsSceneTool<Curve::Point>
19 {
20 public:
22 
23 protected:
24  template <typename PointFun, typename SegmentFun, typename NothingFun>
25  void mapTopItem(
26  QPointF scenePoint, const QGraphicsItem* pressedItem, PointFun pt_fun,
27  SegmentFun seg_fun, NothingFun nothing_fun) const
28  {
29  if(!pressedItem)
30  {
31  nothing_fun();
32  return;
33  }
34 
35  switch(pressedItem->type())
36  {
37  case PointView::Type: {
38  auto pt = safe_cast<const PointView*>(pressedItem);
39  if(pt->contains(pt->mapFromScene(scenePoint)))
40  pt_fun(pt);
41  break;
42  }
43 
44  case SegmentView::Type: {
45  auto segt = safe_cast<const SegmentView*>(pressedItem);
46  if(segt->contains(segt->mapFromScene(scenePoint)))
47  {
48  seg_fun(segt);
49  }
50  break;
51  }
52 
53  default: {
54  nothing_fun();
55  break;
56  }
57  }
58  }
59 
60  template <typename Model>
61  void select(
62  const Model& model, const Selection& selected,
63  bool multi = CommonSelectionState::multiSelection())
64  {
65  score::SelectionDispatcher{context().selectionStack}.select(
66  filterSelections(&model, selected, multi));
67  }
68 
69  const Curve::ToolPalette& m_parentSM;
70  const score::DocumentContext& context() const noexcept;
71 };
72 }
Definition: CurveTool.hpp:19
Definition: CurveModel.hpp:25
Definition: CurvePalette.hpp:33
Definition: GraphicsSceneTool.hpp:11
Definition: Selection.hpp:12
The SelectionDispatcher class.
Definition: SelectionDispatcher.hpp:15
Utilities and base classes for 1D curves.
Definition: FocusDispatcher.hpp:12
Definition: DocumentContext.hpp:18