1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2024-11-27 03:15:16 +00:00
harbour-sailfin/sailfish/qml/components/music/NarrowAlbumCover.qml

259 lines
7.9 KiB
QML
Raw Normal View History

2020-10-27 01:35:50 +00:00
/*
Sailfin: a Jellyfin client written using Qt
Copyright (C) 2020 Chris Josten
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
import QtQuick 2.6
import Sailfish.Silica 1.0
import ".."
import "../.."
/**
* Album details for "narrow" devices such as phones in portrait mode.
*/
Item {
property ListView listview
property real releaseYear
2021-01-17 20:11:55 +00:00
property alias albumArt: albumArtImage.source
2020-10-27 01:35:50 +00:00
property string albumArtist
property real duration
property int songCount
property string name
2021-01-17 20:11:55 +00:00
property alias blurhash : albumArtImage.blurhash
property bool twoColumns
2020-10-27 01:35:50 +00:00
2021-01-17 20:11:55 +00:00
readonly property real smallSize: albumHeader.height
readonly property real bigSize: listHeader.width
2020-10-27 01:35:50 +00:00
id: listHeader
width: parent.width
//spacing: Theme.paddingLarge
2021-01-17 20:11:55 +00:00
Connections {
target: listview
onVerticalVelocityChanged: {
if (!listview.draggingVertically && Math.abs(listview.verticalVelocity) < Theme.itemSizeMedium
&& listview.contentY < -smallSize) {
if (listview.verticalVelocity > 0) {
listview.cancelFlick()
listviewShrinkAnimation.start()
} else if (listview.verticalVelocity < 0){
listview.cancelFlick()
listviewGrowAnimation.start()
}
}
}
onDraggingVerticallyChanged: {
if (!listview.draggingVertically && listview.verticalVelocity == 0) {
if (-smallSize - listview.contentY > -bigSize - listview.contentY) {
listviewShrinkAnimation.start()
} else {
listviewGrowAnimation.start()
}
}
}
}
2020-10-27 01:35:50 +00:00
MouseArea {
2021-01-17 20:11:55 +00:00
anchors.fill: albumArtImage
2020-10-27 01:35:50 +00:00
onClicked: {
2021-01-17 20:11:55 +00:00
if (listview.contentY < -bigSize + 10) {
listviewShrinkAnimation.start()
2020-10-27 01:35:50 +00:00
} else {
2021-01-17 20:11:55 +00:00
listviewGrowAnimation.start()
2020-10-27 01:35:50 +00:00
}
}
}
2021-01-17 20:11:55 +00:00
NumberAnimation {
id: listviewShrinkAnimation
target: listview
property: "contentY"
easing.type: Easing.OutCubic
to: -smallSize
}
NumberAnimation {
id: listviewGrowAnimation
target: listview
property: "contentY"
easing.type: Easing.OutCubic
to: -bigSize
2020-10-27 01:35:50 +00:00
}
2021-01-17 20:11:55 +00:00
2020-10-27 01:35:50 +00:00
PageHeader {
id: albumHeader
width: parent.width - Theme.horizontalPageMargin - height
title: name
//: Short description of the album: %1 -> album artist, %2 -> amount of songs, %3 -> duration, %4 -> release year
description: qsTr("%1\n%2 songs | %3 | %4")
.arg(albumArtist)
.arg(songCount)
.arg(Utils.ticksToText(duration))
//: Unknown album release year
.arg(releaseYear >= 0 ? releaseYear : qsTr("Unknown year"))
}
2021-01-17 20:11:55 +00:00
RemoteImage {
id: albumArtImage
anchors {
right: parent.right
bottom: parent.bottom
}
sourceSize.width: listHeader.width
sourceSize.height: listHeader.width
fillMode: Image.PreserveAspectFit
opacity: 1
clip: true
}
2020-10-27 01:35:50 +00:00
states: [
State {
2021-01-17 20:11:55 +00:00
name: "art"
when: albumArtImage.status != Image.Null && !twoColumns
2020-10-27 01:35:50 +00:00
PropertyChanges {
2021-01-17 20:11:55 +00:00
target: listview
//contentY: -smallSize
topMargin: Screen.width - smallSize
bottomMargin: listview.contentHeight < listview.height ? listview.height - listview.contentHeight : 0
2020-10-27 01:35:50 +00:00
}
PropertyChanges {
2021-01-17 20:11:55 +00:00
target: albumArtImage
opacity: 1
width: height
height: smallSize + -(Math.min(listview.contentY + smallSize, 0) / (listview.topMargin)) * (bigSize - smallSize)
2020-10-27 01:35:50 +00:00
}
PropertyChanges {
2021-01-17 20:11:55 +00:00
target: listHeader
height: smallSize
visible: true
2020-10-27 01:35:50 +00:00
}
PropertyChanges {
2021-01-17 20:11:55 +00:00
target: albumHeader
opacity: 1.0 - Math.min(1.0, Math.max(0.0, -Math.min(listview.contentY + smallSize, 0) / (listview.topMargin)))
anchors.rightMargin: Theme.paddingMedium + albumArtImage.width
2020-10-27 01:35:50 +00:00
}
AnchorChanges {
target: albumHeader
2021-01-17 20:11:55 +00:00
anchors.top: albumArtImage.top
2020-10-27 01:35:50 +00:00
anchors.left: undefined
2021-01-17 20:11:55 +00:00
anchors.right: parent.right
2020-10-27 01:35:50 +00:00
}
},
State {
2021-01-17 20:11:55 +00:00
name: "noArt"
when: albumArtImage.status == Image.Null && !twoColumns
2020-10-27 01:35:50 +00:00
PropertyChanges {
2021-01-17 20:11:55 +00:00
target: albumArtImage
opacity: 0
2020-10-27 01:35:50 +00:00
}
PropertyChanges {
target: listHeader
2021-01-17 20:11:55 +00:00
height: smallSize
2020-10-27 01:35:50 +00:00
}
PropertyChanges {
target: albumHeader
2021-01-17 20:11:55 +00:00
width: parent.width - Theme.horizontalPageMargin * 2
2020-10-27 01:35:50 +00:00
opacity: 1
}
AnchorChanges {
target: albumHeader
2021-01-17 20:11:55 +00:00
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
2020-10-27 01:35:50 +00:00
}
2021-01-17 20:11:55 +00:00
2020-10-27 01:35:50 +00:00
},
State {
2021-01-17 20:11:55 +00:00
name: "hidden"
when: twoColumns
2020-10-27 01:35:50 +00:00
PropertyChanges {
2021-01-17 20:11:55 +00:00
target: listview
topMargin: 0
2020-10-27 01:35:50 +00:00
}
2021-01-17 20:11:55 +00:00
2020-10-27 01:35:50 +00:00
PropertyChanges {
2021-01-17 20:11:55 +00:00
target: listHeader
height: 0
visible: false
2020-10-27 01:35:50 +00:00
}
}
]
transitions: [
2021-01-17 20:11:55 +00:00
/*Transition {
2020-10-27 01:35:50 +00:00
from: "noArt"
// No transitions from "noArt", otherwise the layout animates every load
2021-01-17 20:11:55 +00:00
},*/
Transition {
from: "hidden"
SequentialAnimation {
PauseAnimation {
duration: 50
}
ScriptAction {
script: {
if (listview.contentY < 10) {
listviewShrinkAnimation.start()
}
}
}
}
},
Transition {
to: "noArt"
SequentialAnimation {
PauseAnimation {
duration: 10
}
ScriptAction {
script: {
if (listview.contentY < 10) {
listview.contentY = -smallSize
}
}
}
}
},
Transition {
to: "art"
SequentialAnimation {
PauseAnimation {
duration: 10
}
ScriptAction {
script: {
if (listview.contentY < 10) {
listview.contentY = -smallSize
}
}
}
}
2020-10-27 01:35:50 +00:00
},
Transition {
OpacityAnimator { target: albumHeader}
OpacityAnimator { target: _albumArt}
NumberAnimation {
properties: "width,height,contentY"
//velocity: 1600
duration: 300
easing.type: Easing.OutQuad
}
AnchorAnimation {}
}
]
}