ElisaMainWindow.qml 11.7 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 org.kde.elisa.host 1.0
14
import Qt.labs.settings 1.0
15
import Qt.labs.platform 1.1
16 17

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

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

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

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

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

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

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

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

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

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

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

69 70 71 72
    ApplicationMenu {
        id: applicationMenu
    }

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

78 79 80 81
    Theme {
        id: elisaTheme
    }

82
    Settings {
83 84 85 86
        id: persistentSettings

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

90
        property var playListState
91

92
        property var audioPlayerState
93

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

97
        property bool expandedFilterView: false
98

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

        property bool headerBarIsMaximized: false
102 103 104 105
    }

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

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

123 124
            persistentSettings.playListState = ElisaApplication.mediaPlayListProxyModel.persistentState;
            persistentSettings.audioPlayerState = ElisaApplication.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 143 144 145 146 147 148
            playListModel: ElisaApplication.mediaPlayListProxyModel
            audioPlayerManager: ElisaApplication.audioControl
            player: ElisaApplication.audioPlayer
            headerBarManager: ElisaApplication.manageHeaderBar
            manageMediaPlayerControl: ElisaApplication.playerControl
            showProgressOnTaskBar: ElisaApplication.showProgressOnTaskBar
            showSystemTrayIcon: ElisaApplication.showSystemTrayIcon
149
            elisaMainWindow: mainWindow
150

151
            function 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
    Connections {
161
        target: ElisaApplication.audioPlayer
162 163 164 165 166 167
        function onVolumeChanged() {
            headerBar.playerControl.volume = ElisaApplication.audioPlayer.volume
        }
        function onMutedChanged() {
            headerBar.playerControl.muted = ElisaApplication.audioPlayer.muted
        }
168 169
    }

170
    Rectangle {
171
        color: myPalette.base
172 173
        anchors.fill: parent

174 175 176
        ColumnLayout {
            anchors.fill: parent
            spacing: 0
177

178 179 180 181 182
            HeaderBar {
                id: headerBar

                focus: true

183 184
                Layout.minimumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
                Layout.maximumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
185
                Layout.fillWidth: true
Matthieu Gallien's avatar
Matthieu Gallien committed
186

187 188 189 190 191 192 193
                tracksCount: ElisaApplication.mediaPlayListProxyModel.remainingTracks
                album: (ElisaApplication.manageHeaderBar.album !== undefined ? ElisaApplication.manageHeaderBar.album : '')
                title: ElisaApplication.manageHeaderBar.title
                artist: (ElisaApplication.manageHeaderBar.artist !== undefined ? ElisaApplication.manageHeaderBar.artist : '')
                albumArtist: (ElisaApplication.manageHeaderBar.albumArtist !== undefined ? ElisaApplication.manageHeaderBar.albumArtist : '')
                image: ElisaApplication.manageHeaderBar.image
                albumID: ElisaApplication.manageHeaderBar.albumId
194 195 196

                ratingVisible: false

stef lep's avatar
stef lep committed
197
                playerControl.duration: ElisaApplication.audioControl.audioDuration
198
                playerControl.seekable: ElisaApplication.audioPlayer.seekable
199 200 201

                playerControl.volume: persistentSettings.playControlItemVolume
                playerControl.muted: persistentSettings.playControlItemMuted
stef lep's avatar
stef lep committed
202
                playerControl.position: ElisaApplication.audioControl.playerPosition
203 204 205 206
                playerControl.skipBackwardEnabled: ElisaApplication.playerControl.skipBackwardControlEnabled
                playerControl.skipForwardEnabled: ElisaApplication.playerControl.skipForwardControlEnabled
                playerControl.playEnabled: ElisaApplication.playerControl.playControlEnabled
                playerControl.isPlaying: ElisaApplication.playerControl.musicPlaying
207

208 209
                playerControl.repeat: ElisaApplication.mediaPlayListProxyModel.repeatPlay
                playerControl.shuffle: ElisaApplication.mediaPlayListProxyModel.shufflePlayList
210

211
                playerControl.onSeek: ElisaApplication.audioPlayer.seek(position)
212

213 214
                playerControl.onPlay: ElisaApplication.audioControl.playPause()
                playerControl.onPause: ElisaApplication.audioControl.playPause()
215
                playerControl.onPlayPrevious: ElisaApplication.mediaPlayListProxyModel.skipPreviousTrack(ElisaApplication.audioPlayer.position)
216
                playerControl.onPlayNext: ElisaApplication.mediaPlayListProxyModel.skipNextTrack()
217 218 219 220 221 222 223 224 225 226 227 228 229

                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
230 231
                        rightMargin: Kirigami.Units.largeSpacing * 2
                        topMargin: Kirigami.Units.largeSpacing * 3
232
                    }
233
                }
234

235 236
                Binding {
                    id: indexerBusyBinding
237

238 239
                    target: importedTracksCountNotification
                    property: 'indexingRunning'
240 241
                    value: ElisaApplication.musicManager.indexerBusy
                    when: ElisaApplication.musicManager !== undefined
242
                }
243

244 245 246
                Binding {
                    target: importedTracksCountNotification
                    property: 'importedTracksCount'
247 248
                    value: ElisaApplication.musicManager.importedTracksCount
                    when: ElisaApplication.musicManager !== undefined
249
                }
250
            }
251

252
            Kirigami.Separator {
253 254 255
                Layout.fillWidth: true
            }

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

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

311 312
    Component.onCompleted:
    {
313
        ElisaApplication.initialize()
314

315
        if (persistentSettings.playListState) {
316
            ElisaApplication.mediaPlayListProxyModel.persistentState = persistentSettings.playListState
317
        }
Diego Gangl's avatar
Diego Gangl committed
318

Alexander Stippich's avatar
Alexander Stippich committed
319
        if (persistentSettings.audioPlayerState) {
320
            ElisaApplication.audioControl.persistentState = persistentSettings.audioPlayerState
Alexander Stippich's avatar
Alexander Stippich committed
321
        }
Alexander Stippich's avatar
Alexander Stippich committed
322

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

Alexander Stippich's avatar
Alexander Stippich committed
328
        mprisloader.active = true
329 330

        ElisaApplication.arguments = ElisaArguments.arguments
331
    }
332
}