~ubuntu-branches/ubuntu/natty/unity-2d/natty-updates

« back to all changes in this revision

Viewing changes to .pc/debian-changes-0.1-0ubuntu4/places/RendererGrid.qml

  • Committer: Bazaar Package Importer
  • Author(s): Oliver Grawert
  • Date: 2011-01-21 13:11:45 UTC
  • Revision ID: james.westby@ubuntu.com-20110121131145-tn95f1z7mxi4n1bx
Tags: 0.1-0ubuntu4
* add Vcs-Bzr location to debian/control
* update branch location in debian/copyright
* pull in some upstream fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import Qt 4.7
 
2
import UnityApplications 1.0 /* Necessary for the ImageProvider serving image://icons */
 
3
import UnityPlaces 1.0
 
4
 
 
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.
 
10
*/
 
11
Renderer {
 
12
    id: renderer
 
13
 
 
14
    property variant cellRenderer
 
15
    property bool folded: true
 
16
 
 
17
    property int cellWidth: 158
 
18
    property int cellHeight: 76
 
19
    property int horizontalSpacing: 26
 
20
    property int verticalSpacing: 26
 
21
 
 
22
    /* Using results.contentHeight produces binding loop warnings and potential
 
23
       rendering issues. We compute the height manually.
 
24
    */
 
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.
 
28
    */
 
29
    height: results.count > 0 ? header.height + results_layout.anchors.topMargin + results.totalHeight : 0
 
30
    //Behavior on height {NumberAnimation {duration: 200}}
 
31
 
 
32
    GroupHeader {
 
33
        id: header
 
34
 
 
35
        visible: results.count > 0
 
36
        availableCount: results.count - results.cellsPerLine
 
37
        folded: parent.folded
 
38
        anchors.top: parent.top
 
39
        anchors.left: parent.left
 
40
        anchors.right: parent.right
 
41
        height: 28
 
42
        icon: parent.iconHint
 
43
        label: parent.displayName
 
44
 
 
45
        onClicked: parent.folded = !parent.folded
 
46
    }
 
47
 
 
48
    Item {
 
49
        id: results_layout
 
50
 
 
51
        anchors.top: header.bottom
 
52
        anchors.topMargin: 14
 
53
        anchors.left: parent.left
 
54
        anchors.leftMargin: 2
 
55
        anchors.right: parent.right
 
56
        anchors.bottom: parent.bottom
 
57
 
 
58
        GridView {
 
59
            id: results
 
60
 
 
61
            /* FIXME: this is a gross hack compensating for the lack of sections
 
62
               in GridView (see ListView.section).
 
63
 
 
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.
 
72
 
 
73
               We assume that renderer.parentListView is the ListView we nest our
 
74
               GridView into.
 
75
            */
 
76
            property variant flickable: renderer.parentListView
 
77
 
 
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.
 
80
            */
 
81
            property int inFlickableY: flickable.contentY*0+parent.mapToItem(flickable, 0, 0).y
 
82
            property int compensateY: inFlickableY > 0 ? 0 : -inFlickableY
 
83
 
 
84
            width: flickable.width
 
85
            height: Math.min(totalHeight, flickable.height)
 
86
            onCompensateYChanged: {
 
87
                if (flickable.height > 0 && totalHeight >= flickable.height) {
 
88
                    y = compensateY
 
89
                    contentY = compensateY
 
90
                }
 
91
            }
 
92
 
 
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)
 
97
 
 
98
            cellWidth: renderer.cellWidth+renderer.horizontalSpacing
 
99
            cellHeight: renderer.cellHeight+renderer.verticalSpacing
 
100
 
 
101
            interactive: false
 
102
            clip: true
 
103
 
 
104
            delegate: Loader {
 
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
 
111
 
 
112
                width: renderer.cellWidth
 
113
                height: renderer.cellHeight
 
114
 
 
115
                sourceComponent: cellRenderer
 
116
                onLoaded: {
 
117
                    item.uri = uri
 
118
                    item.iconHint = iconHint
 
119
                    item.mimetype = mimetype
 
120
                    item.displayName = displayName
 
121
                    item.comment = comment
 
122
                }
 
123
            }
 
124
 
 
125
            model: renderer.model
 
126
        }
 
127
    }
 
128
}