2 * This file is part of CameraPlus.
4 * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "videoresolutionmodel.h"
22 #include "qtcamvideosettings.h"
25 VideoResolutionModel::VideoResolutionModel(QtCamVideoSettings *settings, QObject *parent) :
26 QAbstractListModel(parent), m_settings(settings) {
28 m_roles[IdRole] = "resolutionId";
29 m_roles[NameRole] = "resolutionName";
30 m_roles[CaptureRole] = "captureResolution";
31 m_roles[PreviewRole] = "previewResolution";
32 m_roles[FpsRole] = "frameRate";
33 m_roles[NightFpsRole] = "nightFrameRate";
34 m_roles[ResolutionRole] = "resolution";
35 m_roles[AspectRatioRole] = "resolutionAspectRatio";
37 m_resolutions = m_settings->resolutions(m_aspectRatio);
40 VideoResolutionModel::~VideoResolutionModel() {
44 int VideoResolutionModel::rowCount(const QModelIndex& parent) const {
45 if (!parent.isValid()) {
46 return m_resolutions.size();
52 QVariant VideoResolutionModel::data(const QModelIndex& index, int role) const {
53 if (index.row() < 0 || index.row() >= m_resolutions.size()) {
57 const QtCamVideoResolution& res = m_resolutions[index.row()];
67 return res.captureResolution();
70 return res.previewResolution();
73 return res.frameRate();
76 return res.nightFrameRate();
79 return res.resolution();
82 return res.aspectRatio();
89 QString VideoResolutionModel::aspectRatio() const {
93 void VideoResolutionModel::setAspectRatio(const QString& aspectRatio) {
94 if (aspectRatio != m_aspectRatio) {
96 m_aspectRatio = aspectRatio;
98 emit aspectRatioChanged();
102 m_resolutions = m_settings->resolutions(m_aspectRatio);
108 QHash<int, QByteArray> VideoResolutionModel::roleNames() const {