#endif
#include <QPainter>
#include "qtcamdevice.h"
+#include <QMatrix4x4>
#if defined(QT4)
Viewfinder::Viewfinder(QDeclarativeItem *parent) :
m_renderer(0),
m_cam(0),
m_conf(0),
+ m_dev(0),
m_enabled(true) {
#if defined(QT4)
}
Viewfinder::~Viewfinder() {
+ if (m_cam) {
+ m_cam->stop(true);
+ }
+ if (m_dev) {
+ m_dev->setViewfinder(0);
+ }
}
bool Viewfinder::isRenderingEnabled() const {
if (m_cam) {
QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
+ QObject::disconnect(m_cam, SIGNAL(prepareForDeviceChange()), this, SLOT(prepareForDeviceChange()));
}
m_cam = camera;
if (m_cam) {
QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
+ QObject::connect(m_cam, SIGNAL(prepareForDeviceChange()), this, SLOT(prepareForDeviceChange()));
}
if (isComponentComplete()) {
}
void Viewfinder::componentComplete() {
+#if defined(QT4)
+ QDeclarativeItem::componentComplete();
+#elif defined(QT5)
+ QQuickPaintedItem::componentComplete();
+#endif
+
if (!m_cam) {
qmlInfo(this) << "Camera not set";
return;
return;
}
- QtCamDevice *dev = m_cam->device();
+ if (m_dev) {
+ qmlInfo(this) << "Cannot set a new device without cleaning up the existing one";
+ abort();
+ }
- if (dev) {
- dev->setViewfinder(this);
+ m_dev = m_cam->device();
+
+ if (m_dev) {
+ m_dev->setViewfinder(this);
}
emit renderAreaChanged();
return m_renderer ? m_renderer->sinkElement() : 0;
}
-bool Viewfinder::setDevice(QtCamDevice *device) {
- Q_UNUSED(device);
-
- return true;
-}
-
void Viewfinder::stop() {
if (m_renderer) {
m_renderer->reset();
update();
}
}
+
+void Viewfinder::prepareForDeviceChange() {
+ if (m_dev) {
+ m_dev->setViewfinder(0);
+ m_dev = 0;
+ }
+}