TimeSignatureItem.hpp
1 #pragma once
2 #include <Scenario/Document/Interval/FullView/Timebar.hpp>
3 #include <Scenario/Document/Interval/TimeSignatureMap.hpp>
4 
5 #include <ossia/editor/scenario/time_signature.hpp>
6 
7 #include <QGraphicsTextItem>
8 #include <QObject>
9 
10 #include <verdigris>
11 
12 namespace Process
13 {
14 class MagnetismAdjuster;
15 }
16 
17 namespace Scenario
18 {
19 class IntervalModel;
20 class FullViewIntervalPresenter;
21 class LineTextItem final : public QGraphicsTextItem
22 {
23  W_OBJECT(LineTextItem)
24 public:
25  LineTextItem(QGraphicsItem* parent) noexcept;
26 
27  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
28  override;
29 
30  void keyPressEvent(QKeyEvent* ev) override;
31  void keyReleaseEvent(QKeyEvent* ev) override;
32  void focusOutEvent(QFocusEvent* event) override;
33  void done(QString s) W_SIGNAL(done, s)
34 };
35 
37  : public QObject
38  , public QGraphicsItem
39 {
40  W_OBJECT(TimeSignatureHandle)
41 public:
42  explicit TimeSignatureHandle(QGraphicsItem* parent);
44 
45  QRectF boundingRect() const final override;
46 
47  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
48  override;
49 
50  void setSignature(TimeVal time, ossia::time_signature sig);
51 
52  const TimeVal& time() const;
53  const ossia::time_signature& signature() const;
54 
55  void move(double originalPos, double delta) W_SIGNAL(move, originalPos, delta);
56  void press() W_SIGNAL(press);
57  void release() W_SIGNAL(release);
58  void remove() W_SIGNAL(remove);
59  void signatureChange(ossia::time_signature sig) W_SIGNAL(signatureChange, sig);
60 
61  bool pressed{};
62 
63 protected:
64  void updateImpl();
65 
66  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* mv) override;
67  TimeVal m_time{};
68  ossia::time_signature m_sig{0, 0};
69  QPixmap m_signature;
70  QRectF m_rect;
71 
72 public:
73  bool m_visible{true};
74 };
75 
77  : public QObject
78  , public QGraphicsItem
79 {
80  W_OBJECT(StartMarker)
81 public:
82  explicit StartMarker(QGraphicsItem* parent);
83  ~StartMarker();
84 
85  QRectF boundingRect() const final override;
86 
87  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
88  override;
89 
90  void move(double originalPos, double delta) W_SIGNAL(move, originalPos, delta);
91  void press() W_SIGNAL(press);
92  void release() W_SIGNAL(release);
93  void remove() W_SIGNAL(remove);
94 
95  void mousePressEvent(QGraphicsSceneMouseEvent* mv) override;
96  void mouseMoveEvent(QGraphicsSceneMouseEvent* mv) override;
97  void mouseReleaseEvent(QGraphicsSceneMouseEvent* mv) override;
98 
99  bool pressed{};
100 
101 private:
102  double m_origItemX{};
103  double m_pressX{};
104  TimeVal m_time{};
105 };
106 
107 class FixedHandle final : public TimeSignatureHandle
108 {
109 public:
110  using TimeSignatureHandle::TimeSignatureHandle;
111 };
112 
113 class MovableHandle final : public TimeSignatureHandle
114 {
115 public:
116  using TimeSignatureHandle::TimeSignatureHandle;
117 
118 private:
119  double m_origItemX{};
120  double m_pressX{};
121 
122  void mousePressEvent(QGraphicsSceneMouseEvent* mv) override;
123  void mouseMoveEvent(QGraphicsSceneMouseEvent* mv) override;
124  void mouseReleaseEvent(QGraphicsSceneMouseEvent* mv) override;
125 };
126 
128  : public QObject
129  , public QGraphicsItem
130 {
131 public:
132  TimeSignatureItem(const FullViewIntervalPresenter& itv, QGraphicsItem* parent);
133 
134  void createHandle(TimeVal time, ossia::time_signature sig);
135  void setZoomRatio(ZoomRatio r);
136  void setWidth(double w);
137  void setModel(const IntervalModel* model, TimeVal delta);
138  void updateStartMarker();
139 
140 private:
141  void handlesChanged();
142 
143  void moveHandle(TimeSignatureHandle& handle, double originalPos, double delta);
144 
145  void removeHandle(TimeSignatureHandle& handle);
146  QRectF boundingRect() const final override;
147  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
148  override;
149  void requestNewHandle(QPointF pos);
150  void setStartMarker(QPointF pos);
151  void removeStartMarker();
152  void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
153 
154  double m_width{100.};
155  ZoomRatio m_ratio{1.};
156 
157  const FullViewIntervalPresenter& m_itv;
158  const IntervalModel* m_model{};
159  TimeVal m_timeDelta;
160  Process::MagnetismAdjuster& m_magnetic;
161 
162  StartMarker* m_start{};
163  std::vector<TimeSignatureHandle*> m_handles;
164  TimeSignatureMap m_origHandles{};
165 
166  TimeVal m_origTime{};
167  ossia::time_signature m_origSig{};
168 };
169 
171 struct Timebars
172 {
174 
175  TimeSignatureItem timebar;
176 
177  LightBars lightBars;
178  LighterBars lighterBars;
179  std::vector<TimeVal> magneticTimings;
180 };
181 }
Definition: MagnetismAdjuster.hpp:24
Definition: TimeSignatureItem.hpp:108
Definition: FullViewIntervalPresenter.hpp:30
Definition: IntervalModel.hpp:50
Definition: Timebar.hpp:14
Definition: Timebar.hpp:59
Definition: TimeSignatureItem.hpp:22
Definition: TimeSignatureItem.hpp:114
Definition: TimeSignatureItem.hpp:79
Definition: TimeSignatureItem.hpp:39
Definition: TimeSignatureItem.hpp:130
Base classes and tools to implement processes and layers.
Definition: JSONVisitor.hpp:1324
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14
Definition: TimeSignatureMap.hpp:26
Definition: TimeSignatureItem.hpp:172
Definition: TimeValue.hpp:21