Unity 8
CardGrid.qml
1 /*
2  * Copyright (C) 2013 Canonical, Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 import QtQuick 2.4
18 import "../Components"
19 
20 DashRenderer {
21  id: root
22 
23  readonly property int collapsedRows: {
24  if (!cardTool || !cardTool.template || typeof cardTool.template["collapsed-rows"] != "number") return 2;
25  return cardTool.template["collapsed-rows"];
26  }
27 
28  expandedHeight: grid.totalContentHeight
29  collapsedHeight: Math.min(grid.contentHeightForRows(collapsedRows, grid.cellHeight), expandedHeight)
30  collapsedItemCount: collapsedRows * grid.columns
31  originY: grid.originY
32 
33  function cardPosition(index) {
34  var pos = {};
35  var row = Math.floor(index / grid.columns);
36  var column = index % grid.columns;
37  // Bit sad this is not symmetrical
38  pos.x = column * grid.cellWidth + grid.margins;
39  pos.y = row * grid.cellHeight;
40  return pos;
41  }
42 
43  ResponsiveGridView {
44  id: grid
45  anchors.fill: parent
46  minimumHorizontalSpacing: units.gu(1)
47  delegateWidth: cardTool.cardWidth
48  delegateHeight: cardTool.cardHeight
49  verticalSpacing: units.gu(1)
50  model: root.model
51  displayMarginBeginning: root.displayMarginBeginning
52  displayMarginEnd: root.displayMarginEnd
53  cacheBuffer: root.cacheBuffer
54  interactive: false
55  delegate: Item {
56  width: grid.cellWidth
57  height: grid.cellHeight
58  Loader {
59  id: loader
60  sourceComponent: cardTool.cardComponent
61  anchors.horizontalCenter: parent.horizontalCenter
62  onLoaded: {
63  item.objectName = "delegate" + index;
64  item.width = Qt.binding(function() { return cardTool.cardWidth; });
65  item.height = Qt.binding(function() { return cardTool.cardHeight; });
66  item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
67  item.fixedArtShapeSize = Qt.binding(function() { return cardTool.artShapeSize; });
68  item.cardData = Qt.binding(function() { return model; });
69  item.components = Qt.binding(function() { return cardTool.components; });
70  item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
71  item.scopeStyle = root.scopeStyle;
72  }
73  Connections {
74  target: loader.item
75  onClicked: root.clicked(index, result, loader.item, model)
76  onPressAndHold: root.pressAndHold(index, result, model)
77  }
78  }
79  }
80  }
81 }