#include "qtcamdevice.h"
#include "qtcamvideomode.h"
#include "videoresolutionmodel.h"
+#include "videoresolution.h"
#include <QDebug>
VideoSettings::VideoSettings(QObject *parent) :
- QObject(parent), m_cam(0), m_settings(0), m_resolutions(0) {
+ QObject(parent),
+ m_cam(0),
+ m_settings(0),
+ m_resolutions(0),
+ m_currentResolution(0) {
}
VideoSettings::~VideoSettings() {
m_settings = 0;
+
+ if (m_currentResolution) {
+ delete m_currentResolution;
+ m_currentResolution = 0;
+ }
}
QString VideoSettings::suffix() const {
if (m_cam->device()) {
deviceChanged();
}
+ else {
+ delete m_currentResolution;
+ m_currentResolution = 0;
+ emit currentResolutionChanged();
+ }
}
void VideoSettings::deviceChanged() {
delete m_resolutions;
m_resolutions = 0;
+ delete m_currentResolution;
+ m_currentResolution = 0;
+
emit aspectRatioCountChanged();
emit resolutionsChanged();
+ emit currentResolutionChanged();
}
VideoResolutionModel *VideoSettings::resolutions() {
foreach (const QtCamVideoResolution& r, res) {
if (r.name() == resolution) {
- return m_cam->device()->videoMode()->setResolution(r);
+ return setResolution(r);
}
}
int VideoSettings::aspectRatioCount() const {
return aspectRatios().count();
}
+
+VideoResolution *VideoSettings::currentResolution() {
+ if (m_currentResolution) {
+ return m_currentResolution;
+ }
+
+ if (!m_cam || !m_cam->device()) {
+ return 0;
+ }
+
+ m_currentResolution = new VideoResolution(m_cam->device()->videoMode()->currentResolution());
+
+ return m_currentResolution;
+}
+
+VideoResolution *VideoSettings::findResolution(const QString& aspectRatio,
+ const QString& name) {
+ if (!isReady()) {
+ return 0;
+ }
+
+ QList<QtCamVideoResolution> res = m_settings->resolutions(aspectRatio);
+
+ foreach (const QtCamVideoResolution& r, res) {
+ if (r.name() == name) {
+ return new VideoResolution(r);
+ }
+ }
+
+ return 0;
+}
+
+bool VideoSettings::setResolution(VideoResolution *resolution) {
+ return setResolution(resolution->resolution());
+}
+
+bool VideoSettings::setResolution(const QtCamVideoResolution& resolution) {
+ if (!isReady()) {
+ return false;
+ }
+
+ if (!m_cam || !m_cam->device()) {
+ return false;
+ }
+
+ if (m_cam->device()->videoMode()->setResolution(resolution)) {
+ delete m_currentResolution;
+ m_currentResolution = 0;
+
+ emit currentResolutionChanged();
+
+ return true;
+ }
+
+ return false;
+}
class Camera;
class QtCamVideoSettings;
class VideoResolutionModel;
+class VideoResolution;
+class QtCamVideoResolution;
class VideoSettings : public QObject {
Q_OBJECT
Q_PROPERTY(int aspectRatioCount READ aspectRatioCount NOTIFY aspectRatioCountChanged);
Q_PROPERTY(VideoResolutionModel *resolutions READ resolutions NOTIFY resolutionsChanged);
Q_PROPERTY(bool ready READ isReady NOTIFY readyChanged);
+ Q_PROPERTY(VideoResolution *currentResolution READ currentResolution NOTIFY currentResolutionChanged);
public:
VideoSettings(QObject *parent = 0);
bool isReady() const;
+ VideoResolution *currentResolution();
+
+ Q_INVOKABLE VideoResolution *findResolution(const QString& aspectRatio,
+ const QString& name);
+ Q_INVOKABLE bool setResolution(VideoResolution *resolution);
+
Q_INVOKABLE bool setResolution(const QString& aspectRatio, const QString& resolution);
int aspectRatioCount() const;
void resolutionsChanged();
void readyChanged();
void aspectRatioCountChanged();
+ void currentResolutionChanged();
private slots:
void deviceChanged();
private:
+ bool setResolution(const QtCamVideoResolution& resolution);
+
Camera *m_cam;
QtCamVideoSettings *m_settings;
VideoResolutionModel *m_resolutions;
+ VideoResolution *m_currentResolution;
};
#endif /* VIDEO_SETTINGS_H */