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
21 #include "qtcamzoom.h"
22 #include "qtcamcapability_p.h"
23 #include "qtcamdevice_p.h"
25 class QtCamZoomPrivate : public QtCamCapabilityPrivate {
27 QtCamZoomPrivate(QtCamDevice *d, QtCamZoom *q) :
28 QtCamCapabilityPrivate(d, QtCamCapability::Zoom), q_ptr(q), binHandler(0) {
34 g_signal_handler_disconnect(bin, binHandler);
40 binHandler = g_signal_connect(bin, "notify", G_CALLBACK(camera_bin_notify), this);
44 static void camera_bin_notify(GObject *gobject, GParamSpec *pspec, QtCamZoomPrivate *d) {
47 QLatin1String name(pspec->name);
48 if (name == QLatin1String("max-zoom")) {
49 QMetaObject::invokeMethod(d->q_ptr, "maximumValueChanged", Qt::QueuedConnection);
51 else if (name == QLatin1String("zoom")) {
52 QMetaObject::invokeMethod(d->q_ptr, "valueChanged", Qt::QueuedConnection);
63 g_object_get(bin, "zoom", &v, NULL);
75 g_object_get(bin, "max-zoom", &v, NULL);
80 bool setZoom(qreal zoom) {
85 if (qFuzzyCompare(QtCamZoomPrivate::zoom(), zoom)) {
89 g_object_set(bin, "zoom", zoom, NULL);
98 QtCamZoom::QtCamZoom(QtCamDevice *dev, QObject *parent) :
99 QtCamCapability(new QtCamZoomPrivate(dev, this), parent) {
101 dynamic_cast<QtCamZoomPrivate *>(d_ptr)->init();
104 QtCamZoom::~QtCamZoom() {
108 qreal QtCamZoom::value() {
109 return dynamic_cast<QtCamZoomPrivate *>(d_ptr)->zoom();
112 bool QtCamZoom::setValue(qreal zoom) {
113 if (dynamic_cast<QtCamZoomPrivate *>(d_ptr)->setZoom(zoom)) {
121 qreal QtCamZoom::minimumValue() {
126 GParamSpec *pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(d_ptr->bin), "max-zoom");
127 if (pspec && G_IS_PARAM_SPEC_FLOAT(pspec)) {
128 return G_PARAM_SPEC_FLOAT(pspec)->minimum;
134 qreal QtCamZoom::maximumValue() {
135 return dynamic_cast<QtCamZoomPrivate *>(d_ptr)->maxZoom();