No need for the when condition for binding camera zoom value to slider value
[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: viewfinder.camera
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     property bool inhibitDim: pressed
36
37     property bool isCurrent: mainView.currentIndex == 2 && !mainView.moving
38     property bool inCameraMode: root.inCaptureMode && !mainView.moving
39
40     onIsCurrentChanged: {
41         if (isCurrent) {
42             postCaptureModel.reload()
43         }
44     }
45
46     onInCameraModeChanged: {
47         if (inCameraMode) {
48             postCaptureModel.clear()
49         }
50     }
51
52     Connections {
53         target: view.currentItem
54         onPlayingChanged: {
55             if (view.currentItem.playing) {
56                 hideTimer.running = false
57             }
58         }
59     }
60
61     ShareHelper {
62         id: share
63         settings: platformSettings
64     }
65
66     GalleryHelper {
67         id: gallery
68         settings: platformSettings
69     }
70
71     ListView {
72         id: view
73         anchors.fill: parent
74         snapMode: ListView.SnapOneItem
75         cacheBuffer: height * 3
76         model: postCaptureModel
77         highlightRangeMode: ListView.StrictlyEnforceRange
78         interactive: view.currentItem && view.currentItem.playing ? false : true
79
80         delegate: PostCaptureItem {
81             width: view.width
82             height: view.height
83             onClicked: hideTimer.running = !hideTimer.running
84         }
85
86         onFlickingChanged: {
87             if (flicking && hideTimer.running) {
88                 restartTimer()
89             }
90         }
91     }
92
93     PostCaptureModel {
94         id: postCaptureModel
95         imagePath: platformSettings.imagePath
96         videoPath: platformSettings.videoPath
97     }
98
99     Timer {
100         id: hideTimer
101         running: false
102         interval: 3000
103     }
104
105     CameraToolBar {
106         id: toolBar
107         expanded: true
108         hideBack: true
109         anchors.bottom: parent.bottom
110         anchors.bottomMargin: 20
111         anchors.left: parent.left
112         anchors.leftMargin: 20
113         anchors.right: parent.right
114         anchors.rightMargin: 20
115         opacity: show ? 0.8 : 0.0
116         visible: opacity > 0
117         property bool show: deleteDialog.isOpen || deleteDialog.isOpening ||
118             hideTimer.running ||
119             (view.currentItem != null && view.currentItem.error) && !view.currentItem.playing
120
121         Behavior on opacity {
122             PropertyAnimation { duration: view.currentItem && view.currentItem.playing ? 0 : 200 }
123         }
124
125         tools: CameraToolBarTools {
126             CameraToolIcon {
127                 iconSource: cameraTheme.shareIconId
128                 enabled: view.currentItem != null
129                 onClicked: {
130                     shareCurrentItem()
131                     restartTimer()
132                 }
133             }
134
135             CameraToolIcon {
136                 iconSource: cameraTheme.deleteIconId
137                 enabled: view.currentItem != null
138                 onClicked: {
139                     deleteCurrentItem()
140                     restartTimer()
141                 }
142             }
143
144             CameraToolIcon {
145                 iconSource: cameraTheme.galleryIconId
146                 onClicked: {
147                     launchGallery()
148                     restartTimer()
149                 }
150             }
151         }
152     }
153
154     CameraQueryDialog {
155         id: deleteDialog
156         titleText: qsTr("Delete item?");
157         acceptButtonText: qsTr("Yes");
158         rejectButtonText: qsTr("No");
159
160         onStatusChanged: restartTimer()
161
162         onAccepted: {
163             if (!remove.remove(view.currentItem.itemUrl)) {
164                 showError(qsTr("Failed to delete item"))
165             } else {
166                 view.model.remove(view.currentItem.itemUrl)
167             }
168         }
169
170         DeleteHelper {
171             id: remove
172         }
173     }
174
175     Rectangle {
176         opacity: toolBar.opacity
177         anchors.top: parent.top
178         anchors.topMargin: 20
179         anchors.left: parent.left
180         anchors.leftMargin: 20
181         anchors.right: parent.right
182         anchors.rightMargin: 20
183         visible: toolBar.visible
184         height: screen.isPortrait ? toolBar.height * 2 : toolBar.height
185         color: toolBar.color
186         border.color: toolBar.border.color
187         radius: toolBar.radius
188
189         Flow {
190             width: parent.width - 40
191             x: 20
192             height: parent.height
193
194             CameraLabel {
195                 text: view.currentItem ? view.currentItem.itemTitle : ""
196                 width: parent.width / 2
197                 height: parent.height
198                 font.bold: true
199                 verticalAlignment: Text.AlignVCenter
200                 horizontalAlignment: Text.AlignLeft
201             }
202
203             CameraLabel {
204                 text: view.currentItem ? view.currentItem.itemCreated : ""
205                 width: parent.width / 2
206                 height: parent.height
207                 font.bold: true
208                 verticalAlignment: Text.AlignVCenter
209                 horizontalAlignment: Text.AlignRight
210             }
211         }
212     }
213
214     function launchGallery() {
215         if (!gallery.launch()) {
216             showError(qsTr("Failed to launch gallery"))
217         }
218     }
219
220     function deleteCurrentItem() {
221         if (view.currentItem == null) {
222             return
223         }
224
225         deleteDialog.message = view.currentItem.itemFileName
226         deleteDialog.open()
227     }
228
229     function shareCurrentItem() {
230         if (view.currentItem != null && !share.share(view.currentItem.itemUrl)) {
231             showError(qsTr("Failed to launch share service"))
232         }
233     }
234
235     function restartTimer() {
236         hideTimer.restart()
237     }
238
239     function policyLost() {
240         if (view.currentItem && view.currentItem.playing) {
241             view.currentItem.stopPlayback()
242         }
243     }
244 }