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 MouseArea {
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  sourceFillMode: UbuntuShape.PreserveAspectCrop
53  source: Image {
54  id: shapeImage
55  cache: true
56  sourceSize { width: shape.width; height: shape.height }
57  }
58  }
59 
60  ColumnLayout {
61  visible: !hideChildren
62  anchors {
63  left: shape.right
64  leftMargin: units.gu(1)
65  right: starArea.left
66  verticalCenter: parent.verticalCenter
67  }
68  Label {
69  id: titleLabel
70  Layout.fillWidth: true
71  elide: Text.ElideRight
72  wrapMode: Text.Wrap
73  maximumLineCount: 1
74  verticalAlignment: Text.AlignHCenter
75  }
76  Label {
77  id: subtitleLabel
78  Layout.fillWidth: true
79  elide: Text.ElideRight
80  fontSize: "xx-small"
81  wrapMode: Text.Wrap
82  maximumLineCount: 1
83  verticalAlignment: Text.AlignHCenter
84  visible: text != ""
85  }
86  }
87  MouseArea {
88  id: starArea
89  objectName: "starArea"
90  height: parent.height
91  width: height
92  anchors.right: parent.right
93  onClicked: if (!editMode) root.requestFavorite(model.scopeId, !isFavorite);
94  onPressed: if (editMode) root.handlePressed(starArea);
95  onReleased: if (editMode) root.handleReleased(starArea);
96  visible: editMode || showStar
97  Icon {
98  id: star
99  anchors.centerIn: parent
100  height: units.gu(2)
101  width: units.gu(2)
102  visible: !hideChildren
103  // TODO is view-grid-symbolic what we really want here? Looks good but seems semantically wrong
104  source: editMode ? "image://theme/view-grid-symbolic" : isFavorite ? "image://theme/starred" : "image://theme/non-starred"
105  }
106  }
107  }
108 }