on 436b607 help sign in
unity8/qml/Dash/Previews/PreviewWidgetFactory.qml
81 lines 2.9 kB history raw
1/*
2 * Copyright 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 Lesser 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
18import QtQuick 2.0
20//! \brief This component loads the widgets based on widgetData["type"].
22Loader {
23 id: root
25 //! Identifier of the widget.
26 property string widgetId: ""
28 //! Type of the widget to display.
29 property string widgetType: ""
31 //! Widget data, forwarded to the widget as is.
32 property var widgetData: null
34 //! The ScopeStyle component.
35 property var scopeStyle: null
37 //! Should the widget show in expanded mode (For those that support it)
38 property bool expanded: true
40 //! Set to true if the parent preview is displayed.
41 property bool isCurrentPreview: false
43 //! Triggered signal forwarded from the widgets.
44 signal triggered(string widgetId, string actionId, var data)
46 source: widgetSource
48 //! \cond private
49 property url widgetSource: {
50 switch (widgetType) {
51 case "actions": return "PreviewActions.qml";
52 case "audio": return "PreviewAudioPlayback.qml";
53 case "expandable": return "PreviewExpandable.qml";
54 case "gallery": return "PreviewImageGallery.qml";
55 case "header": return "PreviewHeader.qml";
56 case "image": return "PreviewZoomableImage.qml";
57 case "progress": return "PreviewProgress.qml";
58 case "payments": return "PreviewPayments.qml";
59 case "rating-input": return "PreviewRatingInput.qml";
60 case "reviews": return "PreviewRatingDisplay.qml";
61 case "table": return "PreviewTable.qml";
62 case "text": return "PreviewTextSummary.qml";
63 case "video": return "PreviewVideoPlayback.qml";
64 default: return "";
65 }
66 }
67 //! \endcond
69 onLoaded: {
70 item.widgetId = Qt.binding(function() { return root.widgetId } )
71 item.widgetData = Qt.binding(function() { return root.widgetData } )
72 item.isCurrentPreview = Qt.binding(function() { return root.isCurrentPreview } )
73 item.expanded = Qt.binding(function() { return root.expanded } )
74 item.scopeStyle = Qt.binding(function() { return root.scopeStyle } )
75 }
77 Connections {
78 target: root.item
79 onTriggered: root.triggered(widgetId, actionId, data)
80 }