Added ROI an face detection
[harmattan/cameraplus] / declarative / roi.cpp
1 /*!
2  * This file is part of CameraPlus.
3  *
4  * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "roi.h"
22 #include "qtcamroi.h"
23
24 Roi::Roi(QtCamDevice *device, QObject *parent) :
25   QObject(parent),
26   m_roi(new QtCamRoi(device)) {
27
28   QObject::connect(m_roi,
29                    SIGNAL(regionsOfInterestUpdated(const QList<QRectF>&, const QRectF&, const QList<QRectF>&)),
30                    this,
31                    SLOT(handleRegionsChanged(const QList<QRectF>&, const QRectF&, const QList<QRectF>&)));
32 }
33
34 Roi::~Roi() {
35   delete m_roi; m_roi = 0;
36 }
37
38
39 void Roi::setEnabled(bool enabled) {
40   if (Roi::isEnabled() != enabled) {
41     m_roi->setEnabled(enabled);
42     emit enabledChanged();
43   }
44 }
45
46 bool Roi::isEnabled() {
47   return m_roi->isEnabled();
48 }
49
50 void Roi::setRegionOfInterest(const QRectF& region) {
51   m_roi->setRegionOfInterest(region);
52 }
53
54 void Roi::resetRegionOfInterest() {
55   m_roi->resetRegionOfInterest();
56 }
57
58 void Roi::handleRegionsChanged(const QList<QRectF>& regions, const QRectF& primary,
59                                const QList<QRectF>& rest) {
60
61   QVariantList regionsList = variantList(regions);
62   QVariantList restList = variantList(rest);
63   QVariant primaryRect = QVariant::fromValue(primary);
64
65   emit regionsChanged(regionsList, primaryRect, restList);
66 }
67
68 QVariantList Roi::variantList(const QList<QRectF>& rects) {
69   QVariantList list;
70
71   foreach(const QRectF& rect, rects) {
72     list.append(QVariant::fromValue(rect));
73   }
74
75   return list;
76 }