Debian Codegraph @

src/context/applets/similarartists/package/contents/ui/main.qml

raw
1 /****************************************************************************************
2 * Copyright (c) 2024 Tuomas Nurmi <[email protected]> *
3 * *
4 * This program is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU General Public License as *
6 * published by the Free Software Foundation; either version 2 of *
7 * the License or (at your option) version 3 or any later version *
8 * accepted by the membership of KDE e.V. (or its successor approved *
9 * by the membership of KDE e.V.), which shall act as a proxy *
10 * defined in Section 14 of version 3 of the license. *
11 * *
12 * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
14 * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License along with *
17 * this program. If not, see <http://www.gnu.org/licenses/>. *
18 ****************************************************************************************/
19
20 import QtQuick 2.15
21 import QtQuick.Controls 2.15
22 import QtQuick.Layouts 1.15
23 import org.kde.kirigami 2.16 as Kirigami
24 import org.kde.amarok.qml 1.0 as AmarokQml
25 import org.kde.amarok.similarartists 1.0
26
27 AmarokQml.Applet {
28 id: applet
29
30 RowLayout {
31 anchors.fill: parent
32 Layout.margins: applet.spacing
33
34 ColumnLayout {
35 Layout.margins: applet.spacing
36 Layout.maximumWidth: Math.min(parent.width / 2, 300)
37
38 Label {
39 id: artistLabel
40 text: SimilarArtistsEngine.currentTarget ? i18nc("%1 is the artist for which similars are currently shown", "Similar to <b>%1</b>", SimilarArtistsEngine.currentTarget) : ""
41 width: 100
42 }
43 ListView {
44 id: similarArtistsList
45 model: SimilarArtistsEngine.model
46 visible: SimilarArtistsEngine.currentTarget
47 Layout.fillHeight: true
48 interactive: false
49 contentHeight: height
50 boundsBehavior: Flickable.StopAtBounds
51 width: parent.width
52 delegate: Rectangle {
53 height: ( applet.height - artistLabel.height - Kirigami.Units.smallSpacing ) / ( SimilarArtistsEngine.maximumArtists + 1 )
54 width: applet.width - Kirigami.Units.smallSpacing * 4 - ( currentlyHighlighted && currentlyHighlighted.visible ? currentlyHighlighted.width : 0 )
55 color: palette.window
56 MouseArea {
57 height: parent.height
58 hoverEnabled: true
59 anchors.fill: parent
60 z: 1
61
62 Rectangle {
63 anchors.fill: parent
64 color: Kirigami.Theme.highlightColor
65 opacity: currentlyHighlighted.header === name ? 0.2 : parent.containsMouse ? 0.1 : 0.0
66 z: 1
67 }
68
69 onClicked:
70 {
71 if( currentlyHighlighted.header == name )
72 {
73 currentlyHighlighted.header = ""
74 return
75 }
76 currentlyHighlighted.header = name;
77 currentlyHighlighted.lastfmLink = link;
78 currentlyHighlighted.cover = Qt.binding(function() { return albumcover });
79 currentlyHighlighted.bio = Qt.binding(function() { return bio });
80 currentlyHighlighted.counts = Qt.binding(function() {
81 if( listeners.length == 0 )
82 return ""
83 let str = i18nc( "Artist's listener and playcount from Last.fm", "%1 listeners<br>%2 plays", listeners, plays )
84 if( parseInt( ownplays ) > 0 )
85 str += i18nc( "Number of user's own scrobbles of an artist on Last.fm, appended to previous string if not 0", "<br>%1 plays by you", ownplays )
86 return "<i>" + str + "</i>"
87 });
88 // unfortunately disabled in last.fm api since 2019 or so
89 // currentlyHighlighted.image = image;
90 }
91
92 ProgressBar {
93 id: matchBar
94 from: 0
95 to: 100
96 width: parent.width / 3
97 anchors.left: parent.left
98 anchors.verticalCenter: parent.verticalCenter
99 value: match
100 }
101
102 Label {
103 id: nameLabel
104 text: name
105 elide: Text.ElideRight
106 anchors.left: matchBar.right
107 anchors.right: currentlyHighlighted.visible ? parent.right : undefined
108 anchors.verticalCenter: parent.verticalCenter
109 }
110 }
111 }
112 }
113 }
114 Rectangle {
115 id: currentlyHighlighted
116 Layout.fillHeight: true
117 Layout.fillWidth: true
118 property alias header: headerLabel.text
119 property alias bio: bioText.text
120 property alias cover: albumCover.source
121 property alias counts: countLabel.text
122 property alias lastfmLink: lastfmLink.url
123 color: palette.base
124 radius: Kirigami.Units.smallSpacing / 2
125 visible: header.length > 0
126
127 Label {
128 id: headerLabel
129 anchors.topMargin: applet.spacing
130 anchors.top: parent.top
131 anchors.left: parent.left
132 font.weight: Font.Bold
133 }
134 RoundButton {
135 id: lastfmLink
136 visible: headerLabel.text.length > 0
137 property string url
138 anchors.left: parent.left
139 anchors.top: headerLabel.bottom
140 width: height * 2
141 icon.width: width * 0.8
142 icon.source: applet.imageUrl("lastfm.png")
143 radius: Kirigami.Units.smallSpacing
144 onClicked: if(url) { Qt.openUrlExternally(url) }
145 }
146 Label {
147 id: countLabel
148 anchors.top: lastfmLink.bottom
149 anchors.left: parent.left
150 }
151
152 Item {
153 id: coverRect
154
155 visible: albumCover.status == Image.Ready
156 anchors.top: countLabel.bottom
157 anchors.bottom: parent.bottom
158 anchors.left: parent.left
159 width: albumCover.width + Kirigami.Units.smallSpacing
160
161 Rectangle {
162 id: albumCoverBg
163 width: parent.width
164 height: albumCover.paintedHeight + Kirigami.Units.smallSpacing
165 anchors.centerIn: parent
166 color: "white"
167 radius: Kirigami.Units.smallSpacing / 2
168 border.width: albumCoverMouse.containsMouse ? 3 : 1
169 border.color: albumCoverMouse.containsMouse ? Kirigami.Theme.highlightColor : applet.palette.light
170 MouseArea {
171 id: albumCoverMouse
172 anchors.fill: parent
173 hoverEnabled: true
174 onClicked: SimilarArtistsEngine.navigateToArtist( headerLabel.text )
175 }
176 }
177 Image {
178 id: albumCover
179 anchors.margins: albumCoverBg.radius
180 anchors.centerIn: parent
181 height: parent.height - Kirigami.Units.smallSpacing
182 fillMode: Image.PreserveAspectFit
183 }
184 }
185
186 Flickable {
187 clip: true
188 width: parent.width - Math.max( coverRect.width, headerLabel.width, countLabel.width ) - Kirigami.Units.smallSpacing
189 anchors.right: parent.right
190 anchors.top: parent.top
191 anchors.bottom: parent.bottom
192 anchors.topMargin: applet.spacing
193 contentHeight: bioText.height
194 Label {
195 id: bioText
196 width: parent.width
197 wrapMode: Text.Wrap
198 onLinkActivated: Qt.openUrlExternally(link)
199 }
200 }
201 }
202 }
203 SystemPalette {
204 id: palette
205 }
206 }