~phablet-team/camera-app/staging

« back to all changes in this revision

Viewing changes to ViewFinderView.qml

  • Committer: Ugo Riboni
  • Date: 2015-12-10 12:35:14 UTC
  • mfrom: (621 staging)
  • mto: This revision was merged to the branch mainline in revision 622.
  • Revision ID: ugo.riboni@canonical.com-20151210123514-gxlk30tq50w8jgyj
Merge changes from staging

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    signal photoTaken(string filePath)
35
35
    signal videoShot(string filePath)
36
36
 
 
37
    onInViewChanged: decideCameraState()
 
38
    Connections {
 
39
        target: viewFinderOverlay
 
40
        onStatusChanged: decideCameraState()
 
41
    }
 
42
 
 
43
    function decideCameraState() {
 
44
        if (viewFinderOverlay.status == Loader.Ready) {
 
45
            if (viewFinderView.inView) {
 
46
                camera.cameraState = Camera.LoadedState;
 
47
                viewFinderOverlay.updateResolutionOptions();
 
48
                camera.cameraState = Camera.ActiveState;
 
49
            } else {
 
50
                camera.cameraState = Camera.LoadedState;
 
51
                viewFinderOverlay.updateResolutionOptions();
 
52
            }
 
53
        } else {
 
54
            if (camera.videoRecorder.recorderState == CameraRecorder.RecordingState) {
 
55
                camera.videoRecorder.stop();
 
56
            }
 
57
            camera.cameraState = Camera.UnloadedState;
 
58
        }
 
59
    }
 
60
 
37
61
    property Camera camera: Camera {
38
62
        id: camera
39
63
        captureMode: Camera.CaptureStillImage
76
100
        property alias currentZoom: camera.digitalZoom
77
101
        property alias maximumZoom: camera.maximumDigitalZoom
78
102
        property bool switchInProgress: false
79
 
        
 
103
 
80
104
        imageCapture {
81
105
            onReadyChanged: {
82
106
                if (camera.imageCapture.ready && main.transfer) {
109
133
                console.log("Picture saved as " + path);
110
134
            }
111
135
        }
112
 
        
 
136
 
113
137
        videoRecorder {
114
138
            onRecorderStateChanged: {
115
139
                if (videoRecorder.recorderState === CameraRecorder.StoppedState) {
126
150
        }
127
151
    }
128
152
 
129
 
    Connections {
130
 
        target: Qt.application
131
 
        onActiveChanged: {
132
 
            if (Qt.application.active) {
133
 
                if (camera.cameraState == Camera.LoadedState) {
134
 
                    camera.cameraState = Camera.ActiveState;
135
 
                }
136
 
            } else if (!application.desktopMode) {
137
 
                if (camera.videoRecorder.recorderState == CameraRecorder.RecordingState) {
138
 
                    camera.videoRecorder.stop();
139
 
                }
140
 
                camera.cameraState = Camera.LoadedState;
141
 
            }
142
 
        }
143
 
    }
144
 
 
145
153
    Item {
146
154
        id: viewFinderSwitcher
147
155
        anchors.fill: parent
158
166
                    // 'viewFinder.visible = false' prevents the camera switching
159
167
                    viewFinder.width = 1;
160
168
                    viewFinder.height = 1;
 
169
                    camera.cameraState = Camera.LoadedState;
161
170
                    camera.advanced.activeCameraIndex = (camera.advanced.activeCameraIndex === 0) ? 1 : 0;
 
171
                    decideCameraState();
162
172
                    viewFinderSwitcherRotation.angle = 180;
163
173
                }
164
174
            }
169
179
                angle: 180
170
180
            }
171
181
        }
172
 
        
 
182
 
173
183
        transform: [
174
184
            Scale {
175
185
                id: viewFinderSwitcherScale
186
196
                angle: 0
187
197
            }
188
198
        ]
189
 
        
190
 
        
 
199
 
 
200
 
191
201
        SequentialAnimation {
192
202
            id: viewFinderSwitcherAnimation
193
 
            
 
203
 
194
204
            SequentialAnimation {
195
205
                ParallelAnimation {
196
206
                    UbuntuNumberAnimation {target: viewFinderSwitcherScale; property: "xScale"; from: 1.0; to: 0.8; duration: UbuntuAnimation.BriskDuration ; easing: UbuntuAnimation.StandardEasing}
219
229
                }
220
230
            }
221
231
        }
222
 
        
 
232
 
223
233
        VideoOutput {
224
234
            id: viewFinder
225
 
            
 
235
 
226
236
            x: 0
227
237
            y: -viewFinderGeometry.y
228
238
            width: parent.width
229
239
            height: parent.height
230
240
            source: camera
231
 
            
 
241
 
232
242
            /* This rotation need to be applied since the camera hardware in the
233
243
                   Galaxy Nexus phone is mounted at an angle inside the device, so the video
234
244
                   feed is rotated too.
246
256
                // may change.
247
257
                orientation = Screen.primaryOrientation === Qt.PortraitOrientation  ? -90 : 0;
248
258
            }
249
 
            
 
259
 
250
260
            /* Convenience item tracking the real position and size of the real video feed.
251
261
                   Having this helps since these values depend on a lot of rules:
252
262
                   - the feed is automatically scaled to fit the viewfinder
254
264
                   - the resolution and aspect ratio of the feed changes depending on the active camera
255
265
                   The item is also separated in a component so it can be unit tested.
256
266
                 */
257
 
            
 
267
 
258
268
            transform: Rotation {
259
269
                origin.x: viewFinder.width / 2
260
270
                origin.y: viewFinder.height / 2