Added copyright headers and COPYING file.
[harmattan/cameraplus] / qml / ModeButton.qml
1 // -*- qml -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012 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
24 import QtQuick 1.1
25 import QtCamera 1.0
26
27 Rectangle {
28         id: button
29         property int mode: settings.mode
30
31         color: "black"
32         width: 60
33         height: 120
34         smooth: true
35         radius: width
36         border.width: 2
37         border.color: "gray"
38
39         visible: cam.running && cam.idle && !cameraMode.animationRunning
40
41         Rectangle {
42                 id: highlighter
43                 width: parent.width
44                 height: parent.width
45                 color: mouse.pressed ? "lightblue" : "white"
46                 radius: parent.width
47                 y: mode == 1 ? video.y : image.y
48         }
49
50         Column {
51                 Image {
52                         id: image
53                         width: button.width
54                         height: width
55                         property string released: "icon-m-viewfinder-camera"
56                         property string active: "icon-m-viewfinder-camera-selected"
57                         source: mouse.pressed ? "image://theme/" + released : button.mode == 0 ? "image://theme/" + active : "image://theme/" + released
58                 }
59
60                 Image {
61                         id: video
62                         width: button.width
63                         height: width
64                         property string released: "icon-m-camera-video-record"
65                         property string active: "icon-m-camera-video-selected"
66                         source: mouse.pressed ? "image://theme/" + released : button.mode == 1 ? "image://theme/" + active : "image://theme/" + released
67                 }
68         }
69
70         MouseArea {
71                 anchors.fill: parent
72                 id: mouse
73                 drag.target: highlighter
74                 drag.axis: Drag.YAxis
75                 drag.minimumY: 0
76                 drag.maximumY: parent.height / 2
77                 onReleased: {
78
79                         if (!drag.active) {
80                                 if (mode == 0) {
81                                         settings.mode = Camera.VideoMode;
82                                 }
83                                 else {
84                                         settings.mode = Camera.ImageMode;
85                                 }
86
87                                 return;
88                         }
89
90                         if (mouse.y >= video.y) {
91                                 settings.mode = Camera.VideoMode;
92                         }
93                         else {
94                                 settings.mode = Camera.ImageMode;
95                         }
96                 }
97
98                 onPressed: {
99                         var y = mouse.y - highlighter.height / 2;
100
101                         if (y > drag.maximumY) {
102                                 y = drag.maximumY;
103                         }
104
105                         else if (y < drag.minimumY) {
106                                 y = 0;
107                         }
108
109                         highlighter.y = y
110                 }
111         }
112 }