Marble

MovieCaptureDialog.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2013 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
4//
5
6#include "MovieCaptureDialog.h"
7#include "ui_MovieCaptureDialog.h"
8
9#include <QFileDialog>
10#include <QMessageBox>
11
12#include "MarbleWidget.h"
13#include "MovieCapture.h"
14
15namespace Marble
16{
17
18MovieCaptureDialog::MovieCaptureDialog(MarbleWidget *widget, QWidget *parent)
19 : QDialog(parent)
20 , ui(new Ui::MovieCaptureDialog)
21 , m_recorder(new MovieCapture(widget, parent))
22{
23 ui->setupUi(this);
24 m_recorder->setSnapshotMethod(MovieCapture::TimeDriven);
25 QPushButton *startButton = ui->buttonBox->addButton(tr("&Start", "Start recording a movie"), QDialogButtonBox::ActionRole);
26
27 connect(ui->fpsSlider, &QAbstractSlider::valueChanged, ui->fpsSpin, &QSpinBox::setValue);
28
29 connect(ui->fpsSpin, &QSpinBox::valueChanged, ui->fpsSlider, &QAbstractSlider::setValue);
30
31 connect(ui->fpsSlider, &QAbstractSlider::valueChanged, m_recorder, &MovieCapture::setFps);
32
33 connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QWidget::close);
34
35 connect(startButton, &QAbstractButton::clicked, this, &MovieCaptureDialog::startRecording);
36
37 connect(ui->openButton, &QAbstractButton::clicked, this, &MovieCaptureDialog::loadDestinationFile);
38}
39
40MovieCaptureDialog::~MovieCaptureDialog()
41{
42 delete ui;
43}
44
45void MovieCaptureDialog::loadDestinationFile()
46{
47 const QList<MovieFormat> formats = m_recorder->availableFormats();
48 if (formats.isEmpty()) {
49 QMessageBox::warning(this, tr("Codecs are unavailable"), tr("Supported codecs are not found."));
50 return;
51 }
52 QString filter = formats.first().name() + QLatin1StringView(" (*.") + formats.first().extension() + QLatin1Char(')');
53 for (int i = 1; i < formats.size(); i++) {
54 filter += QLatin1StringView(";;") + formats.at(i).name() + QLatin1StringView(" (*.") + formats.at(i).extension() + QLatin1Char(')');
55 }
56 const QString defaultFileName = ui->destinationEdit->text().isEmpty() ? QString() : ui->destinationEdit->text();
57
58 const QString destination = QFileDialog::getSaveFileName(this, tr("Save video file"), defaultFileName, filter);
59
60 if (destination.isEmpty()) {
61 return;
62 }
63
64 bool supported = false;
65 for (const MovieFormat &format : formats) {
66 if (destination.endsWith(QLatin1Char('.') + format.extension())) {
67 supported = true;
68 break;
69 }
70 }
71
72 if (!supported) {
73 QString formatsExtensions = QLatin1Char('.') + formats.at(0).extension();
74 for (int i = 1; i < formats.size(); ++i) {
75 formatsExtensions += QLatin1StringView(", .") + formats.at(i).extension();
76 }
78 tr("Filename is not valid"),
79 tr("This file format is not supported. "
80 "Please, use %1 instead")
81 .arg(formatsExtensions));
82 return;
83 }
84
85 ui->destinationEdit->setText(destination);
86 m_recorder->setFilename(destination);
87}
88
89void MovieCaptureDialog::startRecording()
90{
91 const QString path = ui->destinationEdit->text();
92
93 if (path.isEmpty()) {
95 tr("Missing filename"),
96 tr("Destination video file is not set. "
97 "I don't know where to save recorded "
98 "video. Please, specify one."));
99 return;
100 }
101
102 hide();
103
104 m_recorder->setFps(ui->fpsSlider->value());
105 if (m_recorder->startRecording())
106 Q_EMIT started();
107}
108
109void MovieCaptureDialog::stopRecording()
110{
111 m_recorder->stopRecording();
112}
113
114} // namespace Marble
115
116#include "moc_MovieCaptureDialog.cpp"
This file contains the headers for MarbleWidget.
QString path(const QString &relativePath)
Binds a QML item to a specific geodetic location in screen coordinates.
void clicked(bool checked)
void setValue(int)
void valueChanged(int value)
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, Options options)
QLatin1Char at(qsizetype pos) const const
const_reference at(qsizetype i) const const
T & first()
bool isEmpty() const const
qsizetype size() const const
StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons, StandardButton defaultButton)
void setValue(int val)
void valueChanged(int i)
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool close()
void setupUi(QWidget *widget)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.