13bcb3070ebf4d7cd1be4cfeb7d6f75418d12a6c
[harmattan/cameraplus] / imports / camera.h
1 // -*- c++ -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #ifndef CAMERA_H
24 #define CAMERA_H
25
26 #include <QDeclarativeItem>
27 #include <QVariant>
28 #include <QPointer>
29
30 class QtCamera;
31 class QtCamDevice;
32 class QtCamGraphicsViewfinder;
33 class Notifications;
34 class NotificationsContainer;
35 class Zoom;
36 class Flash;
37 class Scene;
38 class EvComp;
39 class WhiteBalance;
40 class ColorTone;
41 class Iso;
42 class Exposure;
43 class Aperture;
44 class NoiseReduction;
45 class FlickerReduction;
46 class Focus;
47 class AutoFocus;
48 class VideoMute;
49 class VideoTorch;
50
51 class Camera : public QDeclarativeItem {
52   Q_OBJECT
53
54   Q_PROPERTY(int deviceCount READ deviceCount NOTIFY deviceCountChanged)
55   Q_PROPERTY(QVariant deviceId READ deviceId NOTIFY deviceIdChanged);
56   Q_PROPERTY(CameraMode mode READ mode NOTIFY modeChanged);
57   Q_PROPERTY(bool idle READ isIdle NOTIFY idleStateChanged);
58   Q_PROPERTY(bool running READ isRunning NOTIFY runningStateChanged);
59   Q_PROPERTY(QString imageSuffix READ imageSuffix CONSTANT);
60   Q_PROPERTY(QString videoSuffix READ videoSuffix CONSTANT);
61   Q_PROPERTY(Notifications *notifications READ notifications WRITE setNotifications NOTIFY notificationsChanged);
62
63   Q_PROPERTY(Zoom *zoom READ zoom NOTIFY zoomChanged);
64   Q_PROPERTY(Flash *flash READ flash NOTIFY flashChanged);
65   Q_PROPERTY(Scene *scene READ scene NOTIFY sceneChanged);
66   Q_PROPERTY(EvComp *evComp READ evComp NOTIFY evCompChanged);
67   Q_PROPERTY(WhiteBalance *whiteBalance READ whiteBalance NOTIFY whiteBalanceChanged);
68   Q_PROPERTY(ColorTone *colorTone READ colorTone NOTIFY colorToneChanged);
69   Q_PROPERTY(Iso *iso READ iso NOTIFY isoChanged);
70   Q_PROPERTY(Exposure *exposure READ exposure NOTIFY exposureChanged);
71   Q_PROPERTY(Aperture *aperture READ aperture NOTIFY apertureChanged);
72   Q_PROPERTY(NoiseReduction *noiseReduction READ noiseReduction NOTIFY noiseReductionChanged);
73   Q_PROPERTY(FlickerReduction *flickerReduction READ flickerReduction NOTIFY flickerReductionChanged);
74   Q_PROPERTY(Focus *focus READ focus NOTIFY focusChanged);
75   Q_PROPERTY(AutoFocus *autoFocus READ autoFocus NOTIFY autoFocusChanged);
76
77   Q_PROPERTY(VideoMute *videoMute READ videoMute NOTIFY videoMuteChanged);
78   Q_PROPERTY(VideoTorch *videoTorch READ videoTorch NOTIFY videoTorchChanged);
79
80   Q_ENUMS(CameraMode);
81
82 public:
83   typedef enum {
84     UnknownMode,
85     ImageMode,
86     VideoMode
87   } CameraMode;
88
89   Camera(QDeclarativeItem *parent = 0);
90   ~Camera();
91
92   virtual void componentComplete();
93
94   int deviceCount() const;
95   Q_INVOKABLE QString deviceName(int index) const;
96   Q_INVOKABLE QVariant deviceId(int index) const;
97
98   Q_INVOKABLE bool reset(const QVariant& deviceId, const CameraMode& mode);
99
100   QVariant deviceId() const;
101
102   CameraMode mode();
103
104   QtCamDevice *device() const;
105
106   Q_INVOKABLE bool start();
107   Q_INVOKABLE bool stop(bool force = false);
108
109   bool isIdle();
110   bool isRunning();
111
112   QString imageSuffix() const;
113   QString videoSuffix() const;
114
115   Notifications *notifications() const;
116   void setNotifications(Notifications *notifications);
117
118   Zoom *zoom() const;
119   Flash *flash() const;
120   Scene *scene() const;
121   EvComp *evComp() const;
122   WhiteBalance *whiteBalance() const;
123   ColorTone *colorTone() const;
124   Iso *iso() const;
125   Exposure *exposure() const;
126   Aperture *aperture() const;
127   NoiseReduction *noiseReduction() const;
128   FlickerReduction *flickerReduction() const;
129   Focus *focus() const;
130   AutoFocus *autoFocus() const;
131
132   VideoMute *videoMute() const;
133   VideoTorch *videoTorch() const;
134
135 signals:
136   void deviceCountChanged();
137   void deviceIdChanged();
138   void deviceChanged();
139   void modeChanged();
140   void idleStateChanged();
141   void runningStateChanged();
142   void error(const QString& message, int code, const QString& debug);
143   void notificationsChanged();
144
145   void zoomChanged();
146   void flashChanged();
147   void sceneChanged();
148   void evCompChanged();
149   void whiteBalanceChanged();
150   void colorToneChanged();
151   void isoChanged();
152   void exposureChanged();
153   void apertureChanged();
154   void noiseReductionChanged();
155   void flickerReductionChanged();
156   void focusChanged();
157   void autoFocusChanged();
158
159   void videoMuteChanged();
160   void videoTorchChanged();
161
162 protected:
163   void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry);
164
165 private:
166   bool applyMode();
167   bool setDeviceId(const QVariant& deviceId);
168   bool setMode(const CameraMode& mode);
169
170   void resetCapabilities();
171
172   QtCamera *m_cam;
173   QtCamDevice *m_dev;
174   QVariant m_id;
175   QtCamGraphicsViewfinder *m_vf;
176   CameraMode m_mode;
177   NotificationsContainer *m_notifications;
178
179   Zoom *m_zoom;
180   Flash *m_flash;
181   Scene *m_scene;
182   EvComp *m_evComp;
183   WhiteBalance *m_whiteBalance;
184   ColorTone *m_colorTone;
185   Iso *m_iso;
186   Exposure *m_exposure;
187   Aperture *m_aperture;
188   NoiseReduction *m_noiseReduction;
189   FlickerReduction *m_flickerReduction;
190   Focus *m_focus;
191   AutoFocus *m_autoFocus;
192
193   VideoMute *m_videoMute;
194   VideoTorch *m_videoTorch;
195 };
196
197 #endif /* CAMERA_H */