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
17MovieCaptureDialog::MovieCaptureDialog(MarbleWidget *widget, QWidget *parent) :
18 QDialog(parent),
19 ui(new Ui::MovieCaptureDialog),
20 m_recorder(new MovieCapture(widget, parent))
21{
22 ui->setupUi(this);
23 m_recorder->setSnapshotMethod(MovieCapture::TimeDriven);
24 QPushButton *startButton = ui->buttonBox->addButton(tr("&Start", "Start recording a movie"), QDialogButtonBox::ActionRole);
25
26 connect(ui->fpsSlider, SIGNAL(valueChanged(int)),
27 ui->fpsSpin, SLOT(setValue(int)));
28
29 connect(ui->fpsSpin, SIGNAL(valueChanged(int)),
30 ui->fpsSlider, SLOT(setValue(int)));
31
32 connect(ui->fpsSlider, SIGNAL(valueChanged(int)),
33 m_recorder, SLOT(setFps(int)));
34
35 connect(ui->buttonBox, SIGNAL(rejected()),
36 this, SLOT(close()));
37
38 connect(startButton, SIGNAL(clicked()),
39 this, SLOT(startRecording()));
40
41 connect(ui->openButton, SIGNAL(clicked()),
42 this, SLOT(loadDestinationFile()));
43}
44
45MovieCaptureDialog::~MovieCaptureDialog()
46{
47 delete ui;
48}
49
50void MovieCaptureDialog::loadDestinationFile()
51{
52 const QVector<MovieFormat> formats = m_recorder->availableFormats();
53 if( formats.isEmpty() ) {
54 QMessageBox::warning( this, tr( "Codecs are unavailable" ), tr( "Supported codecs are not found." ) );
55 return;
56 }
57 QString filter = formats.first().name() + QLatin1String(" (*.") + formats.first().extension() + QLatin1Char(')');
58 for( int i = 1; i < formats.size(); i++ )
59 {
60 filter += QLatin1String(";;") + formats.at(i).name() + QLatin1String(" (*.") + formats.at(i).extension() + QLatin1Char(')');
61 }
62 const QString defaultFileName =
63 ui->destinationEdit->text().isEmpty() ? "" : ui->destinationEdit->text();
64
65 const QString destination =
66 QFileDialog::getSaveFileName(this, tr("Save video file"), defaultFileName,
67 filter );
68
69 if (destination.isEmpty()) {
70 return;
71 }
72
73 bool supported = false;
74 for(const MovieFormat &format: formats) {
75 if (destination.endsWith(QLatin1Char('.') + format.extension())) {
76 supported = true;
77 break;
78 }
79 }
80
81 if (!supported) {
82 QString formatsExtensions = QLatin1Char('.') + formats.at(0).extension();
83 for( int i = 1; i < formats.size(); ++i )
84 {
85 formatsExtensions += QLatin1String(", .") + formats.at(i).extension();
86 }
87 QMessageBox::warning(this, tr("Filename is not valid"),
88 tr("This file format is not supported. "
89 "Please, use %1 instead").arg( formatsExtensions ) );
90 return;
91 }
92
93 ui->destinationEdit->setText(destination);
94 m_recorder->setFilename(destination);
95}
96
97void MovieCaptureDialog::startRecording()
98{
99 const QString path = ui->destinationEdit->text();
100
101 if (path.isEmpty()) {
102 QMessageBox::warning(this, tr("Missing filename"),
103 tr("Destination video file is not set. "
104 "I don't know where to save recorded "
105 "video. Please, specify one."));
106 return;
107 }
108
109 hide();
110
111 m_recorder->setFps(ui->fpsSlider->value());
112 if (m_recorder->startRecording())
113 emit started();
114}
115
116void MovieCaptureDialog::stopRecording()
117{
118 m_recorder->stopRecording();
119}
120
121} // namespace Marble
122
123#include "moc_MovieCaptureDialog.cpp"
This file contains the headers for MarbleWidget.
QString path(const QString &relativePath)
KGuiItem close()
Binds a QML item to a specific geodetic location in screen coordinates.
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, Options options)
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)
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)
void setupUi(QWidget *widget)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.