File: scoreview.h

package info (click to toggle)
musescore3 3.2.3%2Bdfsg2-16
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 214,188 kB
  • sloc: cpp: 291,198; xml: 200,238; sh: 3,779; ansic: 1,447; python: 393; makefile: 244; perl: 82; pascal: 79
file content (424 lines) | stat: -rw-r--r-- 14,318 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
//=============================================================================
//  MuseScore
//  Music Composition & Notation
//
//  Copyright (C) 2002-2009 Werner Schweer
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License version 2
//  as published by the Free Software Foundation and appearing in
//  the file LICENCE.GPL
//=============================================================================

#ifndef __SCANVAS_H__
#define __SCANVAS_H__

#include "globals.h"
#include "libmscore/element.h"
#include "libmscore/durationtype.h"
#include "libmscore/mscore.h"
#include "libmscore/mscoreview.h"
#include "libmscore/pos.h"

namespace Ms {

class ChordRest;
class Rest;
class Element;
class Page;
class XmlWriter;
class Note;
class Lasso;
class FotoLasso;
class ShadowNote;
class Segment;
class Measure;
class System;
class Score;
class ScoreView;
class Text;
class MeasureBase;
class Staff;
class OmrView;
class PositionCursor;
class ContinuousPanel;
class Tuplet;
class FretDiagram;
class Bend;
class TremoloBar;

#ifdef Q_OS_MAC
#define CONTROL_MODIFIER Qt::AltModifier
#else
#define CONTROL_MODIFIER Qt::ControlModifier
#endif

enum class Grip : int;
enum class POS : char;
enum class MagIdx : char;

//---------------------------------------------------------
//   ViewState
//---------------------------------------------------------

enum class ViewState {
      NORMAL,
      DRAG,
      DRAG_OBJECT,
      EDIT,
      DRAG_EDIT,
      LASSO,
      NOTE_ENTRY,
      PLAY,
      ENTRY_PLAY,

      FOTO,
      FOTO_DRAG,
      FOTO_DRAG_EDIT,
      FOTO_DRAG_OBJECT,
      FOTO_LASSO,
      };

//---------------------------------------------------------
//   ScoreView
//---------------------------------------------------------

class ScoreView : public QWidget, public MuseScoreView {
      Q_OBJECT

      ViewState state;
      OmrView* _omrView;

      // the next elements are used during dragMove to give some visual
      // feedback:
      //    dropTarget:       if valid, the element is drawn in a different color
      //                      to mark it as a valid drop target
      //    dropRectangle:    if valid, the rectangle is filled with a
      //                      color to visualize a valid drop area
      //    dropAnchor:       if valid the line is drawn from the current
      //                      cursor position to the current anchor point
      // Note:
      //    only one of the elements is active during drag

      const Element* dropTarget;    ///< current drop target during dragMove
      QRectF dropRectangle;         ///< current drop rectangle during dragMove
      QLineF dropAnchor;            ///< line to current anchor point during dragMove

      QTransform _matrix, imatrix;
      MagIdx _magIdx;

      QFocusFrame* focusFrame;

      EditData editData;

      //--input state:
      PositionCursor* _cursor;
      ShadowNote* shadowNote;

      // Realtime state:      Note: always set allowRealtimeRests to desired value before starting a timer.
      QTimer* realtimeTimer;   // multi-shot timer for advancing in automatic realtime mode
      QTimer* extendNoteTimer; // single-shot timer for initial advancement when a note is held
      bool allowRealtimeRests = false; // Allow entering rests in realtime mode? (See note above)

      bool tripleClickPending = false;
      bool popupActive = false;

      // Loop In/Out marks in the score
      PositionCursor* _curLoopIn;
      PositionCursor* _curLoopOut;

      // Continuous panel
      ContinuousPanel* _continuousPanel;

      Lasso* lasso;           ///< temporarily drawn lasso selection
      FotoLasso* _foto;

      QColor _bgColor;
      QColor _fgColor;
      QPixmap* _bgPixmap;
      QPixmap* _fgPixmap;

      // By default when the view will prevent viewpoint changes if
      // it is inactive. Set this flag to true to change this behaviour.
      bool _moveWhenInactive = false;

      virtual void paintEvent(QPaintEvent*);
      void paint(const QRect&, QPainter&);

      void objectPopup(const QPoint&, Element*);
      void measurePopup(QContextMenuEvent* ev, Measure*);

      void saveChord(XmlWriter&);

      virtual bool event(QEvent* event) override;
      virtual bool gestureEvent(QGestureEvent*);            // ??
      virtual void resizeEvent(QResizeEvent*) override;
      virtual void dragEnterEvent(QDragEnterEvent*) override;
      virtual void dragLeaveEvent(QDragLeaveEvent*) override;
      virtual void dragMoveEvent(QDragMoveEvent*) override;
      virtual void dropEvent(QDropEvent*) override;
      virtual void focusInEvent(QFocusEvent*) override;
      virtual void focusOutEvent(QFocusEvent*) override;

