Unity 8
 All Classes Functions Properties
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.0
19 
21 
22 Loader {
23  id: root
24 
26  property string widgetId: ""
27 
29  property string widgetType: ""
30 
32  property var widgetData: null
33 
35  property var scopeStyle: null
36 
38  property bool isCurrentPreview: false
39 
41  signal triggered(string widgetId, string actionId, var data)
42 
43  source: widgetSource
44 
46  property url widgetSource: {
47  switch (widgetType) {
48  case "actions": return "PreviewActions.qml";
49  case "audio": return "PreviewAudioPlayback.qml";
50  case "gallery": return "PreviewImageGallery.qml";
51  case "header": return "PreviewHeader.qml";
52  case "image": return "PreviewZoomableImage.qml";
53  case "progress": return "PreviewProgress.qml";
54  case "payments": return "PreviewPayments.qml";
55  case "rating-input": return "PreviewRatingInput.qml";
56  case "reviews": return "PreviewRatingDisplay.qml";
57  case "text": return "PreviewTextSummary.qml";
58  case "video": return "PreviewVideoPlayback.qml";
59  default: return "";
60  }
61  }
63 
64  onLoaded: {
65  item.widgetId = Qt.binding(function() { return root.widgetId } )
66  item.widgetData = Qt.binding(function() { return root.widgetData } )
67  item.isCurrentPreview = Qt.binding(function() { return root.isCurrentPreview } )
68  if (item.hasOwnProperty("scopeStyle")) item.scopeStyle = root.scopeStyle;
69  }
70 
71  Connections {
72  target: root.item
73  onTriggered: root.triggered(widgetId, actionId, data)
74  }
75 }