[vlc-devel] [PATCH v2 1/5] qml: remove unnecessary components from GridItem

Prince Gupta guptaprince8832 at gmail.com
Mon Apr 12 11:50:16 UTC 2021


improve instantiation times for GridItem component
---
 modules/gui/qt/widgets/qml/GridItem.qml | 213 ++++++++++++------------
 1 file changed, 103 insertions(+), 110 deletions(-)

diff --git a/modules/gui/qt/widgets/qml/GridItem.qml b/modules/gui/qt/widgets/qml/GridItem.qml
index 302c0ed8bb..dc3463c4af 100644
--- a/modules/gui/qt/widgets/qml/GridItem.qml
+++ b/modules/gui/qt/widgets/qml/GridItem.qml
@@ -61,7 +61,7 @@ FocusScope {
     implicitWidth: mouseArea.implicitWidth
     implicitHeight: mouseArea.implicitHeight
 
-    readonly property bool _highlighted: mouseArea.containsMouse || content.activeFocus
+    readonly property bool _highlighted: mouseArea.containsMouse || root.activeFocus
 
     readonly property int selectedBorderWidth: VLCStyle.gridItemSelectedBorder
 
@@ -193,11 +193,11 @@ FocusScope {
 
     MouseArea {
         id: mouseArea
-        hoverEnabled: true
 
+        hoverEnabled: true
         anchors.fill: parent
-        implicitWidth: content.implicitWidth
-        implicitHeight: content.implicitHeight
+        implicitWidth: layout.implicitWidth
+        implicitHeight: layout.implicitHeight
         drag.target: root.dragItem
         drag.axis: Drag.XAndYAxis
         drag.onActiveChanged: {
@@ -237,131 +237,124 @@ FocusScope {
             }
         }
 
-        FocusScope {
-            id: content
+        /* background visible when selected */
+        Rectangle {
+            id: selectionRect
 
-            anchors.fill: parent
-            implicitWidth: layout.implicitWidth
-            implicitHeight: layout.implicitHeight
-            focus: true
+            x: - root.selectedBorderWidth
+            y: - root.selectedBorderWidth
+            width: root.width + ( root.selectedBorderWidth * 2 )
+            height:  root.height + ( root.selectedBorderWidth * 2 )
+            color: VLCStyle.colors.bgHover
+            visible: root.selected || root._highlighted
+        }
 
-            /* background visible when selected */
-            Rectangle {
-                id: selectionRect
+        Rectangle {
+            id: baseRect
 
-                x: - root.selectedBorderWidth
-                y: - root.selectedBorderWidth
-                width: root.width + ( root.selectedBorderWidth * 2 )
-                height:  root.height + ( root.selectedBorderWidth * 2 )
-                color: VLCStyle.colors.bgHover
-                visible: root.selected || root._highlighted
-            }
+            x: layout.x + 1 // this rect is set such that it hides behind picture component
+            y: layout.y + 1
+            width: pictureWidth - 2
+            height: pictureHeight - 2
+            radius: picture.radius
+            color: VLCStyle.colors.bg
+        }
 
-            Rectangle {
-                id: baseRect
+        // animating shadows properties are expensive and not smooth
+        // thus we use two different shadows for states "selected" and "unselected"
+        // and animate their opacity on state changes to get better animation
+        CoverShadow {
+            id: unselectedShadow
+
+            anchors.fill: baseRect
+            source: baseRect
+            cached: true
+            visible: false
+            secondaryVerticalOffset: VLCStyle.dp(1, VLCStyle.scale)
+            secondaryRadius: VLCStyle.dp(2, VLCStyle.scale)
+            secondarySamples: 1 + VLCStyle.dp(2, VLCStyle.scale) * 2
+            primaryVerticalOffset: VLCStyle.dp(4, VLCStyle.scale)
+            primaryRadius: VLCStyle.dp(9, VLCStyle.scale)
+            primarySamples: 1 + VLCStyle.dp(9, VLCStyle.scale) * 2
+        }
 
-                x: layout.x + 1 // this rect is set such that it hides behind picture component
-                y: layout.y + 1
-                width: pictureWidth - 2
-                height: pictureHeight - 2
-                radius: picture.radius
-                color: VLCStyle.colors.bg
-            }
+        CoverShadow {
+            id: selectedShadow
+
+            anchors.fill: baseRect
+            source: baseRect
+            cached: true
+            visible: false
+            secondaryVerticalOffset: VLCStyle.dp(6, VLCStyle.scale)
+            secondaryRadius: VLCStyle.dp(18, VLCStyle.scale)
+            secondarySamples: 1 + VLCStyle.dp(18, VLCStyle.scale) * 2
+            primaryVerticalOffset: VLCStyle.dp(32, VLCStyle.scale)
+            primaryRadius: VLCStyle.dp(72, VLCStyle.scale)
+            primarySamples: 1 + VLCStyle.dp(72, VLCStyle.scale) * 2
+        }
 
-            // animating shadows properties are expensive and not smooth
-            // thus we use two different shadows for states "selected" and "unselected"
-            // and animate their opacity on state changes to get better animation
-            CoverShadow {
-                id: unselectedShadow
-
-                anchors.fill: baseRect
-                source: baseRect
-                cached: true
-                secondaryVerticalOffset: VLCStyle.dp(1, VLCStyle.scale)
-                secondaryRadius: VLCStyle.dp(2, VLCStyle.scale)
-                secondarySamples: 1 + VLCStyle.dp(2, VLCStyle.scale) * 2
-                primaryVerticalOffset: VLCStyle.dp(4, VLCStyle.scale)
-                primaryRadius: VLCStyle.dp(9, VLCStyle.scale)
-                primarySamples: 1 + VLCStyle.dp(9, VLCStyle.scale) * 2
-            }
+        Column {
+            id: layout
 
-            CoverShadow {
-                id: selectedShadow
-
-                anchors.fill: baseRect
-                source: baseRect
-                cached: true
-                secondaryVerticalOffset: VLCStyle.dp(6, VLCStyle.scale)
-                secondaryRadius: VLCStyle.dp(18, VLCStyle.scale)
-                secondarySamples: 1 + VLCStyle.dp(18, VLCStyle.scale) * 2
-                primaryVerticalOffset: VLCStyle.dp(32, VLCStyle.scale)
-                primaryRadius: VLCStyle.dp(72, VLCStyle.scale)
-                primarySamples: 1 + VLCStyle.dp(72, VLCStyle.scale) * 2
-            }
+            anchors.centerIn: parent
 
-            Column {
-                id: layout
+            Widgets.MediaCover {
+                id: picture
 
-                anchors.centerIn: parent
+                width: pictureWidth
+                height: pictureHeight
+                playCoverVisible: root._highlighted
+                onPlayIconClicked: root.playClicked()
+                clip: true
+                radius: VLCStyle.gridCover_radius
 
-                Widgets.MediaCover {
-                    id: picture
+                /* new indicator (triangle at top-left of cover)*/
+                Rectangle {
+                    id: newIndicator
 
-                    width: pictureWidth
-                    height: pictureHeight
-                    playCoverVisible: root._highlighted
-                    onPlayIconClicked: root.playClicked()
-                    clip: true
-                    radius: VLCStyle.gridCover_radius
-
-                    /* new indicator (triangle at top-left of cover)*/
-                    Rectangle {
-                        id: newIndicator
-
-                        // consider this Rectangle as a triangle, then following property is its median length
-                        property alias median: root._newIndicatorMedian
-
-                        x: parent.width - median
-                        y: - median
-                        width: 2 * median
-                        height: 2 * median
-                        color: VLCStyle.colors.accent
-                        rotation: 45
-                        visible: root.showNewIndicator && root.progress === 0
-                    }
+                    // consider this Rectangle as a triangle, then following property is its median length
+                    property alias median: root._newIndicatorMedian
+
+                    x: parent.width - median
+                    y: - median
+                    width: 2 * median
+                    height: 2 * median
+                    color: VLCStyle.colors.accent
+                    rotation: 45
+                    visible: root.showNewIndicator && root.progress === 0
                 }
+            }
 
-                Widgets.ScrollingText {
-                    id: titleTextRect
+            Widgets.ScrollingText {
+                id: titleTextRect
 
-                    label: titleLabel
-                    scroll: _highlighted
-                    height: titleLabel.height
-                    width: titleLabel.width
-                    visible: root.title !== ""
+                label: titleLabel
+                scroll: _highlighted
+                height: titleLabel.height
+                width: titleLabel.width
+                visible: root.title !== ""
 
-                    Widgets.ListLabel {
-                        id: titleLabel
+                Widgets.ListLabel {
+                    id: titleLabel
 
-                        elide: Text.ElideNone
-                        width: pictureWidth
-                        horizontalAlignment: root.textHorizontalAlignment
-                        topPadding: root.titleMargin
-                        color: selectionRect.visible ? VLCStyle.colors.bgHoverText : VLCStyle.colors.text
-                    }
+                    elide: Text.ElideNone
+                    width: pictureWidth
+                    horizontalAlignment: root.textHorizontalAlignment
+                    topPadding: root.titleMargin
+                    color: selectionRect.visible ? VLCStyle.colors.bgHoverText : VLCStyle.colors.text
                 }
+            }
 
-                Widgets.MenuCaption {
-                    id: subtitleTxt
+            Widgets.MenuCaption {
+                id: subtitleTxt
 
-                    visible: text !== ""
-                    text: root.subtitle
-                    width: pictureWidth
-                    topPadding: VLCStyle.margin_xsmall
-                    color: selectionRect.visible
-                           ? VLCStyle.colors.setColorAlpha(VLCStyle.colors.bgHoverText, .6)
-                           : VLCStyle.colors.menuCaption
-                }
+                visible: text !== ""
+                text: root.subtitle
+                width: pictureWidth
+                topPadding: VLCStyle.margin_xsmall
+                color: selectionRect.visible
+                       ? VLCStyle.colors.setColorAlpha(VLCStyle.colors.bgHoverText, .6)
+                       : VLCStyle.colors.menuCaption
             }
         }
     }
-- 
2.27.0



More information about the vlc-devel mailing list