      virtual void wheelEvent(QWheelEvent*) override;
      virtual void mouseMoveEvent(QMouseEvent*) override;
      virtual void mousePressEvent(QMouseEvent*) override;
      virtual void mouseReleaseEvent(QMouseEvent*) override;
      virtual void mouseDoubleClickEvent(QMouseEvent*);

      virtual void keyPressEvent(QKeyEvent*) override;
      virtual void keyReleaseEvent(QKeyEvent*) override;
      virtual void inputMethodEvent(QInputMethodEvent*) override;

      virtual void contextMenuEvent(QContextMenuEvent*) override;

      void mousePressEventNormal(QMouseEvent*);
      void escapeCmd();
      bool startTextEditingOnMouseRelease(QMouseEvent*);
      void adjustCursorForTextEditing(QMouseEvent*);

      void constraintCanvas(int *dxx, int *dyy);
      void contextItem(Element*);
      void lassoSelect();

      void setShadowNote(const QPointF&);
      void drawElements(QPainter& p,QList<Element*>& el, Element* editElement);
      bool dragTimeAnchorElement(const QPointF& pos);
      bool dragMeasureAnchorElement(const QPointF& pos);
      virtual void lyricsTab(bool back, bool end, bool moveOnly) override;
      virtual void lyricsReturn() override;
      virtual void lyricsEndEdit() override;
      virtual void lyricsUpDown(bool up, bool end) override;
      virtual void lyricsMinus() override;
      virtual void lyricsUnderscore() override;
      virtual void textTab(bool back = false) override;
      void harmonyEndEdit();
      void harmonyTab(bool back);
      void harmonyBeatsTab(bool noterest, bool back);
      void harmonyTicksTab(const Fraction& ticks);
      void figuredBassTab(bool meas, bool back);
      void figuredBassTicksTab(const Fraction& ticks);
      void figuredBassEndEdit();
      void realtimeAdvance(bool allowRests);
      void cmdAddFret(int fret);
      void cmdAddChordName();
      void cmdAddText(Tid tid);
      void cmdEnterRest(const TDuration&);
      void cmdEnterRest();
      void cmdTuplet(int n, ChordRest*);
      void cmdTuplet(int);
      void cmdCreateTuplet(ChordRest* cr, Tuplet* tuplet);
      void cmdRepeatSelection();
      void cmdChangeEnharmonic(bool);

      MeasureBase* insertMeasure(ElementType, MeasureBase*);
      MeasureBase* checkSelectionStateForInsertMeasure();

      void appendMeasures(int, ElementType);
      MeasureBase* appendMeasure(ElementType);
      void cmdInsertMeasure(ElementType);
      void createElementPropertyMenu(Element* e, QMenu*);
      void genPropertyMenu1(Element* e, QMenu* popup);
      void genPropertyMenuText(Element* e, QMenu* popup);
      void elementPropertyAction(const QString&, Element* e);
      void paintPageBorder(QPainter& p, Page* page);
      bool dropCanvas(Element*);
      void editCmd(const QString&);
      void setLoopCursor(PositionCursor* curLoop, const Fraction& tick, bool isInPos);
      void cmdMoveCR(bool left);
      void cmdGotoElement(Element*);
      bool checkCopyOrCut();
      QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
      void startFotomode();
      void stopFotomode();
      void startFotoDrag();
      void endFotoDrag();
      void endFotoDragEdit();
      QImage getRectImage(const QRectF& rect, double dpi, bool transparent, bool printMode);

      virtual void startEdit();
      void endEdit();

      void startDrag();
      void endDrag();

      void endDragEdit();

      void startNoteEntry();
      virtual void startNoteEntryMode() override;
      void endNoteEntry();

      void endLasso();
      Element* getDropTarget(EditData&);

   private slots:
      void posChanged(POS pos, unsigned tick);
      void loopToggled(bool);
      void triggerCmdRealtimeAdvance();
      void cmdRealtimeAdvance();
      void extendCurrentNote();
      void seqStopped();
      void tripleClickTimeOut();

   public slots:
      void setViewRect(const QRectF&);

      void deselectAll();

      void editCopy();
      void editCut();
      void editPaste();
      void editSwap();

      void normalCut();
      void normalCopy();
      void fotoModeCopy(bool includeLink = false);
      bool normalPaste(Fraction scale = Fraction(1, 1));
      void normalSwap();

      void cloneElement(Element* e);
      void doFotoDragEdit(QMouseEvent* ev);

      void updateContinuousPanel();
      void ticksTab(const Fraction& ticks);     // helper function

   signals:
      void viewRectChanged();
      void scaleChanged(double);
      void offsetChanged(double, double);
      void sizeChanged();

   public:
      ScoreView(QWidget* parent = 0);
      ~ScoreView();

      QPixmap* fgPixmap() { return _fgPixmap; }

      virtual void startEdit(Element*, Grip) override;
      virtual void startEditMode(Element*) override;

