[vlc-commits] qml: allow header part to gain focus in ExpandGridView

Pierre Lamot git at videolan.org
Fri Jan 10 15:06:23 CET 2020


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Fri Dec 13 09:45:28 2019 +0100| [0ff34701a50e98420f7b6ca1a8047ba5ba84bf8b] | committer: Jean-Baptiste Kempf

qml: allow header part to gain focus in ExpandGridView

  this is done by:

  - exposing the intance of the header
  - moving the flickable to 0 when gaining focus to make the header visible
  - restoring the focus to the current item when losing focus
  - loading the header early so the header can be accessed from the first row

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

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

 modules/gui/qt/widgets/qml/ExpandGridView.qml | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/modules/gui/qt/widgets/qml/ExpandGridView.qml b/modules/gui/qt/widgets/qml/ExpandGridView.qml
index 41e52f4633..915d8c2af0 100644
--- a/modules/gui/qt/widgets/qml/ExpandGridView.qml
+++ b/modules/gui/qt/widgets/qml/ExpandGridView.qml
@@ -51,6 +51,7 @@ NavigableFocusScope {
 
     property Component headerDelegate: Item{}
     property int headerHeight: headerItemLoader.implicitHeight
+    property alias headerItem: headerItemLoader.item
 
     //signals emitted when selected items is updated from keyboard
     signal selectionUpdated( int keyModifiers, int oldIndex,int newIndex )
@@ -124,8 +125,19 @@ NavigableFocusScope {
 
         Loader {
             id: headerItemLoader
-            visible: flickable.contentY < root.headerHeight
+            //load the header early (when the first row is visible)
+            visible: flickable.contentY < root.headerHeight + root.cellHeight
             sourceComponent: headerDelegate
+            focus: item.focus
+            onFocusChanged: {
+                if (focus) {
+                    //when we gain the focus ensure the widget is fully visible
+                    animateFlickableContentY(0)
+                } else {
+                    //when we lose the focus restore the focus on the current grid item
+                    flickable.setCurrentItemFocus()
+                }
+            }
             onLoaded: {
                 item.x = 0
                 item.y = 0



More information about the vlc-commits mailing list