#include "PianoKeyBoard.h" #include "MainWindow.h" #include #include PianoKeyBoard::PianoKeyBoard(qreal x, qreal y, qreal w, qreal h, MainWindow *parent): QGraphicsScene(x,y,w,h){ addItem(keys[0] = new PianoKey(parent->colorScale.getToneByName("C"))); addItem(keys[1] = new PianoKey(parent->colorScale.getToneByName("Cis"))); addItem(keys[2] = new PianoKey(parent->colorScale.getToneByName("D"))); addItem(keys[3] = new PianoKey(parent->colorScale.getToneByName("Dis"))); addItem(keys[4] = new PianoKey(parent->colorScale.getToneByName("E"))); addItem(keys[5] = new PianoKey(parent->colorScale.getToneByName("F"))); addItem(keys[6] = new PianoKey(parent->colorScale.getToneByName("Fis"))); addItem(keys[7] = new PianoKey(parent->colorScale.getToneByName("G"))); addItem(keys[8] = new PianoKey(parent->colorScale.getToneByName("Gis"))); addItem(keys[9] = new PianoKey(parent->colorScale.getToneByName("A"))); addItem(keys[10] = new PianoKey(parent->colorScale.getToneByName("Ais"))); addItem(keys[11] = new PianoKey(parent->colorScale.getToneByName("H"))); for(int i=0; i<12; i++) QObject::connect(keys[i]->getTone(), &Tone::colorchanged, keys[i], &PianoKey::redraw); }; void PianoKeyBoard::mousePressEvent(QGraphicsSceneMouseEvent *event){ QString title = "Bitte Farbe wählen für Ton "; if(event->button() == Qt::LeftButton){ //first check "black" Piano keys as they are in foreground for(int i=6; i<12; i++){ if(keys[i]->sceneBoundingRect().contains(event->scenePos())){ keys[i]->getTone()->setColor( QColorDialog::getColor( keys[i]->getTone()->getColor(), nullptr, title.append(keys[i]->getTone()->getName()), QColorDialog::DontUseNativeDialog ) ); return; } } for(int i=0; i<6; i++){ if(keys[i]->sceneBoundingRect().contains(event->scenePos())){ keys[i]->getTone()->setColor( QColorDialog::getColor( keys[i]->getTone()->getColor(), nullptr, title.append(keys[i]->getTone()->getName()), QColorDialog::DontUseNativeDialog ) ); return; } } } }; PianoKey * PianoKeyBoard::getKey(int number)const{ return keys[number]; }; PianoKeyBoard::~PianoKeyBoard(){ };