All Classes Namespaces Functions Variables Enumerations Properties Pages
exportmoviedialog.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 #include "exportmoviedialog.h"
19 #include "ui_exportmovieoptions.h"
20 #include "util.h"
21 
22 ExportMovieDialog::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  connect(this, &ExportMovieDialog::filePathsChanged, this, &ExportMovieDialog::onFilePathsChanged);
35 }
36 
37 ExportMovieDialog::~ExportMovieDialog()
38 {
39  delete ui;
40 }
41 
42 void ExportMovieDialog::setCamerasInfo(const std::vector<std::pair<QString, QSize>> camerasInfo)
43 {
44  if ( ui->cameraCombo->count() > 0 )
45  {
46  ui->cameraCombo->clear();
47  }
48 
49  for (const std::pair<QString, QSize>& camera : camerasInfo)
50  {
51  ui->cameraCombo->addItem( camera.first, camera.second );
52  }
53 
54  auto indexChanged = static_cast< void(QComboBox::*)( int i ) >( &QComboBox::currentIndexChanged );
55  connect( ui->cameraCombo, indexChanged, this, &ExportMovieDialog::updateResolutionCombo );
56 
57  updateResolutionCombo( 0 );
58 }
59 
60 void ExportMovieDialog::updateResolutionCombo( int index )
61 {
62  QSize camSize = ui->cameraCombo->itemData( index ).toSize();
63 
64  QSignalBlocker b1( ui->widthSpinBox );
65  QSignalBlocker b2( ui->heightSpinBox );
66 
67  ui->widthSpinBox->setValue( camSize.width() );
68  ui->heightSpinBox->setValue( camSize.height() );
69 }
70 
71 void ExportMovieDialog::setDefaultRange(int startFrame, int endFrame, int endFrameWithSounds)
72 {
73  mEndFrame = endFrame;
74  mEndFrameWithSounds = endFrameWithSounds;
75 
76  QSignalBlocker b1( ui->startSpinBox );
77  QSignalBlocker b2( ui->endSpinBox );
78 
79  ui->startSpinBox->setValue( startFrame );
80  ui->endSpinBox->setValue( endFrame );
81 
82  connect(ui->frameCheckBox, &QCheckBox::clicked, this, &ExportMovieDialog::frameCheckboxClicked);
83 }
84 
85 QString ExportMovieDialog::getSelectedCameraName()
86 {
87  return ui->cameraCombo->currentText();
88 }
89 
90 QSize ExportMovieDialog::getExportSize()
91 {
92  return QSize( ui->widthSpinBox->value(), ui->heightSpinBox->value() );
93 }
94 
95 bool ExportMovieDialog::getTransparency() const
96 {
97  return ui->transparencyCheckBox->isChecked() && supportsTransparency(getFilePath());
98 }
99 
100 int ExportMovieDialog::getStartFrame()
101 {
102  return ui->startSpinBox->value();
103 }
104 
105 int ExportMovieDialog::getEndFrame()
106 {
107  return ui->endSpinBox->value();
108 }
109 
110 bool ExportMovieDialog::getLoop()
111 {
112  return ui->loopCheckBox->isChecked();
113 }
114 
115 void ExportMovieDialog::frameCheckboxClicked(bool checked)
116 {
117  int e = (checked) ? mEndFrameWithSounds : mEndFrame;
118  ui->endSpinBox->setValue(e);
119 }
120 
121 void ExportMovieDialog::onFilePathsChanged(QStringList filePaths)
122 {
123  QString filePath = filePaths.first().toLower();
124  bool canLoop = supportsLooping(filePath);
125  ui->loopCheckBox->setEnabled(canLoop);
126  if (!canLoop)
127  {
128  ui->loopCheckBox->setChecked(false);
129  }
130  ui->transparencyCheckBox->setEnabled(supportsTransparency(filePath));
131 }
132 
133 bool ExportMovieDialog::supportsLooping(QString filePath) const
134 {
135  return filePath.endsWith(".apng", Qt::CaseInsensitive) ||
136  filePath.endsWith(".gif", Qt::CaseInsensitive);
137 }
138 
139 bool ExportMovieDialog::supportsTransparency(QString filePath) const
140 {
141  return filePath.endsWith(".apng", Qt::CaseInsensitive) ||
142  filePath.endsWith(".webm", Qt::CaseInsensitive);
143 }
int width() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
CaseInsensitive
void clicked(bool checked)
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const const
T & first()
void setWindowTitle(const QString &)
int height() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void currentIndexChanged(int index)