chore(DoubleFlickableWithFolding): Component api and usage simplified

Now the header don't have to be reparented manually. Everything
is done internally in the component. Additionally the usage
in CollectiblesView is adjusted to the change.
This commit is contained in:
Michał Cieślak 2024-01-29 10:59:26 +01:00 committed by Michał
parent f2db89573f
commit 9fe60e650f
3 changed files with 88 additions and 83 deletions

View File

@ -82,20 +82,12 @@ SplitView {
cellWidth: 120
cellHeight: 30
header: Item {
id: header1
header: Rectangle {
z: 1
height: root.header1Size
width: GridView.view.width
Rectangle {
parent: doubleFlickable.contentItem
y: doubleFlickable.gridHeader1YInContentItem
z: 1
width: header1.width
height: header1.height
color: "orange"
Label {
@ -111,7 +103,6 @@ SplitView {
onClicked: doubleFlickable.flip1Folding()
}
}
}
delegate: Rectangle {
width: grid1.cellWidth
@ -143,20 +134,12 @@ SplitView {
cellWidth: 100
cellHeight: 100
header: Item {
id: header2
header: Rectangle {
z: 1
height: root.header2Size
width: GridView.view.width
Rectangle {
parent: doubleFlickable.contentItem
y: doubleFlickable.gridHeader2YInContentItem
z: 1
width: header2.width
height: header2.height
color: "red"
Label {
@ -172,7 +155,6 @@ SplitView {
onClicked: doubleFlickable.flip2Folding()
}
}
}
delegate: Rectangle {
width: grid2.cellWidth

View File

@ -2,9 +2,6 @@ import QtQuick 2.15
import QtQml 2.15
DoubleFlickable {
readonly property real gridHeader1YInContentItem: contentY
readonly property real gridHeader2YInContentItem: contentY + d.grid2HeaderOffset
readonly property bool flickable1Folded: !d.grid1ContentInViewport
readonly property bool flickable2Folded: d.grid2HeaderAtEnd || d.model2Blocked
@ -52,11 +49,57 @@ DoubleFlickable {
}
}
HeaderWrapper {
id: header1Wrapper
parent: contentItem
flickable: flickable1
y: contentY
}
HeaderWrapper {
id: header2Wrapper
parent: contentItem
flickable: flickable2
y: contentY + d.grid2HeaderOffset
}
// The Flickable component (ListView or GridView) controls y positioning
// of the header and it cannot be effectively overriden. As a solution to
// this problem, the header can be reparented to a wrapper compensating
// for the y offset.
component HeaderWrapper: Item {
property Flickable flickable
z: 1
Binding {
when: flickable.headerItem
target: flickable.headerItem
property: "parent"
value: container
restoreMode: Binding.RestoreBindingOrValue
}
Binding {
when: flickable.headerItem
target: container
property: "y"
value: -flickable.headerItem.y
restoreMode: Binding.RestoreBindingOrValue
}
Item { id: container }
}
QtObject {
id: d
readonly property real header1Size: flickable1.headerItem ? flickable1.headerItem.height : 0
readonly property real header2Size: flickable2.headerItem ? flickable2.headerItem.height : 0
readonly property real header1Size: flickable1.headerItem
? flickable1.headerItem.height : 0
readonly property real header2Size: flickable2.headerItem
? flickable2.headerItem.height : 0
readonly property bool grid1ContentInViewport:
flickable1.y > contentY - Math.min(height, flickable1ContentHeight) + header1Size

View File

@ -263,18 +263,9 @@ ColumnLayout {
flickable1: CustomGridView {
id: communityCollectiblesView
header: Item {
id: communityHeader
header: HeaderDelegate {
height: d.headerHeight
width: doubleFlickable.width
HeaderDelegate {
width: communityHeader.width
height: communityHeader.height
parent: doubleFlickable.contentItem
y: doubleFlickable.gridHeader1YInContentItem
z: 1
text: qsTr("Community minted")
@ -285,7 +276,6 @@ ColumnLayout {
onToggleClicked: doubleFlickable.flip1Folding()
onInfoClicked: Global.openPopup(communityInfoPopupCmp)
}
}
Binding {
target: communityCollectiblesView
@ -305,18 +295,9 @@ ColumnLayout {
flickable2: CustomGridView {
id: regularCollectiblesView
header: Item {
id: nonCommunityHeader
header: HeaderDelegate {
height: d.headerHeight
width: doubleFlickable.width
HeaderDelegate {
width: nonCommunityHeader.width
height: nonCommunityHeader.height
parent: doubleFlickable.contentItem
y: doubleFlickable.gridHeader2YInContentItem
z: 1
text: qsTr("Others")
@ -329,7 +310,6 @@ ColumnLayout {
onToggleClicked: doubleFlickable.flip2Folding()
}
}
Binding {
target: regularCollectiblesView