[vlc-devel] [PATCH 11/18] qml: lazily update availableRowWidth of KeyNaviagableTableView

Prince Gupta guptaprince8832 at gmail.com
Thu Apr 1 14:29:46 UTC 2021


solves slow animation of Playlist collapsing and expanding
---
 .../qt/widgets/qml/KeyNavigableTableView.qml  | 45 +++++++++++++++++--
 1 file changed, 42 insertions(+), 3 deletions(-)

diff --git a/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml b/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
index 14c8864a1b..b732198e52 100644
--- a/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
+++ b/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
@@ -74,12 +74,12 @@ NavigableFocusScope {
     property var selectionDelegateModel
     property real rowHeight: VLCStyle.tableRow_height
     readonly property int _contextButtonHorizontalSpace: VLCStyle.icon_normal + VLCStyle.margin_xxsmall * 2
-    readonly property real availableRowWidth: width
-                                              - ( !!section.property ? VLCStyle.table_section_width * 2 : 0 )
-                                              - _contextButtonHorizontalSpace
     property alias spacing: view.spacing
     property int horizontalSpacing: VLCStyle.column_margin_width
 
+    property real availableRowWidth: 0
+    property real _availabeRowWidthLastUpdateTime: Date.now()
+
     property alias fadeColor:             view.fadeColor
     property alias fadeRectBottomHovered: view.fadeRectBottomHovered
     property alias fadeRectTopHovered:    view.fadeRectTopHovered
@@ -96,6 +96,45 @@ NavigableFocusScope {
         view.positionViewAtIndex(index, mode)
     }
 
+    Timer {
+        id: availableRowWidthUpdater
+
+        interval: 100
+        triggeredOnStart: false
+        repeat: false
+        onTriggered: {
+            _update()
+        }
+
+        function _update() {
+            root.availableRowWidth = root.width
+                    - ( !!section.property ? VLCStyle.table_section_width * 2 : 0 )
+                    - _contextButtonHorizontalSpace
+            root._availabeRowWidthLastUpdateTime = Date.now()
+        }
+
+        function enqueueUpdate() {
+            // updating availableRowWidth is expensive because of property bindings in sortModel
+            // and availableRowWidth is dependent on root.width which can update in a burst
+            // so try to maintain a minimum time gap between subsequent availableRowWidth updates
+            var sinceLastUpdate = Date.now() - root._availabeRowWidthLastUpdateTime
+            if ((root.availableRowWidth === 0) || (sinceLastUpdate > 128 && !availableRowWidthUpdater.running)) {
+                _update()
+            } else if (!availableRowWidthUpdater.running) {
+                availableRowWidthUpdater.interval = Math.max(128 - sinceLastUpdate, 32)
+                availableRowWidthUpdater.start()
+            }
+        }
+    }
+
+    onWidthChanged: {
+        availableRowWidthUpdater.enqueueUpdate()
+    }
+
+    onSectionChanged: {
+        availableRowWidthUpdater.enqueueUpdate()
+    }
+
     KeyNavigableListView {
         id: view
 
-- 
2.27.0



More information about the vlc-devel mailing list