Skip to content

Commit

Permalink
Support fps/resolution presets
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Oct 16, 2023
1 parent e12144c commit b5acc01
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 27 deletions.
54 changes: 29 additions & 25 deletions src/app/GUI/Dialogs/scenesettingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "scenesettingsdialog.h"
#include "canvas.h"
#include "GUI/coloranimatorbutton.h"
#include "appsupport.h"

SceneSettingsDialog::SceneSettingsDialog(Canvas * const canvas,
QWidget * const parent) :
Expand Down Expand Up @@ -76,11 +77,18 @@ SceneSettingsDialog::SceneSettingsDialog(const QString &name,
mHeightSpinBox->setRange(1, 9999);
mHeightSpinBox->setValue(height);

mResToolButton = new QToolButton(this);
mResToolButton->setArrowType(Qt::NoArrow);
mResToolButton->setPopupMode(QToolButton::InstantPopup);
mResToolButton->setObjectName("ToolButton");
mResToolButton->setIcon(QIcon::fromTheme("dots"));

mSizeLayout = new QHBoxLayout();
mSizeLayout->addWidget(mWidthLabel);
mSizeLayout->addWidget(mWidthSpinBox);
mSizeLayout->addWidget(mHeightLabel);
mSizeLayout->addWidget(mHeightSpinBox);
mSizeLayout->addWidget(mResToolButton);
mMainLayout->addLayout(mSizeLayout);

mFrameRangeLabel = new QLabel("Duration:", this);
Expand Down Expand Up @@ -152,6 +160,7 @@ SceneSettingsDialog::SceneSettingsDialog(const QString &name,

validate();

populateResPresets();
populateFpsPresets();
}

Expand Down Expand Up @@ -198,37 +207,15 @@ 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();
QStringList presets = AppSupport::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);
for (const auto &preset : presets) {
const auto act = new QAction(preset, this);
connect (act, &QAction::triggered, [this, preset]() {
mFPSSpinBox->setValue(preset.toDouble());
Expand All @@ -237,13 +224,30 @@ void SceneSettingsDialog::populateFpsPresets()
}
}

void SceneSettingsDialog::populateResPresets()
{
const auto presets = AppSupport::getResolutionPresets();
for (const auto &preset : presets) {
const auto act = new QAction(QString("%1 x %2")
.arg(preset.first)
.arg(preset.second),
this);
connect (act, &QAction::triggered, [this, preset]() {
mWidthSpinBox->setValue(preset.first);
mHeightSpinBox->setValue(preset.second);
});
mResToolButton->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();
AppSupport::saveFpsPreset(getFps());
AppSupport::saveResolutionPreset(getCanvasWidth(), getCanvasHeight());
if(canvas != mTargetCanvas) {
canvas->getBgColorAnimator()->setColor(mBgColorButton->color());
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/GUI/Dialogs/scenesettingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ class SceneSettingsDialog : public QDialog {
FrameRange getFrameRange() const;
qreal getFps() const;

const QStringList getFpsPresets() const;
void checkFpsPresets() const;
void populateFpsPresets();
void populateResPresets();

void applySettingsToCanvas(Canvas * const canvas) const;

Expand Down Expand Up @@ -108,6 +107,7 @@ class SceneSettingsDialog : public QDialog {
QPushButton *mCancelButton;
QHBoxLayout *mButtonsLayout;

QToolButton *mResToolButton;
QToolButton *mFpsToolButton;
};

Expand Down
97 changes: 97 additions & 0 deletions src/core/appsupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,100 @@ const QByteArray AppSupport::filterShader(QByteArray data)
#endif
return data;
}

const QStringList AppSupport::getFpsPresets()
{
QStringList presets;
QSettings settings;
settings.beginGroup("presets");
presets = settings.value("fps",
QStringList()
<< "24"
<< "25"
<< "30"
<< "50"
<< "60").toStringList();
settings.endGroup();
return presets;
}

void AppSupport::saveFpsPreset(const double value)
{
if (value <= 0) { return; }
auto presets = getFpsPresets();
if (presets.contains(QString::number(value))) { return; }
presets << QString::number(value);
QSettings settings;
settings.beginGroup("presets");
settings.setValue("fps", presets);
settings.endGroup();
}

bool AppSupport::removeFpsPreset(const double value)
{
if (value <= 0) { return false; }
auto presets = getFpsPresets();
if (!presets.removeAll(QString::number(value))) { return false; }
QSettings settings;
settings.beginGroup("presets");
settings.setValue("fps", presets);
settings.endGroup();
return true;
}

const QStringList AppSupport::getResolutionPresetsList()
{
QStringList presets;
QSettings settings;
settings.beginGroup("presets");
presets = settings.value("resolution",
QStringList()
<< "1280x720"
<< "1920x1080"
<< "2560x1440"
<< "3840x2160").toStringList();
settings.endGroup();
return presets;
}

const QList<QPair<int, int> > AppSupport::getResolutionPresets()
{
const auto presets = getResolutionPresetsList();
QList<QPair<int, int>> l;
for (auto &v: presets) {
auto res = v.split("x");
if (res.count() != 2) { continue; }
l.append(QPair<int, int>(res.at(0).trimmed().toInt(),
res.at(1).trimmed().toInt()));
}
std::sort(l.begin(), l.end());
return l;
}

void AppSupport::saveResolutionPreset(const int w,
const int h)
{
if (w <= 0 || h <= 0) { return; }
const auto v = QString("%1x%2").arg(w).arg(h);
auto presets = getResolutionPresetsList();
if (presets.contains(v)) { return; }
presets << v;
QSettings settings;
settings.beginGroup("presets");
settings.setValue("resolution", presets);
settings.endGroup();
}

bool AppSupport::removeResolutionPreset(const int w,
const int h)
{
if (w <= 0 || h <= 0) { return false; }
const auto v = QString("%1x%2").arg(w).arg(h);
auto presets = getResolutionPresetsList();
if (!presets.removeAll(v)) { return false; }
QSettings settings;
settings.beginGroup("presets");
settings.setValue("resolution", presets);
settings.endGroup();
return true;
}
7 changes: 7 additions & 0 deletions src/core/appsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ class CORE_EXPORT AppSupport : public QObject
static const QString getRasterEffectHardwareSupportString(const QString &effect,
HardwareSupport fallback);
static const QByteArray filterShader(QByteArray data);
static const QStringList getFpsPresets();
static void saveFpsPreset(const double value);
static bool removeFpsPreset(const double value);
static const QStringList getResolutionPresetsList();
static const QList<QPair<int, int>> getResolutionPresets();
static void saveResolutionPreset(const int w, const int h);
static bool removeResolutionPreset(const int w, const int h);
};

#endif // APPSUPPORT_H

0 comments on commit b5acc01

Please sign in to comment.