Unity 8
 All Classes Functions Properties
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.0
18 import Ubuntu.Components 0.1
19 import "../Components"
20 
21 DashRenderer {
22  id: root
23 
24  readonly property double collapseLimit: units.gu(35)
25 
26  uncollapsedHeight: cardVerticalJournal.implicitHeight
27  collapsedHeight: Math.min(collapseLimit, cardVerticalJournal.implicitHeight)
28  expandable: uncollapsedHeight > collapseLimit
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  height: filtered ? Math.max(collapsedHeight, minHeight) : uncollapsedHeight
36 
37  Behavior on height {
38  id: heightBehaviour
39  enabled: false
40  animation: UbuntuNumberAnimation {
41  onRunningChanged: {
42  if (!running) {
43  heightBehaviour.enabled = false
44  }
45  }
46  }
47  }
48 
49  function setFilter(filter, animate) {
50  heightBehaviour.enabled = animate;
51  filtered = filter;
52  }
53 
55  id: cardVerticalJournal
56 
57  model: root.model
58 
59  anchors.fill: parent
60  rowSpacing: minimumColumnSpacing
61  columnWidth: cardTool.cardWidth
62 
63  displayMarginBeginning: root.displayMarginBeginning
64  displayMarginEnd: root.displayMarginEnd
65 
66  delegate: Loader {
67  id: loader
68  sourceComponent: cardTool.cardComponent
69  width: cardTool.cardWidth
70  anchors.horizontalCenter: parent.horizontalCenter
71  onLoaded: {
72  item.objectName = "delegate" + index;
73  item.width = Qt.binding(function() { return cardTool.cardWidth; });
74  item.height = Qt.binding(function() { return cardTool.cardHeight; });
75  item.fixedArtShapeSize = Qt.binding(function() { return cardTool.artShapeSize; });
76  item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
77  item.cardData = Qt.binding(function() { return model; });
78  item.template = Qt.binding(function() { return cardTool.template; });
79  item.components = Qt.binding(function() { return cardTool.components; });
80  item.headerAlignment = Qt.binding(function() { return cardTool.headerAlignment; });
81  }
82  Connections {
83  target: loader.item
84  onClicked: root.clicked(index, result)
85  onPressAndHold: root.pressAndHold(index)
86  }
87  }
88  }
89 }
A responsive wrapper around VerticalJournal.