Unity 8
 All Classes Functions Properties
PreviewActions.qml
1 /*
2  * Copyright (C) 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 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 General Public License for more details.
12  *
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/>.
15  */
16 
17 import QtQuick 2.1
18 
24 PreviewWidget {
25  id: root
26 
27  height: row.height + units.gu(1)
28 
29  Row {
30  id: row
31  readonly property var actions: root.widgetData ? root.widgetData["actions"] : null
32  anchors.right: parent.right
33 
34  spacing: units.gu(1)
35 
36  Loader {
37  id: loader
38  readonly property bool button: row.actions && row.actions.length == 2
39  readonly property bool combo: row.actions && row.actions.length > 2
40  source: button ? "PreviewActionButton.qml" : (combo ? "PreviewActionCombo.qml" : "")
41  width: (root.width - units.gu(1)) / 2
42  onLoaded: {
43  if (button) {
44  item.data = row.actions[1];
45  } else if (combo) {
46  item.model = row.actions.slice(1);
47  }
48  }
49  Connections {
50  target: loader.item
51  onTriggeredAction: {
52  root.triggered(root.widgetId, actionData.id, actionData);
53  }
54  }
55  }
56 
57  PreviewActionButton {
58  data: visible ? row.actions[0] : null
59  visible: row.actions && row.actions.length > 0
60  onTriggeredAction: root.triggered(root.widgetId, actionData.id, actionData)
61  width: (root.width - units.gu(1)) / 2
62  }
63  }
64 }