Dekko
AttachmentPanel.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 */
18 import QtQuick 2.4
19 import QtQuick.Controls.Suru 2.2
20 import Lomiri.Components 1.3
21 import Dekko.Components 1.0
22 import Dekko.Mail.API 1.0
23 import Dekko.Mail.Stores.Composer 1.0
24 import Dekko.Lomiri.Constants 1.0
25 import Dekko.Lomiri.Components 1.0
26 import "../delegates"
27 
28 Rectangle {
29  id: attachmentPanel
30 
31  property var attachments
32  property bool isReadOnly
33  property int maxHeight
34  property int attachmentDelegateHeight: units.gu(6)
35  readonly property int expandedHeight: internalHeight > maxHeight ? maxHeight : internalHeight
36  readonly property int internalHeight: header.height + attachmentList.contentHeight
37  readonly property int collapsedHeight: attachmentPanel.visible ? header.height : 0
38  readonly property bool expanded: state === "expanded"
39  color: Suru.backgroundColor
40  visible: attachments.count
41 
42  MouseArea {
43  anchors.fill: parent
44  acceptedButtons: Qt.LeftButton | Qt.RightButton
45  onClicked: mouse.accepted = true
46  onWheel: wheel.accepted = true
47  }
48  Line {
49  anchors {
50  left: parent.left
51  right: parent.right
52  top: parent.top
53  }
54  }
55 
56  ListItem {
57  id: header
58  anchors {
59  left: parent.left
60  right: parent.right
61  top: parent.top
62  }
63  height: units.gu(6)
64  onClicked: d.isExpanded = !d.isExpanded
65 
66  CachedImage {
67  id: ai
68  name: Icons.AttachmentIcon
69  height: Style.defaultIconSize
70  width: height
71  anchors {
72  left: parent.left
73  leftMargin: Style.defaultSpacing
74  verticalCenter: parent.verticalCenter
75  }
76  }
77 
78  Label {
79  id: l
80  anchors {
81  left: ai.right
82  leftMargin: Style.smallSpacing
83  verticalCenter: parent.verticalCenter
84  }
85  text: qsTr("Attachments")
86  }
87 
88  LomiriShape {
89  id: shape
90  anchors {
91  left: l.right
92  leftMargin: Style.smallSpacing
93  verticalCenter: parent.verticalCenter
94  }
95 
96  aspect: LomiriShape.Flat
97  color: Suru.secondaryBackgroundColor
98  height: units.gu(2.2)
99  width: countLable.width < height ? height : countLable.width + Style.smallSpacing
100  Label {
101  id: countLable
102  anchors.margins: units.gu(0.5)
103  anchors.centerIn: parent
104  fontSize: "small"
105  text: attachments.count
106  }
107  }
108 
109  Icon {
110  id: icon
111  name: "up"
112  anchors {
113  right: parent.right
114  rightMargin: Style.defaultSpacing
115  verticalCenter: parent.verticalCenter
116  }
117  color: LomiriColors.ash
118  rotation: attachmentPanel.expanded ? 180 : 0
119  height: Style.defaultSpacing; width: height
120  state: attachmentPanel.expanded ? "rotated" : "normal"
121  states: [
122  State {
123  name: "rotated"
124  PropertyChanges { target: icon; rotation: 180 }
125  },
126  State {
127  name: "normal"
128  PropertyChanges { target: icon; rotation: 0 }
129  }
130  ]
131  transitions: Transition {
132  RotationAnimation {
133  duration: LomiriAnimation.FastDuration
134  direction: icon.state === "normal" ? RotationAnimation.Clockwise : RotationAnimation.Counterclockwise
135  }
136  }
137  }
138  }
139 
140  ScrollView {
141  anchors {
142  left: parent.left
143  top: header.bottom
144  right: parent.right
145  bottom: parent.bottom
146  }
147 
148  ListView {
149  id: attachmentList
150  anchors.fill: parent
151  add: DekkoAnimation.listViewAddTransition
152  addDisplaced: DekkoAnimation.listViewAddDisplacedTransition
153  remove: DekkoAnimation.listViewRemoveTransition
154  removeDisplaced: DekkoAnimation.listViewRemoveDisplacedTransition
155  model: attachments ? attachments : 0
156  delegate: AttachmentDelegate {
157  height: attachmentDelegateHeight
158  leftSideAction: isReadOnly ? 0 : ComposerStore.actions.deleteAttachment
159  }
160  }
161  }
162 
163  QtObject {
164  id: d
165  property bool isExpanded: false
166  }
167 
168  Behavior on height {
169  LomiriNumberAnimation{}
170  }
171 
172  state: d.isExpanded ? "expanded" : "collapsed"
173  states: [
174  State {
175  name: "collapsed"
176  PropertyChanges {
177  target: attachmentPanel
178  height: collapsedHeight
179  }
180  },
181  State {
182  name: "expanded"
183  PropertyChanges {
184  target: attachmentPanel
185  height: expandedHeight
186  }
187  }
188  ]
189 }
190 
AttachmentDelegate
Definition: AttachmentDelegate.qml:24
Dekko::Lomiri::Constants::DekkoAnimation
Definition: DekkoAnimation.qml:22
Dekko
Definition: Dekko.qml:30
Dekko::Lomiri::Components::CachedImage
Definition: CachedImage.qml:22
Dekko::Lomiri::Components::Line
Definition: Line.qml:22
Dekko::Lomiri::Constants::Style::defaultSpacing
int defaultSpacing
Definition: Style.qml:27
Dekko::Lomiri::Constants::Style
Definition: Style.qml:23
Dekko::Lomiri::Constants::Style::defaultIconSize
int defaultIconSize
Definition: Style.qml:50
Dekko::Lomiri::Constants::Style::smallSpacing
int smallSpacing
Definition: Style.qml:33