GraphicsSceneTool.hpp
1 #pragma once
2 #include <score/statemachine/StateMachineUtils.hpp>
3 
4 #include <QApplication>
5 #include <QGraphicsItem>
6 #include <QGraphicsScene>
7 #include <QStateMachine>
8 
9 template <typename Coordinates>
11 {
12 public:
13  virtual ~GraphicsSceneTool() = default;
14  void start()
15  {
16  if(!localSM().isRunning())
17  localSM().start();
18  }
19 
20  void stop()
21  {
22  if(localSM().isRunning())
23  {
24  on_cancel();
25  localSM().stop();
26  }
27  }
28 
29  virtual void on_cancel()
30  {
31  localSM().postEvent(new score::Cancel_Event);
32  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
33  }
34 
35  const QGraphicsScene& scene() const { return m_scene; }
36  QStateMachine& localSM() { return m_localSM; }
37 
38 protected:
39  GraphicsSceneTool(const QGraphicsScene& scene)
40  : m_scene{scene}
41  {
42  }
43 
44  QGraphicsItem* itemUnderMouse(const QPointF& point) const
45  {
46  return m_scene.itemAt(point, QTransform());
47  }
48 
49 private:
50  const QGraphicsScene& m_scene;
51  QStateMachine m_localSM;
52 };
Definition: GraphicsSceneTool.hpp:11
Definition: StateMachineUtils.hpp:18