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")
97 cam.roi.resetRegionOfInterest()
101 // TODO: rework this and move to unnormalized coordinates
102 // in terms of video resolution:
103 var rx = (cam.videoResolution.width * reticle.x) / mouse.width
104 var rwidth = (cam.videoResolution.width * reticle.width) / mouse.width
105 var ry = (cam.videoResolution.height * reticle.y) / mouse.height
106 var rheight = (cam.videoResolution.height * reticle.height) / mouse.height
108 // Translate to normalized coordinates (1x1 square) as expected by our C++ backend
109 rx = rx / cam.videoResolution.width
110 rwidth = rwidth / cam.videoResolution.width
111 ry = ry / cam.videoResolution.height
112 rheight = rheight / cam.videoResolution.height
114 // console.log("Setting ROI to: " + rx + "x" + ry)
115 cam.roi.setRegionOfInterest(Qt.rect(rx, ry, rwidth, rheight))
118 function calculateTouchPoint(x, y) {
119 if (x >= centerRect.x && y >= centerRect.y &&
120 x <= centerRect.x + centerRect.width &&
121 y <= centerRect.y + centerRect.height) {
123 touchPoint = Qt.point(mouse.width / 2, mouse.height / 2)
128 touchPoint = Qt.point(x, y)
131 function predictColor(caf, status) {
132 if (status == AutoFocus.Success) {
134 } else if (status == AutoFocus.Fail) {
136 } else if (status == AutoFocus.Running) {
138 } else if (caf == AutoFocus.Success) {
147 model: roiMode ? roiRects : 0
149 delegate: Rectangle {
152 width: modelData.width
153 height: modelData.height
162 width: mouse.pressed ? 150 : mouse.touchMode ? 200 : roiMode ? primaryRoiRect.width : 250
163 height: mouse.pressed ? 90 : mouse.touchMode ? 120 : roiMode ? primaryRoiRect.height : 150
164 x: Math.min(Math.max(mouse.touchPoint.x - (width / 2), drag.minimumX), drag.maximumX)
165 y: Math.min(Math.max(mouse.touchPoint.y - (height / 2), drag.minimumY), drag.maximumY)
166 color: predictColor(cafStatus, status)
168 onXChanged: setRegionOfInterest()
169 onYChanged: setRegionOfInterest()
172 PropertyAnimation { duration: 100 }
173 enabled: !mouse.pressed
177 PropertyAnimation { duration: 100 }
178 enabled: !mouse.pressed
182 PropertyAnimation { duration: 100 }
186 PropertyAnimation { duration: 100 }
193 // Changing mode (which implies changing pages) will not reset ROI
194 // thus we do it here
195 onModeChanged: resetReticle()
200 onRunningChanged: resetReticle()
201 onVideoResolutionChanged: resetReticle()
207 allRoiRects = regions
208 primaryRoiRect = primary
211 if (regions.length == 0) {
216 touchPoint = Qt.point(primary.x + (reticle.width / 2),
217 primary.y + (reticle.height / 2))
222 // This is for debugging
234 width: centerRect.width
235 height: centerRect.height
240 running: status == AutoFocus.Running
241 triggeredOnStart: true
243 onTriggered: reticle.visible = !reticle.visible
246 reticle.visible = true