[vlc-commits] qml: refresh elements from ExpandGridView on data update
Pierre Lamot
git at videolan.org
Thu Feb 20 13:56:40 CET 2020
vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Thu Feb 13 18:14:03 2020 +0100| [6f62e4dcd7d5b1101285d1dee8596fb2cec0c4eb] | committer: Jean-Baptiste Kempf
qml: refresh elements from ExpandGridView on data update
We need to monitor the original model directly as the DelegateModel won't
notify us when the data is updated.
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6f62e4dcd7d5b1101285d1dee8596fb2cec0c4eb
---
modules/gui/qt/medialibrary/qml/MusicAlbums.qml | 1 +
modules/gui/qt/medialibrary/qml/MusicGenres.qml | 1 +
modules/gui/qt/medialibrary/qml/VideoDisplay.qml | 1 +
.../gui/qt/network/qml/NetworkBrowseDisplay.qml | 1 +
modules/gui/qt/widgets/qml/ExpandGridView.qml | 88 ++++++++++++----------
5 files changed, 54 insertions(+), 38 deletions(-)
diff --git a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
index 1a2c68481a..8779ba9a05 100644
--- a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
@@ -141,6 +141,7 @@ Widgets.NavigableFocusScope {
headerDelegate: root.header
delegateModel: delegateModelId
+ model: albumModelId
delegate: AudioGridItem {
id: audioGridItem
diff --git a/modules/gui/qt/medialibrary/qml/MusicGenres.qml b/modules/gui/qt/medialibrary/qml/MusicGenres.qml
index c67a33892f..3722616dfd 100644
--- a/modules/gui/qt/medialibrary/qml/MusicGenres.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicGenres.qml
@@ -165,6 +165,7 @@ Widgets.NavigableFocusScope {
id: gridView_id
delegateModel: delegateModelId
+ model: genreModel
headerDelegate: headerComponent
diff --git a/modules/gui/qt/medialibrary/qml/VideoDisplay.qml b/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
index c49dfb64ef..a4272fa42d 100644
--- a/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
@@ -157,6 +157,7 @@ Widgets.NavigableFocusScope {
activeFocusOnTab:true
delegateModel: videosDelegate
+ model: videoModel
headerDelegate: Widgets.LabelSeparator {
id: videosSeparator
diff --git a/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml b/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
index 79c0f0e02f..209e270c9d 100644
--- a/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
+++ b/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
@@ -120,6 +120,7 @@ Widgets.NavigableFocusScope {
id: gridView
delegateModel: delegateModelId
+ model: providerModel
headerDelegate: Widgets.LabelSeparator {
width: view.width
diff --git a/modules/gui/qt/widgets/qml/ExpandGridView.qml b/modules/gui/qt/widgets/qml/ExpandGridView.qml
index 237a4ffea3..ac6aadf755 100644
--- a/modules/gui/qt/widgets/qml/ExpandGridView.qml
+++ b/modules/gui/qt/widgets/qml/ExpandGridView.qml
@@ -32,6 +32,7 @@ NavigableFocusScope {
property int marginTop: root.cellHeight / 3
property variant delegateModel
+ property variant model
property int currentIndex: 0
property alias contentHeight: flickable.contentHeight
@@ -48,6 +49,7 @@ NavigableFocusScope {
//delegate to display the extended item
property Component delegate: Item{}
property Component expandDelegate: Item{}
+ property alias expandItem: expandItemLoader.item
property Component headerDelegate: Item{}
property int headerHeight: headerItemLoader.implicitHeight
@@ -166,12 +168,48 @@ NavigableFocusScope {
root._isInitialised = true;
}
+ function _getFirstAndLastInstanciatedItemIds() {
+ var myContentY = flickable.contentY - root.headerHeight
+
+ var contentYWithoutExpand = myContentY
+ var heightWithoutExpand = flickable.height
+ if (root._expandIndex !== -1) {
+ if (myContentY >= expandItem.y && myContentY < expandItem.y + expandItem.height)
+ contentYWithoutExpand = expandItem.y
+ if (myContentY >= expandItem.y + expandItem.height)
+ contentYWithoutExpand = myContentY - expandItem.height
+
+ var expandYStart = Math.max(myContentY, expandItem.y)
+ var expandYEnd = Math.min(myContentY + height, expandItem.y + expandItem.height)
+ var expandDisplayedHeight = Math.max(expandYEnd - expandYStart, 0)
+ heightWithoutExpand -= expandDisplayedHeight
+ }
+
+ var rowId = Math.floor(contentYWithoutExpand / root.cellHeight)
+ var firstId = Math.max(rowId * root.getNbItemsPerRow(), 0)
+
+ rowId = Math.ceil((contentYWithoutExpand + heightWithoutExpand) / root.cellHeight)
+ var lastId = Math.min(rowId * root.getNbItemsPerRow(), delegateModel.count)
+
+ return [firstId, lastId]
+ }
+
+ Connections {
+ target: model
+ onDataChanged: {
+ var iMin = topLeft.row
+ var iMax = bottomRight.row
+ var f_l = _getFirstAndLastInstanciatedItemIds()
+ if (iMin <= f_l[1] && f_l[0] <= iMax) {
+ flickable.layout(true)
+ }
+ }
+ }
+
//Gridview visible above the expanded item
Flickable {
id: flickable
- property alias expandItem: expandItemLoader.item
-
clip: true
flickableDirection: Flickable.VerticalFlick
@@ -225,32 +263,6 @@ NavigableFocusScope {
return ret
}
- function getFirstAndLastInstanciatedItemIds() {
- var myContentY = contentY - root.headerHeight
-
- var contentYWithoutExpand = myContentY
- var heightWithoutExpand = height
- if (root._expandIndex !== -1) {
- if (myContentY >= expandItem.y && myContentY < expandItem.y + expandItem.height)
- contentYWithoutExpand = expandItem.y
- if (myContentY >= expandItem.y + expandItem.height)
- contentYWithoutExpand = myContentY - expandItem.height
-
- var expandYStart = Math.max(myContentY, expandItem.y)
- var expandYEnd = Math.min(myContentY + height, expandItem.y + expandItem.height)
- var expandDisplayedHeight = Math.max(expandYEnd - expandYStart, 0)
- heightWithoutExpand -= expandDisplayedHeight
- }
-
- var rowId = Math.floor(contentYWithoutExpand / root.cellHeight)
- var firstId = Math.max(rowId * root.getNbItemsPerRow(), 0)
-
- rowId = Math.ceil((contentYWithoutExpand + heightWithoutExpand) / root.cellHeight)
- var lastId = Math.min(rowId * root.getNbItemsPerRow(), delegateModel.count)
-
- return [firstId, lastId]
- }
-
function getChild(id, toUse) {
var ret
if (id in _idChildrenMap) {
@@ -291,7 +303,7 @@ NavigableFocusScope {
var i
var expandItemGridId = getExpandItemGridId()
- var f_l = getFirstAndLastInstanciatedItemIds()
+ var f_l = _getFirstAndLastInstanciatedItemIds()
var nbItems = f_l[1] - f_l[0]
var firstId = f_l[0]
var lastId = f_l[1]
@@ -359,14 +371,14 @@ NavigableFocusScope {
// Hide the expandItem with no animation
_expandIndex = -1
- //flickable.expandItem.height = 0
+ //expandItem.height = 0
// Regenerate the gridview layout
flickable.layout(true)
}
}
Connections {
- target: flickable.expandItem
+ target: expandItem
onHeightChanged: {
flickable.layout(true)
}
@@ -378,11 +390,11 @@ NavigableFocusScope {
}
onCurrentItemYChanged: {
var newContentY = flickable.contentY;
- var currentItemYPos = root.getItemPos(currentIndex)[1] + cellHeight + flickable.expandItem.currentItemY
- if (currentItemYPos + flickable.expandItem.currentItemHeight > flickable.contentY + flickable.height) {
+ var currentItemYPos = root.getItemPos(currentIndex)[1] + cellHeight + expandItem.currentItemY
+ if (currentItemYPos + expandItem.currentItemHeight > flickable.contentY + flickable.height) {
//move viewport to see current item bottom
newContentY = Math.min(
- currentItemYPos + flickable.expandItem.currentItemHeight - flickable.height,
+ currentItemYPos + expandItem.currentItemHeight - flickable.height,
flickable.contentHeight - flickable.height)
} else if (currentItemYPos < flickable.contentY) {
//move viewport to see current item top
@@ -408,11 +420,11 @@ NavigableFocusScope {
if (_expandIndex === -1)
return
- var expandItemHeight = flickable.expandItem.implicitHeight;
+ var expandItemHeight = expandItem.implicitHeight;
// Expand animation
- flickable.expandItem.focus = true
+ expandItem.focus = true
// The animation may have already been triggered, we must stop it.
animateExpandItem.stop()
animateExpandItem.to = expandItemHeight
@@ -430,7 +442,7 @@ NavigableFocusScope {
NumberAnimation {
id: animateRetractItem;
- target: flickable.expandItem;
+ target: expandItem;
properties: "height"
easing.type: Easing.OutQuad
duration: 250
@@ -446,7 +458,7 @@ NavigableFocusScope {
NumberAnimation {
id: animateExpandItem;
- target: flickable.expandItem;
+ target: expandItem;
properties: "height"
easing.type: Easing.InQuad
duration: 250
More information about the vlc-commits
mailing list