1 //============================================================================= 2 // MusE Score 3 // Linux Music Score Editor 4 // 5 // Copyright (C) 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 __PIANOLEVELS_H__ 21 #define __PIANOLEVELS_H__ 22 23 #include <QWidget> 24 25 #include "libmscore/pos.h" 26 27 namespace Ms { 28 29 class Score; 30 class Staff; 31 class Chord; 32 class Note; 33 class NoteEvent; 34 class PianoItem; 35 36 37 38 //--------------------------------------------------------- 39 // PianoLevels 40 //--------------------------------------------------------- 41 42 class PianoLevels : public QWidget 43 { 44 Q_OBJECT 45 46 enum DragStyle { 47 LERP, OFFSET 48 }; 49 50 Score* _score; 51 int _xpos; 52 qreal _xZoom; 53 Pos _cursor; 54 Pos* _locator; 55 Staff* _staff; 56 int _tuplet; 57 int _subdiv; 58 int _levelsIndex; 59 int vMargin; 60 int levelLen; 61 int pickRadius = 4; 62 63 bool mouseDown; 64 QPointF mouseDownPos; 65 QPointF lastMousePos; 66 int dragging = false; 67 DragStyle dragStyle = DragStyle::OFFSET; 68 Note* singleNoteDrag = nullptr; 69 NoteEvent* singleNoteEventDrag = nullptr; 70 71 int minBeatGap; 72 73 QList<Note*> noteList; 74 75 virtual void paintEvent(QPaintEvent*); 76 virtual void mousePressEvent(QMouseEvent*); 77 virtual void mouseReleaseEvent(QMouseEvent* event); 78 virtual void mouseMoveEvent(QMouseEvent* event); 79 virtual void leaveEvent(QEvent*); 80 81 int pixelXToTick(int pixX); 82 int tickToPixelX(int tick); 83 int valToPixelY(int value); 84 int pixelYToVal(int value); 85 int noteStartTick(Note* note, NoteEvent* evt); 86 void moveLocator(QMouseEvent*); 87 void addChord(Chord* chord, int voice); 88 void clearNoteData(); 89 90 bool pickNoteEvent(int x, int y, bool selectedOnly, 91 Note*& pickedNote, NoteEvent*& pickedNoteEvent); 92 void adjustLevelLerp(int tick0, int value0, int tick1, int value1, bool selectedOnly = true); 93 void adjustLevel(Note* note, NoteEvent* noteEvt, int value); 94 95 signals: 96 void posChanged(const Pos&); 97 void tupletChanged(int); 98 void subdivChanged(int); 99 void levelsIndexChanged(int); 100 void locatorMoved(int idx, const Pos&); 101 void noteLevelsChanged(); 102 103 public slots: 104 void setXpos(int); 105 void setTuplet(int); 106 void setSubdiv(int); 107 void setXZoom(qreal); 108 void setPos(const Pos&); 109 void setLevelsIndex(int index); 110 111 public: 112 PianoLevels(QWidget *parent = 0); 113 ~PianoLevels(); 114 115 void setScore(Score*, Pos* locator); staff()116 Staff* staff() { return _staff; } 117 void setStaff(Staff*, Pos* locator); 118 void updateNotes(); tuplet()119 int tuplet() const { return _tuplet; } subdiv()120 int subdiv() const { return _subdiv; } 121 xpos()122 int xpos() const { return _xpos; } xZoom()123 qreal xZoom() const { return _xZoom; } 124 }; 125 126 } 127 #endif // __PIANOLEVELS_H__ 128