Switch toolbar animation to opacity
[harmattan/cameraplus] / qml / PostCaptureView.qml
1 // -*- qml -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 import QtQuick 2.0
24 import CameraPlus 1.0
25 import QtCamera 1.0
26
27 Item {
28     id: postCaptureView
29
30     property Camera camera: null
31     property bool pressed: view.currentItem ? view.currentItem.playing : false
32     property int policyMode: view.currentItem && view.currentItem.playing ?
33         CameraResources.Player : settings.mode == Camera.VideoMode ? CameraResources.Video :
34         CameraResources.Image
35
36     property bool isCurrent: mainView.currentIndex == 2 && !mainView.moving
37     property bool inCameraMode: root.inCaptureMode && !mainView.moving
38
39     onIsCurrentChanged: {
40         if (isCurrent) {
41             postCaptureModel.reload()
42         }
43     }
44
45     onInCameraModeChanged: {
46         if (inCameraMode) {
47             postCaptureModel.clear()
48         }
49     }
50
51     Connections {
52         target: view.currentItem
53         onPlayingChanged: {
54             if (view.currentItem.playing) {
55                 hideTimer.running = false
56             }
57         }
58     }
59
60     ShareHelper {
61         id: share
62         settings: platformSettings
63     }
64
65     GalleryHelper {
66         id: gallery
67         settings: platformSettings
68     }
69
70     ListView {
71         id: view
72         anchors.fill: parent
73         snapMode: ListView.SnapOneItem
74         cacheBuffer: height * 3
75         model: postCaptureModel
76         highlightRangeMode: ListView.StrictlyEnforceRange
77         interactive: view.currentItem && view.currentItem.playing ? false : true
78
79         delegate: PostCaptureItem {
80             width: view.width
81             height: view.height
82             onClicked: hideTimer.running = !hideTimer.running
83         }
84
85         onFlickingChanged: {
86             if (flicking && hideTimer.running) {
87                 restartTimer()
88             }
89         }
90     }
91
92     PostCaptureModel {
93         id: postCaptureModel
94         imagePath: platformSettings.imagePath
95         videoPath: platformSettings.videoPath
96     }
97
98     Timer {
99         id: hideTimer
100         running: false
101         interval: 3000
102     }
103
104     CameraToolBar {
105         id: toolBar
106         expanded: true
107         hideBack: true
108         anchors.bottom: parent.bottom
109         anchors.bottomMargin: 20
110         anchors.left: parent.left
111         anchors.leftMargin: 20
112         anchors.right: parent.right
113         anchors.rightMargin: 20
114         opacity: show ? 0.8 : 0.0
115         visible: opacity > 0
116         property bool show: deleteDialog.isOpen || deleteDialog.isOpening ||
117             hideTimer.running ||
118             (view.currentItem != null && view.currentItem.error) && !view.currentItem.playing
119
120         Behavior on opacity {
121             PropertyAnimation { duration: view.currentItem && view.currentItem.playing ? 0 : 200 }
122         }
123
124         tools: CameraToolBarTools {
125             CameraToolIcon {
126                 iconSource: cameraTheme.shareIconId
127                 onClicked: {
128                     shareCurrentItem()
129                     restartTimer()
130                 }
131             }
132
133             CameraToolIcon {
134                 iconSource: cameraTheme.deleteIconId
135                 onClicked: {
136                     deleteCurrentItem()
137                     restartTimer()
138                 }
139             }
140
141             CameraToolIcon {
142                 iconSource: cameraTheme.galleryIconId
143                 onClicked: {
144                     launchGallery()
145                     restartTimer()
146                 }
147             }
148         }
149     }
150
151     CameraQueryDialog {
152         id: deleteDialog
153         titleText: qsTr("Delete item?");
154         acceptButtonText: qsTr("Yes");
155         rejectButtonText: qsTr("No");
156
157         onStatusChanged: restartTimer()
158
159         onAccepted: {
160             if (!remove.remove(view.currentItem.itemUrl)) {
161                 showError(qsTr("Failed to delete item"))
162             } else {
163                 view.model.remove(view.currentItem.itemUrl)
164             }
165         }
166
167         DeleteHelper {
168             id: remove
169         }
170     }
171
172     Rectangle {
173         opacity: toolBar.opacity
174         anchors.top: parent.top
175         anchors.topMargin: 20
176         anchors.left: parent.left
177         anchors.leftMargin: 20
178         anchors.right: parent.right
179         anchors.rightMargin: 20
180         visible: toolBar.visible
181         height: screen.isPortrait ? toolBar.height * 2 : toolBar.height
182         color: toolBar.color
183         border.color: toolBar.border.color
184         radius: toolBar.radius
185
186         Flow {
187             width: parent.width - 40
188             x: 20
189             height: parent.height
190
191             CameraLabel {
192                 text: view.currentItem ? view.currentItem.itemTitle : ""
193                 width: parent.width / 2
194                 height: parent.height
195                 font.bold: true
196                 verticalAlignment: Text.AlignVCenter
197                 horizontalAlignment: Text.AlignLeft
198             }
199
200             CameraLabel {
201                 text: view.currentItem ? view.currentItem.itemCreated : ""
202                 width: parent.width / 2
203                 height: parent.height
204                 font.bold: true
205                 verticalAlignment: Text.AlignVCenter
206                 horizontalAlignment: Text.AlignRight
207             }
208         }
209     }
210
211     function launchGallery() {
212         if (!gallery.launch()) {
213             showError(qsTr("Failed to launch gallery"))
214         }
215     }
216
217     function deleteCurrentItem() {
218         if (view.currentItem == null) {
219             return
220         }
221
222         deleteDialog.message = view.currentItem.itemFileName
223         deleteDialog.open()
224     }
225
226     function shareCurrentItem() {
227         if (view.currentItem != null && !share.share(view.currentItem.itemUrl)) {
228             showError(qsTr("Failed to launch share service"))
229         }
230     }
231
232     function restartTimer() {
233         hideTimer.restart()
234     }
235
236     function policyLost() {
237         if (view.currentItem && view.currentItem.playing) {
238             view.currentItem.stopPlayback()
239         }
240     }
241 }