      void moveCursor(const Fraction& tick);
      Fraction cursorTick() const;
      void setCursorOn(bool);
      void setBackground(QPixmap*);
      void setBackground(const QColor&);
      void setForeground(QPixmap*);
      void setForeground(const QColor&);

      Page* addPage();
      virtual void setScore(Score* s);
      virtual void removeScore()  { _score = 0; }

      void setMag(qreal m);
      bool navigatorVisible() const;
      void cmd(const QAction*);
      void cmd(const char*);

      void startUndoRedo(bool);
      void zoomStep(qreal step, const QPoint& pos);
      void zoom(qreal _mag, const QPointF& pos);
      void contextPopup(QContextMenuEvent* ev);
      bool editKeyLyrics();
      bool editKeySticking();
      void dragScoreView(QMouseEvent* ev);
      void doDragElement(QMouseEvent* ev);
      void doDragLasso(QMouseEvent* ev);
      void doDragFoto(QMouseEvent* ev);
      void doDragEdit(QMouseEvent* ev);
      bool testElementDragTransition(QMouseEvent* ev);
      bool fotoEditElementDragTransition(QMouseEvent* ev);
      void addSlur();
      virtual void cmdAddSlur(ChordRest*, ChordRest*) override;
      virtual void cmdAddHairpin(HairpinType);
      void cmdAddNoteLine();

      bool noteEntryMode() const { return state == ViewState::NOTE_ENTRY; }
      bool editMode() const      { return state == ViewState::EDIT; }
      bool fotoMode() const;

      virtual void setDropRectangle(const QRectF&);
      virtual void setDropTarget(const Element*) override;
      void setDropAnchor(const QLineF&);
      const QTransform& matrix() const  { return _matrix; }
      qreal mag() const;
      qreal lmag() const;
      MagIdx magIdx() const             { return _magIdx; }
      void setMag(MagIdx idx, double mag);
      qreal xoffset() const;
      qreal yoffset() const;
      void setOffset(qreal x, qreal y);
      QSizeF fsize() const;
      void pageNext();
      void pagePrev();
      void pageTop();
      void pageEnd();
      QPointF toLogical(const QPoint& p) const   { return imatrix.map(QPointF(p)); }
      QPointF toPhysical(const QPointF& p) const {return _matrix.map(p); }
      QRectF toLogical(const QRectF& r) const    { return imatrix.mapRect(r); }
      QRect toPhysical(const QRectF& r) const    { return _matrix.mapRect(r).toRect(); }

      bool searchMeasure(int i);
      bool searchPage(int i);
      bool searchRehearsalMark(const QString& s);
      void gotoMeasure(Measure*);
      void setFocusRect();
      void changeVoice(int voice);
      virtual void drawBackground(QPainter* p, const QRectF& r) const;
      bool fotoScoreViewDragTest(QMouseEvent*);
      bool fotoScoreViewDragRectTest(QMouseEvent*);
      void doDragFotoRect(QMouseEvent*);
      void fotoContextPopup(QContextMenuEvent*);
      bool fotoRectHit(const QPoint& p);
      void paintRect(bool printMode, QPainter& p, const QRectF& r, double mag);
      bool saveFotoAs(bool printMode, const QRectF&);
      void fotoDragDrop(QMouseEvent*);
      void changeEditElement(Element*);

      void cmdAppendMeasures(int, ElementType);
      void cmdInsertMeasures(int, ElementType);

      void cmdAddRemoveBreaks();
      void cmdCopyLyricsToClipboard();

      ScoreState mscoreState() const;
      void setCursorVisible(bool v);
      void showOmr(bool flag);
      void midiNoteReceived(int pitch, bool chord, int velocity);

      virtual void moveCursor() override;

      virtual void layoutChanged();
      virtual void dataChanged(const QRectF&);
      virtual void updateAll()    { update(); }
      virtual void adjustCanvasPosition(const Element* el, bool playBack, int staff = -1) override;
      virtual void setCursor(const QCursor& c) { QWidget::setCursor(c); }
      virtual QCursor cursor() const { return QWidget::cursor(); }
      void loopUpdate(bool val)   {  loopToggled(val); }

      void updateShadowNotes();

      OmrView* omrView() const        { return _omrView; }
      void setOmrView(OmrView* v)     { _omrView = v;    }
      FotoLasso* fotoLasso() const    { return _foto;    }
      Element* getEditElement();
      void onElementDestruction(Element*) override;

      virtual Element* elementNear(QPointF);
      QList<Element*> elementsNear(QPointF);
//      void editFretDiagram(FretDiagram*);
      void editBendProperties(Bend*);
      void editTremoloBarProperties(TremoloBar*);
      EditData& getEditData()        { return editData; }
      void changeState(ViewState);

      virtual const QRect geometry() const override { return QWidget::geometry(); }

      bool clickOffElement = false;
      void updateGrips();
      bool moveWhenInactive() const { return _moveWhenInactive; }
      bool moveWhenInactive(bool move) { bool m = _moveWhenInactive; _moveWhenInactive = move; return m; }
      };

} // namespace Ms
#endif