blob: 74e4c425d54c96fecb7c84de7ddd9027fe7a2d81 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/****************************************************************************
* Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT) *
* *
* This file may be used under the terms of the GNU Lesser *
* General Public License version 2.1 as published by the Free Software *
* Foundation and appearing in the file LICENSE.LGPL included in the *
* packaging of this file. Please review the following information to *
* ensure the GNU Lesser General Public License version 2.1 requirements *
* will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
****************************************************************************/
import QtQuick 2.0
import Snowshoe 1.0
Item {
id: root
property QtObject model: null
property Component delegate: null
property Component emptyItemDelegate: null
property int itemWidth: 192
property int itemHeight: 263
property int rowsPerPage: 2
property int columnsPerPage: 2
property int spacing: 0
property int maxPages: 1
// Read only properties.
property int pageCount: Math.min(maxPages, model != null && itemsPerPage ? Math.ceil(model.count / itemsPerPage) : 0)
property int itemsPerPage: rowsPerPage * columnsPerPage
property int pageWidth: columnsPerPage * itemWidth + (columnsPerPage - 1) * spacing
property int pageHeight: rowsPerPage * itemHeight + (rowsPerPage - 1) * spacing
property bool isEmpty: pageCount === 0
function itemAt(index) {
var pageForIndex = Math.floor(index / grid.itemsPerPage), offset = index % grid.itemsPerPage;
var pageItem = pageRepeater.itemAt(pageForIndex);
if (pageItem == null)
return null;
return pageItem.thumbs.itemAt(offset);
}
Grid {
spacing: root.spacing
rows: root.rowsPerPage
anchors {
top: pages.top
left: pages.left
}
Repeater {
model: maxPages * itemsPerPage
delegate: emptyItemDelegate
}
}
Row {
id: pages
spacing: root.spacing
Repeater {
id: pageRepeater
model: maxPages
Grid {
property alias thumbs: thumbRepeater
property int pageOffset: index * itemsPerPage
width: pageWidth
height: pageHeight
spacing: root.spacing
columns: root.columnsPerPage
RowsRangeFilter {
id: currentPageModel
sourceModel: root.model
startRow: index * itemsPerPage
endRow: startRow + itemsPerPage - 1
}
Repeater {
id: thumbRepeater
model: currentPageModel
delegate: pagedGrid.delegate
}
move: Transition { NumberAnimation { properties: "x,y"; duration: 200 } }
}
}
}
}
|