~baltix/gcompris-qt/0.97.1

« back to all changes in this revision

Viewing changes to src/activities/menu/BackgroundMusicList.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 - BackgroundMusicList.qml
 
2
 *
 
3
 * Copyright (C) 2019 Aman Kumar Gupta <gupta2140@gmail.com>
 
4
 *
 
5
 * Authors:
 
6
 *   Aman Kumar Gupta <gupta2140@gmail.com> (Qt Quick)
 
7
 *
 
8
 *   This program is free software; you can redistribute it and/or modify
 
9
 *   it under the terms of the GNU General Public License as published by
 
10
 *   the Free Software Foundation; either version 3 of the License, or
 
11
 *   (at your option) any later version.
 
12
 *
 
13
 *   This program is distributed in the hope that it will be useful,
 
14
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 *   GNU General Public License for more details.
 
17
 *
 
18
 *   You should have received a copy of the GNU General Public License
 
19
 *   along with this program; if not, see <https://www.gnu.org/licenses/>.
 
20
 */
 
21
 
 
22
import QtQuick 2.6
 
23
import QtQuick.Controls 1.5
 
24
import GCompris 1.0
 
25
 
 
26
import "../../core"
 
27
import "qrc:/gcompris/src/core/core.js" as Core
 
28
 
 
29
Rectangle {
 
30
    id: dialogBackground
 
31
    color: "#696da3"
 
32
    border.color: "black"
 
33
    border.width: 1
 
34
    z: 10000
 
35
    anchors.fill: parent
 
36
    visible: false
 
37
 
 
38
    Keys.onEscapePressed: close()
 
39
 
 
40
    signal close
 
41
 
 
42
    property bool horizontalLayout: dialogBackground.width >= dialogBackground.height
 
43
    property int margin30: Math.round(30 * ApplicationInfo.ratio)
 
44
 
 
45
    Row {
 
46
        spacing: 2
 
47
        Item { width: 10; height: 1 }
 
48
 
 
49
        Column {
 
50
            spacing: 10
 
51
            anchors.top: parent.top
 
52
            Item { width: 1; height: 10 }
 
53
            Rectangle {
 
54
                id: titleRectangle
 
55
                color: "#e6e6e6"
 
56
                radius: 6.0
 
57
                width: dialogBackground.width - 30
 
58
                height: title.height * 1.2
 
59
                border.color: "black"
 
60
                border.width: 2
 
61
 
 
62
                GCText {
 
63
                    id: title
 
64
                    text: qsTr("Background music")
 
65
                    width: dialogBackground.width - 30
 
66
                    horizontalAlignment: Text.AlignHCenter
 
67
                    verticalAlignment: Text.AlignVCenter
 
68
                    color: "black"
 
69
                    fontSize: 20
 
70
                    font.weight: Font.DemiBold
 
71
                    wrapMode: Text.WordWrap
 
72
                }
 
73
            }
 
74
 
 
75
            Rectangle {
 
76
                color: "#e6e6e6"
 
77
                radius: 6.0
 
78
                width: dialogBackground.width - 30
 
79
                height: dialogBackground.height - 100
 
80
                border.color: "black"
 
81
                border.width: 2
 
82
                anchors.margins: 100
 
83
 
 
84
                Flickable {
 
85
                    id: flickableList
 
86
                    anchors.fill: parent
 
87
                    anchors.margins: 10 * ApplicationInfo.ratio
 
88
                    contentHeight: musicGrid.height + musicInfo.height + margin30
 
89
                    flickableDirection: Flickable.VerticalFlick
 
90
                    clip: true
 
91
 
 
92
                    Flow {
 
93
                        id: musicGrid
 
94
                        width: parent.width
 
95
                        spacing: 10 * ApplicationInfo.ratio
 
96
                        anchors.horizontalCenter: parent.horizontalCenter
 
97
 
 
98
                        Repeater {
 
99
                            model: dialogActivityConfig.configItem ? dialogActivityConfig.configItem.allBackgroundMusic : 0
 
100
 
 
101
                            Item {
 
102
                                width: (musicGrid.width - margin30)  * 0.33
 
103
                                height: title.height * 2
 
104
 
 
105
                                Button {
 
106
                                    text: modelData.slice(0, modelData.lastIndexOf('.'))
 
107
                                    onClicked: {
 
108
                                        if(dialogActivityConfig.configItem.filteredBackgroundMusic.indexOf(modelData) == -1) {
 
109
                                            // Keep the filtered playlist sorted w.r.t to their positions in "allBackgroundMusic" to maintain their playing order
 
110
                                            var musicOriginalPosition = dialogActivityConfig.configItem.allBackgroundMusic.indexOf(modelData)
 
111
                                            var i = 0
 
112
                                            while(i < dialogActivityConfig.configItem.filteredBackgroundMusic.length) {
 
113
                                                var filteredMusicName = dialogActivityConfig.configItem.filteredBackgroundMusic[i]
 
114
                                                if(dialogActivityConfig.configItem.allBackgroundMusic.indexOf(filteredMusicName) >  musicOriginalPosition)
 
115
                                                    break
 
116
                                                i++
 
117
                                            }
 
118
                                            dialogActivityConfig.configItem.filteredBackgroundMusic.splice(i, 0, modelData)
 
119
                                        }
 
120
                                        else {
 
121
                                            dialogActivityConfig.configItem.filteredBackgroundMusic.splice(dialogActivityConfig.configItem.filteredBackgroundMusic.indexOf(modelData), 1)
 
122
                                            if(dialogActivityConfig.configItem.filteredBackgroundMusic == 0) {
 
123
                                                dialogActivityConfig.configItem.filteredBackgroundMusic.push(modelData)
 
124
                                                selectedIcon.visible = false
 
125
                                                Core.showMessageDialog(dialogBackground,
 
126
                                                    qsTr("Disable the background music if you don't want to play them."),
 
127
                                                    "", null,
 
128
                                                    "", null,
 
129
                                                    null
 
130
                                                );
 
131
                                            }
 
132
                                        }
 
133
                                        
 
134
                                        selectedIcon.visible = !selectedIcon.visible
 
135
                                    }
 
136
                                    width: parent.width
 
137
                                    height: parent.height * 0.8
 
138
                                    style: GCButtonStyle {
 
139
                                        theme: "dark"
 
140
                                    }
 
141
 
 
142
                                    Image {
 
143
                                        id: selectedIcon
 
144
                                        source: "qrc:/gcompris/src/core/resource/apply.svg"
 
145
                                        sourceSize.width: height
 
146
                                        sourceSize.height: height
 
147
                                        width: height
 
148
                                        height: parent.height / 4
 
149
                                        anchors.bottom: parent.bottom
 
150
                                        anchors.right: parent.right
 
151
                                        anchors.margins: 2
 
152
                                        visible: dialogActivityConfig.configItem.filteredBackgroundMusic ? dialogActivityConfig.configItem.filteredBackgroundMusic.indexOf(modelData) != -1 : false
 
153
                                    }
 
154
                                }
 
155
                            }
 
156
                        }
 
157
                    }
 
158
 
 
159
                    Column {
 
160
                        id: musicInfo
 
161
                        spacing: 10 * ApplicationInfo.ratio
 
162
                        width: parent.width
 
163
                        anchors.top: musicGrid.bottom
 
164
                        anchors.leftMargin: 20
 
165
 
 
166
                        GCText {
 
167
                            //: Current background music playing
 
168
                            text: qsTr("Now Playing:")
 
169
                            width: dialogBackground.width - 30
 
170
                            horizontalAlignment: Text.AlignHCenter
 
171
                            color: "black"
 
172
                            fontSize: mediumSize
 
173
                            wrapMode: Text.WordWrap
 
174
                        }
 
175
                        GCText {
 
176
                            //: Title of the current background music playing
 
177
                            text: qsTr("Title: %1").arg(backgroundMusic.metaDataMusic[0])
 
178
                            width: dialogBackground.width - 30
 
179
                            horizontalAlignment: Text.AlignLeft
 
180
                            color: "black"
 
181
                            fontSize: smallSize
 
182
                            wrapMode: Text.WordWrap
 
183
                        }
 
184
                        GCText {
 
185
                            //: Artist of the current background music playing
 
186
                            text: qsTr("Artist: %1").arg(backgroundMusic.metaDataMusic[1])
 
187
                            width: dialogBackground.width - 30
 
188
                            horizontalAlignment: Text.AlignLeft
 
189
                            color: "black"
 
190
                            fontSize: smallSize
 
191
                            wrapMode: Text.WordWrap
 
192
                        }
 
193
                        GCText {
 
194
                            //: Year of the current background music playing
 
195
                            text: qsTr("Year: %1").arg(backgroundMusic.metaDataMusic[2])
 
196
                            width: dialogBackground.width - 30
 
197
                            horizontalAlignment: Text.AlignLeft
 
198
                            color: "black"
 
199
                            fontSize: smallSize
 
200
                            wrapMode: Text.WordWrap
 
201
                        }
 
202
                        GCText {
 
203
                            //: Copyright of the current background music playing
 
204
                            text: qsTr("Copyright: %1").arg(backgroundMusic.metaDataMusic[3])
 
205
                            width: dialogBackground.width - 30
 
206
                            horizontalAlignment: Text.AlignLeft
 
207
                            color: "black"
 
208
                            fontSize: smallSize
 
209
                            wrapMode: Text.WordWrap
 
210
                        }
 
211
                    }
 
212
                }
 
213
                // The scroll buttons
 
214
                GCButtonScroll {
 
215
                    anchors.right: parent.right
 
216
                    anchors.rightMargin: 5 * ApplicationInfo.ratio
 
217
                    anchors.bottom: flickableList.bottom
 
218
                    anchors.bottomMargin: 30 * ApplicationInfo.ratio
 
219
                    width: parent.width / 20
 
220
                    height: width * heightRatio
 
221
                    onUp: flickableList.flick(0, 1400)
 
222
                    onDown: flickableList.flick(0, -1400)
 
223
                    upVisible: (flickableList.visibleArea.yPosition <= 0) ? false : true
 
224
                    downVisible: ((flickableList.visibleArea.yPosition + flickableList.visibleArea.heightRatio) >= 1) ? false : true
 
225
                }
 
226
            }
 
227
            Item { width: 1; height: 10 }
 
228
        }
 
229
    }
 
230
 
 
231
    GCButtonCancel {
 
232
        onClose: {
 
233
            parent.close()
 
234
        }
 
235
    }
 
236
}