Unity 8
 All Classes Functions
ScopesOverviewFavorites.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.3
18 import Ubuntu.Components 1.1
19 import "../Components/Flickables" as Flickables
20 
21 Flickables.Flickable {
22  id: root
23 
24  signal clicked(int index, var result, var itemModel)
25  signal pressAndHold(int index)
26 
27  property var cardTool: null
28  property real scopeHeight: 0
29  property real scopeWidth: 0
30  property real appliedScale: 1
31  property int currentIndex: -1
32  property var currentItem: currentIndex < repeater.count ? repeater.itemAt(currentIndex) : null
33 
34  property alias model: repeater.model
35 
36  contentHeight: height
37  contentWidth: repeater.count * root.scopeWidth + units.gu(2) / appliedScale * (repeater.count - 1)
38 
39  contentX: {
40  var indexX = currentIndex * scopeWidth + units.gu(2) / appliedScale * currentIndex;
41  var newContentX = indexX - (width - scopeWidth) / 2;
42  newContentX = Math.min(Math.max(newContentX, 0), contentWidth - width);
43  return newContentX;
44  }
45 
46  Repeater {
47  id: repeater
48  objectName: "scopesOverviewFavoritesRepeater"
49 
50  delegate: Loader {
51  id: loader
52 
53  x: index * root.scopeWidth + units.gu(2) / appliedScale * index
54  asynchronous: true
55 
56  sourceComponent: cardTool.cardComponent
57  onLoaded: {
58  item.fixedArtShapeSize = Qt.binding(function() { return Qt.size(root.scopeWidth, root.scopeHeight); });
59  item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight / appliedScale; });
60  item.fontScale = Qt.binding(function() { return 1 / appliedScale; });
61  item.height = Qt.binding(function() { return root.scopeHeight; });
62  item.width = Qt.binding(function() { return root.scopeWidth; });
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.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
67  }
68 
69  Connections {
70  target: loader.item
71  onClicked: root.clicked(index, result, model)
72  }
73  }
74  }
75 }