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 :(
29 // TODO: hide all controls when we are focusing
30 // TODO: hide all controls when we are dragging
33 property int cafStatus: AutoFocus.None
34 property int status: AutoFocus.None
35 property Camera cam: null
38 // A 100x100 central "rectangle"
39 property variant centerRect: Qt.rect((mouse.width / 2 - 50), (mouse.height / 2) - 50, 100, 100);
41 property alias touchMode: reticle.touchMode
43 x: cam ? cam.renderArea.x : 0
44 y: cam ? cam.renderArea.y : 0
45 width: cam ? cam.renderArea.width : 0
46 height: cam ? cam.renderArea.height : 0
50 // Changing mode (which implies changing pages) will not reset ROI
54 cam.autoFocus.setRegionOfInterest(Qt.rect(0, 0, 0, 0));
63 cam.autoFocus.setRegionOfInterest(Qt.rect(0, 0, 0, 0));
68 // This is for debugging
80 width: centerRect.width
81 height: centerRect.height
85 drag.axis: Drag.XandYAxis
86 drag.minimumX: 0 - (0.1 * reticle.width)
87 drag.minimumY: 0 - (0.1 * reticle.height)
88 drag.maximumX: width - reticle.width + (0.1 * reticle.width)
89 drag.maximumY: height - reticle.height + (0.1 * reticle.height)
92 if (status != AutoFocus.Running) {
93 reticle.visible = true;
97 function predictColor(caf, status) {
98 if (status == AutoFocus.Success) {
101 else if (status == AutoFocus.Fail) {
104 else if (status == AutoFocus.Running) {
107 else if (caf == AutoFocus.Success) {
115 function moveToCenter() {
116 reticle.x = reticle.center.x;
117 reticle.y = reticle.center.y;
120 function moveReticle(x, y) {
121 var xPos = x - ((reticle.width * 1) / 2);
122 var yPos = y - ((reticle.height * 1) / 2);
123 xPos = Math.min(Math.max(xPos, drag.minimumX), drag.maximumX);
124 yPos = Math.min(Math.max(yPos, drag.minimumY), drag.maximumY);
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) {
133 reticle.x = reticle.center.x
134 reticle.y = reticle.center.y
138 function setRegionOfInterest() {
139 if (!reticle.touchMode) {
140 cam.autoFocus.setRegionOfInterest(Qt.rect(0, 0, 0, 0));
144 // take into account scale:
145 var x = reticle.x + (reticle.width * 0.1);
146 var y = reticle.y + (reticle.height * 0.1);
148 var width = reticle.width * 0.8;
149 var height = reticle.height * 0.8;
151 // in terms of video resolution:
152 x = (cam.videoResolution.width * x) / mouse.width;
153 width = (cam.videoResolution.width * width) / mouse.width;
154 y = (cam.videoResolution.height * y) / mouse.height;
155 height = (cam.videoResolution.height * height) / mouse.height;
157 // Translate to normalized coordinates (1x1 square) as expected by our C++ backend
158 x = x / cam.videoResolution.width;
159 width = width / cam.videoResolution.width;
160 y = y / cam.videoResolution.height;
161 height = height / cam.videoResolution.height;
163 cam.autoFocus.setRegionOfInterest(Qt.rect(x, y, width, height));
167 moveToCenterIfNeeded(mouse.x, mouse.y);
168 setRegionOfInterest();
172 moveReticle(mouse.x, mouse.y);
177 property variant center: Qt.point((mouse.width - width) / 2, (mouse.height - height) / 2);
178 property bool touchMode: !(reticle.x == center.x && reticle.y == center.y)
180 scale: mouse.pressed ? 0.6 : touchMode ? 0.8 : 1.0
187 color: predictColor(cafStatus, status);
192 running: status == AutoFocus.Running
193 triggeredOnStart: true
195 onTriggered: reticle.visible = !reticle.visible