Dekko
Loading...
Searching...
No Matches
SmartFolderDelegate.qml
1/* Copyright (C) 2016 - 2017 Dan Chapman <dpniel@ubuntu.com>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18import QtQuick 2.4
19import Lomiri.Components 1.3
20import Lomiri.Components.Popups 1.3
21import Dekko.Mail 1.0
22import Dekko.Components 1.0
23import Dekko.Mail.Stores.Views 1.0
24import Dekko.Lomiri.Components 1.0
25import Dekko.Lomiri.Constants 1.0
27ListItem {
28 id: li
29
30 property var folder
31 signal subFolderClicked(string name, var key)
32 property bool supportsDescendents: false
33 property bool smartFolder: false
34 readonly property bool isCurrentIndex: layout ? layout.title.text === ViewStore.selectedNavFolder : false
35
36 expansion.expanded: false
37 expansion.height: layout.height + col.height
38 height: layout.height
39 divider.visible: false
40
41 function getIconForFolderType(f) {
42 switch (f.type) {
43 case SmartFolderSet.SmartTodayFolder:
44 return Icons.CalendarTodayIcon;
45 case SmartFolderSet.SmartTodoFolder:
46 return Icons.ViewListSymbolic;
47 case SmartFolderSet.SmartDoneFolder:
48 return Icons.SelectIcon;
49 case SmartFolderSet.SmartCustomFolder:
50 return Icons.FilterIcon;
51 default:
52 return Icons.FilterIcon;
53 }
54 }
55
56 Rectangle {
57 anchors.fill: layout ? layout : parent
58 color: Qt.rgba(0, 0, 0, 0.05)
59 visible: li.isCurrentIndex
60 }
61 MouseArea {
62 anchors.fill: parent
63 acceptedButtons: Qt.RightButton
64 onClicked: {
65 if (mouse.button === Qt.RightButton) {
66 PopupUtils.open(Qt.resolvedUrl("../popovers/NavViewContextMenu.qml"), li, {folder: li.folder})
67 mouse.accepted = true
68 } else {
69 mouse.accepted = false
70 }
71 }
72 }
73
74 ListItemLayout {
75 id: layout
76 title.text: folder ? folder.displayName : ""
77 title.font.weight: Font.DemiBold
78 title.color: LomiriColors.silk
79 height: units.gu(6)
80
82 id: attachmentImg
83 height: units.gu(2.6)
84 width: height
85 name: folder ? getIconForFolderType(folder) : ""
86 color: LomiriColors.silk
87 SlotsLayout.position: SlotsLayout.Leading
88 }
89
90 LomiriShape {
91 id: shape
92 // TODO: We should probably display total count for To-Do smart folder
93 visible: folder && folder.smartCount > 0
94 aspect: LomiriShape.Flat
95 color: LomiriColors.slate
96 height: units.gu(2.2)
97 width: countLable.width < height ? height : countLable.width + units.gu(1)
98 Label {
99 id: countLable
100 anchors.margins: units.gu(0.5)
101 anchors.centerIn: parent
102 fontSize: "small"
103 color: LomiriColors.porcelain
104 text: folder ? folder.smartCount : ""
105 }
106 }
107
108 Item {
109 visible: model.index === 0 && supportsDescendents
110 height: units.gu(3)
111 width: units.gu(4)
112 Rectangle {
113 anchors.left: parent.left
114 height: parent.height
115 width: units.dp(1)
116 color: LomiriColors.slate
117 }
118 Icon {
119 height: Style.defaultSpacing
120 width: height
121 anchors.right: parent.right
122 anchors.rightMargin: units.gu(0.5)
123 anchors.verticalCenter: parent.verticalCenter
124 name: li.expansion.expanded ? "up" : "down"
125 }
126 SlotsLayout.position: SlotsLayout.Last
127 AbstractButton {
128 anchors.fill: parent
129 onClicked: li.expansion.expanded = !li.expansion.expanded
130 }
131 }
132 }
133 Column {
134 id: col
135 visible: folder && folder.hasDescendents
136 anchors.left: parent.left
137 anchors.leftMargin: units.gu(1.5)
138 anchors.top: layout.bottom
139 anchors.right: parent.right
140 Repeater {
141 model: folder ? folder.descendents : 0
142 delegate: ListItem {
143 id: delegate
144 divider.visible: false
145 height: dlayout.height
146 onClicked: li.subFolderClicked(dlayout.title.text, model.qtObject.messageKey)
147 Rectangle {
148 anchors.fill: parent
149 color: Qt.rgba(0, 0, 0, 0.05)
150 visible: layout ? dlayout.title.text === ViewStore.selectedNavFolder : false
151 }
152 ListItemLayout {
153 id: dlayout
154 height: units.gu(5)
155 title.text: qsTr("Inbox (%1)").arg(qtObject.displayName)
156 title.color: LomiriColors.silk
157
159 height: units.gu(2.4)
160 width: height
161 name: Icons.InboxIcon
162 color: LomiriColors.silk
163 SlotsLayout.position: SlotsLayout.Leading
164 }
165
166 LomiriShape {
167 id: dshape
168 visible: qtObject.smartCount > 0
169 aspect: LomiriShape.Flat
170 color: LomiriColors.slate
171 height: units.gu(2.2)
172 width: dcountLable.width < height ? height : dcountLable.width + units.gu(1)
173 Label {
174 id: dcountLable
175 anchors.margins: units.gu(0.5)
176 anchors.centerIn: parent
177 text: qtObject.smartCount
178 fontSize: "small"
179 color: LomiriColors.porcelain
180 }
181 }
182 }
183 }
184 }
185 }
186}
187