4#include <QMediaRecorder>
5#include <QLoggingCategory>
7 #include <QMediaFormat>
9#include "ParameterRecordUI.h"
10#include "ui_ParameterRecordUI.h"
12static Q_LOGGING_CATEGORY(log,
"Parameter.Record.UI")
16 , m_pParameters(
nullptr)
19 setWindowTitle(tr(
"Record"));
20 setWindowIcon(QIcon::fromTheme(
"media-record"));
21#if HAVE_QT6_MULTIMEDIA
22 QMediaRecorder recorder;
23 auto formats = recorder.mediaFormat().supportedFileFormats(QMediaFormat::Encode);
24 foreach(
auto f, formats) {
25 qDebug(log) <<
"File format name:" << f;
26 ui->cmbFileFormat->addItem(QMediaFormat::fileFormatName(f), f);
28 auto video = recorder.mediaFormat().supportedVideoCodecs(QMediaFormat::Encode);
29 foreach (
auto v, video) {
30 qDebug(log) <<
"Video codec:" << v;
31 ui->cmbVideoEncode->addItem(QMediaFormat::videoCodecName(v), (
int)v);
33 auto audio = recorder.mediaFormat().supportedAudioCodecs(QMediaFormat::Encode);
34 foreach(
auto a, audio) {
35 qDebug(log) <<
"Audio codec:" << a;
36 ui->cmbAudioEncode->addItem(QMediaFormat::audioCodecName(a), (
int)a);
39 ui->cmbQuality->addItem(
"Very height", QMediaRecorder::Quality::VeryHighQuality);
40 ui->cmbQuality->addItem(
"Height", QMediaRecorder::Quality::HighQuality);
41 ui->cmbQuality->addItem(
"Normal", QMediaRecorder::Quality::NormalQuality);
42 ui->cmbQuality->addItem(
"Low", QMediaRecorder::Quality::LowQuality);
43 ui->cmbQuality->addItem(
"Very low", QMediaRecorder::Quality::VeryLowQuality);
45 ui->cmbEncodingMode->addItem(
"Constant quality", QMediaRecorder::EncodingMode::ConstantQualityEncoding);
46 ui->cmbEncodingMode->addItem(
"Constant bit rate", QMediaRecorder::EncodingMode::ConstantBitRateEncoding);
47 ui->cmbEncodingMode->addItem(
"Average bit rate", QMediaRecorder::EncodingMode::AverageBitRateEncoding);
48 ui->cmbEncodingMode->addItem(
"Two pass", QMediaRecorder::EncodingMode::TwoPassEncoding);
52CParameterRecordUI::~CParameterRecordUI()
57int CParameterRecordUI::SetParameter(
CParameter *pParameter)
59 m_pParameters = qobject_cast<CParameterRecord*>(pParameter);
62 ui->gbVideo->setChecked(m_pParameters->GetEnableVideo());
63 ui->gbAudio->setChecked(m_pParameters->GetEnableAudio());
64 ui->leFolder->setText(m_pParameters->GetPath());
65#if HAVE_QT6_MULTIMEDIA
67 nIndex = ui->cmbFileFormat->findData((
int)m_pParameters->GetFileFormat());
69 ui->cmbFileFormat->setCurrentIndex(nIndex);
71 nIndex = ui->cmbVideoEncode->findData((
int)m_pParameters->GetVideoCodec());
73 ui->cmbVideoEncode->setCurrentIndex(nIndex);
75 nIndex = ui->cmbAudioEncode->findData((
int)m_pParameters->GetAudioCodec());
77 ui->cmbAudioEncode->setCurrentIndex(nIndex);
79 nIndex = ui->cmbQuality->findData((
int)m_pParameters->GetQuality());
81 ui->cmbQuality->setCurrentIndex(nIndex);
83 nIndex = ui->cmbEncodingMode->findData((
int)m_pParameters->GetEncodingMode());
85 ui->cmbEncodingMode->setCurrentIndex(nIndex);
87 ui->dsbFrameRate->setValue(m_pParameters->GetVideoFrameRate());
88 ui->sbSampleRate->setValue(m_pParameters->GetAudioSampleRate());
90 switch(m_pParameters->GetEndAction()) {
91 case CParameterRecord::ENDACTION::No:
92 ui->rbNoAction->setChecked(
true);
94 case CParameterRecord::ENDACTION::OpenFile:
95 ui->rbOpenFile->setChecked(
true);
97 case CParameterRecord::ENDACTION::OpenFolder:
98 ui->rbOpenFolder->setChecked(
true);
105int CParameterRecordUI::Accept()
107 m_pParameters->SetEnableVideo(ui->gbVideo->isChecked());
108 m_pParameters->SetEnableAudio(ui->gbAudio->isChecked());
109 m_pParameters->SetPath(ui->leFolder->text());
110 QString szFile = m_pParameters->GetPath()
112 + QDateTime::currentDateTime().toLocalTime()
113 .toString(
"yyyy_MM_dd_hh_mm_ss_zzz");
114 m_pParameters->SetImageFile(szFile +
".png");
115 m_pParameters->SetFile(szFile);
116#if HAVE_QT6_MULTIMEDIA
117 int nData = ui->cmbFileFormat->currentData().toInt();
118 m_pParameters->SetFileFormat((QMediaFormat::FileFormat)nData);
120 nData = ui->cmbVideoEncode->currentData().toInt();
121 m_pParameters->SetVideoCodec((QMediaFormat::VideoCodec)nData);
123 nData = ui->cmbAudioEncode->currentData().toInt();
124 m_pParameters->SetAudioCodec((QMediaFormat::AudioCodec)nData);
126 nData = ui->cmbQuality->currentData().toInt();
127 m_pParameters->SetQuality((QMediaRecorder::Quality)nData);
129 nData = ui->cmbEncodingMode->currentData().toInt();
130 m_pParameters->SetEncodingMode((QMediaRecorder::EncodingMode)nData);
132 m_pParameters->SetVideoFrameRate(ui->dsbFrameRate->value());
133 m_pParameters->SetAudioSampleRate(ui->sbSampleRate->value());
135 if(ui->rbNoAction->isChecked())
136 m_pParameters->SetEndAction(CParameterRecord::ENDACTION::No);
137 else if(ui->rbOpenFile->isChecked())
138 m_pParameters->SetEndAction(CParameterRecord::ENDACTION::OpenFile);
139 else if(ui->rbOpenFolder->isChecked())
140 m_pParameters->SetEndAction(CParameterRecord::ENDACTION::OpenFolder);
144void CParameterRecordUI::on_pbFolder_clicked()
147 szPath = QFileDialog::getExistingDirectory(
148 this, tr(
"Open path"),
149 m_pParameters->GetPath());
152 ui->leFolder->setText(szPath);
155void CParameterRecordUI::on_cmbEncodingMode_currentIndexChanged(
int index)
157#if HAVE_QT6_MULTIMEDIA
158 if(ui->cmbEncodingMode->itemData(index) == QMediaRecorder::ConstantQualityEncoding) {
159 ui->cmbQuality->setEnabled(
true);
160 ui->dsbFrameRate->setEnabled(
false);
161 ui->sbSampleRate->setEnabled(
false);
163 ui->cmbQuality->setEnabled(
false);
164 ui->dsbFrameRate->setEnabled(
true);
165 ui->sbSampleRate->setEnabled(
true);
The parameter UI interface.