From c723a2cd43b21d3e1bce8e5886382d3b85e72ef1 Mon Sep 17 00:00:00 2001 From: Pablo Gil Date: Sun, 10 Nov 2024 23:43:21 +0100 Subject: [PATCH 1/4] duration value converts from frames to seconds and viceversa --- src/ui/dialogs/scenesettingsdialog.cpp | 17 +++++++++++++++++ src/ui/dialogs/scenesettingsdialog.h | 1 + 2 files changed, 18 insertions(+) diff --git a/src/ui/dialogs/scenesettingsdialog.cpp b/src/ui/dialogs/scenesettingsdialog.cpp index 5884a91f1..9261a70ae 100644 --- a/src/ui/dialogs/scenesettingsdialog.cpp +++ b/src/ui/dialogs/scenesettingsdialog.cpp @@ -186,6 +186,7 @@ SceneSettingsDialog::SceneSettingsDialog(const QString &name, connect(mCancelButton, &QPushButton::released, this, &SceneSettingsDialog::reject); connect(this, &QDialog::rejected, this, &QDialog::close); + connect(mTypeTime, QOverload::of(&QComboBox::currentIndexChanged),this, [this]() { updateDuration(); }); validate(); @@ -308,3 +309,19 @@ void SceneSettingsDialog::sNewSceneDialog(Document& document, dialog->show(); } + +void SceneSettingsDialog::updateDuration() { + const QString typetime = mTypeTime->currentData().toString(); + const qreal fps = mFPSSpinBox->value(); + int duration = mMaxFrameSpin->value() - mMinFrameSpin->value(); + + if (typetime == "Frames") { + // Convert seconds to frames + duration = qRound(duration * fps); + } else { + // Convert frames to seconds + duration = qRound(duration / fps); + } + + mMaxFrameSpin->setValue(mMinFrameSpin->value() + duration); +} \ No newline at end of file diff --git a/src/ui/dialogs/scenesettingsdialog.h b/src/ui/dialogs/scenesettingsdialog.h index 3789fab23..65af0da0a 100644 --- a/src/ui/dialogs/scenesettingsdialog.h +++ b/src/ui/dialogs/scenesettingsdialog.h @@ -75,6 +75,7 @@ class UI_EXPORT SceneSettingsDialog : public QDialog private: bool validate(); + void updateDuration(); Canvas * mTargetCanvas = nullptr; From 63c8dddcdf11e0c17163670e58e4b4390baa2185 Mon Sep 17 00:00:00 2001 From: Pablo Gil Date: Mon, 11 Nov 2024 22:59:02 +0100 Subject: [PATCH 2/4] some improvement suggested by @rodlie --- src/ui/dialogs/scenesettingsdialog.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/ui/dialogs/scenesettingsdialog.cpp b/src/ui/dialogs/scenesettingsdialog.cpp index 9261a70ae..4e8c657b0 100644 --- a/src/ui/dialogs/scenesettingsdialog.cpp +++ b/src/ui/dialogs/scenesettingsdialog.cpp @@ -186,7 +186,8 @@ SceneSettingsDialog::SceneSettingsDialog(const QString &name, connect(mCancelButton, &QPushButton::released, this, &SceneSettingsDialog::reject); connect(this, &QDialog::rejected, this, &QDialog::close); - connect(mTypeTime, QOverload::of(&QComboBox::currentIndexChanged),this, [this]() { updateDuration(); }); + connect(mTypeTime, QOverload::of(&QComboBox::currentIndexChanged), + this, &SceneSettingsDialog::updateDuration); validate(); @@ -314,14 +315,22 @@ void SceneSettingsDialog::updateDuration() { const QString typetime = mTypeTime->currentData().toString(); const qreal fps = mFPSSpinBox->value(); int duration = mMaxFrameSpin->value() - mMinFrameSpin->value(); + int index = mTypeTime->currentIndex(); - if (typetime == "Frames") { - // Convert seconds to frames - duration = qRound(duration * fps); - } else { - // Convert frames to seconds - duration = qRound(duration / fps); + if (mMinFrameSpin->value() >= mMaxFrameSpin->value()) { + return; + } + + switch(index) { + case 0: // Convert seconds to frames + duration = qRound(duration * fps); + break; + case 1: // Convert frames to seconds + duration = qRound(duration / fps); + break; + default: + return; } mMaxFrameSpin->setValue(mMinFrameSpin->value() + duration); -} \ No newline at end of file +} From c29542f7e41c202ca18bb529c87a52d8bb5d680c Mon Sep 17 00:00:00 2001 From: Pablo Gil Date: Tue, 12 Nov 2024 10:50:29 +0100 Subject: [PATCH 3/4] simplified the conversion --- src/ui/dialogs/scenesettingsdialog.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ui/dialogs/scenesettingsdialog.cpp b/src/ui/dialogs/scenesettingsdialog.cpp index 4e8c657b0..2802ce73a 100644 --- a/src/ui/dialogs/scenesettingsdialog.cpp +++ b/src/ui/dialogs/scenesettingsdialog.cpp @@ -314,7 +314,6 @@ void SceneSettingsDialog::sNewSceneDialog(Document& document, void SceneSettingsDialog::updateDuration() { const QString typetime = mTypeTime->currentData().toString(); const qreal fps = mFPSSpinBox->value(); - int duration = mMaxFrameSpin->value() - mMinFrameSpin->value(); int index = mTypeTime->currentIndex(); if (mMinFrameSpin->value() >= mMaxFrameSpin->value()) { @@ -323,14 +322,14 @@ void SceneSettingsDialog::updateDuration() { switch(index) { case 0: // Convert seconds to frames - duration = qRound(duration * fps); + mMinFrameSpin->setValue(mMinFrameSpin->value() * fps); + mMaxFrameSpin->setValue(mMaxFrameSpin->value() * fps); break; case 1: // Convert frames to seconds - duration = qRound(duration / fps); + mMinFrameSpin->setValue(mMinFrameSpin->value() / fps); + mMaxFrameSpin->setValue(mMaxFrameSpin->value() / fps); break; default: return; } - - mMaxFrameSpin->setValue(mMinFrameSpin->value() + duration); } From 8e992590dbf39abdbdc55baf72cafd194aca9839 Mon Sep 17 00:00:00 2001 From: Pablo Gil Date: Tue, 12 Nov 2024 22:22:24 +0100 Subject: [PATCH 4/4] more simplification and more robust code --- src/ui/dialogs/scenesettingsdialog.cpp | 21 +++++++-------------- src/ui/dialogs/scenesettingsdialog.h | 2 +- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/ui/dialogs/scenesettingsdialog.cpp b/src/ui/dialogs/scenesettingsdialog.cpp index 2802ce73a..df9519963 100644 --- a/src/ui/dialogs/scenesettingsdialog.cpp +++ b/src/ui/dialogs/scenesettingsdialog.cpp @@ -311,25 +311,18 @@ void SceneSettingsDialog::sNewSceneDialog(Document& document, dialog->show(); } -void SceneSettingsDialog::updateDuration() { - const QString typetime = mTypeTime->currentData().toString(); +void SceneSettingsDialog::updateDuration(int index) +{ const qreal fps = mFPSSpinBox->value(); - int index = mTypeTime->currentIndex(); - - if (mMinFrameSpin->value() >= mMaxFrameSpin->value()) { - return; - } - switch(index) { case 0: // Convert seconds to frames - mMinFrameSpin->setValue(mMinFrameSpin->value() * fps); - mMaxFrameSpin->setValue(mMaxFrameSpin->value() * fps); + mMinFrameSpin->setValue(qRound(mMinFrameSpin->value() * fps)); + mMaxFrameSpin->setValue(qRound(mMaxFrameSpin->value() * fps)); break; case 1: // Convert frames to seconds - mMinFrameSpin->setValue(mMinFrameSpin->value() / fps); - mMaxFrameSpin->setValue(mMaxFrameSpin->value() / fps); + mMinFrameSpin->setValue(qRound(mMinFrameSpin->value() / fps)); + mMaxFrameSpin->setValue(qRound(mMaxFrameSpin->value() / fps)); break; - default: - return; + default:; } } diff --git a/src/ui/dialogs/scenesettingsdialog.h b/src/ui/dialogs/scenesettingsdialog.h index 65af0da0a..6deadcf8c 100644 --- a/src/ui/dialogs/scenesettingsdialog.h +++ b/src/ui/dialogs/scenesettingsdialog.h @@ -75,7 +75,7 @@ class UI_EXPORT SceneSettingsDialog : public QDialog private: bool validate(); - void updateDuration(); + void updateDuration(int index); Canvas * mTargetCanvas = nullptr;