Don't show rounded corners
[harmattan/cameraplus] / qml / FocusReticle.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 import QtQuick 1.1
24 import QtCamera 1.0
25 import CameraPlus 1.0
26
27 // TODO: keep reticle within bounds
28 // TODO: move reticle within bounds if resolution changes
29
30 MouseArea {
31         property int cafStatus: AutoFocus.None
32         property int status: AutoFocus.None
33         property variant topLeft: mapFromItem(cam, cam.renderArea.x, cam.renderArea.y)
34         property variant bottomRight: mapFromItem(cam, cam.renderArea.x + cam.renderArea.width, cam.renderArea.y + cam.renderArea.height)
35         id: mouse
36
37         // A 100x100 central "rectangle"
38         property variant centerRect: Qt.rect((mouse.width / 2 - 50), (mouse.height / 2) - 50, 100, 100);
39
40         property alias touchMode: reticle.touchMode
41
42         x: topLeft.x
43         y: topLeft.y
44         width: bottomRight.x - topLeft.x
45         height: bottomRight.y - topLeft.y
46
47         onStatusChanged: {
48                 if (status != AutoFocus.Running) {
49                         reticle.visible = true;
50                 }
51         }
52
53         function predictColor(caf, status) {
54                 if (status == AutoFocus.Success) {
55                         return "steelblue";
56                 }
57                 else if (status == AutoFocus.Fail) {
58                         return "red";
59                 }
60                 else if (status == AutoFocus.Running) {
61                         return "white";
62                 }
63                 else if (caf == AutoFocus.Success) {
64                         return "steelblue";
65                 }
66                 else {
67                         return "white";
68                 }
69         }
70
71         function moveRect(x, y) {
72                 // TODO: don't put reticle outside area
73                 x = x - (reticle.width / 2)
74                 y = y - (reticle.height / 2)
75
76                 reticle.x = x;
77                 reticle.y = y;
78         }
79
80         function moveToCenterIfNeeded(x, y) {
81                 if (x >= centerRect.x && y >= centerRect.y &&
82                     x <= centerRect.x + centerRect.width &&
83                     y <= centerRect.y + centerRect.height) {
84                         reticle.x = reticle.center.x
85                         reticle.y = reticle.center.y
86                 }
87         }
88
89         onPressed: moveRect(mouse.x, mouse.y);
90         onPositionChanged: moveRect(mouse.x, mouse.y);
91
92         onReleased: moveToCenterIfNeeded(mouse.x, mouse.y);
93
94         onXChanged: {
95                 // TODO:
96 //                moveRect(reticle.x, reticle.y);
97         }
98
99         FocusRectangle {
100                 id: reticle
101                 property variant center: Qt.point((mouse.width - width) / 2, (mouse.height - height) / 2);
102                 property bool touchMode: !(reticle.x == center.x && reticle.y == center.y)
103
104                 scale: mouse.pressed ? 0.6 :  touchMode ? 0.8 : 1.0
105
106                 width: 250
107                 height: 150
108                 x: center.x
109                 y: center.y
110
111                 color: predictColor(cafStatus, status);
112
113                 onXChanged: {
114                         if (mouse.pressed) {
115                                 return;
116                         }
117
118 //                        console.log(x);
119 //                        console.log(x);
120                 }
121         }
122
123         Timer {
124                 interval: 500
125                 running: status == AutoFocus.Running
126                 triggeredOnStart: true
127                 repeat: true
128                 onTriggered: reticle.visible = !reticle.visible
129         }
130 }