diff --git a/mscore/musescore.cpp b/mscore/musescore.cpp index 550b36645308..b79ef4e72f20 100644 --- a/mscore/musescore.cpp +++ b/mscore/musescore.cpp @@ -1282,6 +1282,8 @@ void MuseScore::selectionChanged(SelState selectionState) pianorollEditor->changeSelection(selectionState); if (drumrollEditor) drumrollEditor->changeSelection(selectionState); + if (_pianoTools && _pianoTools->isVisible()) + _pianoTools->changeSelection(cs->selection()); if (_inspector) updateInspector(); } diff --git a/mscore/pianotools.cpp b/mscore/pianotools.cpp index 8357fbfc4085..c89e7fa8be83 100644 --- a/mscore/pianotools.cpp +++ b/mscore/pianotools.cpp @@ -20,6 +20,7 @@ #include "pianotools.h" #include "preferences.h" +#include "libmscore/chord.h" namespace Ms { @@ -167,6 +168,25 @@ void HPiano::releasePitch(int pitch) updateAllKeys(); } +//--------------------------------------------------------- +// changeSelection +//--------------------------------------------------------- + +void HPiano::changeSelection(Selection selection) + { + for (PianoKeyItem* key : keys) { + key->setHighlighted(false); + key->setSelected(false); + } + for (Note* n : selection.uniqueNotes()) { + keys[n->pitch() - _firstKey]->setSelected(true); + for (Note* other : n->chord()->notes()) + keys[other->pitch() - _firstKey]->setHighlighted(true); + } + for (PianoKeyItem* key : keys) + key->update(); + } + //--------------------------------------------------------- // updateAllKeys //--------------------------------------------------------- @@ -189,6 +209,8 @@ PianoKeyItem::PianoKeyItem(HPiano* _piano, int p) piano = _piano; _pitch = p; _pressed = false; + _selected = false; + _highlighted = false; type = -1; } @@ -329,6 +351,13 @@ void PianoKeyItem::paint(QPainter* p, const QStyleOptionGraphicsItem* /*o*/, QWi c.setAlpha(180); p->setBrush(c); } + else if (_selected) { + QColor c(preferences.pianoHlColor); + c.setAlpha(100); + p->setBrush(c); + } + else if (_highlighted) + p->setBrush(type >= 7 ? QColor(125, 125, 125) : QColor(200, 200, 200)); else p->setBrush(type >= 7 ? Qt::black : Qt::white); p->drawPath(path()); @@ -437,5 +466,14 @@ bool HPiano::gestureEvent(QGestureEvent *event) } return true; } + +//--------------------------------------------------------- +// changeSelection +//--------------------------------------------------------- + +void PianoTools::changeSelection(Selection selection) + { + _piano->changeSelection(selection); + } } diff --git a/mscore/pianotools.h b/mscore/pianotools.h index e97f2b829afe..192ad1da085f 100644 --- a/mscore/pianotools.h +++ b/mscore/pianotools.h @@ -22,6 +22,7 @@ #define __PIANOTOOLS_H__ #include "libmscore/note.h" +#include "libmscore/select.h" namespace Ms { @@ -35,6 +36,8 @@ class PianoKeyItem : public QGraphicsPathItem { int type; int _pitch; bool _pressed; + bool _highlighted; + bool _selected; HPiano* piano; virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); @@ -46,6 +49,8 @@ class PianoKeyItem : public QGraphicsPathItem { void setType(int val); int pitch() { return _pitch; } void setPressed(bool p) { _pressed = p; } + void setHighlighted(bool h) { _highlighted = h; } + void setSelected(bool s) { _selected = s; } }; //--------------------------------------------------------- @@ -74,6 +79,7 @@ class HPiano : public QGraphicsView { void setPressedPitches(QSet pitches); void pressPitch(int pitch); void releasePitch(int pitch); + void changeSelection(Selection selection); void updateAllKeys(); virtual QSize sizeHint() const; }; @@ -96,6 +102,7 @@ class PianoTools : public QDockWidget { void pressPitch(int pitch) { _piano->pressPitch(pitch); } void releasePitch(int pitch) { _piano->releasePitch(pitch); } void heartBeat(QList notes); + void changeSelection(Selection selection); };