Commit 40c065e5 authored by Sandro Andrade's avatar Sandro Andrade

Handle userMessage from collectedProperties

parent 5920760c
......@@ -4,7 +4,7 @@
"name": "Chords",
"root": "21..104",
"playMode": "chord",
"userMessage": "the chord",
"userMessage": "Hear the chord and then choose an answer from options below",
"children": [
{
"name": "Root Position",
......
......@@ -4,7 +4,7 @@
"name": "Intervals",
"root": "21..104",
"playMode": "scale",
"userMessage": "the interval",
"userMessage": "Hear the interval and then choose an answer from options below",
"children": [
{
"name": "Ascending Melodic Intervals",
......
......@@ -4,7 +4,7 @@
"name": "Intervals",
"root": "21..104",
"playMode": "scale",
"userMessage": "the interval",
"userMessage": "Hear the interval and then choose an answer from options below",
"children": [
{
"name": "Descending Melodic Intervals",
......
......@@ -3,7 +3,7 @@
{
"name": "Rhythm",
"playMode": "rhythm",
"userMessage": "the rhythm",
"userMessage": "Hear the rhythm and then choose an answer from options below",
"template": "lilypond-templates/rhythm.ly.tmpl",
"children": [
{
......
......@@ -3,7 +3,7 @@
{
"name": "Rhythm",
"playMode": "rhythm",
"userMessage": "the rhythm",
"userMessage": "Hear the rhythm and then choose an answer from options below",
"template": "lilypond-templates/rhythm.ly.tmpl",
"children": [
{
......
......@@ -4,7 +4,7 @@
"name": "Scales",
"root": "21..104",
"playMode": "scale",
"userMessage": "the scale",
"userMessage": "Hear the scale and then choose an answer from options below",
"children": [
{
"name": "Major Scale and its Modes",
......
......@@ -175,7 +175,8 @@ QJsonArray ExerciseController::applyDefinitions(QJsonArray exercises, QJsonArray
}
else {
foreach(const QString &key, collectedProperties.keys())
exerciseObject.insert(key, collectedProperties[key]);
if (!exerciseObject.contains(key))
exerciseObject.insert(key, collectedProperties[key]);
exerciseObject.insert("options", filteredDefinitions);
}
exercises[i1-exercisesBegin] = exerciseObject;
......
......@@ -28,7 +28,6 @@ Item {
property var chosenExercises
property var chosenColors: [4]
property string userMessage
property Item answerRectangle
property var colors: ["#8dd3c7", "#ffffb3", "#bebada", "#fb8072", "#80b1d3", "#fdb462", "#b3de69", "#fccde5", "#d9d9d9", "#bc80bd", "#ccebc5", "#ffed6f", "#a6cee3", "#1f78b4", "#b2df8a", "#33a02c", "#fb9a99", "#e31a1c", "#fdbf6f", "#ff7f00", "#cab2d6", "#6a3d9a", "#ffff99", "#b15928"]
......@@ -66,9 +65,6 @@ Item {
exerciseView.visible = true
exerciseView.state = "initial"
}
function changeUserMessage(message) {
userMessage = message
}
function checkAnswers(answers) {
var answersOk = true
for(var i = 0; i < 4; ++i) {
......@@ -95,8 +91,8 @@ Item {
horizontalAlignment: Text.AlignHCenter
font.pointSize: 18
textFormat: Text.RichText
text: i18n("Hear %1 and then choose an answer from options below!<br/>Click 'play question' if you want to hear again!",
i18nc("technical term, do you have a musician friend?", userMessage))
text: i18n("%1<br/>Click 'play question' if you want to hear again!",
i18nc("technical term, do you have a musician friend?", core.exerciseController.currentExercise["userMessage"]))
}
Row {
anchors { horizontalCenter: parent.horizontalCenter }
......@@ -125,9 +121,9 @@ Item {
break
}
messageText.text = Qt.binding(function() {
return i18n("Hear %1 and then choose an answer from options below!<br/>Click 'play question' if you want to hear again!", i18nc("technical term, do you have a musician friend?", userMessage))
return i18n("%1<br/>Click 'play question' if you want to hear again!", i18nc("technical term, do you have a musician friend?", core.exerciseController.currentExercise["userMessage"]))
})
if (userMessage != "the rhythm")
if (core.exerciseController.currentExercise["playMode"] != "rhythm")
answerHoverEnter(0, core.exerciseController.chosenRootNote(), 0, "white")
core.soundBackend.play()
}
......@@ -147,7 +143,7 @@ Item {
width: 124; height: 44
text: i18n("give up")
onClicked: {
if (userMessage != "the rhythm") {
if (core.exerciseController.currentExercise["playMode"] != "rhythm") {
highlightRightAnswer()
}
else {
......@@ -179,15 +175,15 @@ Item {
property var model
property int index
width: (userMessage != "the rhythm") ? 120:119
height: (userMessage != "the rhythm") ? 40:59
width: (core.exerciseController.currentExercise["playMode"] != "rhythm") ? 120:119
height: (core.exerciseController.currentExercise["playMode"] != "rhythm") ? 40:59
Text {
id: option
property string originalText: model.name
visible: userMessage != "the rhythm"
visible: core.exerciseController.currentExercise["playMode"] != "rhythm"
text: i18nc("technical term, do you have a musician friend?", model.name)
width: parent.width - 4
anchors.centerIn: parent
......@@ -199,14 +195,14 @@ Item {
id: rhythmImage
anchors.centerIn: parent
visible: userMessage == "the rhythm"
source: (userMessage == "the rhythm") ? "exercise-images/" + model.name + ".png":""
visible: core.exerciseController.currentExercise["playMode"] == "rhythm"
source: (core.exerciseController.currentExercise["playMode"] == "rhythm") ? "exercise-images/" + model.name + ".png":""
fillMode: Image.Pad
}
MouseArea {
anchors.fill: parent
onClicked: {
if (userMessage != "the rhythm") {
if (core.exerciseController.currentExercise["playMode"] != "rhythm") {
onExited()
if (option.originalText == chosenExercises[0])
messageText.text = i18n("Congratulations!<br/>You answered correctly!")
......@@ -222,7 +218,7 @@ Item {
hoverEnabled: true
onEntered: {
answerRectangle.color = Qt.darker(answerRectangle.color, 1.1)
if (userMessage != "the rhythm") {
if (core.exerciseController.currentExercise["playMode"] != "rhythm") {
model.sequence.split(' ').forEach(function(note) {
answerHoverEnter(0, core.exerciseController.chosenRootNote() + parseInt(note), 0, colors[answerRectangle.index])
})
......@@ -230,7 +226,7 @@ Item {
}
onExited: {
answerRectangle.color = colors[answerRectangle.index]
if (userMessage != "the rhythm") {
if (core.exerciseController.currentExercise["playMode"] != "rhythm") {
if (!animation.running)
model.sequence.split(' ').forEach(function(note) {
answerHoverExit(0, core.exerciseController.chosenRootNote() + parseInt(note), 0)
......
......@@ -30,10 +30,6 @@ Item {
property int menuBarWidth: 280
function userMessageChanged(message) {
pianoView.visible = (message != "the rhythm" && message != "exercise")
rhythmAnswerView.visible = (message == "the rhythm")
}
function exerciseViewStateChanged() {
if (exerciseView.state == "waitingForAnswer")
rhythmAnswerView.resetAnswers()
......@@ -55,10 +51,6 @@ Item {
exerciseView.clearExerciseGrid()
pianoView.clearAllMarks()
}
onUserMessageChanged: {
exerciseView.changeUserMessage(message)
mainItem.userMessageChanged(message)
}
}
MidiPlayer {
id: midiPlayer
......@@ -84,13 +76,13 @@ Item {
id: pianoView
anchors { bottom: parent.bottom; bottomMargin: 5; horizontalCenter: parent.horizontalCenter }
visible: false
visible: (Object.keys(core.exerciseController.currentExercise).length > 0 && core.exerciseController.currentExercise["playMode"] != "rhythm")
}
RhythmAnswerView {
id: rhythmAnswerView
anchors { bottom: parent.bottom; bottomMargin: 14; horizontalCenter: parent.horizontalCenter }
visible: false
visible: (core.exerciseController.currentExercise["playMode"] == "rhythm")
exerciseView: exerciseView
onAnswerCompleted: exerciseView.checkAnswers(answers)
......
......@@ -29,11 +29,9 @@ import org.kde.minuet 1.0
Item {
id: minuetMenu
property string message
readonly property alias currentExercise: stackView.currentExercise
signal backPressed
signal userMessageChanged(string message)
Button {
id: breadcrumb
......@@ -41,12 +39,10 @@ Item {
width: (stackView.depth > 1) ? 24:0; height: parent.height
iconName: "go-previous"
onClicked: {
backPressed()
stackView.currentExerciseMenuItem = null
core.exerciseController.currentExercise = {}
stackView.pop()
userMessageChanged("exercise")
if (stackView.depth == 1)
message = "exercise"
backPressed()
}
}
StackView {
......@@ -70,23 +66,14 @@ Item {
text: i18nc("technical term, do you have a musician friend?", modelData.name)
checkable: (!delegateRect.ListView.view.model[index].children) ? true:false
onClicked: {
var userMessage = delegateRect.ListView.view.model[index].userMessage
if (userMessage != undefined)
message = userMessage
var children = delegateRect.ListView.view.model[index].children
if (!children) {
if (stackView.currentExerciseMenuItem != undefined) stackView.currentExerciseMenuItem.checked = false
userMessageChanged(message)
stackView.currentExercise = delegateRect.ListView.view.model[index]
stackView.currentExerciseMenuItem = delegateRect
}
else {
stackView.push(categoryMenu.createObject(stackView, {model: children}))
var root = delegateRect.ListView.view.model[index].root
if (root != undefined) {
core.exerciseController.minRootNote = parseInt(root.split('.')[0])
core.exerciseController.maxRootNote = parseInt(root.split('.')[2])
}
}
}
style: MinuetButtonStyle {}
......
......@@ -99,7 +99,7 @@ Column {
id: correctRhythmImage
anchors.centerIn: parent
source: (correctAnswers != undefined && exerciseView.userMessage == "the rhythm") ? "exercise-images/" + correctAnswers[index] + ".png":""
source: (correctAnswers != undefined && core.exerciseController.currentExercise["playMode"] == "rhythm") ? "exercise-images/" + correctAnswers[index] + ".png":""
fillMode: Image.Pad
}
}
......
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