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