Reworked ModeButton to use a Switch
[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(QRectF renderArea READ renderArea NOTIFY renderAreaChanged);
64   Q_PROPERTY(QSizeF videoResolution READ videoResolution NOTIFY videoResolutionChanged);
65
66   Q_PROPERTY(Zoom *zoom READ zoom NOTIFY zoomChanged);
67   Q_PROPERTY(Flash *flash READ flash NOTIFY flashChanged);
68   Q_PROPERTY(Scene *scene READ scene NOTIFY sceneChanged);
69   Q_PROPERTY(EvComp *evComp READ evComp NOTIFY evCompChanged);
70   Q_PROPERTY(WhiteBalance *whiteBalance READ whiteBalance NOTIFY whiteBalanceChanged);
71   Q_PROPERTY(ColorTone *colorTone READ colorTone NOTIFY colorToneChanged);
72   Q_PROPERTY(Iso *iso READ iso NOTIFY isoChanged);
73   Q_PROPERTY(Exposure *exposure READ exposure NOTIFY exposureChanged);
74   Q_PROPERTY(Aperture *aperture READ aperture NOTIFY apertureChanged);
75   Q_PROPERTY(NoiseReduction *noiseReduction READ noiseReduction NOTIFY noiseReductionChanged);
76   Q_PROPERTY(FlickerReduction *flickerReduction READ flickerReduction NOTIFY flickerReductionChanged);
77   Q_PROPERTY(Focus *focus READ focus NOTIFY focusChanged);
78   Q_PROPERTY(AutoFocus *autoFocus READ autoFocus NOTIFY autoFocusChanged);
79
80   Q_PROPERTY(VideoMute *videoMute READ videoMute NOTIFY videoMuteChanged);
81   Q_PROPERTY(VideoTorch *videoTorch READ videoTorch NOTIFY videoTorchChanged);
82
83   Q_ENUMS(CameraMode);
84
85 public:
86   typedef enum {
87     UnknownMode,
88     ImageMode,
89     VideoMode
90   } CameraMode;
91
92   Camera(QDeclarativeItem *parent = 0);
93   ~Camera();
94
95   virtual void componentComplete();
96
97   int deviceCount() const;
98   Q_INVOKABLE QString deviceName(int index) const;
99   Q_INVOKABLE QVariant deviceId(int index) const;
100
101   Q_INVOKABLE bool reset(const QVariant& deviceId, const CameraMode& mode);
102
103   QVariant deviceId() const;
104
105   CameraMode mode();
106
107   QtCamDevice *device() const;
108
109   Q_INVOKABLE bool start();
110   Q_INVOKABLE bool stop(bool force = false);
111
112   bool isIdle();
113   bool isRunning();
114
115   QString imageSuffix() const;
116   QString videoSuffix() const;
117
118   Notifications *notifications() const;
119   void setNotifications(Notifications *notifications);
120
121   Zoom *zoom() const;
122   Flash *flash() const;
123   Scene *scene() const;
124   EvComp *evComp() const;
125   WhiteBalance *whiteBalance() const;
126   ColorTone *colorTone() const;
127   Iso *iso() const;
128   Exposure *exposure() const;
129   Aperture *aperture() const;
130   NoiseReduction *noiseReduction() const;
131   FlickerReduction *flickerReduction() const;
132   Focus *focus() const;
133   AutoFocus *autoFocus() const;
134
135   VideoMute *videoMute() const;
136   VideoTorch *videoTorch() const;
137
138   QRectF renderArea() const;
139   QSizeF videoResolution() const;
140
141 signals:
142   void deviceCountChanged();
143   void deviceIdChanged();
144   void deviceChanged();
145   void modeChanged();
146   void idleStateChanged();
147   void runningStateChanged();
148   void error(const QString& message, int code, const QString& debug);
149   void notificationsChanged();
150   void renderAreaChanged();
151   void videoResolutionChanged();
152
153   void zoomChanged();
154   void flashChanged();
155   void sceneChanged();
156   void evCompChanged();
157   void whiteBalanceChanged();
158   void colorToneChanged();
159   void isoChanged();
160   void exposureChanged();
161   void apertureChanged();
162   void noiseReductionChanged();
163   void flickerReductionChanged();
164   void focusChanged();
165   void autoFocusChanged();
166
167   void videoMuteChanged();
168   void videoTorchChanged();
169
170 protected:
171   void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry);
172
173 private:
174   bool applyMode();
175   bool setDeviceId(const QVariant& deviceId);
176   bool setMode(const CameraMode& mode);
177
178   void resetCapabilities();
179
180   QtCamera *m_cam;
181   QtCamDevice *m_dev;
182   QVariant m_id;
183   QtCamGraphicsViewfinder *m_vf;
184   CameraMode m_mode;
185   NotificationsContainer *m_notifications;
186
187   Zoom *m_zoom;
188   Flash *m_flash;
189   Scene *m_scene;
190   EvComp *m_evComp;
191   WhiteBalance *m_whiteBalance;
192   ColorTone *m_colorTone;
193   Iso *m_iso;
194   Exposure *m_exposure;
195   Aperture *m_aperture;
196   NoiseReduction *m_noiseReduction;
197   FlickerReduction *m_flickerReduction;
198   Focus *m_focus;
199   AutoFocus *m_autoFocus;
200
201   VideoMute *m_videoMute;
202   VideoTorch *m_videoTorch;
203 };
204
205 #endif /* CAMERA_H */