Convert TextSwitch to a platform specific component and rename it to CameraTextSwitch
[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                 enabled: view.currentItem != null
128                 onClicked: {
129                     shareCurrentItem()
130                     restartTimer()
131                 }
132             }
133
134             CameraToolIcon {
135                 iconSource: cameraTheme.deleteIconId
136                 enabled: view.currentItem != null
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: 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         Flow {
189             width: parent.width - 40
190             x: 20
191             height: parent.height
192
193             CameraLabel {
194                 text: view.currentItem ? view.currentItem.itemTitle : ""
195                 width: parent.width / 2
196                 height: parent.height
197                 font.bold: true
198                 verticalAlignment: Text.AlignVCenter
199                 horizontalAlignment: Text.AlignLeft
200             }
201
202             CameraLabel {
203                 text: view.currentItem ? view.currentItem.itemCreated : ""
204                 width: parent.width / 2
205                 height: parent.height
206                 font.bold: true
207                 verticalAlignment: Text.AlignVCenter
208                 horizontalAlignment: Text.AlignRight
209             }
210         }
211     }
212
213     function launchGallery() {
214         if (!gallery.launch()) {
215             showError(qsTr("Failed to launch gallery"))
216         }
217     }
218
219     function deleteCurrentItem() {
220         if (view.currentItem == null) {
221             return
222         }
223
224         deleteDialog.message = view.currentItem.itemFileName
225         deleteDialog.open()
226     }
227
228     function shareCurrentItem() {
229         if (view.currentItem != null && !share.share(view.currentItem.itemUrl)) {
230             showError(qsTr("Failed to launch share service"))
231         }
232     }
233
234     function restartTimer() {
235         hideTimer.restart()
236     }
237
238     function policyLost() {
239         if (view.currentItem && view.currentItem.playing) {
240             view.currentItem.stopPlayback()
241         }
242     }
243 }