2
import UnityApplications 1.0 /* Necessary for the ImageProvider serving image://icons */
5
/* Renderers typically use a grid layout to render the model. The RendererGrid
6
component provides a standard implementation of such a layout where the
7
cells can be customized by providing a QML component to it.
8
A user of RendererGrid would create a renderer inheriting from it
9
and pass a Component via the 'cellRenderer' property.
14
property variant cellRenderer
15
property bool folded: true
17
property int cellWidth: 158
18
property int cellHeight: 76
19
property int horizontalSpacing: 26
20
property int verticalSpacing: 26
22
/* Using results.contentHeight produces binding loop warnings and potential
23
rendering issues. We compute the height manually.
25
/* FIXME: tricking the system by making the delegate of height 0 and with
26
an invisible header is no good: the item in the model still
27
exists and some things such as keyboard selection break.
29
height: results.count > 0 ? header.height + results_layout.anchors.topMargin + results.totalHeight : 0
30
//Behavior on height {NumberAnimation {duration: 200}}
35
visible: results.count > 0
36
availableCount: results.count - results.cellsPerLine
38
anchors.top: parent.top
39
anchors.left: parent.left
40
anchors.right: parent.right
43
label: parent.displayName
45
onClicked: parent.folded = !parent.folded
51
anchors.top: header.bottom
53
anchors.left: parent.left
55
anchors.right: parent.right
56
anchors.bottom: parent.bottom
61
/* FIXME: this is a gross hack compensating for the lack of sections
62
in GridView (see ListView.section).
64
We nest GridViews inside a ListView and add headers manually
65
(GroupHeader). The total height of each Group is computed
66
manually and given back to the ListView. However that size cannot
67
be used by the individual GridViews because it would make them
68
load all of their delegates at once using far too much memory and
69
processing power. Instead we constrain the height of the GridViews
70
and compute their position manually to compensate for the position
71
changes when flicking the ListView.
73
We assume that renderer.parentListView is the ListView we nest our
76
property variant flickable: renderer.parentListView
78
/* flickable.contentY*0 is equal to 0 but is necessary in order to
79
have the entire expression being evaluated at the right moment.
81
property int inFlickableY: flickable.contentY*0+parent.mapToItem(flickable, 0, 0).y
82
property int compensateY: inFlickableY > 0 ? 0 : -inFlickableY
84
width: flickable.width
85
height: Math.min(totalHeight, flickable.height)
86
onCompensateYChanged: {
87
if (flickable.height > 0 && totalHeight >= flickable.height) {
89
contentY = compensateY
93
property int cellsPerLine: Math.floor(width/results.cellWidth)
94
/* Only display one line of items when folded */
95
property int displayedCount: folded ? cellsPerLine : count
96
property int totalHeight: results.cellHeight*Math.ceil(displayedCount/cellsPerLine)
98
cellWidth: renderer.cellWidth+renderer.horizontalSpacing
99
cellHeight: renderer.cellHeight+renderer.verticalSpacing
105
property url uri: column_0
106
property string iconHint: column_1
107
property string groupId: column_2
108
property string mimetype: column_3
109
property string displayName: column_4
110
property string comment: column_5
112
width: renderer.cellWidth
113
height: renderer.cellHeight
115
sourceComponent: cellRenderer
118
item.iconHint = iconHint
119
item.mimetype = mimetype
120
item.displayName = displayName
121
item.comment = comment
125
model: renderer.model