Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • app
  • src
exportmoviedialog.cpp
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17
18#include "exportmoviedialog.h"
19#include "ui_exportmovieoptions.h"
20#include "util.h"
21
22ExportMovieDialog::ExportMovieDialog(QWidget *parent, Mode mode, FileType fileType) :
23 ImportExportDialog(parent, mode, fileType),
24 ui(new Ui::ExportMovieOptions)
25{
26 ui->setupUi(getOptionsGroupBox());
27
28 if (fileType == FileType::GIF) {
29 setWindowTitle(tr("Export Animated GIF"));
30 ui->exporterGroupBox->hide();
31 } else {
32 setWindowTitle(tr("Export Movie"));
33 }
34
35 QSizePolicy policy = ui->unevenWidthLabel->sizePolicy();
36 policy.setRetainSizeWhenHidden(true);
37 ui->unevenWidthLabel->setSizePolicy(policy);
38 policy = ui->unevenHeightLabel->sizePolicy();
39 policy.setRetainSizeWhenHidden(true);
40 ui->unevenHeightLabel->setSizePolicy(policy);
41
42 connect(this, &ExportMovieDialog::filePathsChanged, this, &ExportMovieDialog::onFilePathsChanged);
43 connect(ui->widthSpinBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ExportMovieDialog::validateResolution);
44 connect(ui->heightSpinBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ExportMovieDialog::validateResolution);
45}
46
47ExportMovieDialog::~ExportMovieDialog()
48{
49 delete ui;
50}
51
52void ExportMovieDialog::setCamerasInfo(const std::vector<std::pair<QString, QSize>> camerasInfo)
53{
54 if ( ui->cameraCombo->count() > 0 )
55 {
56 ui->cameraCombo->clear();
57 }
58
59 for (const std::pair<QString, QSize>& camera : camerasInfo)
60 {
61 ui->cameraCombo->addItem( camera.first, camera.second );
62 }
63
64 auto indexChanged = static_cast< void(QComboBox::*)( int i ) >( &QComboBox::currentIndexChanged );
65 connect( ui->cameraCombo, indexChanged, this, &ExportMovieDialog::updateResolutionCombo );
66
67 updateResolutionCombo( 0 );
68}
69
70void ExportMovieDialog::updateResolutionCombo( int index )
71{
72 QSize camSize = ui->cameraCombo->itemData( index ).toSize();
73
74 QSignalBlocker b1( ui->widthSpinBox );
75 QSignalBlocker b2( ui->heightSpinBox );
76
77 ui->widthSpinBox->setValue( camSize.width() );
78 ui->heightSpinBox->setValue( camSize.height() );
79 validateResolution();
80}
81
82void ExportMovieDialog::setDefaultRange(int startFrame, int endFrame, int endFrameWithSounds)
83{
84 mEndFrame = endFrame;
85 mEndFrameWithSounds = endFrameWithSounds;
86
87 QSignalBlocker b1( ui->startSpinBox );
88 QSignalBlocker b2( ui->endSpinBox );
89
90 ui->startSpinBox->setValue( startFrame );
91 ui->endSpinBox->setValue( endFrame );
92
93 connect(ui->frameCheckBox, &QCheckBox::clicked, this, &ExportMovieDialog::frameCheckboxClicked);
94}
95
96QString ExportMovieDialog::getSelectedCameraName()
97{
98 return ui->cameraCombo->currentText();
99}
100
101QSize ExportMovieDialog::getExportSize()
102{
103 return QSize( ui->widthSpinBox->value(), ui->heightSpinBox->value() );
104}
105
106bool ExportMovieDialog::getTransparency() const
107{
108 return ui->transparencyCheckBox->isChecked() && supportsTransparency(getFilePath());
109}
110
111int ExportMovieDialog::getStartFrame()
112{
113 return ui->startSpinBox->value();
114}
115
116int ExportMovieDialog::getEndFrame()
117{
118 return ui->endSpinBox->value();
119}
120
121bool ExportMovieDialog::getLoop()
122{
123 return ui->loopCheckBox->isChecked();
124}
125
126void ExportMovieDialog::frameCheckboxClicked(bool checked)
127{
128 int e = (checked) ? mEndFrameWithSounds : mEndFrame;
129 ui->endSpinBox->setValue(e);
130}
131
132void ExportMovieDialog::onFilePathsChanged(QStringList filePaths)
133{
134 QString filePath = filePaths.first().toLower();
135 bool canLoop = supportsLooping(filePath);
136 ui->loopCheckBox->setEnabled(canLoop);
137 if (!canLoop)
138 {
139 ui->loopCheckBox->setChecked(false);
140 }
141 ui->transparencyCheckBox->setEnabled(supportsTransparency(filePath));
142 validateResolution();
143}
144
145bool ExportMovieDialog::supportsLooping(QString filePath) const
146{
147 return filePath.endsWith(".apng", Qt::CaseInsensitive) ||
148 filePath.endsWith(".gif", Qt::CaseInsensitive);
149}
150
151bool ExportMovieDialog::supportsTransparency(QString filePath) const
152{
153 return filePath.endsWith(".apng", Qt::CaseInsensitive) ||
154 filePath.endsWith(".webm", Qt::CaseInsensitive);
155}
156
157void ExportMovieDialog::validateResolution()
158{
159 const bool isMp4 = getFilePath().endsWith(".mp4", Qt::CaseInsensitive);
160 const bool widthValid = !isMp4 || ui->widthSpinBox->value() % 2 == 0;
161 const bool heightValid = !isMp4 || ui->heightSpinBox->value() % 2 == 0;
162 ui->unevenWidthLabel->setHidden(widthValid);
163 ui->unevenHeightLabel->setHidden(heightValid);
164 setOkButtonEnabled(widthValid && heightValid);
165}
ImportExportDialog
Definition: importexportdialog.h:32
QAbstractButton::clicked
void clicked(bool checked)
QComboBox
QComboBox::currentIndexChanged
void currentIndexChanged(int index)
QList::first
T & first()
QObject::connect
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QSignalBlocker
QSize
QSize::height
int height() const const
QSize::width
int width() const const
QSizePolicy
QSizePolicy::setRetainSizeWhenHidden
void setRetainSizeWhenHidden(bool retainSize)
QSpinBox
QSpinBox::valueChanged
void valueChanged(int i)
QString
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const const
QStringList
Qt::CaseInsensitive
CaseInsensitive
QWidget
QWidget::setupUi
void setupUi(QWidget *widget)
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39