[vlc-commits] [Git][videolan/vlc][master] 2 commits: qml: only use RoundImage in DragItem

Steve Lhomme (@robUx4) gitlab at videolan.org
Tue Aug 6 10:19:17 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
72f086c9 by Pierre Lamot at 2024-08-06T09:39:09+00:00
qml: only use RoundImage in DragItem

network cover specialized item can easily be replaced by the default
implementation, as both its artwork and fallback image are URI.

DragItem shows the artworks in a rounded shape and low resolution, the default
fill policy of roundimage (PreserveAspectCrop) gives good results for this use
case

fixes: #28301

- - - - -
101dd0f4 by Pierre Lamot at 2024-08-06T09:39:09+00:00
qml: remove Qt5Compat dependecy from DragItem

- - - - -


3 changed files:

- modules/gui/qt/network/qml/BrowseTreeDisplay.qml
- modules/gui/qt/network/qml/NetworkThumbnailItem.qml
- modules/gui/qt/widgets/qml/DragItem.qml


Changes:

=====================================
modules/gui/qt/network/qml/BrowseTreeDisplay.qml
=====================================
@@ -94,10 +94,33 @@ MainViewLoader {
         defaultText:  qsTr("Unknown Share")
 
         coverProvider: function(index, data) {
-            // this is used to provide context to NetworkCustomCover
-            // indexData is networkModel (model data) for this index
-            // cover is our custom cover that will be loaded insted of default DragItem cover
-            return {"indexData": data, "cover": custom_cover}
+            function _baseUri(type) {
+                switch (type) {
+                case NetworkMediaModel.TYPE_DISC:
+                    return "qrc:///sd/disc.svg"
+                case NetworkMediaModel.TYPE_CARD:
+                    return "qrc:///sd/capture-card.svg"
+                case NetworkMediaModel.TYPE_STREAM:
+                    return "qrc:///sd/stream.svg"
+                case NetworkMediaModel.TYPE_PLAYLIST:
+                    return "qrc:///sd/playlist.svg"
+                case NetworkMediaModel.TYPE_FILE:
+                    return "qrc:///sd/file.svg"
+                default:
+                    return "qrc:///sd/directory.svg"
+                }
+            }
+
+            const fallbackImage = SVGColorImage.colorize(_baseUri(data.type))
+                .background(networkDragItem.colorContext.bg.secondary)
+                .color1(networkDragItem.colorContext.fg.primary)
+                .accent(networkDragItem.colorContext.accent)
+                .uri()
+
+            return {
+                artwork: data.artwork,
+                fallback: fallbackImage
+            }
         }
 
         onRequestData: (indexes, resolve, reject) => {
@@ -111,25 +134,6 @@ MainViewLoader {
                 model.getItemsForIndexes(indexes)
             )
         }
-
-        Component {
-            id: custom_cover
-
-            NetworkCustomCover {
-                networkModel: model.indexData
-
-                width: networkDragItem.coverSize
-                height: networkDragItem.coverSize
-
-                // we can not change the size of cover and shodows from here,
-                // so for best visual use scale image to fit
-                fillMode: Image.PreserveAspectCrop
-
-                bgColor: networkDragItem.colorContext.bg.secondary
-                color1: networkDragItem.colorContext.fg.primary
-                accent: networkDragItem.colorContext.accent
-            }
-        }
     }
 
     Component{


=====================================
modules/gui/qt/network/qml/NetworkThumbnailItem.qml
=====================================
@@ -90,6 +90,8 @@ Widgets.TableRowDelegate {
                 rectHeight: artwork.paintedHeight
             }
 
+            //FIXME: implement fillMode in RoundImage and use MediaCover here instead
+            //or directly TableCollumns.titleHeaderDelegate in place of NetworkThumbnailItem
             NetworkCustomCover {
                 id: artwork
 


=====================================
modules/gui/qt/widgets/qml/DragItem.qml
=====================================
@@ -21,9 +21,6 @@ import QtQuick
 import QtQuick.Templates as T
 import QtQml.Models
 
-import Qt5Compat.GraphicalEffects
-
-
 import VLC.MainInterface
 import VLC.Style
 import VLC.Widgets as Widgets
@@ -51,7 +48,7 @@ Item {
 
     property string defaultText: qsTr("Unknown")
 
-    // function(index, data) - returns cover for the index in the model in the form {artwork: <string> (file-name), cover: <component>}
+    // function(index, data) - returns cover for the index in the model in the form {artwork: <string> (file-name), fallback: <string> (file-name)}
     property var coverProvider: null
 
     // string => role
@@ -157,7 +154,10 @@ Item {
         }
 
         if (covers.length === 0)
-            covers.push({artwork: dragItem.defaultCover})
+            covers.push({
+                artwork: "",
+                fallback: dragItem.defaultCover
+            })
 
         _covers = covers
     }
@@ -177,7 +177,10 @@ Item {
         if (!!dragItem.coverProvider)
             return dragItem.coverProvider(index, data)
         else
-            return {artwork: data[dragItem.coverRole] || dragItem.defaultCover}
+            return {
+                artwork: data[dragItem.coverRole] || dragItem.defaultCover,
+                fallback: dragItem.defaultCover
+            }
     }
 
     function _startNativeDrag() {
@@ -415,44 +418,26 @@ Item {
             }
 
             Widgets.RoundImage {
-                id: fallbackCover
+                id: artworkCover
 
                 anchors.centerIn: parent
                 width: coverSize
                 height: coverSize
                 radius: bg.radius
-                source: dragItem.defaultCover
-                sourceSize.width: width
-                sourceSize.height: height
-                visible: !loader.visible
+                source: modelData.artwork ?? ""
+                sourceSize: dragItem.imageSourceSize ?? Qt.size(width, height)
             }
 
-            Loader {
-                id: loader
-
-                // parent may provide extra data with covers
-                property var model: modelData
+            Widgets.RoundImage {
+                id: fallbackCover
 
                 anchors.centerIn: parent
-
-                visible: (status === Loader.Ready)
-                         && (!("status" in item) || (item.status === Image.Ready))
-
-                sourceComponent: (!modelData.artwork || modelData.artwork.toString() === "") ? modelData.cover : artworkLoader
-                layer.enabled: true
-                layer.effect: OpacityMask {
-                    maskSource: Rectangle {
-                        width: bg.width
-                        height: bg.height
-                        radius: bg.radius
-                        visible: false
-                    }
-                }
-
-                onItemChanged: {
-                    if (modelData.artwork && modelData.artwork.toString() !== "")
-                        item.source = modelData.artwork
-                }
+                width: coverSize
+                height: coverSize
+                radius: bg.radius
+                source: modelData.fallback ?? defaultCover
+                sourceSize: dragItem.imageSourceSize ?? Qt.size(width, height)
+                visible: artworkCover.status !== Image.Ready
             }
 
             Rectangle {
@@ -510,14 +495,4 @@ Item {
         color: theme.fg.secondary
     }
 
-    Component {
-        id: artworkLoader
-
-        ScaledImage {
-            fillMode: Image.PreserveAspectCrop
-            width: coverSize
-            height: coverSize
-            cache: false
-        }
-    }
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6c2b7c06625b80f8074cf2a131a8a2740ec88f48...101dd0f44148cb871ec61d00b3883a37b3500550

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6c2b7c06625b80f8074cf2a131a8a2740ec88f48...101dd0f44148cb871ec61d00b3883a37b3500550
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list