[vlc-commits] [Git][videolan/vlc][master] qml: fix drag item no longer showing any image regression

Steve Lhomme (@robUx4) gitlab at videolan.org
Mon Sep 16 06:11:18 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
45b36521 by Fatih Uzunoglu at 2024-09-16T05:58:28+00:00
qml: fix drag item no longer showing any image regression

Since 72f086c9, `RoundImage` has been used in `DragItem`.
However, it only works asynchronously and by the time
the input items are resolved, `RoundImage` instance(s)
are still in the progress of loading the image.

I added an intermediate state to wait for images to be
loaded. If the loading takes too much time, then the
timer is going to start the drag, so this change does
not make drag initalization synchronous.

- - - - -


1 changed file:

- modules/gui/qt/widgets/qml/DragItem.qml


Changes:

=====================================
modules/gui/qt/widgets/qml/DragItem.qml
=====================================
@@ -248,6 +248,8 @@ Item {
         signal startDrag()
         signal stopDrag()
 
+        signal allImagesAreLoaded()
+
         //internal signals
         signal resolveData(var requestId, var indexes)
         signal resolveInputItems(var requestId, var indexes)
@@ -258,7 +260,8 @@ Item {
             stopDrag: stopDrag,
             resolveData: resolveData,
             resolveInputItems: resolveInputItems,
-            resolveFailed: resolveFailed
+            resolveFailed: resolveFailed,
+            allImagesAreLoaded: allImagesAreLoaded
         })
 
         initialState: fsmDragInactive
@@ -354,12 +357,31 @@ Item {
                         action: (requestId, items) => {
                             dragItem._setInputItems(items)
                         },
-                        target: fsmLoadingDone,
+                        target: fsmWaitingForImages,
                     },
                     resolveFailed: fsmLoadingFailed
                 })
             }
 
+            FSMState {
+                id: fsmWaitingForImages
+
+                transitions: ({
+                    allImagesAreLoaded: {
+                        target: fsmLoadingDone
+                    }
+                })
+
+                function enter() {
+                    if (coverRepeater.notReadyCount === 0) {
+                        // By the time the state changes
+                        // the images might have been
+                        // already loaded:
+                        fsm.allImagesAreLoaded()
+                    }
+                }
+            }
+
             FSMState {
                 id: fsmLoadingDone
 
@@ -405,6 +427,19 @@ Item {
 
         model: dragItem._covers
 
+        property int notReadyCount: count
+
+        onModelChanged: {
+            notReadyCount = count
+        }
+
+        onNotReadyCountChanged: {
+            if (notReadyCount === 0) {
+                // All the images are loaded, don't wait anymore
+                fsm.allImagesAreLoaded()
+            }
+        }
+
         Item {
             required property var modelData
             required property int index
@@ -437,18 +472,18 @@ Item {
                 radius: bg.radius
                 source: modelData.artwork ?? ""
                 sourceSize: dragItem.imageSourceSize ?? Qt.size(width, height)
-            }
-
-            Widgets.RoundImage {
-                id: fallbackCover
 
-                anchors.centerIn: parent
-                width: coverSize
-                height: coverSize
-                radius: bg.radius
-                source: modelData.fallback ?? defaultCover
-                sourceSize: dragItem.imageSourceSize ?? Qt.size(width, height)
-                visible: artworkCover.status !== Image.Ready
+                onStatusChanged: {
+                    if (status === Widgets.RoundImage.Ready)
+                        coverRepeater.notReadyCount -= 1
+                    else if (status === Widgets.RoundImage.Error) {
+                        const fallbackSource = modelData.fallback ?? defaultCover
+                        if (source === fallbackSource)
+                            coverRepeater.notReadyCount -= 1
+                        else
+                            source = fallbackSource
+                    }
+                }
             }
 
             Rectangle {



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/45b36521edbac9d375e915ceda8ff29dda5cc416

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/45b36521edbac9d375e915ceda8ff29dda5cc416
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