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