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 bool isCurrentPreview: false
36 
38  signal triggered(string widgetId, string actionId, var data)
39 
40  source: widgetSource
41 
43  property url widgetSource: {
44  switch (widgetType) {
45  case "actions": return "PreviewActions.qml";
46  case "audio": return "PreviewAudioPlayback.qml";
47  case "gallery": return "PreviewImageGallery.qml";
48  case "header": return "PreviewHeader.qml";
49  case "image": return "PreviewZoomableImage.qml";
50  case "progress": return "PreviewProgress.qml";
51  case "rating-input": return "PreviewRatingInput.qml";
52  case "reviews": return "PreviewRatingDisplay.qml";
53  case "text": return "PreviewTextSummary.qml";
54  case "video": return "PreviewVideoPlayback.qml";
55  default: return "";
56  }
57  }
59 
60  onLoaded: {
61  item.widgetId = Qt.binding(function() { return root.widgetId } )
62  item.widgetData = Qt.binding(function() { return root.widgetData } )
63  item.isCurrentPreview = Qt.binding(function() { return root.isCurrentPreview } )
64  }
65 
66  Connections {
67  target: root.item
68  onTriggered: root.triggered(widgetId, actionId, data)
69  }
70 }