Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
ParameterRecordUI.cpp
1#include <QDir>
2#include <QDateTime>
3#include <QFileDialog>
4#include <QMediaRecorder>
5#include <QLoggingCategory>
6#if HAVE_QT6_MULTIMEDIA
7 #include <QMediaFormat>
8#endif
9#include "ParameterRecordUI.h"
10#include "ui_ParameterRecordUI.h"
11
12static Q_LOGGING_CATEGORY(log, "Parameter.Record.UI")
14 : CParameterUI(parent)
15 , ui(new Ui::CParameterRecordUI)
16 , m_pParameters(nullptr)
17{
18 ui->setupUi(this);
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);
27 }
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);
32 }
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);
37 }
38
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);
44
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);
49#endif
50}
51
52CParameterRecordUI::~CParameterRecordUI()
53{
54 delete ui;
55}
56
57int CParameterRecordUI::SetParameter(CParameter *pParameter)
58{
59 m_pParameters = qobject_cast<CParameterRecord*>(pParameter);
60 if(!m_pParameters)
61 return 1;
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
66 int nIndex = -1;
67 nIndex = ui->cmbFileFormat->findData((int)m_pParameters->GetFileFormat());
68 if(-1 < nIndex)
69 ui->cmbFileFormat->setCurrentIndex(nIndex);
70
71 nIndex = ui->cmbVideoEncode->findData((int)m_pParameters->GetVideoCodec());
72 if(-1 < nIndex)
73 ui->cmbVideoEncode->setCurrentIndex(nIndex);
74
75 nIndex = ui->cmbAudioEncode->findData((int)m_pParameters->GetAudioCodec());
76 if(-1 < nIndex)
77 ui->cmbAudioEncode->setCurrentIndex(nIndex);
78
79 nIndex = ui->cmbQuality->findData((int)m_pParameters->GetQuality());
80 if(-1 < nIndex)
81 ui->cmbQuality->setCurrentIndex(nIndex);
82
83 nIndex = ui->cmbEncodingMode->findData((int)m_pParameters->GetEncodingMode());
84 if(-1 < nIndex)
85 ui->cmbEncodingMode->setCurrentIndex(nIndex);
86#endif
87 ui->dsbFrameRate->setValue(m_pParameters->GetVideoFrameRate());
88 ui->sbSampleRate->setValue(m_pParameters->GetAudioSampleRate());
89
90 switch(m_pParameters->GetEndAction()) {
91 case CParameterRecord::ENDACTION::No:
92 ui->rbNoAction->setChecked(true);
93 break;
94 case CParameterRecord::ENDACTION::OpenFile:
95 ui->rbOpenFile->setChecked(true);
96 break;
97 case CParameterRecord::ENDACTION::OpenFolder:
98 ui->rbOpenFolder->setChecked(true);
99 break;
100 }
101
102 return 0;
103}
104
105int CParameterRecordUI::Accept()
106{
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()
111 + QDir::separator()
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);
119
120 nData = ui->cmbVideoEncode->currentData().toInt();
121 m_pParameters->SetVideoCodec((QMediaFormat::VideoCodec)nData);
122
123 nData = ui->cmbAudioEncode->currentData().toInt();
124 m_pParameters->SetAudioCodec((QMediaFormat::AudioCodec)nData);
125
126 nData = ui->cmbQuality->currentData().toInt();
127 m_pParameters->SetQuality((QMediaRecorder::Quality)nData);
128
129 nData = ui->cmbEncodingMode->currentData().toInt();
130 m_pParameters->SetEncodingMode((QMediaRecorder::EncodingMode)nData);
131#endif
132 m_pParameters->SetVideoFrameRate(ui->dsbFrameRate->value());
133 m_pParameters->SetAudioSampleRate(ui->sbSampleRate->value());
134
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);
141 return 0;
142}
143
144void CParameterRecordUI::on_pbFolder_clicked()
145{
146 QString szPath;
147 szPath = QFileDialog::getExistingDirectory(
148 this, tr("Open path"),
149 m_pParameters->GetPath());
150 if(szPath.isEmpty())
151 return;
152 ui->leFolder->setText(szPath);
153}
154
155void CParameterRecordUI::on_cmbEncodingMode_currentIndexChanged(int index)
156{
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);
162 } else {
163 ui->cmbQuality->setEnabled(false);
164 ui->dsbFrameRate->setEnabled(true);
165 ui->sbSampleRate->setEnabled(true);
166 }
167#endif
168}
169
The parameter UI interface.
Definition ParameterUI.h:15
Parameter interface.
Definition Parameter.h:169