Unity 8
ScopesListCategoryItem.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.4
18 import QtQuick.Layouts 1.1
19 import Ubuntu.Components 1.3
20 
21 AbstractButton {
22  id: root
23 
24  signal requestFavorite(string scopeId, bool favorite)
25  signal handlePressed(var handle)
26  signal handleReleased(var handle)
27 
28  property real topMargin: 0
29  property alias icon: shapeImage.source
30  property alias text: titleLabel.text
31  property alias subtext: subtitleLabel.text
32 
33  property bool showStar: false
34  property bool isFavorite: false
35  property bool hideChildren: false
36 
37  Item {
38  id: holder
39  anchors.fill: parent
40  anchors.topMargin: root.topMargin
41 
42  UbuntuShape {
43  id: shape
44  anchors {
45  left: parent.left
46  leftMargin: units.gu(1)
47  verticalCenter: parent.verticalCenter
48  }
49  width: units.gu(5)
50  height: units.gu(5)
51  visible: !hideChildren
52  aspect: UbuntuShape.Flat
53  sourceFillMode: UbuntuShape.PreserveAspectCrop
54  source: Image {
55  id: shapeImage
56  cache: true
57  sourceSize { width: shape.width; height: shape.height }
58  }
59  }
60 
61  ColumnLayout {
62  visible: !hideChildren
63  anchors {
64  left: shape.right
65  leftMargin: units.gu(1)
66  right: starArea.left
67  verticalCenter: parent.verticalCenter
68  }
69  Label {
70  id: titleLabel
71  Layout.fillWidth: true
72  elide: Text.ElideRight
73  wrapMode: Text.Wrap
74  maximumLineCount: 1
75  verticalAlignment: Text.AlignHCenter
76  }
77  Label {
78  id: subtitleLabel
79  Layout.fillWidth: true
80  elide: Text.ElideRight
81  fontSize: "xx-small"
82  wrapMode: Text.Wrap
83  maximumLineCount: 1
84  verticalAlignment: Text.AlignHCenter
85  visible: text != ""
86  }
87  }
88  AbstractButton {
89  id: starArea
90  objectName: "starArea"
91  height: parent.height
92  width: height
93  anchors.right: parent.right
94  onClicked: if (!editMode) root.requestFavorite(model.scopeId, !isFavorite);
95  onPressedChanged: {
96  if (editMode) {
97  if (pressed) root.handlePressed(starArea.__mouseArea);
98  else root.handleReleased(starArea.__mouseArea);
99  }
100  }
101  visible: editMode || showStar
102  Icon {
103  id: star
104  anchors.centerIn: parent
105  height: units.gu(2)
106  width: units.gu(2)
107  visible: !hideChildren
108  // TODO is view-grid-symbolic what we really want here? Looks good but seems semantically wrong
109  source: editMode ? "image://theme/view-grid-symbolic" : isFavorite ? "image://theme/starred" : "image://theme/non-starred"
110  }
111  }
112  }
113 }