Unity 8
 All Classes Functions Properties
Preview.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 import Ubuntu.Components 0.1
19 
25 Item {
26  id: root
27 
34  property var previewModel
35 
37  property bool isCurrent: false
38 
39  clip: true
40 
41  Binding {
42  target: previewModel
43  property: "widgetColumnCount"
44  value: row.columns
45  }
46 
47  MouseArea {
48  anchors.fill: parent
49  }
50 
51  Row {
52  id: row
53 
54  spacing: units.gu(1)
55  anchors { fill: parent; margins: spacing }
56 
57  property int columns: width >= units.gu(80) ? 2 : 1
58  property real columnWidth: width / columns
59 
60  Repeater {
61  model: previewModel
62 
63  delegate: ListView {
64  id: column
65  anchors { top: parent.top; bottom: parent.bottom }
66  width: row.columnWidth
67  spacing: row.spacing
68  bottomMargin: Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0
69 
70  model: columnModel
71  cacheBuffer: height
72 
73  Behavior on contentY { UbuntuNumberAnimation { } }
74 
75  delegate: PreviewWidgetFactory {
76  widgetId: model.widgetId
77  widgetType: model.type
78  widgetData: model.properties
79  isCurrentPreview: root.isCurrent
80  anchors {
81  left: parent.left
82  right: parent.right
83  leftMargin: units.gu(1)
84  rightMargin: units.gu(1)
85  }
86 
87  onTriggered: {
88  previewModel.triggered(widgetId, actionId, data);
89  }
90 
91  onFocusChanged: if (focus) column.positionViewAtIndex(index, ListView.Contain)
92 
93  onHeightChanged: if (focus) column.positionViewAtIndex(index, ListView.Contain)
94  }
95  }
96  }
97  }
98 }