MuseScore  3.4
Music composition and notation
pianoview.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2009-2011 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 __PIANOVIEW_H__
14 #define __PIANOVIEW_H__
15 
16 #include "libmscore/pos.h"
17 
18 namespace Ms {
19 
20 class Score;
21 class Staff;
22 class Chord;
23 class ChordRest;
24 class Note;
25 class NoteEvent;
26 class PianoView;
27 
28 enum class NoteSelectType {
29  REPLACE = 0,
30  XOR,
31  ADD,
32  SUBTRACT,
33  FIRST
34  };
35 
36 enum class DragStyle {
37  NONE = 0,
40  };
41 
42 struct BarPattern {
43  QString name;
44  char isWhiteKey[12]; //Set to 1 for white keys, 0 for black
45  };
46 
47 //---------------------------------------------------------
48 // PianoItem
49 //---------------------------------------------------------
50 
51 class PianoItem {
54 
55  void paintNoteBlock(QPainter* painter, NoteEvent* evt);
56  QRect boundingRectTicks(NoteEvent* evt);
57  QRect boundingRectPixels(NoteEvent* evt);
58  bool intersectsBlock(int startTick, int endTick, int highPitch, int lowPitch, NoteEvent* evt);
59 
60  public:
63  Note* note() { return _note; }
64  void paint(QPainter* painter);
65  bool intersects(int startTick, int endTick, int highPitch, int lowPitch);
66 
67  QRect boundingRect();
68 
69  NoteEvent* getTweakNoteEvent();
70  };
71 
72 //---------------------------------------------------------
73 // PianoView
74 //---------------------------------------------------------
75 
76 class PianoView : public QGraphicsView {
77  Q_OBJECT
78 
79 public:
80  static const BarPattern barPatterns[];
81 
82 private:
85 
86  Pos trackingPos; //Track mouse position
88  int ticks;
91  qreal _xZoom;
92  int _tuplet; //Tuplet divisions
93  int _subdiv; //Beat subdivisions
95 
97  bool mouseDown;
99  QPointF mouseDownPos;
100  QPointF lastMousePos;
104 
105  QList<PianoItem*> noteList;
106 
107  virtual void drawBackground(QPainter* painter, const QRectF& rect);
108 
109  void addChord(Chord* chord, int voice);
110  void updateBoundingSize();
111  void clearNoteData();
112  void selectNotes(int startTick, int endTick, int lowPitch, int highPitch, NoteSelectType selType);
113  void showPopupMenu(const QPoint& pos);
114  bool cutChordRest(ChordRest* e, int track, int cutTick, ChordRest*& cr0, ChordRest*& cr1);
115 
116  QAction* getAction(const char* id);
117 
118  protected:
119  virtual void wheelEvent(QWheelEvent* event);
120  virtual void mousePressEvent(QMouseEvent* event);
121  virtual void mouseReleaseEvent(QMouseEvent* event);
122  virtual void mouseMoveEvent(QMouseEvent* event);
123  virtual void leaveEvent(QEvent*);
124  virtual void contextMenuEvent(QContextMenuEvent *event);
125 
126  signals:
127  void xZoomChanged(qreal);
128  void tupletChanged(int);
129  void subdivChanged(int);
130  void barPatternChanged(int);
131  void noteHeightChanged(int);
132  void pitchChanged(int);
133  void trackingPosChanged(const Pos&);
134  void selectionChanged();
135 
136  public slots:
137  void moveLocator(int);
138  void updateNotes();
139  void setXZoom(int);
140  void setTuplet(int);
141  void setSubdiv(int);
142  void setBarPattern(int);
143 
144  public:
145  PianoView();
146  ~PianoView();
147  Staff* staff() { return _staff; }
148  void setStaff(Staff*, Pos* locator);
149  void ensureVisible(int tick);
150  int noteHeight() { return _noteHeight; }
151  qreal xZoom() { return _xZoom; }
152  int tuplet() { return _tuplet; }
153  int subdiv() { return _subdiv; }
154  int barPattern() { return _barPattern; }
155  QList<QGraphicsItem*> items() { return scene()->selectedItems(); }
156 
157  int pixelXToTick(int pixX);
158  int tickToPixelX(int tick);
159  int pixelYToPitch(int pixY) { return (int)floor(128 - pixY / (qreal)_noteHeight); }
160 
161  PianoItem* pickNote(int tick, int pitch);
162 
163  QList<PianoItem*> getSelectedItems();
164  QList<PianoItem*> getItems();
165 
166  bool playEventsView() { return _playEventsView; }
167  };
168 
169 
170 } // namespace Ms
171 #endif
172 
Note * _note
Definition: pianoview.h:52
int _noteHeight
Definition: pianoview.h:90
Pos trackingPos
Definition: pianoview.h:86
DragStyle
Definition: pianoview.h:36
bool dragStarted
Definition: pianoview.h:98
Global staff data not directly related to drawing.
Definition: staff.h:62
Definition: pianoview.h:76
qreal _xZoom
Definition: pianoview.h:91
Definition: noteevent.h:25
Definition: pianoview.h:42
int barPattern()
Definition: pianoview.h:154
bool inProgressUndoEvent
Definition: pianoview.h:103
int tuplet()
Definition: pianoview.h:152
Chord * chord
Definition: pianoview.h:84
~PianoItem()
Definition: pianoview.h:62
TType _timeType
Definition: pianoview.h:89
bool playEventsView()
Definition: pianoview.h:166
Pos * _locator
Definition: pianoview.h:87
int subdiv()
Definition: pianoview.h:153
int noteHeight()
Definition: pianoview.h:150
PianoView * _pianoView
Definition: pianoview.h:53
int pixelYToPitch(int pixY)
Definition: pianoview.h:159
bool mouseDown
Definition: pianoview.h:97
Definition: pianoview.h:51
QString name
Definition: pianoview.h:43
Definition: aeolus.cpp:26
bool _playEventsView
Definition: pianoview.h:96
int lastDragPitch
Definition: pianoview.h:102
Staff * staff()
Definition: pianoview.h:147
QList< QGraphicsItem * > items()
Definition: pianoview.h:155
int _subdiv
Definition: pianoview.h:93
NoteSelectType
Definition: pianoview.h:28
int ticks
Definition: pianoview.h:88
Graphic representation of a chord.
Definition: chord.h:55
QPointF mouseDownPos
Definition: pianoview.h:99
int _tuplet
Definition: pianoview.h:92
qreal xZoom()
Definition: pianoview.h:151
Definition: chordrest.h:48
Note * note()
Definition: pianoview.h:63
QAction * getAction(const char *)
Definition: shortcut.cpp:3952
DragStyle dragStyle
Definition: pianoview.h:101
Graphic representation of a note.
Definition: note.h:212
QPointF lastMousePos
Definition: pianoview.h:100
TType
Definition: pos.h:32
QList< PianoItem * > noteList
Definition: pianoview.h:105
int _barPattern
Definition: pianoview.h:94
Staff * _staff
Definition: pianoview.h:83
Definition: pos.h:42