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 Should be set to true if this preview is currently displayed.
38  property bool isCurrent: false
39 
40  //! \brief The ScopeStyle component.
41  property var scopeStyle: null
42 
43  clip: true
44 
45  Binding {
46  target: previewModel
47  property: "widgetColumnCount"
48  value: row.columns
49  }
50 
51  MouseArea {
52  anchors.fill: parent
53  }
54 
55  Row {
56  id: row
57 
58  spacing: units.gu(1)
59  anchors { fill: parent; margins: spacing }
60 
61  property int columns: width >= units.gu(80) ? 2 : 1
62  property real columnWidth: width / columns
63 
64  Repeater {
65  model: previewModel
66 
67  delegate: ListView {
68  id: column
69  objectName: "previewListRow" + index
70  anchors {
71  top: parent.top
72  bottom: parent.bottom
73  }
74  width: row.columnWidth
75  spacing: row.spacing
76 
77  ListViewOSKScroller {
78  id: oskScroller
79  list: column
80  }
81 
82  model: columnModel
83  cacheBuffer: height
84 
85  Behavior on contentY { UbuntuNumberAnimation { } }
86 
87  delegate: PreviewWidgetFactory {
88  widgetId: model.widgetId
89  widgetType: model.type
90  widgetData: model.properties
91  isCurrentPreview: root.isCurrent
92  scopeStyle: root.scopeStyle
93  anchors {
94  left: parent.left
95  right: parent.right
96  leftMargin: widgetMargins
97  rightMargin: widgetMargins
98  }
99 
100  onTriggered: {
101  previewModel.triggered(widgetId, actionId, data);
102  }
103 
104  onMakeSureVisible: {
105  oskScroller.setMakeSureVisibleItem(item);
106  }
107 
108  onFocusChanged: if (focus) column.positionViewAtIndex(index, ListView.Contain)
109 
110  onHeightChanged: if (focus) column.positionViewAtIndex(index, ListView.Contain)
111  }
112  }
113  }
114  }
115 }