Unity 8
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.4
18 import Ubuntu.Components 1.3
19 import "../../Components"
20 
21 /*! \brief This component constructs the Preview UI.
22  *
23  * Currently it displays all the widgets in a flickable column.
24  */
25 
26 Item {
27  id: root
28 
29  /*! \brief Model containing preview widgets.
30  *
31  * The model should expose "widgetId", "type" and "properties" roles, as well as
32  * have a triggered(QString widgetId, QString actionId, QVariantMap data) method,
33  * that's called when actions are executed in widgets.
34  */
35  property var previewModel
36 
37  //! \brief The ScopeStyle component.
38  property var scopeStyle: null
39 
40  clip: true
41 
42  Binding {
43  target: previewModel
44  property: "widgetColumnCount"
45  value: row.columns
46  }
47 
48  MouseArea {
49  anchors.fill: parent
50  }
51 
52  Row {
53  id: row
54 
55  spacing: units.gu(1)
56  anchors { fill: parent; margins: spacing }
57 
58  property int columns: width >= units.gu(80) ? 2 : 1
59  property real columnWidth: width / columns
60 
61  Repeater {
62  model: previewModel
63 
64  delegate: ListView {
65  id: column
66  objectName: "previewListRow" + index
67  anchors {
68  top: parent.top
69  bottom: parent.bottom
70  }
71  width: row.columnWidth
72  spacing: row.spacing
73 
74  ListViewOSKScroller {
75  id: oskScroller
76  list: column
77  }
78 
79  model: columnModel
80  cacheBuffer: height
81  highlightMoveDuration: 0 // QTBUG-53460
82 
83  Behavior on contentY { UbuntuNumberAnimation { } }
84 
85  delegate: PreviewWidgetFactory {
86  widgetId: model.widgetId
87  widgetType: model.type
88  widgetData: model.properties
89  scopeStyle: root.scopeStyle
90  parentFlickable: column
91 
92  anchors {
93  left: parent.left
94  right: parent.right
95  leftMargin: widgetMargins
96  rightMargin: widgetMargins
97  }
98 
99  onTriggered: {
100  previewModel.triggered(widgetId, actionId, data);
101  }
102 
103  onMakeSureVisible: {
104  oskScroller.setMakeSureVisibleItem(item);
105  }
106 
107  onFocusChanged: if (focus) column.positionViewAtIndex(index, ListView.Contain)
108 
109  onHeightChanged: if (focus) {
110  column.forceLayout();
111  column.positionViewAtIndex(index, ListView.Contain)
112  }
113  }
114  }
115  }
116  }
117 }