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