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 property int cafStatus: AutoFocus.None
30 property int status: AutoFocus.None
33 // A 100x100 central "rectangle"
34 property variant centerRect: Qt.rect((mouse.width / 2 - 50), (mouse.height / 2) - 50, 100, 100);
36 property alias touchMode: reticle.touchMode
40 width: cam.renderArea.width
41 height: cam.renderArea.height
43 // Changing mode (which implies changing pages) will not reset ROI thus we do it here
44 Component.onCompleted: cam.autoFocus.setRegionOfInterest(Qt.rect(0, 0, 0, 0));
47 // This is for debugging
59 width: centerRect.width
60 height: centerRect.height
64 drag.axis: Drag.XandYAxis
65 drag.minimumX: 0 - (0.1 * reticle.width)
66 drag.minimumY: 0 - (0.1 * reticle.height)
67 drag.maximumX: width - reticle.width + (0.1 * reticle.width)
68 drag.maximumY: height - reticle.height + (0.1 * reticle.height)
71 if (status != AutoFocus.Running) {
72 reticle.visible = true;
76 function predictColor(caf, status) {
77 if (status == AutoFocus.Success) {
80 else if (status == AutoFocus.Fail) {
83 else if (status == AutoFocus.Running) {
86 else if (caf == AutoFocus.Success) {
94 function moveReticle(x, y) {
95 var xPos = x - ((reticle.width * 1) / 2);
96 var yPos = y - ((reticle.height * 1) / 2);
97 xPos = Math.min(Math.max(xPos, drag.minimumX), drag.maximumX);
98 yPos = Math.min(Math.max(yPos, drag.minimumY), drag.maximumY);
103 function moveToCenterIfNeeded(x, y) {
104 if (x >= centerRect.x && y >= centerRect.y &&
105 x <= centerRect.x + centerRect.width &&
106 y <= centerRect.y + centerRect.height) {
107 reticle.x = reticle.center.x
108 reticle.y = reticle.center.y
112 function setRegionOfInterest() {
113 if (!reticle.touchMode) {
114 cam.autoFocus.setRegionOfInterest(Qt.rect(0, 0, 0, 0));
118 // take into account scale:
119 var x = reticle.x + (reticle.width * 0.1);
120 var y = reticle.y + (reticle.height * 0.1);
122 var width = reticle.width * 0.8;
123 var height = reticle.height * 0.8;
125 // in terms of video resolution:
126 x = (cam.videoResolution.width * x) / mouse.width;
127 width = (cam.videoResolution.width * width) / mouse.width;
128 y = (cam.videoResolution.height * y) / mouse.height;
129 height = (cam.videoResolution.height * height) / mouse.height;
131 // Translate to normalized coordinates (1x1 square) as expected by our C++ backend
132 x = x / cam.videoResolution.width;
133 width = width / cam.videoResolution.width;
134 y = y / cam.videoResolution.height;
135 height = height / cam.videoResolution.height;
137 cam.autoFocus.setRegionOfInterest(Qt.rect(x, y, width, height));
141 moveToCenterIfNeeded(mouse.x, mouse.y);
142 setRegionOfInterest();
146 moveReticle(mouse.x, mouse.y);
151 property variant center: Qt.point((mouse.width - width) / 2, (mouse.height - height) / 2);
152 property bool touchMode: !(reticle.x == center.x && reticle.y == center.y)
154 scale: mouse.pressed ? 0.6 : touchMode ? 0.8 : 1.0
161 color: predictColor(cafStatus, status);
166 running: status == AutoFocus.Running
167 triggeredOnStart: true
169 onTriggered: reticle.visible = !reticle.visible