viewfinderwrapper.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef VIEWFINDERWRAPPER_H
  2. #define VIEWFINDERWRAPPER_H
  3. #include <QDeclarativeItem>
  4. #include <QPainter>
  5. #include <QStyleOptionGraphicsItem>
  6. #include <QCamera>
  7. #include <QPixmap>
  8. #include "videosurface.h"
  9. #include "processingthread.h"
  10. class ViewFinderWrapper : public QDeclarativeItem
  11. {
  12. Q_OBJECT
  13. Q_PROPERTY(int cameraStatus READ cameraStatus NOTIFY cameraStatusChanged);
  14. Q_PROPERTY(int cameraError READ cameraError NOTIFY cameraErrorChanged);
  15. Q_PROPERTY(long frameCount READ frameCount NOTIFY frameCountChanged);
  16. Q_PROPERTY(long processedCount READ processedCount NOTIFY processedCountChanged);
  17. Q_PROPERTY(long skippedCount READ skippedCount NOTIFY skippedCountChanged);
  18. Q_PROPERTY(bool running READ running NOTIFY runningChanged);
  19. public:
  20. explicit ViewFinderWrapper(QDeclarativeItem *parent = 0);
  21. virtual ~ViewFinderWrapper();
  22. signals:
  23. void cameraStatusChanged(int status);
  24. void cameraErrorChanged(int error);
  25. void frameCountChanged(long count);
  26. void processedCountChanged(long count);
  27. void skippedCountChanged(long count);
  28. void runningChanged();
  29. public slots:
  30. int cameraStatus() const;
  31. int cameraError() const;
  32. long frameCount() const;
  33. long processedCount() const;
  34. long skippedCount() const;
  35. bool running() const;
  36. void startCamera();
  37. void stopCamera();
  38. private slots:
  39. // Camera
  40. void onStateChanged(QCamera::State state);
  41. void onStatusChanged(QCamera::Status status);
  42. void onCameraError(QCamera::Error error);
  43. // Surface
  44. void frameReady();
  45. // ProcessingThread
  46. void onFrameProcessed();
  47. void onFrameSkipped();
  48. private:
  49. void reset();
  50. void startViewFinder();
  51. void stopViewFinder();
  52. // From QDeclarativeItem
  53. virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
  54. private:
  55. QCamera* m_camera;
  56. QCamera::Status m_cameraStatus;
  57. QCamera::Error m_cameraError;
  58. bool m_cameraActive;
  59. VideoSurface m_surface;
  60. bool m_viewFinderActive;
  61. QPixmap m_currentFrame;
  62. long m_receivedFrameCounter;
  63. long m_processedFrameCounter;
  64. long m_skippedFrameCounter;
  65. ProcessingThread* m_processor;
  66. };
  67. #endif // VIEWFINDERWRAPPER_H