1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "settings.h" |
|
43 #ifdef Q_OS_SYMBIAN |
|
44 #include "ui_settings_s60.h" |
|
45 #else |
|
46 #include "ui_settings.h" |
|
47 #endif |
|
48 |
|
49 #include <QtGui/qcombobox.h> |
|
50 #include <QtCore/qdebug.h> |
|
51 #include <qmediarecorder.h> |
|
52 #include <qmediaservice.h> |
|
53 #include <QFile> |
|
54 |
|
55 |
|
56 |
|
57 Settings::Settings(QMediaRecorder *mediaRecorder, QWidget *parent) : |
|
58 QDialog(parent), |
|
59 ui(new Ui::SettingsUi), |
|
60 mediaRecorder(mediaRecorder) |
|
61 { |
|
62 ui->setupUi(this); |
|
63 |
|
64 //audio codecs |
|
65 foreach(const QString &codecName, mediaRecorder->supportedAudioCodecs()) { |
|
66 QString description = mediaRecorder->audioCodecDescription(codecName); |
|
67 ui->audioCodecBox->addItem(codecName+": "+description, QVariant(codecName)); |
|
68 } |
|
69 //sample rate: |
|
70 foreach(int sampleRate, mediaRecorder->supportedAudioSampleRates()) { |
|
71 ui->audioSampleRateBox->addItem(QString::number(sampleRate), QVariant(sampleRate)); |
|
72 } |
|
73 ui->audioQualitySlider->setRange(0, int(QtMedia::VeryHighQuality)); |
|
74 |
|
75 //video codecs |
|
76 foreach(const QString &codecName, mediaRecorder->supportedVideoCodecs()) { |
|
77 QString description = mediaRecorder->videoCodecDescription(codecName); |
|
78 ui->videoCodecBox->addItem(codecName+": "+description, QVariant(codecName)); |
|
79 } |
|
80 ui->videoQualitySlider->setRange(0, int(QtMedia::VeryHighQuality)); |
|
81 |
|
82 |
|
83 ui->videoResolutionBox->addItem(tr("Default")); |
|
84 QList<QSize> supportedResolutions = mediaRecorder->supportedResolutions(); |
|
85 foreach(const QSize &resolution, supportedResolutions) { |
|
86 ui->videoResolutionBox->addItem(QString("%1x%2").arg(resolution.width()).arg(resolution.height()), |
|
87 QVariant(resolution)); |
|
88 } |
|
89 ui->videoFramerateBox->addItem(tr("Default")); |
|
90 QList<qreal> supportedFrameRates = mediaRecorder->supportedFrameRates(); |
|
91 qreal rate; |
|
92 foreach(rate, supportedFrameRates) { |
|
93 QString rateString = QString("%1").arg(rate, 0, 'f', 2); |
|
94 ui->videoFramerateBox->addItem(rateString, QVariant(rate)); |
|
95 } |
|
96 //containers |
|
97 foreach(const QString &format, mediaRecorder->supportedContainers()) { |
|
98 ui->containerFormatBox->addItem(format+":"+mediaRecorder->containerDescription(format), |
|
99 QVariant(format)); |
|
100 } |
|
101 connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); |
|
102 connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject())); |
|
103 } |
|
104 |
|
105 Settings::~Settings() |
|
106 { |
|
107 delete ui; |
|
108 } |
|
109 |
|
110 void Settings::changeEvent(QEvent *e) |
|
111 { |
|
112 QDialog::changeEvent(e); |
|
113 switch (e->type()) { |
|
114 case QEvent::LanguageChange: |
|
115 ui->retranslateUi(this); |
|
116 break; |
|
117 default: |
|
118 break; |
|
119 } |
|
120 } |
|
121 |
|
122 QAudioEncoderSettings Settings::audioSettings() const |
|
123 { |
|
124 QAudioEncoderSettings settings = mediaRecorder->audioSettings(); |
|
125 settings.setCodec(boxValue(ui->audioCodecBox).toString()); |
|
126 settings.setQuality(QtMedia::EncodingQuality(ui->audioQualitySlider->value())); |
|
127 settings.setSampleRate(boxValue(ui->audioSampleRateBox).toInt()); |
|
128 return settings; |
|
129 } |
|
130 |
|
131 void Settings::setAudioSettings(const QAudioEncoderSettings &audioSettings) |
|
132 { |
|
133 selectComboBoxItem(ui->audioCodecBox, QVariant(audioSettings.codec())); |
|
134 selectComboBoxItem(ui->audioSampleRateBox, QVariant(audioSettings.sampleRate())); |
|
135 ui->audioQualitySlider->setValue(audioSettings.quality()); |
|
136 } |
|
137 |
|
138 QVideoEncoderSettings Settings::videoSettings() const |
|
139 { |
|
140 QVideoEncoderSettings settings = mediaRecorder->videoSettings(); |
|
141 settings.setCodec(boxValue(ui->videoCodecBox).toString()); |
|
142 settings.setQuality(QtMedia::EncodingQuality(ui->videoQualitySlider->value())); |
|
143 settings.setResolution(boxValue(ui->videoResolutionBox).toSize()); |
|
144 settings.setFrameRate(boxValue(ui->videoFramerateBox).value<qreal>()); |
|
145 return settings; |
|
146 } |
|
147 |
|
148 void Settings::setVideoSettings(const QVideoEncoderSettings &videoSettings) |
|
149 { |
|
150 selectComboBoxItem(ui->videoCodecBox, QVariant(videoSettings.codec())); |
|
151 selectComboBoxItem(ui->videoResolutionBox, QVariant(videoSettings.resolution())); |
|
152 ui->videoQualitySlider->setValue(videoSettings.quality()); |
|
153 //special case for frame rate |
|
154 for (int i=0; i<ui->videoFramerateBox->count(); i++) { |
|
155 qreal itemRate = ui->videoFramerateBox->itemData(i).value<qreal>(); |
|
156 if (qFuzzyCompare(itemRate, videoSettings.frameRate())) { |
|
157 ui->videoFramerateBox->setCurrentIndex(i); |
|
158 break; |
|
159 } |
|
160 } |
|
161 } |
|
162 |
|
163 QString Settings::format() const |
|
164 { |
|
165 return boxValue(ui->containerFormatBox).toString(); |
|
166 } |
|
167 |
|
168 void Settings::setFormat(const QString &format) |
|
169 { |
|
170 selectComboBoxItem(ui->containerFormatBox, QVariant(format)); |
|
171 } |
|
172 |
|
173 QVariant Settings::boxValue(const QComboBox *box) const |
|
174 { |
|
175 int idx = box->currentIndex(); |
|
176 if (idx == -1) |
|
177 return QVariant(); |
|
178 |
|
179 return box->itemData(idx); |
|
180 } |
|
181 |
|
182 void Settings::selectComboBoxItem(QComboBox *box, const QVariant &value) |
|
183 { |
|
184 for (int i=0; i<box->count(); i++) { |
|
185 if (box->itemData(i) == value) { |
|
186 box->setCurrentIndex(i); |
|
187 break; |
|
188 } |
|
189 } |
|
190 } |
|