blob: c2b022a70a3ba412d37969bfa97df6140dc3ca14 (
plain)
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
|
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "imagesettings.h"
#include "ui_imagesettings.h"
#include <QCamera>
#include <QImageCapture>
#include <QMediaCaptureSession>
#include <QComboBox>
#include <QDebug>
using namespace Qt::StringLiterals;
ImageSettings::ImageSettings(QImageCapture *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 auto supportedImageFormats = QImageCapture::supportedFormats();
for (const auto &f : supportedImageFormats) {
QString description = QImageCapture::fileFormatDescription(f);
ui->imageCodecBox->addItem(QImageCapture::fileFormatName(f) + ": " + description,
QVariant::fromValue(f));
}
ui->imageQualitySlider->setRange(0, int(QImageCapture::VeryHighQuality));
ui->imageResolutionBox->addItem(tr("Default Resolution"));
const QList<QSize> supportedResolutions =
imagecapture->captureSession()->camera()->cameraDevice().photoResolutions();
for (const QSize &resolution : supportedResolutions) {
ui->imageResolutionBox->addItem(
u"%1x%2"_s.arg(resolution.width()).arg(resolution.height()),
QVariant(resolution));
}
selectComboBoxItem(ui->imageCodecBox, QVariant::fromValue(imagecapture->fileFormat()));
selectComboBoxItem(ui->imageResolutionBox, QVariant(imagecapture->resolution()));
ui->imageQualitySlider->setValue(imagecapture->quality());
}
ImageSettings::~ImageSettings()
{
delete ui;
}
void ImageSettings::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void ImageSettings::applyImageSettings() const
{
imagecapture->setFileFormat(boxValue(ui->imageCodecBox).value<QImageCapture::FileFormat>());
imagecapture->setQuality(QImageCapture::Quality(ui->imageQualitySlider->value()));
imagecapture->setResolution(boxValue(ui->imageResolutionBox).toSize());
}
QVariant ImageSettings::boxValue(const QComboBox *box) const
{
const int idx = box->currentIndex();
return idx != -1 ? box->itemData(idx) : QVariant{};
}
void ImageSettings::selectComboBoxItem(QComboBox *box, const QVariant &value)
{
const int idx = box->findData(value);
if (idx != -1)
box->setCurrentIndex(idx);
}
#include "moc_imagesettings.cpp"
|