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