Loading...
Searching...
No Matches
TimeRuler.hpp
1#pragma once
2#include <Process/TimeValue.hpp>
3
4#include <Scenario/Document/TimeRuler/TimeRuler.hpp>
5
6#include <score/model/ColorReference.hpp>
7
8#include <ossia/editor/scenario/time_value.hpp>
9
10#include <ossia-qt/time.hpp>
11
12#include <QGlyphRun>
13#include <QGraphicsItem>
14#include <QPainterPath>
15#include <QPoint>
16#include <QPointer>
17#include <QTextLayout>
18
19#include <score_plugin_scenario_export.h>
20
21#include <chrono>
22#include <deque>
23#include <verdigris>
24class QGraphicsSceneMouseEvent;
25class QPainter;
26class QStyleOptionGraphicsItem;
27class QWidget;
28class QGraphicsView;
29
30namespace Scenario
31{
32class MusicalGrid;
33class SCORE_PLUGIN_SCENARIO_EXPORT TimeRulerBase
34 : public QObject
35 , public QGraphicsItem
36{
37 W_OBJECT(TimeRulerBase)
38public:
39 qreal width() const { return m_width; }
40 void setWidth(qreal newWidth);
41 void setStartPoint(ossia::time_value dur);
42 virtual void setZoomRatio(double factor) = 0;
43 virtual void setGrid(MusicalGrid& grid);
44
45 void drag(QPointF arg_1, QPointF arg_2) W_SIGNAL(drag, arg_1, arg_2);
46 void rescale() W_SIGNAL(rescale);
47
48protected:
49 virtual void createRulerPath() = 0;
50 virtual void computeGraduationSpacing() = 0;
51 QRectF boundingRect() const final override;
52 void mousePressEvent(QGraphicsSceneMouseEvent*) final override;
53 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*) final override;
54 void mouseMoveEvent(QGraphicsSceneMouseEvent*) final override;
55 void mouseReleaseEvent(QGraphicsSceneMouseEvent*) final override;
56 ossia::time_value m_startPoint{};
57 qreal m_width{};
58};
59
60class TimeRuler final : public TimeRulerBase
61{
62 Q_INTERFACES(QGraphicsItem)
63
64public:
65 enum class Format
66 {
67 Hours,
68 Seconds,
69 Milliseconds,
70 Microseconds,
71 };
72
73 TimeRuler(QGraphicsView*);
74
75private:
76 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
77 override;
78
79 qreal graduationSpacing() const
80 {
81 return m_intervalsBetweenMark * m_graduationsSpacing;
82 }
83
84 void computeGraduationSpacing() override;
85 void createRulerPath() override;
86 void setZoomRatio(double factor) final override;
87
88 struct Mark
89 {
90 double pos;
91 std::chrono::nanoseconds time;
92 QGlyphRun text;
93 };
94
95 double m_pixelPerMillis{0.01};
96
97 std::vector<Mark> m_marks;
98
99 qreal m_graduationsSpacing{};
100 qreal m_graduationDelta{};
101 qreal m_intervalsBetweenMark{};
102 Format m_timeFormat{};
103
104 QPainterPath m_path;
105
106 QGraphicsView* m_viewport{};
107
108 QGlyphRun getGlyphs(std::chrono::nanoseconds);
109 QTextLayout m_layout;
110 std::deque<std::pair<std::chrono::nanoseconds, QGlyphRun>> m_stringCache;
111};
112
113class MusicalRuler final : public TimeRulerBase
114{
115 Q_INTERFACES(QGraphicsItem)
116
117public:
118 enum class Format
119 {
120 Bars,
121 Quarters,
122 Semiquavers,
123 Cents,
124 };
125
126 MusicalRuler(QGraphicsView*);
127
128private:
129 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
130 override;
131
132 void computeGraduationSpacing() override;
133 void createRulerPath() override;
134 void setZoomRatio(double factor) final override;
135 void setGrid(MusicalGrid& grid) final override;
136
137 QPointer<MusicalGrid> m_grid{};
138
139 QGraphicsView* m_viewport{};
140
141 QGlyphRun getGlyphs(ossia::bar_time timings, ossia::bar_time increments);
142 QTextLayout m_layout;
143 std::deque<std::tuple<ossia::bar_time, ossia::bar_time, QGlyphRun>> m_stringCache;
144};
145}
Definition MusicalGrid.hpp:16
Definition TimeRuler.hpp:114
Definition TimeRuler.hpp:36
Definition TimeRuler.hpp:61
Main plug-in of score.
Definition score-plugin-dataflow/Dataflow/PortItem.hpp:13