00001 #ifndef QNATIVECAMERA_H
00002 #define QNATIVECAMERA_H
00003
00004 #include <QDeclarativeItem>
00005 #include <QVideoFrame>
00006 #include <QCamera>
00007 #include <QSize>
00008 #include <QCameraImageCapture>
00009 #include <QMediaRecorder>
00010
00011 #include "qdll_global.h"
00012
00013 class VideoSurface;
00014
00015
00016
00017
00018 class QDLLSHARED_EXPORT FrameObserver
00019 {
00020 public:
00021 virtual bool updateFrame(const QVideoFrame &frame) = 0;
00022 };
00023
00024 class QDLLSHARED_EXPORT QNativeCamera : public QDeclarativeItem, FrameObserver
00025 {
00026 Q_OBJECT
00027
00028 Q_ENUMS(State)
00029
00030
00031 Q_PROPERTY(State cameraState READ cameraState NOTIFY cameraStateChanged)
00032
00033
00034 Q_PROPERTY(QStringList availableDevices READ availableDevices)
00035
00036 Q_PROPERTY(QString currentDevice READ currentDevice NOTIFY currentDeviceChanged)
00037 Q_PROPERTY(bool frontCamera READ frontCamera NOTIFY frontCameraChanged)
00038 Q_PROPERTY(QSize resolution READ resolution WRITE setResolution NOTIFY resolutionChanged)
00039 Q_PROPERTY(qreal exposureCompensation READ exposureCompensation WRITE setExposureCompensation NOTIFY exposureCompensationChanged)
00040
00041 public:
00042
00043 enum State {
00044 ActiveState = QCamera::ActiveState,
00045 LoadedState = QCamera::LoadedState,
00046 UnloadedState = QCamera::UnloadedState
00047 };
00048
00049 explicit QNativeCamera(QDeclarativeItem *parent = 0);
00050 ~QNativeCamera();
00051
00052 QStringList availableDevices() const;
00053
00054 virtual void paint(QPainter *painter,
00055 const QStyleOptionGraphicsItem *option,
00056 QWidget *widget);
00057
00058 virtual bool updateFrame(const QVideoFrame &frame);
00059
00060 QSize resolution();
00061 void setResolution(QSize& value);
00062
00063 qreal exposureCompensation();
00064 void setExposureCompensation(qreal);
00065
00066 protected:
00067 void destroyResources();
00068 State cameraState() const;
00069 QString currentDevice() const;
00070 bool frontCamera() const;
00071
00072 signals:
00073 void resolutionChanged(QSize resolution);
00074
00075 void digitalZoomChanged();
00076 void maximumDigitalZoomChanged();
00077
00078 void exposureCompensationChanged();
00079 void exposureModeChanged();
00080 void supportedExposureModesChanged();
00081
00082 void flashModeChanged();
00083 void supportedFlashModesChanged();
00084
00085 void locked();
00086 void lockFailed();
00087
00088 void isoValueChanged();
00089 void supportedIsoValuesChanged();
00090
00091 void imageSaved(const QString &fileName);
00092
00093 void cameraStateChanged();
00094
00095 void whiteBalanceModeChanged();
00096 void supportedWhiteBalanceModesChanged();
00097
00098
00099
00100 void currentDeviceChanged();
00101 void frontCameraChanged();
00102
00103
00104
00105 public slots:
00106 void start(const QString &device);
00107 void stop();
00108
00109 void cameraStateChanged(QCamera::State state);
00110 void handleImageSaved(int id, const QString &fileName);
00111 virtual void captureImage();
00112 virtual void imageAvailable(int,QVideoFrame);
00113 virtual void imageCaptured ( int id, const QImage & preview );
00114 virtual void imageExposed(int);
00115
00116 void emitImageSavedSignal();
00117
00118 protected:
00119 qreal m_exposureCompensation;
00120
00121 protected:
00122 QCamera *m_camera;
00123
00124 QString m_currentDevice;
00125 bool m_frontCamera;
00126
00127 QCameraImageCapture *m_cameraImageCapture;
00128
00129
00130 QMediaRecorder *m_mediaRecorder;
00131
00132
00133 VideoSurface *m_videoSurface;
00134
00135
00136 unsigned int m_processedFrameCounter;
00137 unsigned int m_incomingFrameCounter;
00138 QImage m_imageFrame;
00139
00140
00141 QString m_galleryImage;
00142 QSize m_resolution;
00143 };
00144
00145 #endif // QNATIVECAMERA_H