Unity 8
PreviewWidgetFactory.qml
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  */
17 
18 import QtQuick 2.4
19 
20 //! \brief This component loads the widgets based on widgetData["type"].
21 
22 Loader {
23  id: root
24 
25  //! Identifier of the widget.
26  property string widgetId: ""
27 
28  //! Type of the widget to display.
29  property string widgetType: ""
30 
31  //! Widget data, forwarded to the widget as is.
32  property var widgetData: null
33 
34  //! The ScopeStyle component.
35  property var scopeStyle: null
36 
37  //! Should the widget show in expanded mode (For those that support it)
38  property bool expanded: widgetType !== "expandable" || widgetData["expanded"] === true
39 
40  //! Set to true if the parent preview is displayed.
41  property bool isCurrentPreview: false
42 
43  //! Set margins width.
44  property real widgetMargins: status === Loader.Ready ? item.widgetMargins : units.gu(1)
45 
46  //! Triggered signal forwarded from the widgets.
47  signal triggered(string widgetId, string actionId, var data)
48 
49  //! MakesureVisible signal forwarded from the widgets.
50  signal makeSureVisible(var item)
51 
52  source: widgetSource
53 
54  //! \cond private
55  property url widgetSource: {
56  switch (widgetType) {
57  case "actions": return "PreviewActions.qml";
58  case "audio": return "PreviewAudioPlayback.qml";
59  case "comment": return "PreviewComment.qml";
60  case "comment-input": return "PreviewCommentInput.qml";
61  case "expandable": return "PreviewExpandable.qml";
62  case "gallery": return "PreviewImageGallery.qml";
63  case "header": return "PreviewHeader.qml";
64  case "icon-actions": return "PreviewIconActions.qml";
65  case "image": return "PreviewZoomableImage.qml";
66  case "progress": return "PreviewProgress.qml";
67  case "payments": return "PreviewPayments.qml";
68  case "rating-input": return "PreviewRatingInput.qml";
69  case "rating-edit": return "PreviewRatingEdit.qml";
70  case "reviews": return "PreviewRatingDisplay.qml";
71  case "table": return "PreviewTable.qml";
72  case "text": return "PreviewTextSummary.qml";
73  case "video": return "PreviewVideoPlayback.qml";
74  default: return "";
75  }
76  }
77  //! \endcond
78 
79  onLoaded: {
80  item.widgetId = Qt.binding(function() { return root.widgetId } )
81  item.widgetData = Qt.binding(function() { return root.widgetData } )
82  item.isCurrentPreview = Qt.binding(function() { return root.isCurrentPreview } )
83  item.expanded = Qt.binding(function() { return root.expanded } )
84  item.scopeStyle = Qt.binding(function() { return root.scopeStyle } )
85  }
86 
87  Connections {
88  target: root.item
89  onTriggered: root.triggered(widgetId, actionId, data)
90  onMakeSureVisible: root.makeSureVisible(item)
91  }
92 }