Don't try to change the resolution while we are changing the device.
[harmattan/cameraplus] / qml / ZoomSlider.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 QtCamera 1.0
25
26 CameraSlider {
27     id: slider
28     property Camera camera: null
29
30     handleBackground: ""
31     handleBackgroundPressed: ""
32
33     Binding {
34         target: camera ? camera.zoom : null
35         property: "value"
36         value: slider.value
37         when: camera != null
38     }
39
40     Connections {
41         target: camera
42         onModeChanged: slider.value = camera.zoom.minimum;
43     }
44
45     Connections {
46         target: keys
47
48         onVolumeUpPressed: {
49             if (settings.zoomAsShutter) {
50                 return;
51             }
52
53             slider.value = Math.min(slider.value + slider.stepSize, slider.maximumValue)
54             hackTimer.running = true
55         }
56
57         onVolumeDownPressed: {
58             if (settings.zoomAsShutter) {
59                 return;
60             }
61
62             slider.value = Math.max(slider.value - slider.stepSize, slider.minimumValue)
63             hackTimer.running = true
64         }
65     }
66
67     orientation: Qt.Horizontal
68     width: 500
69     height: 50
70     stepSize:0.1
71     value: camera ? camera.zoom.value : 0
72     minimumValue: camera ? camera.zoom.minimum : 0
73     maximumValue: camera ? camera.zoom.maximum : 0
74
75     state: "hidden"
76     states: [
77         State {
78             name: "visible"
79             when: slider.pressed || hackTimer.running
80             PropertyChanges { target: slider; opacity: 1.0 }
81         },
82         State {
83             name: "hidden"
84             when: !slider.pressed
85             PropertyChanges { target: slider; opacity: 0.2 }
86         }
87     ]
88
89     transitions: Transition {
90         to: "hidden"
91             SequentialAnimation {
92                 PauseAnimation { duration: 2000 }
93                 NumberAnimation { target: slider; property: "opacity"; duration: 250 }
94             }
95     }
96
97     Timer {
98         id: hackTimer
99         interval: 1
100     }
101 }