diff --git a/src/app/qml/ExerciseView.qml b/src/app/qml/ExerciseView.qml index 841d719077daae357685f98dc52be3e3333bc672..8166fb4ccfb1c363470f6ca43f10ddf842ed5f0f 100644 --- a/src/app/qml/ExerciseView.qml +++ b/src/app/qml/ExerciseView.qml @@ -52,23 +52,21 @@ Item { } onCurrentExerciseChanged: { exerciseView.state = "hidden" - if (exerciseView.currentExercise != undefined) { - var currentExerciseOptions = exerciseView.currentExercise["options"]; + if (currentExercise != undefined) { + var currentExerciseOptions = currentExercise["options"]; if (currentExerciseOptions != undefined) { var length = currentExerciseOptions.length - answerGrid.columns = Math.min(6, length) - answerGrid.rows = Math.ceil(length/6) for (var i = 0; i < length; ++i) answerOption.createObject(answerGrid, {model: currentExerciseOptions[i], index: i, color: colors[i%24]}) - exerciseView.visible = true + exerciseView.state = "initial" } - exerciseView.state = "initial" } } function checkAnswers(answers) { var answersOk = true 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) answersOk = false } @@ -79,8 +77,6 @@ Item { exerciseView.state = "nextQuestion" } - visible: false - Column { anchors.centerIn: parent spacing: 20 @@ -91,7 +87,7 @@ Item { width: parent.width horizontalAlignment: Text.AlignHCenter 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 { id: messageText @@ -124,7 +120,7 @@ Item { chosenColors[i] = answerGrid.children[j].color break } - if (exerciseView.currentExercise["playMode"] != "rhythm") + if (currentExercise["playMode"] != "rhythm") answerHoverEnter(0, core.exerciseController.chosenRootNote(), 0, "white") core.soundBackend.play() } @@ -142,7 +138,7 @@ Item { width: 124; height: 44 text: i18n("give up") onClicked: { - if (exerciseView.currentExercise["playMode"] != "rhythm") { + if (currentExercise["playMode"] != "rhythm") { highlightRightAnswer() } else { @@ -163,8 +159,12 @@ Item { id: answerGrid anchors.centerIn: parent - spacing: 10; columns: 2; rows: 1 + spacing: 10 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 { id: answerOption @@ -174,15 +174,15 @@ Item { property var model property int index - width: (exerciseView.currentExercise != undefined && exerciseView.currentExercise["playMode"] != "rhythm") ? 120:119 - height: (exerciseView.currentExercise != undefined && exerciseView.currentExercise["playMode"] != "rhythm") ? 40:59 + width: (currentExercise != undefined && currentExercise["playMode"] != "rhythm") ? 120:119 + height: (currentExercise != undefined && currentExercise["playMode"] != "rhythm") ? 40:59 Text { id: option 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) width: parent.width - 4 anchors.centerIn: parent @@ -194,14 +194,14 @@ Item { id: rhythmImage anchors.centerIn: parent - visible: exerciseView.currentExercise != undefined && exerciseView.currentExercise["playMode"] == "rhythm" - source: (exerciseView.currentExercise != undefined && exerciseView.currentExercise["playMode"] == "rhythm") ? "exercise-images/" + model.name + ".png":"" + visible: currentExercise != undefined && currentExercise["playMode"] == "rhythm" + source: (currentExercise != undefined && currentExercise["playMode"] == "rhythm") ? "exercise-images/" + model.name + ".png":"" fillMode: Image.Pad } MouseArea { anchors.fill: parent onClicked: { - if (exerciseView.currentExercise["playMode"] != "rhythm") { + if (currentExercise["playMode"] != "rhythm") { onExited() if (option.originalText == core.exerciseController.selectedExerciseOptions[0].name) messageText.text = i18n("Congratulations, you answered correctly!") @@ -217,7 +217,7 @@ Item { hoverEnabled: true onEntered: { answerRectangle.color = Qt.darker(answerRectangle.color, 1.1) - if (exerciseView.currentExercise["playMode"] != "rhythm") { + if (currentExercise["playMode"] != "rhythm") { model.sequence.split(' ').forEach(function(note) { answerHoverEnter(0, core.exerciseController.chosenRootNote() + parseInt(note), 0, colors[answerRectangle.index]) }) @@ -225,7 +225,7 @@ Item { } onExited: { answerRectangle.color = colors[answerRectangle.index] - if (exerciseView.currentExercise["playMode"] != "rhythm") { + if (currentExercise["playMode"] != "rhythm") { if (!animation.running) model.sequence.split(' ').forEach(function(note) { answerHoverExit(0, core.exerciseController.chosenRootNote() + parseInt(note), 0) @@ -253,6 +253,7 @@ Item { name: "initial" StateChangeScript { script: { + exerciseView.visible = true newQuestionButton.enabled = true playQuestionButton.enabled = false giveUpButton.enabled = false diff --git a/src/app/qml/Main.qml b/src/app/qml/Main.qml index 63687e942c73d0af2d7cb08cd1d638c692c82cce..e15c9f860d80e5e68206ef6e9c4d184b9a583488 100644 --- a/src/app/qml/Main.qml +++ b/src/app/qml/Main.qml @@ -88,10 +88,10 @@ ApplicationWindow { } ExerciseView { id: exerciseView - + width: background.width; height: minuetMenu.height + 20 anchors { top: background.top; horizontalCenter: background.horizontalCenter } - + currentExercise: minuetMenu.currentExercise onAnswerHoverEnter: pianoView.noteMark(chan, pitch, vel, color) diff --git a/src/interfaces/iexercisecontroller.cpp b/src/interfaces/iexercisecontroller.cpp index 1995aeb4707164eb2520dc316145416c9ab8fc08..a5f66e382b7060581e4cd948a23b0fd259eba999 100644 --- a/src/interfaces/iexercisecontroller.cpp +++ b/src/interfaces/iexercisecontroller.cpp @@ -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 { return m_selectedExerciseOptions; diff --git a/src/interfaces/iexercisecontroller.h b/src/interfaces/iexercisecontroller.h index 644d3b92d1221a7f70e91ca1f97c6e8cd43486c5..407b1247eb853960fdbffb1b44abb77ca608dbb9 100644 --- a/src/interfaces/iexercisecontroller.h +++ b/src/interfaces/iexercisecontroller.h @@ -37,13 +37,14 @@ class MINUETINTERFACES_EXPORT IExerciseController : public QObject { Q_OBJECT 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) public: virtual ~IExerciseController() override; virtual QJsonArray exercises() const = 0; + void setCurrentExercise(QVariantMap currentExercise); QJsonArray selectedExerciseOptions() const; public Q_SLOTS: