This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimagesettings.cpp
86 lines (72 loc) · 2.54 KB
/
imagesettings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "imagesettings.h"
#include "ui_imagesettings.h"
#include <QComboBox>
#include <QDebug>
#include <QCameraImageCapture>
#include <QMediaService>
ImageSettings::ImageSettings(QCameraImageCapture *imageCapture, QWidget *parent) :
QDialog(parent),
ui(new Ui::ImageSettingsUi),
imagecapture(imageCapture)
{
ui->setupUi(this);
//image codecs
ui->imageCodecBox->addItem(tr("Default image format"), QVariant(QString()));
const QStringList supportedImageCodecs = imagecapture->supportedImageCodecs();
for (const QString &codecName : supportedImageCodecs) {
QString description = imagecapture->imageCodecDescription(codecName);
ui->imageCodecBox->addItem(codecName + ": " + description, QVariant(codecName));
}
ui->imageQualitySlider->setRange(0, int(QMultimedia::VeryHighQuality));
ui->imageResolutionBox->addItem(tr("Default Resolution"));
const QList<QSize> supportedResolutions = imagecapture->supportedResolutions();
for (const QSize &resolution : supportedResolutions) {
ui->imageResolutionBox->addItem(QString("%1x%2").arg(resolution.width()).arg(resolution.height()),
QVariant(resolution));
}
}
ImageSettings::~ImageSettings()
{
delete ui;
}
void ImageSettings::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
QImageEncoderSettings ImageSettings::imageSettings() const
{
QImageEncoderSettings settings = imagecapture->encodingSettings();
settings.setCodec(boxValue(ui->imageCodecBox).toString());
settings.setQuality(QMultimedia::EncodingQuality(ui->imageQualitySlider->value()));
settings.setResolution(boxValue(ui->imageResolutionBox).toSize());
return settings;
}
void ImageSettings::setImageSettings(const QImageEncoderSettings &imageSettings)
{
selectComboBoxItem(ui->imageCodecBox, QVariant(imageSettings.codec()));
selectComboBoxItem(ui->imageResolutionBox, QVariant(imageSettings.resolution()));
ui->imageQualitySlider->setValue(imageSettings.quality());
}
QVariant ImageSettings::boxValue(const QComboBox *box) const
{
int idx = box->currentIndex();
if (idx == -1)
return QVariant();
return box->itemData(idx);
}
void ImageSettings::selectComboBoxItem(QComboBox *box, const QVariant &value)
{
for (int i = 0; i < box->count(); ++i) {
if (box->itemData(i) == value) {
box->setCurrentIndex(i);
break;
}
}
}