From e12144c27e4a65aec2340132013d333b471d99c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole-Andr=C3=A9=20Rodlie?= Date: Sun, 15 Oct 2023 23:29:40 +0200 Subject: [PATCH] Scene dialog: support fps presets Basic fps preset selector. * has a list of common fps * any fps spinbox value not in presets will be added on Ok Not able to remove preset(s) from UI yet. --- src/app/GUI/Dialogs/scenesettingsdialog.cpp | 50 +++++++++++++++++++++ src/app/GUI/Dialogs/scenesettingsdialog.h | 8 ++++ 2 files changed, 58 insertions(+) diff --git a/src/app/GUI/Dialogs/scenesettingsdialog.cpp b/src/app/GUI/Dialogs/scenesettingsdialog.cpp index 9120f6c17..991f40834 100644 --- a/src/app/GUI/Dialogs/scenesettingsdialog.cpp +++ b/src/app/GUI/Dialogs/scenesettingsdialog.cpp @@ -104,16 +104,24 @@ SceneSettingsDialog::SceneSettingsDialog(const QString &name, mMainLayout->addLayout(mFrameRangeLayout); + mFpsToolButton = new QToolButton(this); + mFpsToolButton->setArrowType(Qt::NoArrow); + mFpsToolButton->setPopupMode(QToolButton::InstantPopup); + mFpsToolButton->setObjectName("ToolButton"); + mFpsToolButton->setIcon(QIcon::fromTheme("dots")); + mFPSLabel = new QLabel("Fps:", this); mFPSSpinBox = new QDoubleSpinBox(this); mFPSSpinBox->setLocale(QLocale(QLocale::English, QLocale::UnitedStates)); mFPSSpinBox->setRange(1, 300); + mFPSSpinBox->setDecimals(3); mFPSSpinBox->setValue(fps); mFPSLayout = new QHBoxLayout(); mFPSLayout->addWidget(mFPSLabel); mFPSLayout->addWidget(mFPSSpinBox); + mFPSLayout->addWidget(mFpsToolButton); mMainLayout->addLayout(mFPSLayout); mBgColorLabel = new QLabel("Background:", this); @@ -143,6 +151,8 @@ SceneSettingsDialog::SceneSettingsDialog(const QString &name, connect(this, &QDialog::rejected, this, &QDialog::close); validate(); + + populateFpsPresets(); } bool SceneSettingsDialog::validate() { @@ -188,12 +198,52 @@ qreal SceneSettingsDialog::getFps() const { return mFPSSpinBox->value(); } +const QStringList SceneSettingsDialog::getFpsPresets() const +{ + QStringList presets; + QSettings settings; + settings.beginGroup("presets"); + presets = settings.value("fps", QStringList() << "23.976" << "24" << "25" << "30" << "50" << "60").toStringList(); + settings.endGroup(); + return presets; +} + +void SceneSettingsDialog::checkFpsPresets() const +{ + QStringList presets = getFpsPresets(); + if (presets.contains(QString::number(getFps()))) { return; } + presets << QString::number(getFps()); + QSettings settings; + settings.beginGroup("presets"); + settings.setValue("fps", presets); + settings.endGroup(); +} + +void SceneSettingsDialog::populateFpsPresets() +{ + QStringList presets = getFpsPresets(); + + QMap m; + for (auto s : presets) { m[s.toDouble()] = s; } + presets = QStringList(m.values()); + + for (int i = 0; i < presets.count(); ++i) { + QString preset = presets.at(i); + const auto act = new QAction(preset, this); + connect (act, &QAction::triggered, [this, preset]() { + mFPSSpinBox->setValue(preset.toDouble()); + }); + mFpsToolButton->addAction(act); + } +} + void SceneSettingsDialog::applySettingsToCanvas(Canvas * const canvas) const { if(!canvas) return; canvas->prp_setNameAction(getCanvasName()); canvas->setCanvasSize(getCanvasWidth(), getCanvasHeight()); canvas->setFps(getFps()); canvas->setFrameRange(getFrameRange()); + checkFpsPresets(); if(canvas != mTargetCanvas) { canvas->getBgColorAnimator()->setColor(mBgColorButton->color()); } diff --git a/src/app/GUI/Dialogs/scenesettingsdialog.h b/src/app/GUI/Dialogs/scenesettingsdialog.h index b5a049e09..2a12f59d8 100644 --- a/src/app/GUI/Dialogs/scenesettingsdialog.h +++ b/src/app/GUI/Dialogs/scenesettingsdialog.h @@ -33,6 +33,8 @@ #include #include #include +#include + #include "smartPointers/ememory.h" #include "framerange.h" @@ -62,6 +64,10 @@ class SceneSettingsDialog : public QDialog { FrameRange getFrameRange() const; qreal getFps() const; + const QStringList getFpsPresets() const; + void checkFpsPresets() const; + void populateFpsPresets(); + void applySettingsToCanvas(Canvas * const canvas) const; static void sNewSceneDialog(Document &document, QWidget * const parent); @@ -101,6 +107,8 @@ class SceneSettingsDialog : public QDialog { QPushButton *mOkButton; QPushButton *mCancelButton; QHBoxLayout *mButtonsLayout; + + QToolButton *mFpsToolButton; }; #endif // SCENESETTINGSDIALOG_H