3 #include "qtcamdevice.h"
5 #include "qtcamimagemode.h"
6 #include "qtcamvideomode.h"
7 #include "qtcamgraphicsviewfinder.h"
8 #include "qtcamconfig.h"
10 // TODO: a viewfinder class that inherits QDeclarativeItem
12 Camera::Camera(QDeclarativeItem *parent) :
13 QDeclarativeItem(parent),
14 m_cam(new QtCamera(this)),
16 m_vf(new QtCamGraphicsViewfinder(m_cam->config(), this)),
17 m_mode(Camera::ImageMode) {
26 void Camera::componentComplete() {
27 QDeclarativeItem::componentComplete();
30 QVariant oldId = m_id;
35 emit deviceCountChanged();
38 int Camera::deviceCount() const {
39 return m_cam ? m_cam->devices().size() : 0;
42 QString Camera::deviceName(int index) const {
43 return m_cam->devices().at(index).first;
46 QVariant Camera::deviceId(int index) const {
47 return m_cam->devices().at(index).second;
50 void Camera::setDeviceId(const QVariant& id) {
55 if (!isComponentComplete()) {
57 emit deviceIdChanged();
61 if (m_dev && m_dev->stop()) {
65 qWarning() << "Failed to stop device";
69 m_dev = m_cam->device(id, this);
73 m_vf->setDevice(m_dev);
75 QObject::connect(m_dev, SIGNAL(runningStateChanged(bool)),
76 this, SIGNAL(runningStateChanged()));
77 QObject::connect(m_dev, SIGNAL(idleStateChanged(bool)), this, SIGNAL(idleStateChanged()));
79 emit deviceIdChanged();
83 QVariant Camera::deviceId() const {
87 void Camera::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) {
88 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
90 m_vf->setGeometry(newGeometry);
93 QtCamDevice *Camera::device() const {
97 void Camera::setMode(const Camera::CameraMode& mode) {
108 if (m_dev->isRunning()) {
115 Camera::CameraMode Camera::mode() {
119 bool Camera::start() {
126 return m_dev->start();
129 bool Camera::stop() {
131 return m_dev->stop();
137 bool Camera::isIdle() {
138 return m_dev ? m_dev->isIdle() : true;
141 bool Camera::isRunning() {
142 return m_dev ? m_dev->isRunning() : false;
145 void Camera::applyMode() {
146 if (m_mode == Camera::VideoMode && m_dev->activeMode() != m_dev->videoMode()) {
147 m_dev->videoMode()->activate();
149 else if (m_mode == Camera::ImageMode && m_dev->activeMode() != m_dev->imageMode()) {
150 m_dev->imageMode()->activate();
154 QString Camera::imageSuffix() const {
155 return m_cam->config()->imageSuffix();
158 QString Camera::videoSuffix() const {
159 return m_cam->config()->videoSuffix();