@@ -0,0 +1,28 @@ | |||
#include "CircleElement.h" | |||
#include <QLineF> | |||
#include <QBrush> | |||
CircleElement::CircleElement(Tone *tone): tone(tone){ | |||
QLineF * guidingLine = new QLineF(); | |||
guidingLine->setP1(QPoint(0,100)); | |||
guidingLine->setP2(QPoint(0,0)); | |||
guidingLine->setAngle(90- 30 * tone->getQuintenPosition()); | |||
setRect(guidingLine->p2().x(),guidingLine->p2().y(), 70,70); | |||
setPos(guidingLine->p2()); | |||
setBrush(QBrush(tone->getColor())); | |||
delete guidingLine; | |||
}; | |||
CircleElement::CircleElement(){}; | |||
CircleElement::~CircleElement(){}; | |||
Tone * CircleElement::getTone()const{ | |||
return tone; | |||
}; | |||
//SLOTS: | |||
void CircleElement::redraw(){ | |||
setBrush(QBrush(tone->getColor())); | |||
}; |
@@ -0,0 +1,46 @@ | |||
/* CIRCLEELEMENT_H | |||
* CLASS DECLARATION | |||
* | |||
* CHANGLOG: | |||
* NAME: | CHANGES: | DATE: | | |||
* Mewes, Lars | Neuerstellung | 24.09.2021 | | |||
* | | | | |||
* | | | | |||
* | | | | |||
* | |||
* DESCRIPTION: | |||
* Diese Klasse "CircleElement" realisiert die einzelnen, farbigen Kreise des Quintenzirkels "CircleOfFifths". | |||
* Um den Signal-Slot-Mechanismus von Qt nutzen zu können, ist sowohl die Ableitung von der "QObject"-Klasse, als auch das "Q_OBJECT"-Makro notwendig. | |||
* (siehe dazu die Qt-Dokumentation) | |||
* Für die graphische Darstellung erbt die "CircleElement"-Klasse von "QGraphicsEllipseItem". Diese Klasse stellt alle wichtigen Funktionen und Attribute | |||
* für die Darstellung in einer "QGraphicsScene" zur Verfügung (siehe Klassendeklaration "CircleOfFifths") | |||
* | |||
* der Slot "void redraw();" wird ausgelöst, sobald (z.B. mittels Color-Picker) die Farbe eines Tons geändert wird. (siehe Klassendeklaration "Tone") | |||
* | |||
* TO-DOs: | |||
* Beschriftung auf den Elementen ergänzen | |||
* | |||
*/ | |||
#pragma once | |||
#include <QGraphicsEllipseItem> | |||
#include "Tone.h" | |||
class CircleElement:public QObject, public QGraphicsEllipseItem{ | |||
Q_OBJECT | |||
Tone * tone; | |||
public: | |||
CircleElement(Tone * tone); | |||
CircleElement(); | |||
Tone * getTone()const; | |||
virtual ~CircleElement(); | |||
public slots: | |||
void redraw(); | |||
}; | |||
@@ -0,0 +1,34 @@ | |||
#include "CircleOfFifths.h" | |||
#include "MainWindow.h" | |||
#include <QColorDialog> | |||
CircleOfFifths::CircleOfFifths(qreal x, qreal y, qreal w, qreal h, MainWindow * parent): QGraphicsScene(x,y,w,h){ | |||
addItem(circleElements[0] = new CircleElement(parent->colorScale.getToneByName("C"))); | |||
addItem(circleElements[1] = new CircleElement(parent->colorScale.getToneByName("G"))); | |||
addItem(circleElements[2] = new CircleElement(parent->colorScale.getToneByName("D"))); | |||
addItem(circleElements[3] = new CircleElement(parent->colorScale.getToneByName("A"))); | |||
addItem(circleElements[4] = new CircleElement(parent->colorScale.getToneByName("E"))); | |||
addItem(circleElements[5] = new CircleElement(parent->colorScale.getToneByName("H"))); | |||
addItem(circleElements[6] = new CircleElement(parent->colorScale.getToneByName("Fis"))); | |||
addItem(circleElements[7] = new CircleElement(parent->colorScale.getToneByName("Cis"))); | |||
addItem(circleElements[8] = new CircleElement(parent->colorScale.getToneByName("Gis"))); | |||
addItem(circleElements[9] = new CircleElement(parent->colorScale.getToneByName("Dis"))); | |||
addItem(circleElements[10] = new CircleElement(parent->colorScale.getToneByName("Ais"))); | |||
addItem(circleElements[11] = new CircleElement(parent->colorScale.getToneByName("F"))); | |||
for(int i=0; i<12; i++) | |||
QObject::connect(circleElements[i]->getTone(), &Tone::colorchanged, circleElements[i], &CircleElement::redraw); | |||
}; | |||
void CircleOfFifths::mousePressEvent(QGraphicsSceneMouseEvent *event){ | |||
if(event->button() == Qt::LeftButton){ | |||
for(int i=0; i<12; i++){ | |||
if(circleElements[i]->sceneBoundingRect().contains(event->scenePos())){ | |||
circleElements[i]->getTone()->setColor(QColorDialog::getColor(circleElements[i]->getTone()->getColor())); | |||
} | |||
}} | |||
}; | |||
CircleElement * CircleOfFifths::getCircleElement(int number)const{ | |||
return circleElements[number]; | |||
}; |
@@ -0,0 +1,35 @@ | |||
/* CIRCLEOFFIFTHS_H | |||
* CLASS DECLARATION | |||
* | |||
* CHANGLOG: | |||
* NAME: | CHANGES: | DATE: | | |||
* Mewes, Lars | Neuerstellung | 24.09.2021 | | |||
* | | | | |||
* | | | | |||
* | | | | |||
* | |||
* DESCRIPTION: | |||
* Diese Klasse enthält die 12 "circleElements" und stellt sie in einer "QGraphicsScene" dar, von der die Klasse abgeleitet ist | |||
* und verarbeitetet außerdem Mouse-Events. | |||
* | |||
* TO-DOs: | |||
* | |||
* | |||
*/ | |||
#pragma once | |||
#include "ColorScale.h" | |||
#include <QGraphicsScene> | |||
#include "CircleElement.h" | |||
#include <QGraphicsSceneMouseEvent> | |||
class MainWindow; | |||
class CircleOfFifths: public QGraphicsScene{ | |||
CircleElement * circleElements[12]; | |||
public: | |||
CircleOfFifths(qreal x, qreal y, qreal w, qreal h, MainWindow * parent); | |||
CircleElement * getCircleElement(int number)const; | |||
void mousePressEvent(QGraphicsSceneMouseEvent *event); | |||
}; |
@@ -0,0 +1,63 @@ | |||
#include "ColorScale.h" | |||
ColorScale::ColorScale(){ | |||
allTones[0].setColor(Qt::red); | |||
allTones[0].setName("C"); | |||
allTones[0].setFlatTone(true); | |||
allTones[1].setColor(QColor(150,127,192)); | |||
allTones[1].setName("Cis"); | |||
allTones[1].setFlatTone(false); | |||
allTones[2].setColor(Qt::yellow); | |||
allTones[2].setName("D"); | |||
allTones[2].setFlatTone(true); | |||
allTones[3].setColor(QColor(63,32,127)); | |||
allTones[3].setName("Dis"); | |||
allTones[3].setFlatTone(false); | |||
allTones[4].setColor(QColor(200,255,255)); | |||
allTones[4].setName("E"); | |||
allTones[4].setFlatTone(true); | |||
allTones[5].setColor(Qt::darkRed); | |||
allTones[5].setName("F"); | |||
allTones[5].setFlatTone(true); | |||
allTones[6].setColor(Qt::cyan); | |||
allTones[6].setName("Fis"); | |||
allTones[6].setFlatTone(false); | |||
allTones[7].setColor(QColor(255,100,0)); | |||
allTones[7].setName("G"); | |||
allTones[7].setFlatTone(true); | |||
allTones[8].setColor(Qt::magenta); | |||
allTones[8].setName("Gis"); | |||
allTones[8].setFlatTone(false); | |||
allTones[9].setColor(Qt::green); | |||
allTones[9].setName("A"); | |||
allTones[9].setFlatTone(true); | |||
allTones[10].setColor(Qt::gray); | |||
allTones[10].setName("Ais"); | |||
allTones[10].setFlatTone(false); | |||
allTones[11].setColor(Qt::blue); | |||
allTones[11].setName("H"); | |||
allTones[11].setFlatTone(true); | |||
} | |||
Tone * ColorScale::getToneByName(QString name){ | |||
for(int i=0; i<12; i++){ | |||
if(QString::compare(allTones[i].getName(), name, Qt::CaseInsensitive)==0) | |||
return allTones+i; | |||
} | |||
return nullptr; | |||
}; | |||
Tone * ColorScale::getToneByKeyboardPosition(int pos){ | |||
return allTones + ((pos-12)%12); | |||
} |