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 QHash<int, QByteArray> roles;
29 roles[IdRole] = "resolutionId";
30 roles[NameRole] = "resolutionName";
31 roles[CaptureRole] = "captureResolution";
32 roles[PreviewRole] = "previewResolution";
33 roles[FpsRole] = "frameRate";
34 roles[NightFpsRole] = "nightFrameRate";
35 roles[ResolutionRole] = "resolution";
36 roles[AspectRatioRole] = "resolutionAspectRatio";
40 m_resolutions = m_settings->resolutions(m_aspectRatio);
43 VideoResolutionModel::~VideoResolutionModel() {
47 int VideoResolutionModel::rowCount(const QModelIndex& parent) const {
48 if (!parent.isValid()) {
49 return m_resolutions.size();
55 QVariant VideoResolutionModel::data(const QModelIndex& index, int role) const {
56 if (index.row() < 0 || index.row() >= m_resolutions.size()) {
60 const QtCamVideoResolution& res = m_resolutions[index.row()];
70 return res.captureResolution();
73 return res.previewResolution();
76 return res.frameRate();
79 return res.nightFrameRate();
82 return res.resolution();
85 return res.aspectRatio();
92 QString VideoResolutionModel::aspectRatio() const {
96 void VideoResolutionModel::setAspectRatio(const QString& aspectRatio) {
97 if (aspectRatio != m_aspectRatio) {
99 m_aspectRatio = aspectRatio;
103 m_resolutions = m_settings->resolutions(m_aspectRatio);
107 emit aspectRatioChanged();
112 int VideoResolutionModel::count() const {
117 QHash<int, QByteArray> VideoResolutionModel::roleNames() const {
121 void VideoResolutionModel::setRoleNames(const QHash<int, QByteArray>& roles) {