From 6d95b00bd7a46efcbe273ab9a0ff9c23a87eb8ff Mon Sep 17 00:00:00 2001 From: Benjamin Arnaud <benjamin.arnaud@videolabs.io> Date: Thu, 2 Sep 2021 12:02:28 +0200 Subject: [PATCH] qml: Create MusicArtistDelegate --- modules/gui/qt/Makefile.am | 1 + .../medialibrary/qml/MusicArtistDelegate.qml | 172 ++++++++++++++++++ .../medialibrary/qml/MusicArtistsAlbums.qml | 104 +---------- modules/gui/qt/vlc.qrc | 1 + po/POTFILES.in | 1 + 5 files changed, 176 insertions(+), 103 deletions(-) create mode 100644 modules/gui/qt/medialibrary/qml/MusicArtistDelegate.qml diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am index 8fd55c87efd4..456f245ae0d9 100644 --- a/modules/gui/qt/Makefile.am +++ b/modules/gui/qt/Makefile.am @@ -698,6 +698,7 @@ libqt_plugin_la_QML = \ gui/qt/medialibrary/qml/MusicAlbumsDisplay.qml \ gui/qt/medialibrary/qml/MusicAlbumsGridExpandDelegate.qml \ gui/qt/medialibrary/qml/MusicArtist.qml \ + gui/qt/medialibrary/qml/MusicArtistDelegate.qml \ gui/qt/medialibrary/qml/MusicArtistsAlbums.qml \ gui/qt/medialibrary/qml/MusicAllArtists.qml \ gui/qt/medialibrary/qml/MusicArtistsDisplay.qml \ diff --git a/modules/gui/qt/medialibrary/qml/MusicArtistDelegate.qml b/modules/gui/qt/medialibrary/qml/MusicArtistDelegate.qml new file mode 100644 index 000000000000..de7270717b4d --- /dev/null +++ b/modules/gui/qt/medialibrary/qml/MusicArtistDelegate.qml @@ -0,0 +1,172 @@ +/***************************************************************************** + * Copyright (C) 2020 VLC authors and VideoLAN + * + * Authors: Benjamin Arnaud <bunjee@omega.gg> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * ( at your option ) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +import QtQuick 2.11 +import QtQuick.Controls 2.4 +import QtQuick.Layouts 1.11 + +import org.videolan.controls 0.1 + +import "qrc:///widgets/" as Widgets +import "qrc:///style/" + +Control { + id: root + + // Properties + + /* required */ property var artistModel + + property bool isCurrent: false + + // Aliases + // Private + + property alias _isHover: mouseArea.containsMouse + + // Signals + + signal itemClicked(variant mouse) + + signal itemDoubleClicked(variant mouse) + + // Settings + + height: VLCStyle.play_cover_small + (VLCStyle.margin_xsmall * 2) + + // Childs + + background: Widgets.AnimatedBackground { + id: background + + active: visualFocus + + backgroundColor: { + if (isCurrent) + return VLCStyle.colors.gridSelect; + else if (_isHover) + return VLCStyle.colors.listHover; + else + return VLCStyle.colors.setColorAlpha(VLCStyle.colors.listHover, 0); + } + } + + contentItem: MouseArea { + id: mouseArea + + hoverEnabled: true + + drag.axis: Drag.XAndYAxis + + drag.target: Widgets.DragItem { + function updateComponents(maxCovers) { + return { + covers: [{ artwork: (model.cover) ? model.cover + : VLCStyle.noArtArtistSmall }], + + title: (model.name) ? model.name + : i18n.qtr("Unknown artist"), + + count: 1 + } + } + + function getSelectedInputItem() { + return artistModel.getItemsForIndexes([artistModel.index(index, 0)]); + } + } + + drag.onActiveChanged: { + var dragItem = drag.target; + + if (drag.active == false) + dragItem.Drag.drop(); + + dragItem.Drag.active = drag.active; + } + + onPositionChanged: { + if (drag.active == false) return; + + var pos = drag.target.parent.mapFromItem(root, mouseX, mouseY); + + drag.target.x = pos.x + VLCStyle.dragDelta; + drag.target.y = pos.y + VLCStyle.dragDelta; + } + + onClicked: itemClicked(mouse) + + onDoubleClicked: itemDoubleClicked(mouse) + + Widgets.CurrentIndicator { + height: parent.height - (margin * 2) + + margin: VLCStyle.dp(4, VLCStyle.scale) + + visible: isCurrent + } + + RowLayout { + anchors.fill: parent + + anchors.leftMargin: VLCStyle.margin_normal + anchors.rightMargin: VLCStyle.margin_normal + anchors.topMargin: VLCStyle.margin_xsmall + anchors.bottomMargin: VLCStyle.margin_xsmall + + spacing: VLCStyle.margin_xsmall + + RoundImage { + width: VLCStyle.play_cover_small + height: width + + radius: width + + source: (model.cover) ? model.cover + : VLCStyle.noArtArtistSmall + + Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter + + Rectangle { + anchors.fill: parent + + radius: VLCStyle.play_cover_small + + color: "transparent" + + border.width: VLCStyle.dp(1, VLCStyle.scale) + + border.color: (isCurrent || _isHover) ? VLCStyle.colors.accent + : VLCStyle.colors.roundPlayCoverBorder + } + } + + Widgets.ListLabel { + text: (model.name) ? model.name + : i18n.qtr("Unknown artist") + + color: background.foregroundColor + + Layout.fillWidth: true + Layout.fillHeight: true + } + } + } +} diff --git a/modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml b/modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml index 427a7290d9aa..b5743a172df8 100644 --- a/modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml +++ b/modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml @@ -141,109 +141,7 @@ FocusScope { topPadding: VLCStyle.margin_xlarge } - delegate: Widgets.AnimatedBackground { - id: item - - property bool _highlighted: mouseArea.containsMouse || this.activeFocus - - height: VLCStyle.play_cover_small + (VLCStyle.margin_xsmall * 2) - width: artistList.width - active: false - backgroundColor: _highlighted ? VLCStyle.colors.bgHover : "transparent" - foregroundColor: _highlighted ? VLCStyle.colors.bgHoverText : VLCStyle.colors.text - - Widgets.CurrentIndicator { - visible: item.ListView.isCurrentItem - } - - RowLayout { - spacing: VLCStyle.margin_xsmall - anchors { - fill: parent - leftMargin: VLCStyle.margin_normal - rightMargin: VLCStyle.margin_normal - topMargin: VLCStyle.margin_xsmall - bottomMargin: VLCStyle.margin_xsmall - } - - RoundImage { - source: model.cover || VLCStyle.noArtArtistSmall - height: VLCStyle.play_cover_small - width: VLCStyle.play_cover_small - radius: VLCStyle.play_cover_small - - Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter - - Rectangle { - anchors.fill: parent - color: "transparent" - radius: VLCStyle.play_cover_small - border.width: VLCStyle.dp(1, VLCStyle.scale) - border.color: !_highlighted ? VLCStyle.colors.roundPlayCoverBorder : VLCStyle.colors.accent - } - } - - Widgets.ListLabel { - text: model.name || i18n.qtr("Unknown artist") - color: item.foregroundColor - - Layout.fillWidth: true - Layout.fillHeight: true - } - } - - MouseArea { - id: mouseArea - - anchors.fill: parent - hoverEnabled: true - - onClicked: { - selectionModel.updateSelection( mouse.modifiers , artistList.currentIndex, index) - artistList.currentIndex = index - artistList.forceActiveFocus() - } - - onDoubleClicked: { - if (mouse.buttons === Qt.LeftButton) - medialib.addAndPlay( model.id ) - else - albumSubView.forceActiveFocus() - } - - drag.axis: Drag.XAndYAxis - drag.target: Widgets.DragItem { - function updateComponents(maxCovers) { - return { - covers: [{artwork: model.cover || VLCStyle.noArtArtistSmall}], - title: model.name || i18n.qtr("Unknown artist"), - count: 1 - } - } - - function getSelectedInputItem() { - return artistModel.getItemsForIndexes([artistModel.index(index, 0)]) - } - } - - drag.onActiveChanged: { - var dragItem = drag.target - - if (!drag.active) - dragItem.Drag.drop() - - dragItem.Drag.active = drag.active - } - - onPositionChanged: { - if (drag.active) { - var pos = drag.target.parent.mapFromItem(item, mouseX, mouseY) - drag.target.x = pos.x + 12 - drag.target.y = pos.y + 12 - } - } - } - } + delegate: MusicArtistDelegate {} Behavior on width { SmoothedAnimation { diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc index 919bbdfe101a..dbcc48101d75 100644 --- a/modules/gui/qt/vlc.qrc +++ b/modules/gui/qt/vlc.qrc @@ -293,6 +293,7 @@ <file alias="MusicAlbumsDisplay.qml">medialibrary/qml/MusicAlbumsDisplay.qml</file> <file alias="MusicAlbumsGridExpandDelegate.qml">medialibrary/qml/MusicAlbumsGridExpandDelegate.qml</file> <file alias="MusicArtist.qml">medialibrary/qml/MusicArtist.qml</file> + <file alias="MusicArtistDelegate.qml">medialibrary/qml/MusicArtistDelegate.qml</file> <file alias="MusicArtistsAlbums.qml">medialibrary/qml/MusicArtistsAlbums.qml</file> <file alias="MusicAllArtists.qml">medialibrary/qml/MusicAllArtists.qml</file> <file alias="MusicArtistsDisplay.qml">medialibrary/qml/MusicArtistsDisplay.qml</file> diff --git a/po/POTFILES.in b/po/POTFILES.in index 307e44c3617d..a61f30ecf29d 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -828,6 +828,7 @@ modules/gui/qt/medialibrary/qml/MusicAlbums.qml modules/gui/qt/medialibrary/qml/MusicAlbumsDisplay.qml modules/gui/qt/medialibrary/qml/MusicAlbumsGridExpandDelegate.qml modules/gui/qt/medialibrary/qml/MusicArtist.qml +modules/gui/qt/medialibrary/qml/MusicArtistDelegate.qml modules/gui/qt/medialibrary/qml/MusicAllArtists.qml modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml -- GitLab