Code cleanup
[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 == Camera.VideoMode ? 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 == Camera.ImageMode ? "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 == Camera.VideoMode ? "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                         if (!drag.active) {
79                                 if (mode == Camera.ImageMode) {
80                                         settings.mode = Camera.VideoMode;
81                                 }
82                                 else if (mode == Camera.VideoMode) {
83                                         settings.mode = Camera.ImageMode;
84                                 }
85
86                                 return;
87                         }
88
89                         if (mouse.y >= video.y) {
90                                 settings.mode = Camera.VideoMode;
91                         }
92                         else {
93                                 settings.mode = Camera.ImageMode;
94                         }
95                 }
96
97                 onPressed: {
98                         var y = mouse.y - highlighter.height / 2;
99
100                         if (y > drag.maximumY) {
101                                 y = drag.maximumY;
102                         }
103
104                         else if (y < drag.minimumY) {
105                                 y = 0;
106                         }
107
108                         highlighter.y = y
109                 }
110         }
111 }