MuseScore  3.4
Music composition and notation
timeline.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Linux Music Score Editor
4 //
5 // Copyright (C) 2002-2009 Werner Schweer and others
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19 
20 #ifndef __TIMELINE_H__
21 #define __TIMELINE_H__
22 
23 
24 #include "libmscore/select.h"
25 #include "scoreview.h"
26 #include <vector>
27 
28 namespace Ms {
29 
30 class Score;
31 class ScoreView;
32 class Page;
33 class Timeline;
34 class ViewRect;
35 
36 //---------------------------------------------------------
37 // TDockWidget
38 // modified QScrollArea for Timeline
39 //---------------------------------------------------------
40 
41 class TDockWidget : public QDockWidget {
42  Q_OBJECT
43 
44  QSplitter* _grid;
45 
46  virtual void closeEvent(QCloseEvent* event);
47 
48  signals:
49  void closed(bool);
50 
51  public:
52  TDockWidget(QWidget* w = 0);
53  QSplitter* grid() { return _grid; }
54  };
55 
56 //---------------------------------------------------------
57 // TRowLabels
58 //---------------------------------------------------------
59 
60 class TRowLabels : public QGraphicsView {
61  Q_OBJECT
62 
63  public:
64  enum class MouseOverValue {
65  NONE,
66  MOVE_UP_ARROW,
67  MOVE_DOWN_ARROW,
68  MOVE_UP_DOWN_ARROW,
69  COLLAPSE_UP_ARROW,
70  COLLAPSE_DOWN_ARROW,
71  OPEN_EYE,
72  CLOSED_EYE
73  };
74 
75  private:
78 
79  QPoint old_loc;
80 
81  bool dragging = false;
82 
83  std::vector<std::pair<QGraphicsItem*, int>> meta_labels;
84  std::map<MouseOverValue, QPixmap*> mouseover_map;
85  std::tuple<QGraphicsPixmapItem*, MouseOverValue, unsigned int> old_item_info;
86 
87  virtual void resizeEvent(QResizeEvent*);
88  virtual void mousePressEvent(QMouseEvent* event);
89  virtual void mouseMoveEvent(QMouseEvent* event);
90  virtual void mouseReleaseEvent(QMouseEvent* event);
91  virtual void contextMenuEvent(QContextMenuEvent*) override;
92  virtual void leaveEvent(QEvent*);
93 
94  private slots:
95  void restrict_scroll(int value);
96 
97  public slots:
98  void mouseOver(QPointF scene_pt);
99 
100  signals:
101  void moved(QPointF p);
102  void swapMeta(unsigned int r, bool up);
103  void requestContextMenu(QContextMenuEvent*);
104 
105  public:
106  TRowLabels(TDockWidget* dock_widget, Timeline* time, QGraphicsView* w = 0);
107  void updateLabels(std::vector<std::pair<QString, bool>> labels, int height);
108  QString cursorIsOn();
109  };
110 
111 //---------------------------------------------------------
112 // Timeline
113 //---------------------------------------------------------
114 
115 class Timeline : public QGraphicsView {
116  Q_OBJECT
117 
118  int grid_width = 20;
119  int grid_height = 20;
120  int max_zoom = 50;
121  int min_zoom = 5;
122  int spacing = 5;
123 
124  std::tuple<int, qreal, Element*, Element*, bool> repeat_info;
125  std::tuple<QGraphicsItem*, int, QColor> old_hover_info;
126 
127  std::map<QString, QPixmap*> barlines;
128  bool is_barline = false;
129 
132 
134  ScoreView* _cv = nullptr;
135 
136  QGraphicsRectItem* selection_box;
137  std::vector<std::pair<QGraphicsItem*, int>> meta_rows;
138 
139  QPainterPath selection_path;
141  bool mouse_pressed = false;
142  QPoint old_loc;
143 
144  bool collapsed_meta = false;
145 
146  std::vector<std::tuple<QString, void (Timeline::*)(Segment*, int*, int), bool>> metas;
147  void tempo_meta(Segment* seg, int* stagger, int pos);
148  void time_meta(Segment* seg, int* stagger, int pos);
149  void measure_meta(Segment*, int*, int pos);
150  void rehearsal_meta(Segment* seg, int* stagger, int pos);
151  void key_meta(Segment* seg, int* stagger, int pos);
152  void barline_meta(Segment* seg, int* stagger, int pos);
153  void jump_marker_meta(Segment* seg, int* stagger, int pos);
154 
155  bool addMetaValue(int x, int pos, QString meta_text, int row, ElementType element_type, Element* element, Segment* seg, Measure* measure, QString tooltip = "");
156  void setMetaData(QGraphicsItem* gi, int staff, ElementType et, Measure* m, bool full_measure, Element* e, QGraphicsItem* pair_item = nullptr, Segment* seg = nullptr);
157  unsigned int getMetaRow(QString target_text);
158 
159  int global_measure_number { 0 };
160  int global_z_value { 0 };
161 
162  //True if meta value was last clicked
163  bool meta_value = false;
165 
166  virtual void mousePressEvent(QMouseEvent* event);
167  virtual void mouseMoveEvent(QMouseEvent* event);
168  virtual void mouseReleaseEvent(QMouseEvent*);
169  virtual void wheelEvent(QWheelEvent *event);
170  virtual void leaveEvent(QEvent*);
171 
172  unsigned int correctMetaRow(unsigned int row);
173  int correctStave(int stave);
174 
175  QList<Part*> getParts();
176 
177  private slots:
178  void handle_scroll(int value);
179  void updateView();
180  void objectDestroyed(QObject*);
181 
182  public slots:
183  void changeSelection(SelState);
184  void mouseOver(QPointF pos);
185  void swapMeta(unsigned int row, bool switch_up);
186  virtual void contextMenuEvent(QContextMenuEvent* event) override;
187  void requestInstrumentDialog();
188  void toggleMetaRow();
189 
190  signals:
191  void moved(QPointF);
192 
193  public:
194  Timeline(TDockWidget* dock_widget, QWidget* parent = 0);
195  int correctPart(int stave);
196 
197  void drawSelection();
198  void drawGrid(int global_rows, int global_cols);
199 
200  void setScore(Score* s);
201  void setScoreView(ScoreView* sv);
202 
203  int nstaves();
204 
205  int getWidth();
206  int getHeight();
207 
208  void updateGrid();
209 
210  QColor colorBox(QGraphicsRectItem* item);
211 
212  std::vector<std::pair<QString, bool>> getLabels();
213 
214  unsigned int nmetas();
215 
216  bool collapsed() { return collapsed_meta; }
217  void setCollapsed(bool st) { collapsed_meta = st; }
218 
219  Staff* numToStaff(int staff);
220  void toggleShow(int staff);
221  QString cursorIsOn();
222  };
223 
224 
225 } // namespace Ms
226 
227 Q_DECLARE_METATYPE(Ms::TRowLabels::MouseOverValue);
228 
229 #endif
Definition: timeline.h:115
Global staff data not directly related to drawing.
Definition: staff.h:62
SelState
Definition: select.h:71
Definition: timeline.h:60
void closed(bool)
std::vector< std::pair< QGraphicsItem *, int > > meta_labels
Definition: timeline.h:83
std::tuple< QGraphicsPixmapItem *, MouseOverValue, unsigned int > old_item_info
Definition: timeline.h:85
one measure in a system
Definition: measure.h:65
Definition: scoreview.h:90
QSplitter * _grid
Definition: timeline.h:44
ViewState
Definition: scoreview.h:68
MouseOverValue
Definition: timeline.h:64
Base class of score layout elements.
Definition: element.h:158
QGraphicsRectItem * selection_box
Definition: timeline.h:136
std::tuple< QGraphicsItem *, int, QColor > old_hover_info
Definition: timeline.h:125
TDockWidget(QWidget *w=0)
Definition: timeline.cpp:71
TDockWidget * scrollArea
Definition: timeline.h:76
std::vector< std::pair< QGraphicsItem *, int > > meta_rows
Definition: timeline.h:137
QSplitter * grid()
Definition: timeline.h:53
Definition: score.h:391
bool collapsed()
Definition: timeline.h:216
TDockWidget * scrollArea
Definition: timeline.h:130
Definition: timeline.h:41
Score * _score
Definition: timeline.h:133
QPainterPath selection_path
Definition: timeline.h:139
Definition: segment.h:50
void setCollapsed(bool st)
Definition: timeline.h:217
Definition: aeolus.cpp:26
Timeline * parent
Definition: timeline.h:77
virtual void closeEvent(QCloseEvent *event)
Definition: timeline.cpp:89
std::map< QString, QPixmap * > barlines
Definition: timeline.h:127
TRowLabels * row_names
Definition: timeline.h:131
QPoint old_loc
Definition: timeline.h:142
std::map< MouseOverValue, QPixmap * > mouseover_map
Definition: timeline.h:84
QRectF old_selection_rect
Definition: timeline.h:140
std::tuple< int, qreal, Element *, Element *, bool > repeat_info
Definition: timeline.h:124
ElementType
Definition: types.h:34
std::vector< std::tuple< QString, void(Timeline::*)(Segment *, int *, int), bool > > metas
Definition: timeline.h:146
QPoint old_loc
Definition: timeline.h:79