Unity 8
 All Classes Functions Properties
CardCarousel.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.0
18 import Ubuntu.Components 0.1
19 import "../Components"
20 
21 
22 DashRenderer {
23  id: cardCarousel
24 
25  property alias cacheBuffer: carousel.cacheBuffer
26  property alias itemComponent: carousel.itemComponent
27  property alias minimumTileWidth: carousel.minimumTileWidth
28  property alias selectedItemScaleFactor: carousel.selectedItemScaleFactor
29  property alias tileAspectRatio: carousel.tileAspectRatio
30 
31  currentItem: carousel.currentItem
32  height: carousel.implicitHeight + units.gu(6)
33  verticalSpacing: units.gu(3)
34 
35  Carousel {
36  id: carousel
37  anchors.fill: parent
38  tileAspectRatio: cardCarousel.components && cardCarousel.components["art"]["aspect-ratio"] || 1.0
39  // FIXME we need to "reverse" the carousel to make the selected item the size
40  // and push others back.
41  minimumTileWidth: cardTool.cardWidth / selectedItemScaleFactor
42  selectedItemScaleFactor: cardTool.carouselSelectedItemScaleFactor
43  cacheBuffer: 1404 // 18px * 13gu * 6
44  model: cardCarousel.model
45 
46  onClicked: cardCarousel.clicked(index, itemY)
47  onPressAndHold: cardCarousel.pressAndHold(index, itemY)
48 
49  property real fontScale: 1 / selectedItemScaleFactor
50  property real headerHeight: cardTool.headerHeight / selectedItemScaleFactor
51 
52  itemComponent: Loader {
53  id: loader
54 
55  property bool explicitlyScaled
56  property var model
57  enabled: false
58 
59  sourceComponent: cardTool.cardComponent
60  onLoaded: {
61  item.objectName = "carouselDelegate" + index;
62  item.fixedHeaderHeight = Qt.binding(function() { return carousel.headerHeight; });
63  item.height = Qt.binding(function() { return cardTool.cardHeight; });
64  item.cardData = Qt.binding(function() { return model; });
65  item.template = Qt.binding(function() { return cardTool.template; });
66  item.components = Qt.binding(function() { return cardTool.components; });
67  item.fontScale = Qt.binding(function() { return carousel.fontScale; });
68  item.showHeader = Qt.binding(function() { return loader.explicitlyScaled; });
69  }
70  }
71  }
72 }