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