diff --git a/src/activities/piano_composition/LyricsArea.qml b/src/activities/piano_composition/LyricsArea.qml new file mode 100644 --- /dev/null +++ b/src/activities/piano_composition/LyricsArea.qml @@ -0,0 +1,125 @@ +/* GCompris - LyricsArea.qml +* +* Copyright (C) 2018 Aman Kumar Gupta +* +* Authors: +* Beth Hadley (GTK+ version) +* Johnny Jazeix (Qt Quick port) +* Aman Kumar Gupta (Qt Quick port) +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see . +*/ +import QtQuick 2.6 +import GCompris 1.0 + +import "../../core" + +Rectangle { + id: lyricsArea + + property string title: "" + property string origin: "" + property string lyrics: "" + + width: horizontalLayout ? parent.width * 0.4 : parent.width * 0.8 + height: horizontalLayout ? parent.height * 0.5 : parent.width * 0.26 + anchors.horizontalCenter: horizontalLayout ? undefined : parent.horizontalCenter + anchors.left: horizontalLayout ? parent.left : undefined + anchors.leftMargin: parent.width * 0.02 + anchors.top: horizontalLayout ? multipleStaff.top : multipleStaff.bottom + anchors.topMargin: horizontalLayout ? parent.height * 0.05 : parent.height * 0.025 + border.width: 3 + radius: 5 + border.color: "black" + opacity: 0.8 + visible: background.isLyricsMode + Item{ + id: melodyTitle + width: parent.width + height: parent.height / 6 + GCText { + id: titleText + fontSizeMode: Text.Fit + wrapMode: Text.WordWrap + text: qsTr("Title: %1").arg(lyricsArea.title) + anchors.fill: parent + anchors.rightMargin: parent.width * 0.02 + anchors.leftMargin: parent.width * 0.02 + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + font.bold: true + color: "green" + } + } + + Rectangle { + id: titleUnderline + width: titleText.contentWidth + height: 3 + color: "black" + anchors.top: melodyTitle.bottom + anchors.horizontalCenter: melodyTitle.horizontalCenter + } + + Item{ + id: melodyOrigin + width: parent.width + height: parent.height / 8 + anchors.top: titleUnderline.bottom + GCText { + fontSizeMode: Text.Fit + wrapMode: Text.WordWrap + text: qsTr("Origin: %1").arg(lyricsArea.origin) + anchors.fill: parent + anchors.rightMargin: parent.width * 0.02 + anchors.leftMargin: parent.width * 0.02 + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + font.italic: true + color: "red" + } + } + + Item{ + id: melodyLyrics + width: parent.width + height: parent.height - melodyTitle.height - melodyOrigin.height + anchors.top: melodyOrigin.bottom + GCText { + fontSizeMode: Text.Fit + wrapMode: Text.WordWrap + text: lyricsArea.lyrics + anchors.fill: parent + anchors.rightMargin: parent.width * 0.1 + anchors.leftMargin: parent.width * 0.1 + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + } + + function resetLyricsArea() { + lyricsArea.title = "" + lyricsArea.origin = "" + lyricsArea.lyrics = "" + lyricsOrPianoModeOption.currentIndex = 0 + } + + function setLyrics(title, origin, lyrics) { + resetLyricsArea() + lyricsArea.title = title + lyricsArea.origin = origin + lyricsArea.lyrics = lyrics + lyricsOrPianoModeOption.currentIndex = 1 + } +} diff --git a/src/activities/piano_composition/MelodyList.qml b/src/activities/piano_composition/MelodyList.qml --- a/src/activities/piano_composition/MelodyList.qml +++ b/src/activities/piano_composition/MelodyList.qml @@ -115,6 +115,7 @@ onClicked: { dialogBackground.selectedMelodyIndex = index items.multipleStaff.loadFromData(melody) + lyricsArea.setLyrics(title, _origin, lyrics) } width: parent.width height: parent.height * 0.8 diff --git a/src/activities/piano_composition/Piano_composition.qml b/src/activities/piano_composition/Piano_composition.qml --- a/src/activities/piano_composition/Piano_composition.qml +++ b/src/activities/piano_composition/Piano_composition.qml @@ -109,6 +109,7 @@ property alias file: file property alias piano: piano property alias staffModesOptions: staffModesOptions + property alias lyricsArea: lyricsArea } onStart: { Activity.start(items) } @@ -118,6 +119,7 @@ property string restType: "Whole" property string clefType: bar.level == 2 ? "bass" : "treble" property string staffMode: "add" + property bool isLyricsMode: (lyricsOrPianoModeOption.currentIndex === 1) && lyricsOrPianoModeOption.visible File { id: file @@ -224,6 +226,7 @@ else if(background.staffMode === "replace") multipleStaff.replaceNote(note, currentType) } + visible: !background.isLyricsMode } Image { @@ -234,7 +237,7 @@ height: width fillMode: Image.PreserveAspectFit rotation: 180 - visible: piano.currentOctaveNb > 0 + visible: (piano.currentOctaveNb > 0) && piano.visible anchors { verticalCenter: piano.verticalCenter right: piano.left @@ -252,7 +255,7 @@ width: sourceSize.width height: width fillMode: Image.PreserveAspectFit - visible: piano.currentOctaveNb < piano.maxNbOctaves - 1 + visible: (piano.currentOctaveNb < piano.maxNbOctaves - 1) && piano.visible anchors { verticalCenter: piano.verticalCenter left: piano.right @@ -263,6 +266,10 @@ } } + LyricsArea { + id: lyricsArea + } + Row { id: optionsRow anchors.top: instructionBox.bottom @@ -272,6 +279,8 @@ readonly property var noteLengthName: ["Whole", "Half", "Quarter", "Eighth"] readonly property var staffModes: ["add", "replace", "erase"] + readonly property var lyricsOrPianoModes: ["piano", "lyrics"] + readonly property real iconsWidth: Math.min(50, (background.width - optionsRow.spacing *12) / 14) SwitchableOptions { id: noteOptions @@ -284,7 +293,7 @@ Image { id: playButton source: "qrc:/gcompris/src/activities/piano_composition/resource/play.svg" - sourceSize.width: 50 + sourceSize.width: optionsRow.iconsWidth MouseArea { anchors.fill: parent onClicked: multipleStaff.play() @@ -294,7 +303,7 @@ Image { id: clefButton source: clefType == "bass" ? "qrc:/gcompris/src/activities/piano_composition/resource/bassClefButton.svg" : "qrc:/gcompris/src/activities/piano_composition/resource/trebbleClefButton.svg" - sourceSize.width: 50 + sourceSize.width: optionsRow.iconsWidth visible: bar.level > 2 MouseArea { anchors.fill: parent @@ -325,17 +334,20 @@ Image { id: clearButton source: "qrc:/gcompris/src/activities/piano_composition/resource/edit-clear.svg" - sourceSize.width: 50 + sourceSize.width: optionsRow.iconsWidth MouseArea { anchors.fill: parent - onClicked: multipleStaff.eraseAllNotes() + onClicked: { + lyricsArea.resetLyricsArea() + multipleStaff.eraseAllNotes() + } } } Image { id: undoButton source: "qrc:/gcompris/src/activities/piano_composition/resource/undo.svg" - sourceSize.width: 50 + sourceSize.width: optionsRow.iconsWidth MouseArea { anchors.fill: parent onClicked: Activity.undoChange() @@ -345,11 +357,12 @@ Image { id: openButton source: "qrc:/gcompris/src/activities/piano_composition/resource/open.svg" - sourceSize.width: 50 + sourceSize.width: optionsRow.iconsWidth visible: bar.level > 6 MouseArea { anchors.fill: parent onClicked: { + melodyList.melodiesModel.clear() var dataset = Dataset.get() for(var i = 0; i < dataset.length; i++) { melodyList.melodiesModel.append(dataset[i]) @@ -365,7 +378,7 @@ Image { id: saveButton source: "qrc:/gcompris/src/activities/piano_composition/resource/save.svg" - sourceSize.width: 50 + sourceSize.width: optionsRow.iconsWidth visible: bar.level == 8 MouseArea { anchors.fill: parent @@ -385,6 +398,15 @@ } } + SwitchableOptions { + id: lyricsOrPianoModeOption + nbOptions: optionsRow.lyricsOrPianoModes.length + source: "qrc:/gcompris/src/activities/piano_composition/resource/%1-icon.svg".arg(optionsRow.lyricsOrPianoModes[currentIndex]) + anchors.top: parent.top + anchors.topMargin: 4 + visible: bar.level > 6 + } + // Since the half rest image is just the rotated image of whole rest image, we check if the current rest type is half, we assign the source as whole rest and rotate it by 180 degrees. SwitchableOptions { id: restOptions @@ -395,7 +417,7 @@ nbOptions: optionsRow.noteLengthName.length onClicked: restType = optionsRow.noteLengthName[currentIndex] rotation: optionsRow.noteLengthName[currentIndex] === "Half" ? 180 : 0 - sourceSize.width: 70 + sourceSize.width: optionsRow.iconsWidth visible: bar.level > 5 } diff --git a/src/activities/piano_composition/SwitchableOptions.qml b/src/activities/piano_composition/SwitchableOptions.qml --- a/src/activities/piano_composition/SwitchableOptions.qml +++ b/src/activities/piano_composition/SwitchableOptions.qml @@ -33,7 +33,7 @@ signal clicked - sourceSize.width: 50 + sourceSize.width: optionsRow.iconsWidth anchors.top: parent.top anchors.topMargin: -6 MouseArea { diff --git a/src/activities/piano_composition/piano_composition.js b/src/activities/piano_composition/piano_composition.js --- a/src/activities/piano_composition/piano_composition.js +++ b/src/activities/piano_composition/piano_composition.js @@ -97,7 +97,7 @@ items.background.staffMode = "add" items.multipleStaff.noteToReplace.noteNumber = -1 items.multipleStaff.noteToReplace.staffNumber = -1 - items.staffModesOptions.currentIndex = 0 + items.lyricsArea.resetLyricsArea() undoStack = [] } diff --git a/src/activities/piano_composition/resource/lyrics-icon.svg b/src/activities/piano_composition/resource/lyrics-icon.svg new file mode 100644 --- /dev/null +++ b/src/activities/piano_composition/resource/lyrics-icon.svg @@ -0,0 +1,60 @@ + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/activities/piano_composition/resource/piano-icon.svg b/src/activities/piano_composition/resource/piano-icon.svg new file mode 100644 --- /dev/null +++ b/src/activities/piano_composition/resource/piano-icon.svg @@ -0,0 +1,59 @@ + + + + + + image/svg+xml + + + + + + + + +