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