Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
5f1d6f6a by Fatih Uzunoglu at 2025-02-08T13:32:13+00:00
qml: use hover handlers in `FadingEdgeForListView`

This makes it possible to detect hovering better,
as `firstVisibleItem` and `lastVisibleItem` do not
work well at all times.

- - - - -
8af08453 by Fatih Uzunoglu at 2025-02-08T13:32:13+00:00
qml: introduce `Helpers::itemIntersects(Item, rect)`

- - - - -
bf5e2572 by Fatih Uzunoglu at 2025-02-08T13:32:13+00:00
qml: get rid of `firstVisibleItem` and `lastVisibleItem` in 
`FadingEdgeForListView.qml`

These properties are not reliable.

- - - - -


2 changed files:

- modules/gui/qt/util/qml/Helpers.qml
- modules/gui/qt/widgets/qml/FadingEdgeForListView.qml


Changes:

=====================================
modules/gui/qt/util/qml/Helpers.qml
=====================================
@@ -115,4 +115,13 @@ QtObject {
         return (obj?.length !== undefined) ?? false
     }
 
+    // Similar to Item::contains(), but accepts area (rectangle):
+    function itemIntersects(item: Item, area: rect) : bool {
+        if (!item)
+            return false
+        if (area.width <= 0.0 || area.height <= 0.0)
+            return false
+        return !(((item.x < (area.x + area.width)) && ((item.x + item.width) > 
area.x)) &&
+                 ((item.y < (area.y + area.height)) && ((item.y + item.height) 
> area.y)))
+    }
 }


=====================================
modules/gui/qt/widgets/qml/FadingEdgeForListView.qml
=====================================
@@ -50,62 +50,27 @@ FadingEdge {
     // FIXME: Delegate with variable size
     readonly property Item delegateItem: (listView.count > 0) ? 
listView.itemAtIndex(0) : null
 
-    readonly property Item firstVisibleItem: {
-        if (transitionsRunning || !delegateItem)
-            return null
-
-        let margin = 0 // -root.beginningMargin
-        if (orientation === Qt.Vertical) {
-            // if (headerItem && headerItem.visible && headerPositioning === 
ListView.OverlayHeader)
-            //    margin += headerItem.height
-
-            return listView.itemAt(sourceX + (delegateItem.x + 
delegateItem.width / 2),
-                                   sourceY + margin - beginningMargin + 
listView.spacing)
-        } else {
-            // if (headerItem && headerItem.visible && headerPositioning === 
ListView.OverlayHeader)
-            //    margin += headerItem.width
-
-            return listView.itemAt(sourceX + margin - beginningMargin + 
listView.spacing,
-                                   sourceY + (delegateItem.y + 
delegateItem.height / 2))
-        }
-    }
-
-    readonly property Item lastVisibleItem: {
-        if (transitionsRunning || !delegateItem)
-            return null
-
-        let margin = 0 // -root.endMargin
-        if (orientation === Qt.Vertical) {
-            // if (footerItem && footerItem.visible && footerPositioning === 
ListView.OverlayFooter)
-            //    margin += footerItem.height
-
-            return listView.itemAt(sourceX + (delegateItem.x + 
delegateItem.width / 2),
-                                   sourceY + listView.height - margin + 
endMargin - listView.spacing - 1)
-        } else {
-            // if (footerItem && footerItem.visible && footerPositioning === 
ListView.OverlayFooter)
-            //    margin += footerItem.width
-
-            return listView.itemAt(sourceX + listView.width - margin + 
endMargin - listView.spacing - 1,
-                                   sourceY + (delegateItem.y + 
delegateItem.height / 2))
-        }
-    }
 
     readonly property bool _fadeRectEnoughSize: (orientation === Qt.Vertical ? 
listView.height
                                                                              : 
listView.width) > (fadeSize * 2 + VLCStyle.dp(25))
 
+    readonly property rect _currentItemMappedRect: listView.currentItem ? 
Qt.rect(listView.currentItem.x - sourceX,
+                                                                               
   listView.currentItem.y - sourceY,
+                                                                               
   listView.currentItem.width,
+                                                                               
   listView.currentItem.height)
+                                                                        : 
Qt.rect(-1, -1, -1, -1)
+
     enableBeginningFade: _fadeRectEnoughSize &&
+                         !beginningHoverHandler.hovered &&
                          (orientation === Qt.Vertical ? !listView.atYBeginning
                                                       : 
!listView.atXBeginning) &&
-                         (!firstVisibleItem ||
-                         (!firstVisibleItem.activeFocus &&
-                          !(firstVisibleItem?.hovered ?? true)))
+                         Helpers.itemIntersects(beginningArea, 
_currentItemMappedRect)
 
     enableEndFade: _fadeRectEnoughSize &&
+                   !endHoverHandler.hovered &&
                    (orientation === Qt.Vertical ? !listView.atYEnd
                                                 : !listView.atXEnd) &&
-                   (!lastVisibleItem ||
-                   (!lastVisibleItem.activeFocus &&
-                    !(lastVisibleItem?.hovered ?? true)))
+                   Helpers.itemIntersects(endArea, _currentItemMappedRect)
 
     Binding on enableBeginningFade {
         when: !!listView.headerItem && (listView.headerPositioning !== 
ListView.InlineHeader)
@@ -116,4 +81,58 @@ FadingEdge {
         when: !!listView.footerItem && (listView.footerPositioning !== 
ListView.InlineFooter)
         value: false
     }
+
+    Item {
+        id: beginningArea
+
+        z: 99
+        parent: root.listView
+
+        anchors {
+            top: parent.top
+            left: parent.left
+
+            topMargin: (orientation === Qt.Vertical) ? beginningMargin : 
undefined
+            leftMargin: (orientation === Qt.Horizontal) ? beginningMargin : 
undefined
+
+            bottom: (orientation === Qt.Horizontal) ? parent.bottom : undefined
+            right: (orientation === Qt.Vertical) ? parent.right : undefined
+        }
+
+        implicitWidth: fadeSize
+        implicitHeight: fadeSize
+
+        HoverHandler {
+            id: beginningHoverHandler
+
+            grabPermissions: PointerHandler.ApprovesTakeOverByAnything
+        }
+    }
+
+    Item {
+        id: endArea
+
+        z: 99
+        parent: root.listView
+
+        anchors {
+            bottom: parent.bottom
+            right: parent.right
+
+            bottomMargin: (orientation === Qt.Vertical) ? beginningMargin : 
undefined
+            rightMargin: (orientation === Qt.Horizontal) ? beginningMargin : 
undefined
+
+            top: (orientation === Qt.Horizontal) ? parent.top : undefined
+            left: (orientation === Qt.Vertical) ? parent.left : undefined
+        }
+
+        implicitWidth: fadeSize
+        implicitHeight: fadeSize
+
+        HoverHandler {
+            id: endHoverHandler
+
+            grabPermissions: PointerHandler.ApprovesTakeOverByAnything
+        }
+    }
 }



View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/0c06c384bc443ba37aae11a96e28fd6abf821b96...bf5e2572b11e14157fff91d63990aec71c5c1640

-- 
View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/0c06c384bc443ba37aae11a96e28fd6abf821b96...bf5e2572b11e14157fff91d63990aec71c5c1640
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance
_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to