1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2024-11-01 07:35:17 +00:00
harbour-sailfin/sailfish/qml/components/music/NarrowAlbumCover.qml

255 lines
7.7 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 {
id: listHeader
2020-10-27 01:35:50 +00:00
property ListView listview
2021-01-17 20:11:55 +00:00
property alias albumArt: albumArtImage.source
2020-10-27 01:35:50 +00:00
property string name
2021-01-17 20:11:55 +00:00
property alias blurhash : albumArtImage.blurhash
property bool twoColumns
2021-09-10 03:18:05 +00:00
property real aspectRatio
property string description
readonly property real smallHeight: albumHeader.height
readonly property real smallWidth: smallHeight * aspectRatio
readonly property real bigWidth: listHeader.width
readonly property real bigHeight: bigWidth / aspectRatio
2020-10-27 01:35:50 +00:00
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 < -smallHeight) {
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 (-smallHeight - listview.contentY > -bigHeight - 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: {
if (listview.contentY < -bigHeight + 10) {
2021-01-17 20:11:55 +00:00
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: -smallHeight
2021-01-17 20:11:55 +00:00
}
NumberAnimation {
id: listviewGrowAnimation
target: listview
property: "contentY"
easing.type: Easing.OutCubic
to: -bigHeight
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
description: listHeader.description
2020-10-27 01:35:50 +00:00
}
2021-01-17 20:11:55 +00:00
RemoteImage {
id: albumArtImage
anchors {
right: parent.right
bottom: parent.bottom
}
aspectRatio: listHeader.aspectRatio
2021-01-17 20:11:55 +00:00
sourceSize.width: listHeader.width
sourceSize.height: listHeader.width / aspectRatio
2021-01-17 20:11:55 +00:00
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: -smallHeight
topMargin: bigHeight - smallHeight
2021-01-17 20:11:55 +00:00
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 * aspectRatio
height: smallHeight + -(Math.min(listview.contentY + smallHeight , 0) / (listview.topMargin)) * (bigHeight - smallHeight)
2020-10-27 01:35:50 +00:00
}
PropertyChanges {
2021-01-17 20:11:55 +00:00
target: listHeader
height: smallHeight
2021-01-17 20:11:55 +00:00
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 + smallHeight, 0) / (listview.topMargin)))
2021-01-17 20:11:55 +00:00
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
height: smallHeight
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 = -smallHeight
2021-01-17 20:11:55 +00:00
}
}
}
}
},
Transition {
to: "art"
SequentialAnimation {
PauseAnimation {
duration: 10
}
ScriptAction {
script: {
if (listview.contentY < 10) {
listview.contentY = -smallHeight
2021-01-17 20:11:55 +00:00
}
}
}
}
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 {}
}
]
}