4 * This file is part of CameraPlus.
6 * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
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.
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.
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
27 // TODO: I've seen the reticle color changing to red while dragging it but failed to reproduce :(
28 // TODO: hide all controls when we are focusing
29 // TODO: hide all controls when we are dragging
32 property int cafStatus: AutoFocus.None
33 property int status: AutoFocus.None
34 property Camera cam: null
37 // A 100x100 central "rectangle"
38 property variant centerRect: Qt.rect((mouse.width / 2 - 50), (mouse.height / 2) - 50, 100, 100);
40 property alias touchMode: reticle.touchMode
42 x: cam ? cam.renderArea.x : 0
43 y: cam ? cam.renderArea.y : 0
44 width: cam ? cam.renderArea.width : 0
45 height: cam ? cam.renderArea.height : 0
49 // Changing mode (which implies changing pages) will not reset ROI
53 cam.autoFocus.setRegionOfInterest(Qt.rect(0, 0, 0, 0));
61 setRegionOfInterest();
66 // This is for debugging
78 width: centerRect.width
79 height: centerRect.height
83 drag.axis: Drag.XandYAxis
84 drag.minimumX: 0 - (0.1 * reticle.width)
85 drag.minimumY: 0 - (0.1 * reticle.height)
86 drag.maximumX: width - reticle.width + (0.1 * reticle.width)
87 drag.maximumY: height - reticle.height + (0.1 * reticle.height)
90 if (status != AutoFocus.Running) {
91 reticle.visible = true;
95 function predictColor(caf, status) {
96 if (status == AutoFocus.Success) {
99 else if (status == AutoFocus.Fail) {
102 else if (status == AutoFocus.Running) {
105 else if (caf == AutoFocus.Success) {
113 function moveToCenter() {
114 reticle.anchors.centerIn = reticle.parent;
115 reticle.touchMode = false;
118 function moveReticle(x, y) {
119 var xPos = x - ((reticle.width * 1) / 2);
120 var yPos = y - ((reticle.height * 1) / 2);
121 xPos = Math.min(Math.max(xPos, drag.minimumX), drag.maximumX);
122 yPos = Math.min(Math.max(yPos, drag.minimumY), drag.maximumY);
125 reticle.anchors.centerIn = undefined;
126 reticle.touchMode = true;
129 function moveToCenterIfNeeded(x, y) {
130 if (x >= centerRect.x && y >= centerRect.y &&
131 x <= centerRect.x + centerRect.width &&
132 y <= centerRect.y + centerRect.height) {
136 reticle.anchors.centerIn = undefined;
137 reticle.touchMode = true;
141 function setRegionOfInterest() {
142 if (!reticle.touchMode) {
143 // console.log("resetting ROI");
144 cam.autoFocus.setRegionOfInterest(Qt.rect(0, 0, 0, 0));
148 // take into account scale:
149 var x = reticle.x + (reticle.width * 0.1);
150 var y = reticle.y + (reticle.height * 0.1);
152 var width = reticle.width * 0.8;
153 var height = reticle.height * 0.8;
155 // in terms of video resolution:
156 x = (cam.videoResolution.width * x) / mouse.width;
157 width = (cam.videoResolution.width * width) / mouse.width;
158 y = (cam.videoResolution.height * y) / mouse.height;
159 height = (cam.videoResolution.height * height) / mouse.height;
161 // Translate to normalized coordinates (1x1 square) as expected by our C++ backend
162 x = x / cam.videoResolution.width;
163 width = width / cam.videoResolution.width;
164 y = y / cam.videoResolution.height;
165 height = height / cam.videoResolution.height;
167 // console.log("Setting ROI to: " + x + " " + y);
168 cam.autoFocus.setRegionOfInterest(Qt.rect(x, y, width, height));
172 moveToCenterIfNeeded(mouse.x, mouse.y);
173 setRegionOfInterest();
177 reticle.anchors.centerIn = undefined;
178 moveReticle(mouse.x, mouse.y);
183 property variant center: Qt.point((mouse.width - width) / 2, (mouse.height - height) / 2);
184 property bool touchMode: false
186 scale: mouse.pressed ? 0.6 : touchMode ? 0.8 : 1.0
191 anchors.centerIn: parent
193 color: predictColor(cafStatus, status);
196 PropertyAnimation { duration: 100; }
200 PropertyAnimation { duration: 100; }
204 PropertyAnimation { duration: 100; }
210 running: status == AutoFocus.Running
211 triggeredOnStart: true
213 onTriggered: reticle.visible = !reticle.visible