Unity 8
PreviewActions.qml
1 /*
2  * Copyright (C) 2014,2015 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.4
18 import Ubuntu.Components 1.3
19 
20 /*! This preview widget shows either one button, two buttons or one button
21  * and a combo button depending on the number of items in widgetData["actions"].
22  * For each of the items we recognize the fields "label", "icon" and "id".
23  */
24 
25 PreviewWidget {
26  id: root
27 
28  implicitHeight: row.height + units.gu(1)
29  readonly property var actions: root.widgetData ? root.widgetData["actions"] : null
30 
31  Row {
32  id: row
33  anchors.right: parent.right
34 
35  spacing: units.gu(1)
36 
37  Loader {
38  id: loader
39  objectName: "loader"
40  readonly property bool button: root.actions && root.actions.length == 2
41  readonly property bool combo: root.actions && root.actions.length > 2
42  source: button ? "PreviewActionButton.qml" : (combo ? "PreviewActionCombo.qml" : "")
43  width: (root.width - units.gu(1)) / 2
44  onLoaded: {
45  if (button) {
46  item.data = Qt.binding(function() { return root.actions[1]; });
47  } else if (combo) {
48  item.model = Qt.binding(function() { return root.actions.slice(1); });
49  }
50  }
51  Binding {
52  target: loader.item
53  property: "strokeColor"
54  value: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText
55  }
56  Connections {
57  target: loader.item
58  onTriggeredAction: {
59  root.triggered(root.widgetId, actionData.id, actionData);
60  }
61  }
62  }
63 
64  PreviewActionButton {
65  data: visible ? root.actions[0] : null
66  visible: root.actions && root.actions.length > 0
67  onTriggeredAction: root.triggered(root.widgetId, actionData.id, actionData)
68  width: (root.width - units.gu(1)) / 2
69  color: root.scopeStyle ? root.scopeStyle.previewButtonColor : theme.palette.normal.positive
70  }
71  }
72 }