ElisaMainWindow.qml 11.6 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 107 108 109 110 111 112
        onOpenMenu: {
            if (applicationMenu.visible) {
                applicationMenu.close()
            } else {
                applicationMenu.popup(mainWindow.width - applicationMenu.width, headerBar.height)
            }
        }
113
    }
114

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

124 125
            persistentSettings.playListState = ElisaApplication.mediaPlayListProxyModel.persistentState;
            persistentSettings.audioPlayerState = ElisaApplication.audioControl.persistentState
126

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

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

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

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

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

143 144 145 146 147 148 149
            playListModel: ElisaApplication.mediaPlayListProxyModel
            audioPlayerManager: ElisaApplication.audioControl
            player: ElisaApplication.audioPlayer
            headerBarManager: ElisaApplication.manageHeaderBar
            manageMediaPlayerControl: ElisaApplication.playerControl
            showProgressOnTaskBar: ElisaApplication.showProgressOnTaskBar
            showSystemTrayIcon: ElisaApplication.showSystemTrayIcon
150
            elisaMainWindow: mainWindow
151

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

158
        }
159 160
    }

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

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

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

175 176 177 178 179
            HeaderBar {
                id: headerBar

                focus: true

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

184 185 186 187 188 189 190
                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
191 192 193

                ratingVisible: false

194 195
                playerControl.duration: ElisaApplication.audioPlayer.duration
                playerControl.seekable: ElisaApplication.audioPlayer.seekable
196 197 198

                playerControl.volume: persistentSettings.playControlItemVolume
                playerControl.muted: persistentSettings.playControlItemMuted
199 200 201 202 203
                playerControl.position: ElisaApplication.audioPlayer.position
                playerControl.skipBackwardEnabled: ElisaApplication.playerControl.skipBackwardControlEnabled
                playerControl.skipForwardEnabled: ElisaApplication.playerControl.skipForwardControlEnabled
                playerControl.playEnabled: ElisaApplication.playerControl.playControlEnabled
                playerControl.isPlaying: ElisaApplication.playerControl.musicPlaying
204

205 206
                playerControl.repeat: ElisaApplication.mediaPlayListProxyModel.repeatPlay
                playerControl.shuffle: ElisaApplication.mediaPlayListProxyModel.shufflePlayList
207

208
                playerControl.onSeek: ElisaApplication.audioPlayer.seek(position)
209

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

                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
227 228
                        rightMargin: Kirigami.Units.largeSpacing * 2
                        topMargin: Kirigami.Units.largeSpacing * 3
229
                    }
230
                }
231

232 233
                Binding {
                    id: indexerBusyBinding
234

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

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

249
            Kirigami.Separator {
250 251 252
                Layout.fillWidth: true
            }

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

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

308 309
    Component.onCompleted:
    {
310
        ElisaApplication.initialize()
311

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

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

320 321 322 323
        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
324

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

        ElisaApplication.arguments = ElisaArguments.arguments
328
    }
329
}