Unity 8
CardSocialActions.qml
1 /*
2  * Copyright 2016 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 QtQuick.Layouts 1.1
19 import Ubuntu.Components 1.3
20 
21 Column {
22  id: socialActions
23  spacing: units.gu(0.5)
24 
25  property alias model: repeater.model
26  property color color: theme.palette.normal.baseText
27 
28  signal clicked(var actionId)
29 
30  Rectangle {
31  id: divider
32  visible: repeater.count > 0
33  anchors {
34  left: parent.left;
35  right: parent.right;
36  leftMargin:units.dp(1);
37  rightMargin: units.dp(1);
38  }
39  color: Qt.darker(theme.palette.normal.background, 1.12)
40  height: visible ? units.dp(1) : 0
41  }
42 
43  Row {
44  id: row
45  anchors {
46  left: parent.left
47  right: parent.right
48  leftMargin: units.gu(1)
49  rightMargin: units.gu(1)
50  }
51  spacing: units.gu(2)
52  readonly property int visibleItems: {
53  if (width <= units.gu(12)) // small card
54  return 2;
55  else if (width <= units.gu(21)) // medium card
56  return 3;
57  else // large or horizontal card
58  return 4;
59  }
60 
61  Repeater {
62  id: repeater
63  delegate: Loader {
64  height: units.gu(2)
65  active: index < row.visibleItems
66  sourceComponent: AbstractButton {
67  objectName: "delegate" + index
68  height: units.gu(2)
69  width: icon.width
70  Icon {
71  id: icon
72  objectName: "icon"
73 
74  readonly property url urlIcon: modelData && modelData["icon"] || ""
75  readonly property url urlTemporaryIcon: "temporaryIcon" in modelData && modelData["temporaryIcon"] || ""
76 
77  height: units.gu(2)
78  // FIXME Workaround for bug https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1421293
79  width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth
80  source: urlIcon
81  color: socialActions.color
82 
83  onUrlIconChanged: {
84  if (urlIcon) source = urlIcon
85  }
86  }
87 
88  onClicked: socialActions.clicked(modelData["id"]);
89  onPressedChanged: if (pressed && icon.urlTemporaryIcon != "") icon.source = icon.urlTemporaryIcon
90  }
91  }
92  }
93  }
94 }