2 * This file is part of CameraPlus.
4 * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "qtcamdevice.h"
24 #include "qtcamviewfinder.h"
28 void init(const QRectF& renderArea, bool normalize) {
30 m_normalize = normalize;
33 QRectF unNormalize(const QRectF& rect) {
38 return QRectF(rect.x() * m_area.width(),
39 rect.y() * m_area.height(),
40 rect.width() * m_area.width(),
41 rect.height() * m_area.height());
44 QVariantList unNormalize(const QList<QRectF>& rects) {
47 foreach (const QRectF& rect, rects) {
48 vars.append(QVariant::fromValue(unNormalize(rect)));
59 Roi::Roi(QtCamDevice *device, QObject *parent) :
61 m_roi(new QtCamRoi(device)),
64 QObject::connect(m_roi,
65 SIGNAL(regionsOfInterestUpdated(const QList<QRectF>&, const QRectF&, const QList<QRectF>&)),
67 SLOT(handleRegionsChanged(const QList<QRectF>&, const QRectF&, const QList<QRectF>&)));
71 delete m_roi; m_roi = 0;
75 void Roi::setEnabled(bool enabled) {
76 if (Roi::isEnabled() != enabled) {
77 m_roi->setEnabled(enabled);
78 emit enabledChanged();
82 bool Roi::isEnabled() {
83 return m_roi->isEnabled();
86 void Roi::setRegionOfInterest(const QRectF& region) {
87 m_roi->setRegionOfInterest(region);
90 void Roi::resetRegionOfInterest() {
91 m_roi->resetRegionOfInterest();
94 void Roi::handleRegionsChanged(const QList<QRectF>& regions, const QRectF& primary,
95 const QList<QRectF>& rest) {
99 n.init(m_roi->device()->viewfinder()->renderArea(), m_normalize);
101 QVariantList regionsList = n.unNormalize(regions);
102 QVariantList restList = n.unNormalize(rest);
103 QVariant primaryRect = QVariant::fromValue(n.unNormalize(primary));
105 emit regionsChanged(regionsList, primaryRect, restList);
108 bool Roi::normalize() const {
112 void Roi::setNormalize(bool normalize) {
113 if (normalize != m_normalize) {
114 m_normalize = normalize;
115 emit normalizeChanged();