Skip to content

Commit

Permalink
Scene dialog: support fps presets
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rodlie committed Oct 15, 2023
1 parent d05b6a8 commit e12144c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/app/GUI/Dialogs/scenesettingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -143,6 +151,8 @@ SceneSettingsDialog::SceneSettingsDialog(const QString &name,
connect(this, &QDialog::rejected, this, &QDialog::close);

validate();

populateFpsPresets();
}

bool SceneSettingsDialog::validate() {
Expand Down Expand Up @@ -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<double, QString> 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());
}
Expand Down
8 changes: 8 additions & 0 deletions src/app/GUI/Dialogs/scenesettingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <QLineEdit>
#include <QLabel>
#include <QComboBox>
#include <QToolButton>

#include "smartPointers/ememory.h"
#include "framerange.h"

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -101,6 +107,8 @@ class SceneSettingsDialog : public QDialog {
QPushButton *mOkButton;
QPushButton *mCancelButton;
QHBoxLayout *mButtonsLayout;

QToolButton *mFpsToolButton;
};

#endif // SCENESETTINGSDIALOG_H

0 comments on commit e12144c

Please sign in to comment.