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
|
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2009-2011 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 __PIANOVIEW_H__
#define __PIANOVIEW_H__
#include "libmscore/pos.h"
namespace Ms {
class Score;
class Staff;
class Chord;
class ChordRest;
class Note;
class NoteEvent;
class PianoView;
enum class NoteSelectType {
REPLACE = 0,
XOR,
ADD,
SUBTRACT,
FIRST
};
enum class DragStyle {
NONE = 0,
SELECTION_RECT,
MOVE_NOTES
};
struct BarPattern {
QString name;
char isWhiteKey[12]; //Set to 1 for white keys, 0 for black
};
//---------------------------------------------------------
// PianoItem
//---------------------------------------------------------
class PianoItem {
Note* _note;
PianoView* _pianoView;
void paintNoteBlock(QPainter* painter, NoteEvent* evt);
QRect boundingRectTicks(NoteEvent* evt);
QRect boundingRectPixels(NoteEvent* evt);
bool intersectsBlock(int startTick, int endTick, int highPitch, int lowPitch, NoteEvent* evt);
public:
PianoItem(Note*, PianoView*);
~PianoItem() {}
Note* note() { return _note; }
void paint(QPainter* painter);
bool intersects(int startTick, int endTick, int highPitch, int lowPitch);
QRect boundingRect();
NoteEvent* getTweakNoteEvent();
};
//---------------------------------------------------------
// PianoView
//---------------------------------------------------------
class PianoView : public QGraphicsView {
Q_OBJECT
public:
static const BarPattern barPatterns[];
private:
Staff* _staff;
Chord* chord;
Pos trackingPos; //Track mouse position
Pos* _locator;
int ticks;
TType _timeType;
int _noteHeight;
qreal _xZoom;
int _tuplet; //Tuplet divisions
int _subdiv; //Beat subdivisions
int _barPattern;
bool _playEventsView;
bool mouseDown;
bool dragStarted;
QPointF mouseDownPos;
QPointF lastMousePos;
DragStyle dragStyle;
int lastDragPitch;
bool inProgressUndoEvent;
QList<PianoItem*> noteList;
virtual void drawBackground(QPainter* painter, const QRectF& rect);
void addChord(Chord* chord, int voice);
void updateBoundingSize();
void clearNoteData();
void selectNotes(int startTick, int endTick, int lowPitch, int highPitch, NoteSelectType selType);
void showPopupMenu(const QPoint& pos);
bool cutChordRest(ChordRest* e, int track, int cutTick, ChordRest*& cr0, ChordRest*& cr1);
QAction* getAction(const char* id);
protected:
virtual void wheelEvent(QWheelEvent* event);
virtual void mousePressEvent(QMouseEvent* event);
virtual void mouseReleaseEvent(QMouseEvent* event);
virtual void mouseMoveEvent(QMouseEvent* event);
virtual void leaveEvent(QEvent*);
virtual void contextMenuEvent(QContextMenuEvent *event);
signals:
void xZoomChanged(qreal);
void tupletChanged(int);
void subdivChanged(int);
void barPatternChanged(int);
void noteHeightChanged(int);
void pitchChanged(int);
void trackingPosChanged(const Pos&);
void selectionChanged();
public slots:
void moveLocator(int);
void updateNotes();
void setXZoom(int);
void setTuplet(int);
void setSubdiv(int);
void setBarPattern(int);
public:
PianoView();
~PianoView();
Staff* staff() { return _staff; }
void setStaff(Staff*, Pos* locator);
void ensureVisible(int tick);
int noteHeight() { return _noteHeight; }
qreal xZoom() { return _xZoom; }
int tuplet() { return _tuplet; }
int subdiv() { return _subdiv; }
int barPattern() { return _barPattern; }
QList<QGraphicsItem*> items() { return scene()->selectedItems(); }
int pixelXToTick(int pixX);
int tickToPixelX(int tick);
int pixelYToPitch(int pixY) { return (int)floor(128 - pixY / (qreal)_noteHeight); }
PianoItem* pickNote(int tick, int pitch);
QList<PianoItem*> getSelectedItems();
QList<PianoItem*> getItems();
bool playEventsView() { return _playEventsView; }
};
} // namespace Ms
#endif
|