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