~baltix/gcompris-qt/0.97.1

« back to all changes in this revision

Viewing changes to src/activities/piano_composition/OptionsRow.qml

  • Committer: Mantas Kriaučiūnas
  • Date: 2020-07-06 18:07:11 UTC
  • Revision ID: baltix@gmail.com-20200706180711-g254osu02cn8bc8p
GCompris-QT 0.97.1 with Lithuanian translation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GCompris - OptionsRow.qml
 
2
*
 
3
* Copyright (C) 2018 Aman Kumar Gupta <gupta2140@gmail.com>
 
4
*
 
5
* Authors:
 
6
*   Beth Hadley <bethmhadley@gmail.com> (GTK+ version)
 
7
*   Johnny Jazeix <jazeix@gmail.com> (Qt Quick port)
 
8
*   Aman Kumar Gupta <gupta2140@gmail.com> (Qt Quick port)
 
9
*   Timothée Giet <animtim@gmail.com> (refactoring)
 
10
*
 
11
*   This program is free software; you can redistribute it and/or modify
 
12
*   it under the terms of the GNU General Public License as published by
 
13
*   the Free Software Foundation; either version 3 of the License, or
 
14
*   (at your option) any later version.
 
15
*
 
16
*   This program is distributed in the hope that it will be useful,
 
17
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
*   GNU General Public License for more details.
 
20
*
 
21
*   You should have received a copy of the GNU General Public License
 
22
*   along with this program; if not, see <https://www.gnu.org/licenses/>.
 
23
*/
 
24
import QtQuick 2.6
 
25
import GCompris 1.0
 
26
 
 
27
import "../../core"
 
