qnativecamera.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #ifndef QNATIVECAMERA_H
  2. #define QNATIVECAMERA_H
  3. #include <QDeclarativeItem>
  4. #include <QVideoFrame>
  5. #include <QCamera>
  6. #include <QCameraImageCapture>
  7. #include <QMediaRecorder>
  8. QT_USE_NAMESPACE
  9. class VideoSurface;
  10. // Observer design pattern to provide the view finder frame for the CustomCamera
  11. // object.
  12. class FrameObserver {
  13. public:
  14. virtual bool updateFrame(const QVideoFrame &frame) = 0;
  15. };
  16. class QNativeCamera : public QDeclarativeItem, FrameObserver
  17. {
  18. Q_OBJECT
  19. Q_ENUMS(State)
  20. // State properties
  21. Q_PROPERTY(State cameraState READ cameraState NOTIFY cameraStateChanged)
  22. // Devices properties
  23. Q_PROPERTY(QStringList availableDevices READ availableDevices)
  24. Q_PROPERTY(QString currentDevice READ currentDevice NOTIFY currentDeviceChanged)
  25. Q_PROPERTY(bool frontCamera READ frontCamera NOTIFY frontCameraChanged)
  26. Q_PROPERTY(bool preview READ preview WRITE setPreview)
  27. Q_PROPERTY(QSize resolution READ resolution WRITE setResolution NOTIFY resolutionChanged)
  28. Q_PROPERTY(qreal exposureCompensation READ exposureCompensation WRITE setExposureCompensation NOTIFY exposureCompensationChanged)
  29. public:
  30. enum State {
  31. ActiveState = QCamera::ActiveState,
  32. LoadedState = QCamera::LoadedState,
  33. UnloadedState = QCamera::UnloadedState
  34. };
  35. explicit QNativeCamera(QDeclarativeItem *parent = 0);
  36. ~QNativeCamera();
  37. QStringList availableDevices() const;
  38. virtual void paint(QPainter *painter,
  39. const QStyleOptionGraphicsItem *option,
  40. QWidget *widget);
  41. virtual bool updateFrame(const QVideoFrame &frame);
  42. QSize resolution();
  43. void setResolution(QSize& value);
  44. qreal exposureCompensation();
  45. void setExposureCompensation(qreal);
  46. bool preview();
  47. void setPreview(bool value);
  48. protected:
  49. void destroyResources();
  50. State cameraState() const;
  51. QString currentDevice() const;
  52. bool frontCamera() const;
  53. signals:
  54. void resolutionChanged(QSize resolution);
  55. void digitalZoomChanged();
  56. void maximumDigitalZoomChanged();
  57. void exposureCompensationChanged();
  58. void exposureModeChanged();
  59. void supportedExposureModesChanged();
  60. void flashModeChanged();
  61. void supportedFlashModesChanged();
  62. void locked();
  63. void lockFailed();
  64. void isoValueChanged();
  65. void supportedIsoValuesChanged();
  66. void imageSaved(const QString &fileName);
  67. void cameraStateChanged();
  68. void whiteBalanceModeChanged();
  69. void supportedWhiteBalanceModesChanged();
  70. //void sharpeningLevelChanged();
  71. //void contrastChanged();
  72. void currentDeviceChanged();
  73. void frontCameraChanged();
  74. //void imageAnalyzerChanged();
  75. public slots:
  76. void start(const QString &device);
  77. void stop();
  78. void cameraStateChanged(QCamera::State state);
  79. void handleImageSaved(int id, const QString &fileName);
  80. virtual void captureImage();
  81. virtual void imageAvailable(int,QVideoFrame);
  82. virtual void imageCaptured ( int id, const QImage & preview );
  83. virtual void imageExposed(int);
  84. void emitImageSavedSignal();
  85. protected:
  86. qreal m_exposureCompensation;
  87. QCamera *m_camera; // Owned
  88. QString m_currentDevice;
  89. bool m_frontCamera;
  90. // Still image capturing
  91. QCameraImageCapture *m_cameraImageCapture; // Owned
  92. // Video capturing
  93. QMediaRecorder *m_mediaRecorder; // Owned
  94. // For showing view finder image
  95. VideoSurface *m_videoSurface; // Owned
  96. // For storing the latest frame
  97. unsigned int m_processedFrameCounter;
  98. unsigned int m_incomingFrameCounter;
  99. QImage m_imageFrame;
  100. QImage i_preview;
  101. bool m_preview;
  102. // File to be opened in the gallery.
  103. QString m_galleryImage;
  104. QSize m_resolution;
  105. };
  106. #endif // QNATIVECAMERA_H