MuseScore  3.4
Music composition and notation
scoreview.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2002-2009 Werner Schweer
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 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __SCANVAS_H__
14 #define __SCANVAS_H__
15 
16 #include "globals.h"
17 #include "libmscore/element.h"
18 #include "libmscore/durationtype.h"
19 #include "libmscore/mscore.h"
20 #include "libmscore/mscoreview.h"
21 #include "libmscore/pos.h"
22 #include "libmscore/harmony.h"
23 
24 namespace Ms {
25 
26 class ChordRest;
27 class Rest;
28 class Element;
29 class Page;
30 class XmlWriter;
31 class Note;
32 class Lasso;
33 class FotoLasso;
34 class ShadowNote;
35 class Segment;
36 class Measure;
37 class System;
38 class Score;
39 class ScoreView;
40 class Text;
41 class MeasureBase;
42 class Staff;
43 class OmrView;
44 class PositionCursor;
45 class ContinuousPanel;
46 class Tuplet;
47 class FretDiagram;
48 class Bend;
49 class TremoloBar;
50 class TimeSig;
51 class StaffTextBase;
52 class Articulation;
53 
54 #ifdef Q_OS_MAC
55 #define CONTROL_MODIFIER Qt::AltModifier
56 #else
57 #define CONTROL_MODIFIER Qt::ControlModifier
58 #endif
59 
60 enum class Grip : int;
61 enum class POS : char;
62 enum class MagIdx : char;
63 
64 //---------------------------------------------------------
65 // ViewState
66 //---------------------------------------------------------
67 
68 enum class ViewState {
69  NORMAL,
70  DRAG,
72  EDIT,
73  DRAG_EDIT,
74  LASSO,
75  NOTE_ENTRY,
76  PLAY,
77  ENTRY_PLAY,
78 
79  FOTO,
80  FOTO_DRAG,
83  FOTO_LASSO,
84  };
85 
86 //---------------------------------------------------------
87 // ScoreView
88 //---------------------------------------------------------
89 
90 class ScoreView : public QWidget, public MuseScoreView {
91  Q_OBJECT
92 
95 
96  // the next elements are used during dragMove to give some visual
97  // feedback:
98  // dropTarget: if valid, the element is drawn in a different color
99  // to mark it as a valid drop target
100  // dropRectangle: if valid, the rectangle is filled with a
101  // color to visualize a valid drop area
102  // dropAnchor: if valid the line is drawn from the current
103  // cursor position to the current anchor point
104  // Note:
105  // only one of the elements is active during drag
106 
108  QRectF dropRectangle;
109  QLineF dropAnchor;
110 
111  QTransform _matrix, imatrix;
113 
114  QFocusFrame* focusFrame;
115 
117 
118  //--input state:
121 
122  // Realtime state: Note: always set allowRealtimeRests to desired value before starting a timer.
123  QTimer* realtimeTimer; // multi-shot timer for advancing in automatic realtime mode
124  QTimer* extendNoteTimer; // single-shot timer for initial advancement when a note is held
125  bool allowRealtimeRests; // Allow entering rests in realtime mode? (See note above)
126 
127  bool tripleClickPending = false;
128  bool popupActive = false;
129  bool modifySelection = false;
130  Element* elementToSelect = nullptr;
131 
132  // Loop In/Out marks in the score
135 
136  // Continuous panel
138 
141 
142  QColor _bgColor;
143  QColor _fgColor;
144  QPixmap* _bgPixmap;
145  QPixmap* _fgPixmap;
146 
147  // By default when the view will prevent viewpoint changes if
148  // it is inactive. Set this flag to true to change this behaviour.
149  bool _moveWhenInactive = false;
150 
151  bool _blockShowEdit = false;
152 
153  virtual void paintEvent(QPaintEvent*);
154  void paint(const QRect&, QPainter&);
155 
156  void objectPopup(const QPoint&, Element*);
157  void measurePopup(QContextMenuEvent* ev, Measure*);
158 
159  void saveChord(XmlWriter&);
160 
161  virtual bool event(QEvent* event) override;
162  virtual bool gestureEvent(QGestureEvent*); // ??
163  virtual void resizeEvent(QResizeEvent*) override;
164  virtual void dragEnterEvent(QDragEnterEvent*) override;
165  virtual void dragLeaveEvent(QDragLeaveEvent*) override;
166  virtual void dragMoveEvent(QDragMoveEvent*) override;
167  virtual void dropEvent(QDropEvent*) override;
168  virtual void focusInEvent(QFocusEvent*) override;
169  virtual void focusOutEvent(QFocusEvent*) override;
170 
171  virtual void wheelEvent(QWheelEvent*) override;
172  virtual void mouseMoveEvent(QMouseEvent*) override;
173  virtual void mousePressEvent(QMouseEvent*) override;
174  virtual void mouseReleaseEvent(QMouseEvent*) override;
175  virtual void mouseDoubleClickEvent(QMouseEvent*);
176 
177  virtual void keyPressEvent(QKeyEvent*) override;
178  virtual void keyReleaseEvent(QKeyEvent*) override;
179  virtual void inputMethodEvent(QInputMethodEvent*) override;
180 
181  bool handleArrowKeyPress(const QKeyEvent*);
182 
183  virtual void contextMenuEvent(QContextMenuEvent*) override;
184 
185  void mousePressEventNormal(QMouseEvent*);
186  void escapeCmd();
187  bool startTextEditingOnMouseRelease(QMouseEvent*);
188  void adjustCursorForTextEditing(QMouseEvent*);
189 
190  void constraintCanvas(int *dxx, int *dyy);
191 
192  void setShadowNote(const QPointF&);
193  void drawElements(QPainter& p,QList<Element*>& el, Element* editElement);
194  bool dragTimeAnchorElement(const QPointF& pos);
195  bool dragMeasureAnchorElement(const QPointF& pos);
196  virtual void lyricsTab(bool back, bool end, bool moveOnly) override;
197  virtual void lyricsReturn() override;
198  virtual void lyricsEndEdit() override;
199  virtual void lyricsUpDown(bool up, bool end) override;
200  virtual void lyricsMinus() override;
201  virtual void lyricsUnderscore() override;
202  virtual void textTab(bool back = false) override;
203  void harmonyEndEdit();
204  void harmonyTab(bool back);
205  void harmonyBeatsTab(bool noterest, bool back);
206  void harmonyTicksTab(const Fraction& ticks);
207  void figuredBassTab(bool meas, bool back);
208  void figuredBassTicksTab(const Fraction& ticks);
209  void figuredBassEndEdit();
210  void realtimeAdvance(bool allowRests);
211  void cmdAddFret(int fret);
212  void cmdAddChordName(HarmonyType ht);
213  void cmdAddText(Tid tid, Tid customTid = Tid::DEFAULT);
214  void cmdEnterRest(const TDuration&);
215  void cmdEnterRest();
216  void cmdTuplet(int n, ChordRest*);
217  void cmdTuplet(int);
218  void cmdCreateTuplet(ChordRest* cr, Tuplet* tuplet);
219  void cmdRepeatSelection();
220  void cmdChangeEnharmonic(bool);
221 
222  MeasureBase* insertMeasure(ElementType, MeasureBase*);
223  MeasureBase* checkSelectionStateForInsertMeasure();
224 
225  void appendMeasures(int, ElementType);
226  MeasureBase* appendMeasure(ElementType);
227  void cmdInsertMeasure(ElementType);
228  void createElementPropertyMenu(Element* e, QMenu*);
229  void genPropertyMenu1(Element* e, QMenu* popup);
230  void genPropertyMenuText(Element* e, QMenu* popup);
231  void elementPropertyAction(const QString&, Element* e);
232  void paintPageBorder(QPainter& p, Page* page);
233  bool dropCanvas(Element*);
234  void editCmd(const QString&);
235  void setLoopCursor(PositionCursor* curLoop, const Fraction& tick, bool isInPos);
236  void cmdMoveCR(bool left);
237  void cmdGotoElement(Element*);
238  bool checkCopyOrCut();
239  QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
240  void startFotomode();
241  void stopFotomode();
242  void startFotoDrag();
243  void endFotoDrag();
244  void endFotoDragEdit();
245  QImage getRectImage(const QRectF& rect, double dpi, bool transparent, bool printMode);
246 
247  void startEdit(bool editMode = true);
248  void endEdit();
249 
250  void startDrag();
251  void endDrag();
252 
253  void endDragEdit();
254 
255  void startNoteEntry();
256  virtual void startNoteEntryMode() override;
257  void endNoteEntry();
258 
259  void endLasso();
260  Element* getDropTarget(EditData&);
261 
262  private slots:
263  void posChanged(POS pos, unsigned tick);
264  void loopToggled(bool);
265  void triggerCmdRealtimeAdvance();
266  void cmdRealtimeAdvance();
267  void extendCurrentNote();
268  void seqStopped();
269  void tripleClickTimeOut();
270 
271  public slots:
272  void setViewRect(const QRectF&);
273 
274  void deselectAll();
275 
276  void editCopy();
277  void editCut();
278  void editPaste();
279  void editSwap();
280 
281  void normalCut();
282  void normalCopy();
283  void fotoModeCopy(bool includeLink = false);
284  bool normalPaste(Fraction scale = Fraction(1, 1));
285  void normalSwap();
286 
287  void cloneElement(Element* e);
288  void doFotoDragEdit(QMouseEvent* ev);
289 
290  void updateContinuousPanel();
291  void ticksTab(const Fraction& ticks); // helper function
292 
293  signals:
294  void viewRectChanged();
295  void scaleChanged(double);
296  void offsetChanged(double, double);
297  void sizeChanged();
298 
299  public:
300  ScoreView(QWidget* parent = 0);
301  ~ScoreView();
302 
303  QPixmap* fgPixmap() { return _fgPixmap; }
304 
305  void startEdit(Element*, Grip) override;
306  void startEditMode(Element*);
307 
308  void moveCursor(const Fraction& tick);
309  Fraction cursorTick() const;
310  void setCursorOn(bool);
311  void setBackground(QPixmap*);
312  void setBackground(const QColor&);
313  void setForeground(QPixmap*);
314  void setForeground(const QColor&);
315 
316  Page* addPage();
317  virtual void setScore(Score* s);
318  virtual void removeScore() { _score = 0; }
319 
320  void setMag(qreal m);
321  bool navigatorVisible() const;
322  void cmd(const QAction*);
323  void cmd(const char*);
324 
325  void startUndoRedo(bool);
326  void zoomStep(qreal step, const QPoint& pos);
327  void zoom(qreal _mag, const QPointF& pos);
328  void contextPopup(QContextMenuEvent* ev);
329  bool editKeyLyrics();
330  bool editKeySticking();
331  void dragScoreView(QMouseEvent* ev);
332  void doDragElement(QMouseEvent* ev);
333  void doDragLasso(QMouseEvent* ev);
334  void doDragFoto(QMouseEvent* ev);
335  void doDragEdit(QMouseEvent* ev);
336  bool testElementDragTransition(QMouseEvent* ev);
337  bool fotoEditElementDragTransition(QMouseEvent* ev);
338  void addSlur(const Slur* slurTemplate = nullptr);
339  void cmdAddSlur(ChordRest*, ChordRest*, const Slur*) override;
340  virtual void cmdAddHairpin(HairpinType);
341  void cmdAddNoteLine();
342 
343  void setEditElement(Element*);
344  void updateEditElement();
345 
346  bool noteEntryMode() const { return state == ViewState::NOTE_ENTRY; }
347  bool editMode() const { return state == ViewState::EDIT; }
348  bool textEditMode() const { return editMode() && editData.element && editData.element->isTextBase(); }
349  bool hasEditGrips() const { return editData.element && editData.grips; }
350  bool fotoMode() const;
351 
352  virtual void setDropRectangle(const QRectF&);
353  virtual void setDropTarget(const Element*) override;
354  void setDropAnchor(const QLineF&);
355  const QTransform& matrix() const { return _matrix; }
356  qreal mag() const;
357  qreal lmag() const;
358  MagIdx magIdx() const { return _magIdx; }
359  void setMag(MagIdx idx, double mag);
360  qreal xoffset() const;
361  qreal yoffset() const;
362  void setOffset(qreal x, qreal y);
363  QSizeF fsize() const;
364  void screenNext();
365  void screenPrev();
366  void pageNext();
367  void pagePrev();
368  void pageTop();
369  void pageEnd();
370  QPointF toLogical(const QPoint& p) const { return imatrix.map(QPointF(p)); }
371  QPointF toPhysical(const QPointF& p) const {return _matrix.map(p); }
372  QRectF toLogical(const QRectF& r) const { return imatrix.mapRect(r); }
373  QRect toPhysical(const QRectF& r) const { return _matrix.mapRect(r).toRect(); }
374 
375  QRectF canvasViewport() const { return toLogical(geometry()); }
376 
377  bool searchMeasure(int i);
378  bool searchPage(int i);
379  bool searchRehearsalMark(const QString& s);
380  void gotoMeasure(Measure*);
381  void setFocusRect();
382  void changeVoice(int voice);
383  virtual void drawBackground(QPainter* p, const QRectF& r) const;
384  bool fotoScoreViewDragTest(QMouseEvent*);
385  bool fotoScoreViewDragRectTest(QMouseEvent*);
386  void doDragFotoRect(QMouseEvent*);
387  void fotoContextPopup(QContextMenuEvent*);
388  bool fotoRectHit(const QPoint& p);
389  void paintRect(bool printMode, QPainter& p, const QRectF& r, double mag);
390  bool saveFotoAs(bool printMode, const QRectF&);
391  void fotoDragDrop(QMouseEvent*);
392  void changeEditElement(Element*);
393 
394  void cmdAppendMeasures(int, ElementType);
395  void cmdInsertMeasures(int, ElementType);
396 
397  void cmdAddRemoveBreaks();
398  void cmdCopyLyricsToClipboard();
399 
400  ScoreState mscoreState() const;
401  void setCursorVisible(bool v);
402  void showOmr(bool flag);
403  void midiNoteReceived(int pitch, bool chord, int velocity);
404 
405  virtual void moveCursor() override;
406 
407  virtual void layoutChanged();
408  virtual void dataChanged(const QRectF&);
409  virtual void updateAll() { update(); }
410  virtual void adjustCanvasPosition(const Element* el, bool playBack, int staff = -1) override;
411  virtual void setCursor(const QCursor& c) { QWidget::setCursor(c); }
412  virtual QCursor cursor() const { return QWidget::cursor(); }
413  void loopUpdate(bool val) { loopToggled(val); }
414 
415  void moveViewportToLastEdit();
416 
417  void updateShadowNotes();
418 
419  OmrView* omrView() const { return _omrView; }
420  void setOmrView(OmrView* v) { _omrView = v; }
421  FotoLasso* fotoLasso() const { return _foto; }
422  Element* getEditElement();
423  void onElementDestruction(Element*) override;
424 
425  virtual Element* elementNear(QPointF);
426  QList<Element*> elementsNear(QPointF);
427  void editArticulationProperties(Articulation*);
428  void editTimeSigProperties(TimeSig*);
429  void editStaffTextProperties(StaffTextBase*);
430  EditData& getEditData() { return editData; }
431  void changeState(ViewState);
432 
433  virtual const QRect geometry() const override { return QWidget::geometry(); }
434 
435  void updateGrips();
436  bool moveWhenInactive() const { return _moveWhenInactive; }
437  bool moveWhenInactive(bool move) { bool m = _moveWhenInactive; _moveWhenInactive = move; return m; }
438  };
439 
440 } // namespace Ms
441 #endif
442 
int grips
Definition: element.h:118
QPixmap * _bgPixmap
Definition: scoreview.h:144
QPixmap * _fgPixmap
Definition: scoreview.h:145
Definition: durationtype.h:28
virtual void setCursor(const QCursor &c)
Definition: scoreview.h:411
ContinuousPanel * _continuousPanel
Definition: scoreview.h:137
HairpinType
Definition: hairpin.h:27
QRectF dropRectangle
current drop rectangle during dragMove
Definition: scoreview.h:108
bool editMode() const
Definition: scoreview.h:347
Virtual base class for Measure, HBox and VBox.
Definition: measurebase.h:61
This class represents a time signature.
Definition: timesig.h:41
EditData & getEditData()
Definition: scoreview.h:430
ShadowNote * shadowNote
Definition: scoreview.h:120
QRectF canvasViewport() const
Definition: scoreview.h:375
FotoLasso * fotoLasso() const
Definition: scoreview.h:421
Graphic representation of a shadow note, which shows the note insert position in note entry mode...
Definition: shadownote.h:30
MagIdx magIdx() const
Definition: scoreview.h:358
ViewState state
Definition: scoreview.h:93
QRect toPhysical(const QRectF &r) const
Definition: scoreview.h:373
PositionCursor * _curLoopOut
Definition: scoreview.h:134
one measure in a system
Definition: measure.h:65
Definition: textcursor.h:36
Definition: scoreview.h:90
const Element * dropTarget
current drop target during dragMove
Definition: scoreview.h:107
Definition: slur.h:55
virtual QCursor cursor() const
Definition: scoreview.h:412
ViewState
Definition: scoreview.h:68
QRectF toLogical(const QRectF &r) const
Definition: scoreview.h:372
Base class of score layout elements.
Definition: element.h:158
Lasso * lasso
temporarily drawn lasso selection
Definition: scoreview.h:139
QColor _bgColor
Definition: scoreview.h:142
bool allowRealtimeRests
Definition: scoreview.h:125
Definition: fotomode.h:24
ScoreState
Definition: globals.h:53
Definition: stafftextbase.h:35
Definition: score.h:391
HarmonyType
Definition: harmony.h:66
QTimer * realtimeTimer
Definition: scoreview.h:123
const QTransform & matrix() const
Definition: scoreview.h:355
Example of 1/8 triplet: _baseLen = 1/8 _actualNotes = 3 _normalNotes = 2 (3 notes played in the time ...
Definition: tuplet.h:37
MagIdx _magIdx
Definition: scoreview.h:112
bool isTextBase() const
Definition: scoreElement.cpp:840
QPointF toLogical(const QPoint &p) const
Definition: scoreview.h:370
QTransform imatrix
Definition: scoreview.h:111
Grip
Definition: element.h:43
Tid
Enumerates the list of built-in text substyles.
Definition: types.h:371
Element * element
Definition: element.h:137
FotoLasso * _foto
Definition: scoreview.h:140
articulation marks
Definition: articulation.h:57
Definition: lasso.h:24
MagIdx
Definition: magbox.h:32
PositionCursor * _curLoopIn
Definition: scoreview.h:133
Definition: aeolus.cpp:26
QPointF toPhysical(const QPointF &p) const
Definition: scoreview.h:371
Definition: continuouspanel.h:24
Definition: xml.h:218
Definition: omrview.h:51
Definition: xmlwriter.h:26
OmrView * omrView() const
Definition: scoreview.h:419
EditData editData
Definition: scoreview.h:116
virtual void updateAll()
Definition: scoreview.h:409
Definition: chordrest.h:48
PositionCursor * _cursor
Definition: scoreview.h:119
virtual const QRect geometry() const override
Definition: scoreview.h:433
QPixmap * fgPixmap()
Definition: scoreview.h:303
Definition: element.h:111
void loopUpdate(bool val)
Definition: scoreview.h:413
bool moveWhenInactive(bool move)
Definition: scoreview.h:437
Definition: fraction.h:46
ElementType
Definition: types.h:34
bool hasEditGrips() const
Definition: scoreview.h:349
bool moveWhenInactive() const
Definition: scoreview.h:436
POS
Definition: score.h:100
QColor _fgColor
Definition: scoreview.h:143
OmrView * _omrView
Definition: scoreview.h:94
bool textEditMode() const
Definition: scoreview.h:348
void setOmrView(OmrView *v)
Definition: scoreview.h:420
virtual void removeScore()
Definition: scoreview.h:318
QFocusFrame * focusFrame
Definition: scoreview.h:114
Definition: page.h:34
QLineF dropAnchor
line to current anchor point during dragMove
Definition: scoreview.h:109
bool noteEntryMode() const
Definition: scoreview.h:346
Definition: mscoreview.h:32
QTimer * extendNoteTimer
Definition: scoreview.h:124