Skip to content

Commit

Permalink
Prevent MP4 export with invalid resolution (#1833)
Browse files Browse the repository at this point in the history
* Prevent MP4 export with invalid resolution

* Fix Qt 5 build error

* Fix export dialog layout jumping

---------

Co-authored-by: scribblemaniac <[email protected]>
  • Loading branch information
J5lx and scribblemaniac authored Apr 29, 2024
1 parent 835545e commit 8c3b530
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
22 changes: 22 additions & 0 deletions app/src/exportmoviedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ ExportMovieDialog::ExportMovieDialog(QWidget *parent, Mode mode, FileType fileTy
} else {
setWindowTitle(tr("Export Movie"));
}

QSizePolicy policy = ui->unevenWidthLabel->sizePolicy();
policy.setRetainSizeWhenHidden(true);
ui->unevenWidthLabel->setSizePolicy(policy);
policy = ui->unevenHeightLabel->sizePolicy();
policy.setRetainSizeWhenHidden(true);
ui->unevenHeightLabel->setSizePolicy(policy);

connect(this, &ExportMovieDialog::filePathsChanged, this, &ExportMovieDialog::onFilePathsChanged);
connect(ui->widthSpinBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ExportMovieDialog::validateResolution);
connect(ui->heightSpinBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ExportMovieDialog::validateResolution);
}

ExportMovieDialog::~ExportMovieDialog()
Expand Down Expand Up @@ -66,6 +76,7 @@ void ExportMovieDialog::updateResolutionCombo( int index )

ui->widthSpinBox->setValue( camSize.width() );
ui->heightSpinBox->setValue( camSize.height() );
validateResolution();
}

void ExportMovieDialog::setDefaultRange(int startFrame, int endFrame, int endFrameWithSounds)
Expand Down Expand Up @@ -128,6 +139,7 @@ void ExportMovieDialog::onFilePathsChanged(QStringList filePaths)
ui->loopCheckBox->setChecked(false);
}
ui->transparencyCheckBox->setEnabled(supportsTransparency(filePath));
validateResolution();
}

bool ExportMovieDialog::supportsLooping(QString filePath) const
Expand All @@ -141,3 +153,13 @@ bool ExportMovieDialog::supportsTransparency(QString filePath) const
return filePath.endsWith(".apng", Qt::CaseInsensitive) ||
filePath.endsWith(".webm", Qt::CaseInsensitive);
}

void ExportMovieDialog::validateResolution()
{
const bool isMp4 = getFilePath().endsWith(".mp4", Qt::CaseInsensitive);
const bool widthValid = !isMp4 || ui->widthSpinBox->value() % 2 == 0;
const bool heightValid = !isMp4 || ui->heightSpinBox->value() % 2 == 0;
ui->unevenWidthLabel->setHidden(widthValid);
ui->unevenHeightLabel->setHidden(heightValid);
setOkButtonEnabled(widthValid && heightValid);
}
1 change: 1 addition & 0 deletions app/src/exportmoviedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ExportMovieDialog : public ImportExportDialog

bool supportsLooping(QString filePath) const;
bool supportsTransparency(QString filePath) const;
void validateResolution();

int mEndFrameWithSounds = 0;
int mEndFrame = 0;
Expand Down
5 changes: 5 additions & 0 deletions app/src/importexportdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ void ImportExportDialog::setInstructionsLabel(const QString& text)
ui->instructionsLabel->setText(text);
}

void ImportExportDialog::setOkButtonEnabled(const bool enabled)
{
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enabled);
}

void ImportExportDialog::init()
{
switch (mMode)
Expand Down
1 change: 1 addition & 0 deletions app/src/importexportdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ImportExportDialog : public QDialog
void hideInstructionsLabel(bool hide);

void setInstructionsLabel(const QString& text);
void setOkButtonEnabled(bool enabled);

private slots:
void browse();
Expand Down
22 changes: 21 additions & 1 deletion app/ui/exportmovieoptions.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<property name="title">
<string>Resolution</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0,1,1,0,1">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
Expand All @@ -60,6 +60,16 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="unevenWidthLabel">
<property name="toolTip">
<string>The MP4 format does not support odd width. Please specify an even width or use a different file format.</string>
</property>
<property name="text">
<string notr="true">⚠</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="widthSpinBox">
<property name="maximum">
Expand Down Expand Up @@ -89,6 +99,16 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="unevenHeightLabel">
<property name="toolTip">
<string>The MP4 format does not support odd height. Please specify an even height or use a different file format.</string>
</property>
<property name="text">
<string notr="true">⚠</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="heightSpinBox">
<property name="maximum">
Expand Down

0 comments on commit 8c3b530

Please sign in to comment.