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 
30  Row {
31  id: row
32  readonly property var actions: root.widgetData ? root.widgetData["actions"] : null
33  anchors.right: parent.right
34 
35  spacing: units.gu(1)
36 
37  Loader {
38  id: loader
39  readonly property bool button: row.actions && row.actions.length == 2
40  readonly property bool combo: row.actions && row.actions.length > 2
41  source: button ? "PreviewActionButton.qml" : (combo ? "PreviewActionCombo.qml" : "")
42  width: (root.width - units.gu(1)) / 2
43  onLoaded: {
44  if (button) {
45  item.data = row.actions[1];
46  } else if (combo) {
47  item.model = row.actions.slice(1);
48  }
49  }
50  Binding {
51  target: loader.item
52  property: "strokeColor"
53  value: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText
54  }
55  Connections {
56  target: loader.item
57  onTriggeredAction: {
58  root.triggered(root.widgetId, actionData.id, actionData);
59  }
60  }
61  }
62 
63  PreviewActionButton {
64  data: visible ? row.actions[0] : null
65  visible: row.actions && row.actions.length > 0
66  onTriggeredAction: root.triggered(root.widgetId, actionData.id, actionData)
67  width: (root.width - units.gu(1)) / 2
68  color: root.scopeStyle ? root.scopeStyle.previewButtonColor : UbuntuColors.orange
69  }
70  }
71 }