4 * This file is part of CameraPlus.
6 * Copyright (C) 2012-2013 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: hide all controls when we are focusing
28 // TODO: hide all controls when we are dragging
32 x: cam ? cam.renderArea.x : 0
33 y: cam ? cam.renderArea.y : 0
34 width: cam ? cam.renderArea.width : 0
35 height: cam ? cam.renderArea.height : 0
38 drag.maximumX: width - reticle.width
39 drag.maximumY: height - reticle.height
41 property bool locked: false
43 property int cafStatus: AutoFocus.None
44 property int status: AutoFocus.None
46 property bool touchMode
48 property variant touchPoint: Qt.point(mouse.width / 2, mouse.height / 2)
50 // A 100x100 central "rectangle"
51 property variant centerRect: Qt.rect((mouse.width / 2 - 50), (mouse.height / 2) - 50, 100, 100)
54 property variant primaryRoiRect: Qt.rect(0, 0, 0, 0)
55 property variant roiRects
56 property variant allRoiRects
57 property bool roiMode: allRoiRects != null && allRoiRects.length > 0 && !touchMode && !pressed
59 property variant __initialPos
62 if (mouse.x >= reticle.x &&
63 mouse.y >= reticle.y &&
64 mouse.x <= reticle.x + reticle.width &&
65 mouse.y <= reticle.y + reticle.height) {
69 __initialPos = touchPoint
70 calculateTouchPoint(mouse.x, mouse.y)
74 calculateTouchPoint(mouse.x, mouse.y)
78 onPositionChanged: calculateTouchPoint(mouse.x, mouse.y)
80 calculateTouchPoint(__initialPos.x, __initialPos.y)
84 function resetReticle() {
85 calculateTouchPoint(centerRect.x, centerRect.y)
88 function setRegionOfInterest() {
90 // console.log("Cannot set ROI without camera object")
92 } else if (mouse.pressed) {
93 // console.log("Will not set ROI while pressed")
95 } else if (!touchMode && !roiMode) {
96 // console.log("resetting ROI")
98 cam.roi.resetRegionOfInterest()
104 // TODO: rework this and move to unnormalized coordinates
105 // in terms of video resolution:
106 var rx = (cam.videoResolution.width * reticle.x) / mouse.width
107 var rwidth = (cam.videoResolution.width * reticle.width) / mouse.width
108 var ry = (cam.videoResolution.height * reticle.y) / mouse.height
109 var rheight = (cam.videoResolution.height * reticle.height) / mouse.height
111 // Translate to normalized coordinates (1x1 square) as expected by our C++ backend
112 rx = rx / cam.videoResolution.width
113 rwidth = rwidth / cam.videoResolution.width
114 ry = ry / cam.videoResolution.height
115 rheight = rheight / cam.videoResolution.height
117 // console.log("Setting ROI to: " + rx + "x" + ry)
118 cam.roi.setRegionOfInterest(Qt.rect(rx, ry, rwidth, rheight))
121 function calculateTouchPoint(x, y) {
122 if (x >= centerRect.x && y >= centerRect.y &&
123 x <= centerRect.x + centerRect.width &&
124 y <= centerRect.y + centerRect.height) {
126 touchPoint = Qt.point(mouse.width / 2, mouse.height / 2)
131 touchPoint = Qt.point(x, y)
134 function predictColor(caf, status) {
135 if (status == AutoFocus.Success) {
137 } else if (status == AutoFocus.Fail) {
139 } else if (status == AutoFocus.Running) {
141 } else if (caf == AutoFocus.Success) {
150 model: roiMode ? roiRects : 0
152 delegate: Rectangle {
155 width: modelData.width
156 height: modelData.height
165 width: mouse.pressed ? 150 : mouse.touchMode ? 200 : roiMode ? primaryRoiRect.width : 250
166 height: mouse.pressed ? 90 : mouse.touchMode ? 120 : roiMode ? primaryRoiRect.height : 150
167 x: Math.min(Math.max(mouse.touchPoint.x - (width / 2), drag.minimumX), drag.maximumX)
168 y: Math.min(Math.max(mouse.touchPoint.y - (height / 2), drag.minimumY), drag.maximumY)
169 color: predictColor(cafStatus, status)
171 onXChanged: setRegionOfInterest()
172 onYChanged: setRegionOfInterest()
175 PropertyAnimation { duration: 100 }
176 enabled: !mouse.pressed
180 PropertyAnimation { duration: 100 }
181 enabled: !mouse.pressed
185 PropertyAnimation { duration: 100 }
189 PropertyAnimation { duration: 100 }
196 // Changing mode (which implies changing pages) will not reset ROI
197 // thus we do it here
198 onModeChanged: resetReticle()
203 onRunningChanged: resetReticle()
204 onVideoResolutionChanged: resetReticle()
210 allRoiRects = regions
211 primaryRoiRect = primary
214 if (regions.length == 0) {
219 touchPoint = Qt.point(primary.x + (reticle.width / 2),
220 primary.y + (reticle.height / 2))
225 // This is for debugging
237 width: centerRect.width
238 height: centerRect.height
243 running: status == AutoFocus.Running
244 triggeredOnStart: true
246 onTriggered: reticle.visible = !reticle.visible
249 reticle.visible = true