ElisaMainWindow.qml 10.9 KB
Newer Older
1
/*
Matthieu Gallien's avatar
Matthieu Gallien committed
2 3 4
   SPDX-FileCopyrightText: 2016 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr>

   SPDX-License-Identifier: LGPL-3.0-or-later
5 6
 */

7
import QtQuick 2.7
8
import QtQuick.Controls 2.3
9 10
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
11
import org.kde.kirigami 2.5 as Kirigami
12
import org.kde.elisa 1.0
13
import Qt.labs.settings 1.0
14
import Qt.labs.platform 1.1
15 16

ApplicationWindow {
17
    id: mainWindow
18
    
19
    visible: true
20 21 22
    
    minimumWidth: 590
    property int minHeight: 320
23

Safa AlFulaij's avatar
Safa AlFulaij committed
24 25 26
    LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft
    LayoutMirroring.childrenInherit: true

27 28 29 30 31
    x: persistentSettings.x
    y: persistentSettings.y
    width: persistentSettings.width
    height: persistentSettings.height

Safa AlFulaij's avatar
Safa AlFulaij committed
32
    title: i18n("Elisa")
33

34 35 36
    Accessible.role: Accessible.Application
    Accessible.name: title

37
    property var goBackAction: elisa.action("go_back")
38 39
    property var seekAction: elisa.action("Seek")
    property var scrubAction: elisa.action("Scrub")
40
    property var playPauseAction: elisa.action("Play-Pause")
41
    property var findAction: elisa.action("edit_find")
Diego Gangl's avatar
Diego Gangl committed
42

43
    Action {
44
        shortcut: goBackAction.shortcut
45
        onTriggered: contentView.goBack()
46 47
    }

48
    Action {
49 50
        shortcut: seekAction.shortcut
        onTriggered: elisa.audioControl.seek(headerBar.playerControl.position + 10000)
51 52 53
    }

    Action {
54 55
        shortcut: scrubAction.shortcut
        onTriggered: elisa.audioControl.seek(headerBar.playerControl.position - 10000)
56 57
    }

58
    Action {
59 60 61 62 63 64 65
        shortcut: playPauseAction.shortcut
        onTriggered: elisa.audioControl.playPause()
    }

    Action {
        shortcut: findAction.shortcut
        onTriggered: persistentSettings.expandedFilterView = !persistentSettings.expandedFilterView
66 67
    }

68 69 70 71
    ApplicationMenu {
        id: applicationMenu
    }

72 73 74 75 76
    SystemPalette {
        id: myPalette
        colorGroup: SystemPalette.Active
    }

77 78 79 80
    Theme {
        id: elisaTheme
    }

81
    Settings {
82 83 84 85
        id: persistentSettings

        property int x
        property int y
86 87
        property int width : 900
        property int height : 650
88

89
        property var playListState
90

91
        property var audioPlayerState
92

93
        property double playControlItemVolume : 100.0
94
        property bool playControlItemMuted : false
95

96
        property bool expandedFilterView: false
97

Diego Gangl's avatar
Diego Gangl committed
98
        property bool showPlaylist: true
99 100

        property bool headerBarIsMaximized: false
101 102 103 104
    }

    Connections {
        target: headerBar.playerControl
105 106 107 108 109 110 111
        onOpenMenu: {
            if (applicationMenu.visible) {
                applicationMenu.close()
            } else {
                applicationMenu.popup(mainWindow.width - applicationMenu.width, headerBar.height)
            }
        }
112
    }
113

114 115 116 117 118 119 120 121 122
    Connections {
        target: Qt.application
        onAboutToQuit:
        {
            persistentSettings.x = mainWindow.x;
            persistentSettings.y = mainWindow.y;
            persistentSettings.width = mainWindow.width;
            persistentSettings.height = mainWindow.height;

123
            persistentSettings.playListState = elisa.mediaPlayListProxyModel.persistentState;
Alexander Stippich's avatar
Alexander Stippich committed
124
            persistentSettings.audioPlayerState = elisa.audioControl.persistentState
125

126 127
            persistentSettings.playControlItemVolume = headerBar.playerControl.volume
            persistentSettings.playControlItemMuted = headerBar.playerControl.muted
Diego Gangl's avatar
Diego Gangl committed
128

Diego Gangl's avatar
Diego Gangl committed
129
            persistentSettings.showPlaylist = contentView.showPlaylist
130 131

            persistentSettings.headerBarIsMaximized = headerBar.isMaximized
132 133 134
        }
    }

Alexander Stippich's avatar
Alexander Stippich committed
135 136 137
    Loader {
        id: mprisloader
        active: false
138

Alexander Stippich's avatar
Alexander Stippich committed
139 140
        sourceComponent:  PlatformIntegration {
            id: platformInterface
141

142
            playListModel: elisa.mediaPlayListProxyModel
Alexander Stippich's avatar
Alexander Stippich committed
143 144
            audioPlayerManager: elisa.audioControl
            player: elisa.audioPlayer
145 146
            headerBarManager: elisa.manageHeaderBar
            manageMediaPlayerControl: elisa.playerControl
147
            showProgressOnTaskBar: elisa.showProgressOnTaskBar
148 149
            showSystemTrayIcon: elisa.showSystemTrayIcon
            elisaMainWindow: mainWindow
150

151
            onRaisePlayer: {
152
                mainWindow.visible = true
Alexander Stippich's avatar
Alexander Stippich committed
153 154 155
                mainWindow.raise()
                mainWindow.requestActivate()
            }
156

157
        }
158 159
    }

Alexander Stippich's avatar
Alexander Stippich committed
160 161
    Connections {
        target: elisa.audioPlayer
162 163
        onVolumeChanged: headerBar.playerControl.volume = elisa.audioPlayer.volume
        onMutedChanged: headerBar.playerControl.muted = elisa.audioPlayer.muted
164 165
    }

166
    Rectangle {
167
        color: myPalette.base
168 169
        anchors.fill: parent

170 171 172
        ColumnLayout {
            anchors.fill: parent
            spacing: 0
173

174 175 176 177 178
            HeaderBar {
                id: headerBar

                focus: true

179 180
                Layout.minimumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
                Layout.maximumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
181
                Layout.fillWidth: true
Matthieu Gallien's avatar
Matthieu Gallien committed
182

183
                tracksCount: elisa.mediaPlayListProxyModel.remainingTracks
184
                album: (elisa.manageHeaderBar.album !== undefined ? elisa.manageHeaderBar.album : '')
185
                title: elisa.manageHeaderBar.title
186 187
                artist: (elisa.manageHeaderBar.artist !== undefined ? elisa.manageHeaderBar.artist : '')
                albumArtist: (elisa.manageHeaderBar.albumArtist !== undefined ? elisa.manageHeaderBar.albumArtist : '')
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
                image: elisa.manageHeaderBar.image
                albumID: elisa.manageHeaderBar.albumId

                ratingVisible: false

                playerControl.duration: elisa.audioPlayer.duration
                playerControl.seekable: elisa.audioPlayer.seekable

                playerControl.volume: persistentSettings.playControlItemVolume
                playerControl.muted: persistentSettings.playControlItemMuted
                playerControl.position: elisa.audioPlayer.position
                playerControl.skipBackwardEnabled: elisa.playerControl.skipBackwardControlEnabled
                playerControl.skipForwardEnabled: elisa.playerControl.skipForwardControlEnabled
                playerControl.playEnabled: elisa.playerControl.playControlEnabled
                playerControl.isPlaying: elisa.playerControl.musicPlaying

204
                playerControl.repeat: elisa.mediaPlayListProxyModel.repeatPlay
205
                playerControl.shuffle: elisa.mediaPlayListProxyModel.shufflePlayList
206 207 208 209 210

                playerControl.onSeek: elisa.audioPlayer.seek(position)

                playerControl.onPlay: elisa.audioControl.playPause()
                playerControl.onPause: elisa.audioControl.playPause()
211 212
                playerControl.onPlayPrevious: elisa.mediaPlayListProxyModel.skipPreviousTrack()
                playerControl.onPlayNext: elisa.mediaPlayListProxyModel.skipNextTrack()
213 214 215 216 217 218 219 220 221 222 223 224 225

                playerControl.isMaximized: persistentSettings.headerBarIsMaximized
                onOpenArtist: { contentView.openArtist(artist) }
                onOpenNowPlaying: { contentView.openNowPlaying() }
                onOpenAlbum: { contentView.openAlbum(album, albumArtist, image, albumID) }

                TrackImportNotification {
                    id: importedTracksCountNotification

                    anchors
                    {
                        right: headerBar.right
                        top: headerBar.top
226 227
                        rightMargin: Kirigami.Units.largeSpacing * 2
                        topMargin: Kirigami.Units.largeSpacing * 3
228
                    }
229
                }
230

231 232
                Binding {
                    id: indexerBusyBinding
233

234 235 236 237 238
                    target: importedTracksCountNotification
                    property: 'indexingRunning'
                    value: elisa.musicManager.indexerBusy
                    when: elisa.musicManager !== undefined
                }
239

240 241 242 243 244
                Binding {
                    target: importedTracksCountNotification
                    property: 'importedTracksCount'
                    value: elisa.musicManager.importedTracksCount
                    when: elisa.musicManager !== undefined
245
                }
246
            }
247

248 249 250 251 252 253
            Rectangle {
                Layout.fillWidth: true
                height: 1
                color: myPalette.mid
            }

254 255
            ContentView {
                id: contentView
256
                Layout.fillHeight: true
257
                Layout.fillWidth: true
Diego Gangl's avatar
Diego Gangl committed
258
                showPlaylist: persistentSettings.showPlaylist
259
                showExpandedFilterView: persistentSettings.expandedFilterView
260
            }
261 262
        }
    }
263

264 265 266
    StateGroup {
        id: mainWindowState
        states: [
267 268 269 270 271 272
            State {
                name: "headerBarIsNormal"
                when: !headerBar.isMaximized
                changes: [
                    PropertyChanges {
                        target: mainWindow
273
                        minimumHeight: mainWindow.minHeight * 1.5
274 275 276
                        explicit: true
                    },
                    PropertyChanges {
277
                        target: headerBar
278 279 280 281 282
                        Layout.minimumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
                        Layout.maximumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
                    }
                ]
            },
283 284
            State {
                name: "headerBarIsMaximized"
Matthieu Gallien's avatar
Matthieu Gallien committed
285
                when: headerBar.isMaximized
286 287 288
                changes: [
                    PropertyChanges {
                        target: mainWindow
289
                        minimumHeight: mainWindow.minHeight
290 291 292
                        explicit: true
                    },
                    PropertyChanges {
293
                        target: headerBar
294 295 296 297 298 299
                        Layout.minimumHeight: mainWindow.height
                        Layout.maximumHeight: mainWindow.height
                    }
                ]
            }
        ]
300 301 302 303
        transitions: Transition {
            NumberAnimation {
                properties: "Layout.minimumHeight, Layout.maximumHeight, minimumHeight"
                easing.type: Easing.InOutQuad
304
                duration: Kirigami.Units.longDuration
305 306
            }
        }
307 308
    }

309 310 311 312
    Component.onCompleted:
    {
        elisa.initialize()

313
        if (persistentSettings.playListState) {
314
            elisa.mediaPlayListProxyModel.persistentState = persistentSettings.playListState
315
        }
Diego Gangl's avatar
Diego Gangl committed
316

Alexander Stippich's avatar
Alexander Stippich committed
317 318 319
        if (persistentSettings.audioPlayerState) {
            elisa.audioControl.persistentState = persistentSettings.audioPlayerState
        }
Alexander Stippich's avatar
Alexander Stippich committed
320

321
        elisa.mediaPlayListProxyModel.shufflePlayList = Qt.binding(function() { return headerBar.playerControl.shuffle })
322
        elisa.mediaPlayListProxyModel.repeatPlay = Qt.binding(function() { return headerBar.playerControl.repeat })
Alexander Stippich's avatar
Alexander Stippich committed
323 324 325
        elisa.audioPlayer.muted = Qt.binding(function() { return headerBar.playerControl.muted })
        elisa.audioPlayer.volume = Qt.binding(function() { return headerBar.playerControl.volume })

Alexander Stippich's avatar
Alexander Stippich committed
326
        mprisloader.active = true
327
    }
328
}