Unity 8
CardVerticalJournal.qml
1 /*
2  * Copyright (C) 2014 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 Ubuntu.Components 1.3
19 import "../Components"
20 
21 DashRenderer {
22  id: root
23 
24  readonly property double collapseLimit: units.gu(35)
25 
26  expandedHeight: Math.max(cardVerticalJournal.implicitHeight, minHeight)
27  collapsedHeight: Math.max(Math.min(collapseLimit, cardVerticalJournal.implicitHeight), minHeight)
28  // TODO: implement collapsedItemCount
29 
30  // This minHeight is used as bootstrapper for the height. Vertical Journal
31  // is special by the fact that it doesn't know how to calculate its implicit height unless we give it
32  // enough height that it can start creating its children so we make sure it has enough height for that
33  // in case the model is non empty
34  readonly property double minHeight: root.model.count >= 1 ? cardVerticalJournal.rowSpacing + 1 : 0
35 
36  function clearView() {
37  cardVerticalJournal.model = null;
38  cardVerticalJournal.model = root.model;
39  }
40 
41  // Clear the view if the cardTool changes its sizes
42  // means it is still settling. This is
43  // necessary because the VerticalJournal does
44  // not support its elements changing height so
45  // we need to construct all the items with the settled
46  // size of the cardTool
47  Connections {
48  target: cardTool
49  onArtShapeSizeChanged: root.clearView();
50  onHeaderHeightChanged: root.clearView();
51  }
52 
53  ResponsiveVerticalJournal {
54  id: cardVerticalJournal
55 
56  model: root.model
57 
58  anchors.fill: parent
59  rowSpacing: minimumColumnSpacing
60  columnWidth: cardTool.cardWidth
61 
62  cacheBuffer: root.cacheBuffer
63  displayMarginBeginning: root.displayMarginBeginning
64  displayMarginEnd: root.displayMarginEnd
65 
66  delegate: Loader {
67  id: loader
68  sourceComponent: cardTool.cardComponent
69  width: cardTool.cardWidth
70  onLoaded: {
71  item.objectName = "delegate" + index;
72  item.fixedArtShapeSize = Qt.binding(function() { return cardTool.artShapeSize; });
73  item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
74  item.cardData = Qt.binding(function() { return model; });
75  item.components = Qt.binding(function() { return cardTool.components; });
76  item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
77  item.scopeStyle = root.scopeStyle;
78  }
79  Connections {
80  target: loader.item
81  onClicked: root.clicked(index, result, loader.item, model)
82  onPressAndHold: root.pressAndHold(index, result, model)
83  }
84  }
85  }
86 }