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: keep reticle within bounds
28 // TODO: move reticle within bounds if resolution changes
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)
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
44 width: bottomRight.x - topLeft.x
45 height: bottomRight.y - topLeft.y
48 if (status != AutoFocus.Running) {
49 reticle.visible = true;
53 function predictColor(caf, status) {
54 if (status == AutoFocus.Success) {
57 else if (status == AutoFocus.Fail) {
60 else if (status == AutoFocus.Running) {
63 else if (caf == AutoFocus.Success) {
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)
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
89 onPressed: moveRect(mouse.x, mouse.y);
90 onPositionChanged: moveRect(mouse.x, mouse.y);
92 onReleased: moveToCenterIfNeeded(mouse.x, mouse.y);
96 // moveRect(reticle.x, reticle.y);
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)
104 scale: mouse.pressed ? 0.6 : touchMode ? 0.8 : 1.0
111 color: predictColor(cafStatus, status);
125 running: status == AutoFocus.Running
126 triggeredOnStart: true
128 onTriggered: reticle.visible = !reticle.visible