2 * Copyright (C) 2014 Canonical, Ltd.
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.
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.
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/>.
18 import Ubuntu.Components 0.1
20 /*! \brief This component constructs the Preview UI.
22 * Currently it displays all the widgets in a flickable column.
28 /*! \brief Model containing preview widgets.
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.
34 property var previewModel
36 //! \brief Should be set to true if this preview is currently displayed.
37 property bool isCurrent: false
39 //! \brief The ScopeStyle component.
40 property var scopeStyle: null
46 property: "widgetColumnCount"
58 anchors { fill: parent; margins: spacing }
60 property int columns: width >= units.gu(80) ? 2 : 1
61 property real columnWidth: width / columns
68 objectName: "previewListRow" + index
73 width: row.columnWidth
75 bottomMargin: Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0
76 property var makeSureVisibleItem
77 property real previousVisibleHeight: 0
78 property real visibleHeight: height - bottomMargin
79 onVisibleHeightChanged: {
80 if (makeSureVisibleItem && makeSureVisibleItem.activeFocus && previousVisibleHeight > visibleHeight) {
81 var textAreaPos = makeSureVisibleItem.mapToItem(column, 0, 0);
82 if (textAreaPos.y + makeSureVisibleItem.height > column.visibleHeight) {
83 column.contentY += textAreaPos.y + makeSureVisibleItem.height - column.visibleHeight
86 previousVisibleHeight = visibleHeight;
92 Behavior on contentY { UbuntuNumberAnimation { } }
94 delegate: PreviewWidgetFactory {
95 widgetId: model.widgetId
96 widgetType: model.type
97 widgetData: model.properties
98 isCurrentPreview: root.isCurrent
99 scopeStyle: root.scopeStyle
103 leftMargin: units.gu(1)
104 rightMargin: units.gu(1)
108 previewModel.triggered(widgetId, actionId, data);
111 column.previousVisibleHeight=column.visibleHeight
112 column.makeSureVisibleItem=item
115 onFocusChanged: if (focus) column.positionViewAtIndex(index, ListView.Contain)
117 onHeightChanged: if (focus) column.positionViewAtIndex(index, ListView.Contain)