Commit 91f002fb authored by Sandro Andrade's avatar Sandro Andrade

Use bindings rather than javascript code

parent 33f7dc5e
...@@ -52,23 +52,21 @@ Item { ...@@ -52,23 +52,21 @@ Item {
} }
onCurrentExerciseChanged: { onCurrentExerciseChanged: {
exerciseView.state = "hidden" exerciseView.state = "hidden"
if (exerciseView.currentExercise != undefined) { if (currentExercise != undefined) {
var currentExerciseOptions = exerciseView.currentExercise["options"]; var currentExerciseOptions = currentExercise["options"];
if (currentExerciseOptions != undefined) { if (currentExerciseOptions != undefined) {
var length = currentExerciseOptions.length var length = currentExerciseOptions.length
answerGrid.columns = Math.min(6, length)
answerGrid.rows = Math.ceil(length/6)
for (var i = 0; i < length; ++i) for (var i = 0; i < length; ++i)
answerOption.createObject(answerGrid, {model: currentExerciseOptions[i], index: i, color: colors[i%24]}) answerOption.createObject(answerGrid, {model: currentExerciseOptions[i], index: i, color: colors[i%24]})
exerciseView.visible = true exerciseView.state = "initial"
} }
exerciseView.state = "initial"
} }
} }
function checkAnswers(answers) { function checkAnswers(answers) {
var answersOk = true var answersOk = true
var chosenExercises = core.exerciseController.selectedExerciseOptions var chosenExercises = core.exerciseController.selectedExerciseOptions
for(var i = 0; i < 4; ++i) { var numberOfSelectedOptions = core.exerciseController.currentExercise.numberOfSelectedOptions
for(var i = 0; i < numberOfSelectedOptions; ++i) {
if (answers[i].toString().split("/").pop().split(".")[0] != chosenExercises[i].name) if (answers[i].toString().split("/").pop().split(".")[0] != chosenExercises[i].name)
answersOk = false answersOk = false
} }
...@@ -79,8 +77,6 @@ Item { ...@@ -79,8 +77,6 @@ Item {
exerciseView.state = "nextQuestion" exerciseView.state = "nextQuestion"
} }
visible: false
Column { Column {
anchors.centerIn: parent anchors.centerIn: parent
spacing: 20 spacing: 20
...@@ -91,7 +87,7 @@ Item { ...@@ -91,7 +87,7 @@ Item {
width: parent.width width: parent.width
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
font.pointSize: 18 font.pointSize: 18
text: (exerciseView.currentExercise != undefined) ? i18nc("technical term, do you have a musician friend?", exerciseView.currentExercise["userMessage"]):"" text: (currentExercise != undefined) ? i18nc("technical term, do you have a musician friend?", currentExercise["userMessage"]):""
} }
Text { Text {
id: messageText id: messageText
...@@ -124,7 +120,7 @@ Item { ...@@ -124,7 +120,7 @@ Item {
chosenColors[i] = answerGrid.children[j].color chosenColors[i] = answerGrid.children[j].color
break break
} }
if (exerciseView.currentExercise["playMode"] != "rhythm") if (currentExercise["playMode"] != "rhythm")
answerHoverEnter(0, core.exerciseController.chosenRootNote(), 0, "white") answerHoverEnter(0, core.exerciseController.chosenRootNote(), 0, "white")
core.soundBackend.play() core.soundBackend.play()
} }
...@@ -142,7 +138,7 @@ Item { ...@@ -142,7 +138,7 @@ Item {
width: 124; height: 44 width: 124; height: 44
text: i18n("give up") text: i18n("give up")
onClicked: { onClicked: {
if (exerciseView.currentExercise["playMode"] != "rhythm") { if (currentExercise["playMode"] != "rhythm") {
highlightRightAnswer() highlightRightAnswer()
} }
else { else {
...@@ -163,8 +159,12 @@ Item { ...@@ -163,8 +159,12 @@ Item {
id: answerGrid id: answerGrid
anchors.centerIn: parent anchors.centerIn: parent
spacing: 10; columns: 2; rows: 1 spacing: 10
enabled: exerciseView.state == "waitingForAnswer" enabled: exerciseView.state == "waitingForAnswer"
columns: (currentExercise != undefined) ? Math.min(6, currentExercise["options"].length):0
rows: (currentExercise != undefined) ? Math.ceil(currentExercise["options"].length/6):0
Component { Component {
id: answerOption id: answerOption
...@@ -174,15 +174,15 @@ Item { ...@@ -174,15 +174,15 @@ Item {
property var model property var model
property int index property int index
width: (exerciseView.currentExercise != undefined && exerciseView.currentExercise["playMode"] != "rhythm") ? 120:119 width: (currentExercise != undefined && currentExercise["playMode"] != "rhythm") ? 120:119
height: (exerciseView.currentExercise != undefined && exerciseView.currentExercise["playMode"] != "rhythm") ? 40:59 height: (currentExercise != undefined && currentExercise["playMode"] != "rhythm") ? 40:59
Text { Text {
id: option id: option
property string originalText: model.name property string originalText: model.name
visible: exerciseView.currentExercise != undefined && exerciseView.currentExercise["playMode"] != "rhythm" visible: currentExercise != undefined && currentExercise["playMode"] != "rhythm"
text: i18nc("technical term, do you have a musician friend?", model.name) text: i18nc("technical term, do you have a musician friend?", model.name)
width: parent.width - 4 width: parent.width - 4
anchors.centerIn: parent anchors.centerIn: parent
...@@ -194,14 +194,14 @@ Item { ...@@ -194,14 +194,14 @@ Item {
id: rhythmImage id: rhythmImage
anchors.centerIn: parent anchors.centerIn: parent
visible: exerciseView.currentExercise != undefined && exerciseView.currentExercise["playMode"] == "rhythm" visible: currentExercise != undefined && currentExercise["playMode"] == "rhythm"
source: (exerciseView.currentExercise != undefined && exerciseView.currentExercise["playMode"] == "rhythm") ? "exercise-images/" + model.name + ".png":"" source: (currentExercise != undefined && currentExercise["playMode"] == "rhythm") ? "exercise-images/" + model.name + ".png":""
fillMode: Image.Pad fillMode: Image.Pad
} }
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
if (exerciseView.currentExercise["playMode"] != "rhythm") { if (currentExercise["playMode"] != "rhythm") {
onExited() onExited()
if (option.originalText == core.exerciseController.selectedExerciseOptions[0].name) if (option.originalText == core.exerciseController.selectedExerciseOptions[0].name)
messageText.text = i18n("Congratulations, you answered correctly!") messageText.text = i18n("Congratulations, you answered correctly!")
...@@ -217,7 +217,7 @@ Item { ...@@ -217,7 +217,7 @@ Item {
hoverEnabled: true hoverEnabled: true
onEntered: { onEntered: {
answerRectangle.color = Qt.darker(answerRectangle.color, 1.1) answerRectangle.color = Qt.darker(answerRectangle.color, 1.1)
if (exerciseView.currentExercise["playMode"] != "rhythm") { if (currentExercise["playMode"] != "rhythm") {
model.sequence.split(' ').forEach(function(note) { model.sequence.split(' ').forEach(function(note) {
answerHoverEnter(0, core.exerciseController.chosenRootNote() + parseInt(note), 0, colors[answerRectangle.index]) answerHoverEnter(0, core.exerciseController.chosenRootNote() + parseInt(note), 0, colors[answerRectangle.index])
}) })
...@@ -225,7 +225,7 @@ Item { ...@@ -225,7 +225,7 @@ Item {
} }
onExited: { onExited: {
answerRectangle.color = colors[answerRectangle.index] answerRectangle.color = colors[answerRectangle.index]
if (exerciseView.currentExercise["playMode"] != "rhythm") { if (currentExercise["playMode"] != "rhythm") {
if (!animation.running) if (!animation.running)
model.sequence.split(' ').forEach(function(note) { model.sequence.split(' ').forEach(function(note) {
answerHoverExit(0, core.exerciseController.chosenRootNote() + parseInt(note), 0) answerHoverExit(0, core.exerciseController.chosenRootNote() + parseInt(note), 0)
...@@ -253,6 +253,7 @@ Item { ...@@ -253,6 +253,7 @@ Item {
name: "initial" name: "initial"
StateChangeScript { StateChangeScript {
script: { script: {
exerciseView.visible = true
newQuestionButton.enabled = true newQuestionButton.enabled = true
playQuestionButton.enabled = false playQuestionButton.enabled = false
giveUpButton.enabled = false giveUpButton.enabled = false
......
...@@ -88,10 +88,10 @@ ApplicationWindow { ...@@ -88,10 +88,10 @@ ApplicationWindow {
} }
ExerciseView { ExerciseView {
id: exerciseView id: exerciseView
width: background.width; height: minuetMenu.height + 20 width: background.width; height: minuetMenu.height + 20
anchors { top: background.top; horizontalCenter: background.horizontalCenter } anchors { top: background.top; horizontalCenter: background.horizontalCenter }
currentExercise: minuetMenu.currentExercise currentExercise: minuetMenu.currentExercise
onAnswerHoverEnter: pianoView.noteMark(chan, pitch, vel, color) onAnswerHoverEnter: pianoView.noteMark(chan, pitch, vel, color)
......
...@@ -37,6 +37,15 @@ IExerciseController::~IExerciseController() ...@@ -37,6 +37,15 @@ IExerciseController::~IExerciseController()
{ {
} }
void IExerciseController::setCurrentExercise(QVariantMap currentExercise)
{
if (m_currentExercise != currentExercise) {
m_currentExercise = currentExercise;
m_selectedExerciseOptions = QJsonArray();
emit currentExerciseChanged(m_currentExercise);
}
}
QJsonArray IExerciseController::selectedExerciseOptions() const QJsonArray IExerciseController::selectedExerciseOptions() const
{ {
return m_selectedExerciseOptions; return m_selectedExerciseOptions;
......
...@@ -37,13 +37,14 @@ class MINUETINTERFACES_EXPORT IExerciseController : public QObject ...@@ -37,13 +37,14 @@ class MINUETINTERFACES_EXPORT IExerciseController : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QJsonArray exercises READ exercises) Q_PROPERTY(QJsonArray exercises READ exercises)
Q_PROPERTY(QVariantMap currentExercise MEMBER m_currentExercise NOTIFY currentExerciseChanged) Q_PROPERTY(QVariantMap currentExercise MEMBER m_currentExercise WRITE setCurrentExercise NOTIFY currentExerciseChanged)
Q_PROPERTY(QJsonArray selectedExerciseOptions READ selectedExerciseOptions NOTIFY selectedExerciseOptionsChanged) Q_PROPERTY(QJsonArray selectedExerciseOptions READ selectedExerciseOptions NOTIFY selectedExerciseOptionsChanged)
public: public:
virtual ~IExerciseController() override; virtual ~IExerciseController() override;
virtual QJsonArray exercises() const = 0; virtual QJsonArray exercises() const = 0;
void setCurrentExercise(QVariantMap currentExercise);
QJsonArray selectedExerciseOptions() const; QJsonArray selectedExerciseOptions() const;
public Q_SLOTS: public Q_SLOTS:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment