Unity 8
CardCarousel.qml
1 /*
2  * Copyright (C) 2013-2015 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: cardCarousel
23 
24  readonly property real extraHeaderHeight: cardTool.template && cardTool.template["overlay"] === true ? 0 : cardTool.headerHeight
25 
26  expandedHeight: carousel.implicitHeight + units.gu(6) + extraHeaderHeight
27  collapsedHeight: expandedHeight
28  growsVertically: false
29  innerWidth: carousel.innerWidth
30 
31  Carousel {
32  id: carousel
33  anchors.fill: parent
34  tileAspectRatio: cardTool.components && cardTool.components["art"]["aspect-ratio"] || 1.0
35  extraBottomMargin: cardCarousel.extraHeaderHeight
36  // FIXME we need to "reverse" the carousel to make the selected item the size
37  // and push others back.
38  minimumTileWidth: cardTool.cardWidth / selectedItemScaleFactor
39  selectedItemScaleFactor: cardTool.carouselSelectedItemScaleFactor
40  cacheBuffer: cardCarousel.cacheBuffer
41  displayMarginBeginning: cardCarousel.displayMarginBeginning
42  displayMarginEnd: cardCarousel.displayMarginEnd
43  model: cardCarousel.model
44 
45  property real fontScale: 1 / selectedItemScaleFactor
46  property real headerHeight: cardTool.headerHeight / selectedItemScaleFactor
47 
48  itemComponent: Loader {
49  id: loader
50 
51  property bool explicitlyScaled
52  property var model
53  property int index
54  enabled: false
55 
56  objectName: "carouselDelegate" + index
57 
58  function clicked() { cardCarousel.clicked(index, model.result, loader.item, model) }
59  function pressAndHold() { cardCarousel.pressAndHold(index, model.result, model) }
60 
61  sourceComponent: cardTool.cardComponent
62  asynchronous: true
63  onLoaded: {
64  item.fixedHeaderHeight = Qt.binding(function() { return carousel.headerHeight; });
65  item.height = Qt.binding(function() { return cardTool.cardHeight; });
66  item.cardData = Qt.binding(function() { return model; });
67  item.components = Qt.binding(function() { return cardTool.components; });
68  item.fontScale = Qt.binding(function() { return carousel.fontScale; });
69  item.showHeader = Qt.binding(function() { return loader.explicitlyScaled; });
70  item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
71  item.artShapeStyle = "flat";
72  item.scopeStyle = cardCarousel.scopeStyle;
73  }
74 
75  BorderImage {
76  anchors {
77  fill: parent
78  margins: -units.gu(1)
79  }
80  z: -1
81  source: "graphics/carousel_dropshadow.sci"
82  }
83  }
84  }
85 }