@ -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 {
/ / d e l e g a t e t o d i s p l a y t h e e x t e n d e d i t e m
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 )
}
}
}
/ / G r i d v i e w v i s i b l e a b o v e t h e e x p a n d e d i t e m
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 {
/ / H i d e t h e e x p a n d I t e m w i t h n o a n i m a t i o n
_expandIndex = - 1
/ / f l i c k a b l e . e x p a n d I t e m . h e i g h t = 0
/ / e x p a n d I t e m . h e i g h t = 0
/ / R e g e n e r a t e t h e g r i d v i e w l a y o u t
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 ) {
/ / m o v e v i e w p o r t t o s e e c u r r e n t i t e m b o t t o m
newContentY = Math . min (
currentItemYPos + flickable . expandItem . currentItemHeight - flickable . height ,
currentItemYPos + expandItem . currentItemHeight - flickable . height ,
flickable . contentHeight - flickable . height )
} else if ( currentItemYPos < flickable . contentY ) {
/ / m o v e v i e w p o r t t o s e e c u r r e n t i t e m t o p
@ -408,11 +420,11 @@ NavigableFocusScope {
if ( _expandIndex === - 1 )
return
var expandItemHeight = flickable . expandItem . implicitHeight ;
var expandItemHeight = expandItem . implicitHeight ;
/ / E x p a n d a n i m a t i o n
flickable . expandItem . focus = true
expandItem . focus = true
/ / T h e a n i m a t i o n m a y h a v e a l r e a d y b e e n t r i g g e r e d , w e m u s t s t o p i t .
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