X-Git-Url: https://cgit.sxemacs.org/?a=blobdiff_plain;f=lib%2Fqtcamvideosettings.cpp;h=c05ec754450dabffcca1c2661c0a782ca6f85129;hb=e22873168e4a096cd64816f1cdcf71b09a471dfa;hp=ff28ca704fcb92b597b826346b21e005658702a6;hpb=d73c4932978c622161ede3cccf3183b066aab7c2;p=harmattan%2Fcameraplus diff --git a/lib/qtcamvideosettings.cpp b/lib/qtcamvideosettings.cpp index ff28ca7..c05ec75 100644 --- a/lib/qtcamvideosettings.cpp +++ b/lib/qtcamvideosettings.cpp @@ -1,84 +1,196 @@ +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012-2013 Mohammed Sameer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + #include "qtcamvideosettings.h" -class QtCamVideoSettingsPrivate { +class QtCamVideoResolutionPrivate : public QSharedData { public: QString id; QString name; QSize capture; QSize preview; - int numerator; - int denominator; - int nightNumerator; - int nightDenominator; + int fps; + int nightFps; + QString aspectRatio; + QString resolution; }; -QtCamVideoSettings::QtCamVideoSettings(const QString& id, const QString& name, - const QSize& capture, const QSize& preview, - int numerator, int denominator, - int nightNumerator, int nightDenominator) : - d_ptr(new QtCamVideoSettingsPrivate) { +class QtCamVideoSettingsPrivate : public QSharedData { +public: + QString id; + QString suffix; + QString profileName; + QString profilePath; + QList resolutions; +}; +QtCamVideoResolution::QtCamVideoResolution(const QString& id, const QString& name, + const QSize& capture, const QSize& preview, + int fps, int nightFps, + const QString& aspectRatio, + const QString& resolution) : + d_ptr(new QtCamVideoResolutionPrivate) { d_ptr->id = id; d_ptr->name = name; d_ptr->capture = capture; d_ptr->preview = preview; - d_ptr->numerator = numerator; - d_ptr->denominator = denominator; - d_ptr->nightNumerator = nightNumerator; - d_ptr->nightDenominator = nightDenominator; + d_ptr->fps = fps; + d_ptr->nightFps = nightFps; + d_ptr->aspectRatio = aspectRatio; + d_ptr->resolution = resolution; } -QtCamVideoSettings::QtCamVideoSettings(const QtCamVideoSettings& other) : +QtCamVideoResolution::QtCamVideoResolution(const QtCamVideoResolution& other) : + d_ptr(other.d_ptr) { + +} + +QtCamVideoResolution& QtCamVideoResolution::operator=(const QtCamVideoResolution& other) { + d_ptr = other.d_ptr; + + return *this; +} + +QtCamVideoResolution::~QtCamVideoResolution() { + // QSharedData will take care of reference counting. +} + +QString QtCamVideoResolution::id() const { + return d_ptr->id; +} + +QString QtCamVideoResolution::name() const { + return d_ptr->name; +} + +QSize QtCamVideoResolution::captureResolution() const { + return d_ptr->capture; +} + +QSize QtCamVideoResolution::previewResolution() const { + return d_ptr->preview; +} + +int QtCamVideoResolution::frameRate() const { + return d_ptr->fps; +} + +int QtCamVideoResolution::nightFrameRate() const { + return d_ptr->nightFps; +} + +QString QtCamVideoResolution::aspectRatio() const { + return d_ptr->aspectRatio; +} + +QString QtCamVideoResolution::resolution() const { + return d_ptr->resolution; +} + +QtCamVideoSettings::QtCamVideoSettings(const QString& id, const QString& suffix, + const QString& profileName, + const QString& profilePath, + const QList& resolutions) : d_ptr(new QtCamVideoSettingsPrivate) { - d_ptr->id = other.d_ptr->id; - d_ptr->name = other.d_ptr->name; - d_ptr->capture = other.d_ptr->capture; - d_ptr->preview = other.d_ptr->preview; - d_ptr->numerator = other.d_ptr->numerator; - d_ptr->denominator = other.d_ptr->denominator; - d_ptr->nightNumerator = other.d_ptr->nightNumerator; - d_ptr->nightDenominator = other.d_ptr->nightDenominator; + d_ptr->id = id; + d_ptr->suffix = suffix; + d_ptr->profileName = profileName; + d_ptr->profilePath = profilePath; + d_ptr->resolutions = resolutions; } -QtCamVideoSettings::~QtCamVideoSettings() { - delete d_ptr; +QtCamVideoSettings::QtCamVideoSettings(const QtCamVideoSettings& other) : + d_ptr(other.d_ptr) { + } -QtCamVideoSettings& QtCamVideoSettings::operator=(const QtCamVideoSettings& - other) { - d_ptr->id = other.d_ptr->id; - d_ptr->name = other.d_ptr->name; - d_ptr->capture = other.d_ptr->capture; - d_ptr->preview = other.d_ptr->preview; - d_ptr->numerator = other.d_ptr->numerator; - d_ptr->denominator = other.d_ptr->denominator; - d_ptr->nightNumerator = other.d_ptr->nightNumerator; - d_ptr->nightDenominator = other.d_ptr->nightDenominator; +QtCamVideoSettings& QtCamVideoSettings::operator=(const QtCamVideoSettings& other) { + d_ptr = other.d_ptr; return *this; } +QtCamVideoSettings::~QtCamVideoSettings() { + // QSharedData will take care of reference counting. +} + QString QtCamVideoSettings::id() const { return d_ptr->id; } -QString QtCamVideoSettings::name() const { - return d_ptr->name; +QString QtCamVideoSettings::suffix() const { + return d_ptr->suffix; } -QSize QtCamVideoSettings::captureResolution() const { - return d_ptr->capture; +QString QtCamVideoSettings::profileName() const { + return d_ptr->profileName; } -QSize QtCamVideoSettings::previewResolution() const { - return d_ptr->preview; +QString QtCamVideoSettings::profilePath() const { + return d_ptr->profilePath; } -QPair QtCamVideoSettings::frameRate() const { - return qMakePair(d_ptr->numerator, d_ptr->denominator); +QtCamVideoResolution QtCamVideoSettings::defaultResolution(const QString& aspectRatio) const { + if (d_ptr->resolutions.isEmpty()) { + return QtCamVideoResolution(QString(), QString(), QSize(), QSize(), + -1, -1, QString(), QString()); + } + + if (aspectRatio.isEmpty()) { + return d_ptr->resolutions[0]; + } + + foreach (const QtCamVideoResolution& r, d_ptr->resolutions) { + if (r.aspectRatio() == aspectRatio) { + return r; + } + } + + return d_ptr->resolutions[0]; } -QPair QtCamVideoSettings::nightFrameRate() const { - return qMakePair(d_ptr->nightNumerator, d_ptr->nightDenominator); +QList QtCamVideoSettings::resolutions(const QString& aspectRatio) const { + if (aspectRatio.isEmpty()) { + return d_ptr->resolutions; + } + + QList res; + + foreach (const QtCamVideoResolution& r, d_ptr->resolutions) { + if (r.aspectRatio() == aspectRatio) { + res << r; + } + } + + return res; +} + +QStringList QtCamVideoSettings::aspectRatios() const { + QStringList aspects; + + foreach (const QtCamVideoResolution& r, d_ptr->resolutions) { + if (aspects.indexOf(r.aspectRatio()) == -1) { + aspects << r.aspectRatio(); + } + } + + return aspects; }