[vlc-commits] qml: automatically recenter the view to the focused item in NetworkHomeDisplay

Pierre Lamot git at videolan.org
Fri Jan 10 15:07:02 CET 2020


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Wed Jan  8 17:53:47 2020 +0100| [d10eeadb6fbcddc5562d94260a2a7d97dfe1b92c] | committer: Jean-Baptiste Kempf

qml: automatically recenter the view to the focused item in NetworkHomeDisplay

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d10eeadb6fbcddc5562d94260a2a7d97dfe1b92c
---

 modules/gui/qt/network/qml/NetworkHomeDisplay.qml | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/modules/gui/qt/network/qml/NetworkHomeDisplay.qml b/modules/gui/qt/network/qml/NetworkHomeDisplay.qml
index ad0271d8a9..1e6b090b2e 100644
--- a/modules/gui/qt/network/qml/NetworkHomeDisplay.qml
+++ b/modules/gui/qt/network/qml/NetworkHomeDisplay.qml
@@ -29,6 +29,14 @@ Widgets.NavigableFocusScope {
     id: topFocusScope
     focus: true
 
+    function _centerFlickableOnItem(minY, maxY) {
+        if (maxY > flickable.contentItem.contentY + flickable.height) {
+            flickable.contentItem.contentY = maxY - flickable.height
+        } else if (minY < flickable.contentItem.contentY) {
+            flickable.contentItem.contentY = minY
+        }
+    }
+
     Label {
         anchors.centerIn: parent
         visible: (machineDM.items.count === 0 && lanDM.items.count === 0 )
@@ -68,6 +76,7 @@ Widgets.NavigableFocusScope {
             spacing: VLCStyle.margin_normal
 
             Widgets.LabelSeparator {
+                id: deviceLabel
                 text: i18n.qtr("Devices")
                 width: flickable.width
                 visible: machineDM.items.count !== 0
@@ -93,9 +102,15 @@ Widgets.NavigableFocusScope {
 
                 navigationParent: topFocusScope
                 navigationDownItem: lanSection.visible ?  lanSection : undefined
+
+                onActiveFocusChanged: {
+                    if (activeFocus)
+                        _centerFlickableOnItem(deviceLabel.y, deviceSection.y + deviceSection.height)
+                }
             }
 
             Widgets.LabelSeparator {
+                id: lanLabel
                 text: i18n.qtr("LAN")
                 width: flickable.width
                 visible: lanDM.items.count !== 0
@@ -121,6 +136,11 @@ Widgets.NavigableFocusScope {
 
                 navigationParent: topFocusScope
                 navigationUpItem: deviceSection.visible ? deviceSection : undefined
+
+                onActiveFocusChanged: {
+                    if (activeFocus)
+                        _centerFlickableOnItem(lanLabel.y, lanSection.y + lanSection.height)
+                }
             }
         }
 



More information about the vlc-commits mailing list