28
 
 
29
Grid {
 
30
    id: optionsRow
 
31
    columns: 2
 
32
 
 
33
    //: Whole note, Half note, Quarter note and Eighth note are the different length notes in the musical notation.
 
34
    readonly property var noteLengthName: [[qsTr("Whole note"), "Whole"], [qsTr("Half note"), "Half"], [qsTr("Quarter note"), "Quarter"], [qsTr("Eighth note"), "Eighth"]]
 
35
 
 
36
    //: Whole rest, Half rest, Quarter rest and Eighth rest are the different length rests (silences) in the musical notation.
 
37
    readonly property var restAddedMessage: [qsTr("Added whole rest"), qsTr("Added half rest"), qsTr("Added quarter rest"), qsTr("Added eighth rest")]
 
38
    readonly property var translatedRestNames: [qsTr("Whole rest"), qsTr("Half rest"), qsTr("Quarter rest"), qsTr("Eighth rest")]
 
39
    readonly property var lyricsOrPianoModes: [[qsTr("Piano"), "piano"], [qsTr("Lyrics"), "lyrics"]]
 
40
 
 
41
    property real iconsWidth: score.height * 1.2
 
42
    property alias noteOptionsIndex: noteOptions.currentIndex
 
43
    property alias lyricsOrPianoModeIndex: lyricsOrPianoModeOption.currentIndex
 
44
    property alias keyOption: keyOption
 
45
    property alias bpmMeter: bpmMeter
 
46
    property alias restOptionIndex: restOptions.currentIndex
 
47
 
 
48
    property bool restOptionsVisible: false
 
49
    property bool noteOptionsVisible: false
 
50
    property bool playButtonVisible: false
 
51
    property bool clearButtonVisible: false
 
52
    property bool undoButtonVisible: false
 
53
    property bool openButtonVisible: false
 
54
    property bool saveButtonVisible: false
 
55
    property bool changeAccidentalStyleButtonVisible: false
 
56
    property bool lyricsOrPianoModeOptionVisible: false
 
57
    property bool bpmVisible: false
 
58
 
 
59
    signal undoButtonClicked
 
60
    signal clearButtonClicked
 
61
    signal openButtonClicked
 
62
    signal saveButtonClicked
 
63
    signal playButtonClicked
 
64
    signal bpmIncreased
 
65
    signal bpmDecreased
 
66
    signal bpmChanged
 
67
    signal emitOptionMessage(string message)
 
68
 
 
69
 
 
70
    BpmMeter {
 
71
        id: bpmMeter
 
72
    }
 
73
 
 
74
    BarButton {
 
75
        id: playButton
 
76
        source: "qrc:/gcompris/src/activities/piano_composition/resource/play.svg"
 
77
        sourceSize.width: optionsRow.iconsWidth
 
78
        visible: playButtonVisible
 
79
        onClicked: {
 
80
                optionsRow.playButtonClicked()
 
81
                emitOptionMessage(qsTr("Play melody"))
 
82
                multipleStaff.play()
 
83
        }
 
84
    }
 
85
 
 
86
    BarButton {
 
87
        id: clearButton
 
88
        source: "qrc:/gcompris/src/activities/piano_composition/resource/erase.svg"
 
89
        sourceSize.width: optionsRow.iconsWidth
 
90
        visible: clearButtonVisible
 
91
        onClicked: clearButtonClicked()
 
92
    }
 
93
 
 
94
    BarButton {
 
95
        id: undoButton
 
96
        source: "qrc:/gcompris/src/activities/piano_composition/resource/undo.svg"
 
97
        sourceSize.width: optionsRow.iconsWidth
 
98
        visible: undoButtonVisible
 
99
        onClicked: {
 
100
                emitOptionMessage(qsTr("Undo"))
 
101
                undoButtonClicked()
 
102
        }
 
103
    }
 
104
 
 
105
    KeyOption {
 
106
        id: keyOption
 
107
    }
 
108
 
 
109
    Item {
 
110
        id: rests
 
111
        width: optionsRow.iconsWidth * 2
 
112
        height: optionsRow.iconsWidth
 
113
        visible: restOptionsVisible
 
114
        Rectangle {
 
115
            color: "yellow"
 
116
            opacity: 0.1
 
117
            border.width: 2
 
118
            border.color: "black"
 
119
            anchors.fill: parent
 
120
            radius: 10
 
121
        }
 
122
 
 
123
        SwitchableOptions {
 
124
            id: restOptions
 
125
 
 
126
            readonly property string restTypeImage: (optionsRow.noteLengthName[currentIndex][1]).toLowerCase()
 
127
 
 
128
            source: "qrc:/gcompris/src/activities/piano_composition/resource/%1Rest.svg".arg(restTypeImage)
 
129
            nbOptions: optionsRow.noteLengthName.length
 
130
            onClicked: {
 
131
                background.restType = optionsRow.noteLengthName[currentIndex][1]
 
132
                emitOptionMessage(optionsRow.translatedRestNames[currentIndex])
 
133
            }
 
134
            width: optionsRow.iconsWidth * 0.9
 
135
            sourceSize.width: width
 
136
            visible: restOptionsVisible
 
137
            anchors.topMargin: -3
 
138
            anchors.left: parent.left
 
139
            anchors.leftMargin: 5
 
140
        }
 
141
 
 
142
        BarButton {
 
143
            id: addRestButton
 
144
            width: restOptions.width
 
145
            sourceSize.width: width
 
146
            source: "qrc:/gcompris/src/activities/piano_composition/resource/add.svg"
 
147
            anchors.right: parent.right
 
148
            anchors.verticalCenter: parent.verticalCenter
 
149
            visible: restOptions.visible
 
150
            onClicked: {
 
151
                emitOptionMessage(optionsRow.restAddedMessage[restOptionIndex])
 
152
                parent.scale = 1
 
153
                pianoLayout.addMusicElementAndPushToStack(restType.toLowerCase(), "Rest")
 
154
            }
 
155
        }
 
156
    }
 
157
 
 
158
    BarButton {
 
159
        id: changeAccidentalStyleButton
 
160
        source: changeAccidentalStyleButtonVisible ? (piano.useSharpNotation ? "qrc:/gcompris/src/activities/piano_composition/resource/blacksharp.svg"
 
161
                                                   : "qrc:/gcompris/src/activities/piano_composition/resource/blackflat.svg")
 
162
                                                   : ""
 
163
        sourceSize.width: optionsRow.iconsWidth
 
164
        visible: changeAccidentalStyleButtonVisible
 
165
        onClicked: {
 
166
            piano.useSharpNotation = !piano.useSharpNotation
 
167
            //: Sharp notes and Flat notes represents the accidental style of the notes in the music.
 
168
            emitOptionMessage(piano.useSharpNotation ? qsTr("Sharp notes") : qsTr("Flat notes"))
 
169
        }
 
170
    }
 
171
 
 
172
    SwitchableOptions {
 
173
        id: noteOptions
 
174
        source: "qrc:/gcompris/src/activities/piano_composition/resource/genericNote%1.svg".arg(optionsRow.noteLengthName[currentIndex][1])
 
175
        nbOptions: optionsRow.noteLengthName.length
 
176
        sourceSize.width: optionsRow.iconsWidth
 
177
        sourceSize.height: optionsRow.iconsWidth
 
178
        currentIndex: 2
 
179
        onClicked: {
 
180
            background.currentType = optionsRow.noteLengthName[currentIndex][1]
 
181
            emitOptionMessage(optionsRow.noteLengthName[currentIndex][0])
 
182
        }
 
183
        visible: noteOptionsVisible
 
184
    }
 
185
 
 
186
    BarButton {
 
187
        id: openButton
 
188
        source: "qrc:/gcompris/src/activities/piano_composition/resource/open.svg"
 
189
        sourceSize.width: optionsRow.iconsWidth
 
190
        visible: openButtonVisible
 
191
        onClicked: openButtonClicked()
 
192
    }
 
193
 
 
194
    BarButton {
 
195
        id: saveButton
 
196
        source: "qrc:/gcompris/src/activities/piano_composition/resource/save.svg"
 
197
        sourceSize.width: optionsRow.iconsWidth
 
198
        visible: saveButtonVisible
 
199
        onClicked: saveButtonClicked()
 
200
    }
 
201
 
 
202
    SwitchableOptions {
 
203
        id: lyricsOrPianoModeOption
 
204
        nbOptions: optionsRow.lyricsOrPianoModes.length
 
205
        source: "qrc:/gcompris/src/activities/piano_composition/resource/%1.svg".arg(optionsRow.lyricsOrPianoModes[currentIndex][1])
 
206
        visible: lyricsOrPianoModeOptionVisible
 
207
        onClicked: emitOptionMessage(optionsRow.lyricsOrPianoModes[currentIndex][0])
 
208
    }
 
209
    
 
210
}