Skip to content

Commit

Permalink
Adjust scene to clip: changes/fixes
Browse files Browse the repository at this point in the history
Add an improved dialog and settings integration.
  • Loading branch information
rodlie committed Jul 19, 2024
1 parent 216a156 commit 35a9244
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 19 deletions.
39 changes: 20 additions & 19 deletions src/app/GUI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#include "themesupport.h"

#include "widgets/assetswidget.h"
#include "dialogs/adjustscenedialog.h"

MainWindow *MainWindow::sInstance = nullptr;

Expand Down Expand Up @@ -2076,7 +2077,13 @@ void MainWindow::writeRecentFiles()

void MainWindow::handleNewVideoClip(const VideoBox::VideoSpecs &specs)
{
if (specs.fps < 1 || specs.dim.height() < 1 || specs.dim.width() < 1) { return; }
int act = eSettings::instance().fAdjustSceneFromFirstClip;

// never apply or bad specs?
if (act == eSettings::AdjustSceneNever ||
specs.fps < 1 ||
specs.dim.height() < 1 ||
specs.dim.width() < 1) { return; }

const auto scene = *mDocument.fActiveScene;
if (!scene) { return; }
Expand All @@ -2089,22 +2096,16 @@ void MainWindow::handleNewVideoClip(const VideoBox::VideoSpecs &specs)
scene->getFps() == specs.fps &&
scene->getFrameRange().fMax == specs.range.fMax) { return; }

const auto reply = QMessageBox::question(this,
tr("Adjust scene to clip?"),
tr("Video clip and scene do not match, adjust scene to clip?\n\n"
"Clip: %1x%2 Fps: %3 Frames: %4\n\n"
"Scene: %5x%6 Fps: %7 Frames: %8")
.arg(QString::number(specs.dim.width()),
QString::number(specs.dim.height()),
QString::number(specs.fps),
QString::number(specs.range.fMax),
QString::number(scene->getCanvasWidth()),
QString::number(scene->getCanvasHeight()),
QString::number(scene->getFps()),
QString::number(scene->getFrameRange().fMax)));
if (reply != QMessageBox::Yes) { return; }
scene->setCanvasSize(specs.dim.width(),
specs.dim.height());
scene->setFps(specs.fps);
scene->setFrameRange(specs.range);
// always apply?
if (act == eSettings::AdjustSceneAlways) {
scene->setCanvasSize(specs.dim.width(),
specs.dim.height());
scene->setFps(specs.fps);
scene->setFrameRange(specs.range);
return;
}

// open dialog if ask
AdjustSceneDialog dialog(scene, specs, this);
dialog.exec();
}
14 changes: 14 additions & 0 deletions src/core/Private/esettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ eSettings::eSettings(const int cpuThreads,
fPathControlScaling,
"pathControlScaling", 1.);

gSettings << std::make_shared<eIntSetting>(fAdjustSceneFromFirstClip,
"AdjustSceneFromFirstClip",
AdjustSceneAsk);

/*gSettings << std::make_shared<eBoolSetting>(
fTimelineAlternateRow,
"timelineAlternateRow", true);
Expand Down Expand Up @@ -347,3 +351,13 @@ void eSettings::saveToFile()
setting->writeValue();
}
}

void eSettings::saveKeyToFile(const QString &key)
{
for (const auto& setting : gSettings) {
if (key == setting->fName) {
setting->writeValue();
return;
}
}
}
8 changes: 8 additions & 0 deletions src/core/Private/esettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class CORE_EXPORT eSettings : public QObject
Q_OBJECT

public:
enum AdjustSceneArgs {
AdjustSceneAsk,
AdjustSceneAlways,
AdjustSceneNever
};
eSettings(const int cpuThreads,
const intKB ramKB);

Expand All @@ -70,6 +75,7 @@ class CORE_EXPORT eSettings : public QObject
void loadDefaults();
void loadFromFile();
void saveToFile();
void saveKeyToFile(const QString &key);

// general
QString fUserSettingsDir;
Expand Down Expand Up @@ -120,6 +126,8 @@ class CORE_EXPORT eSettings : public QObject
QColor fPathControlColor;
QColor fPathControlSelectedColor;

int fAdjustSceneFromFirstClip = AdjustSceneAsk;

// timeline settings
bool fTimelineAlternateRow = true;
QColor fTimelineAlternateRowColor = QColor(0, 0, 0, 25);
Expand Down
2 changes: 2 additions & 0 deletions src/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ include_directories(

set(
SOURCES
dialogs/adjustscenedialog.cpp
dialogs/applyexpressiondialog.cpp
dialogs/durationrectsettingsdialog.cpp
dialogs/exportsvgdialog.cpp
Expand Down Expand Up @@ -101,6 +102,7 @@ set(
set(
HEADERS
ui_global.h
dialogs/adjustscenedialog.h
dialogs/applyexpressiondialog.h
dialogs/durationrectsettingsdialog.h
dialogs/exportsvgdialog.h
Expand Down
135 changes: 135 additions & 0 deletions src/ui/dialogs/adjustscenedialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
#
# Friction - https://friction.graphics
#
# Copyright (c) Friction contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# See 'README.md' for more information.
#
*/

#include "adjustscenedialog.h"

#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>

#include "Private/esettings.h"

AdjustSceneDialog::AdjustSceneDialog(Canvas *scene,
const VideoBox::VideoSpecs &specs,
QWidget *parent)
: QDialog(parent)
{
if (!scene ||
specs.dim.width() < 1 ||
specs.dim.height() < 1 ||
specs.fps < 1) {
reject();
return;
}

setMinimumWidth(400);
setWindowTitle(tr("Adjust scene to clip?"));

const auto mLayout = new QVBoxLayout(this);

const auto infoWidget = new QWidget(this);
const auto infoLayout = new QHBoxLayout(infoWidget);

const auto buttonsWidget = new QWidget(this);
const auto buttonsLayout = new QHBoxLayout(buttonsWidget);

const auto pixLabel = new QLabel(this);
pixLabel->setMaximumWidth(96);
pixLabel->setPixmap(QIcon::fromTheme("seq_preview").pixmap(96, 96));

const auto infoLabel = new QLabel(this);
infoLabel->setTextFormat(Qt::RichText);
infoLabel->setWordWrap(true);
infoLabel->setText(QString("<style>th { text-align: left; } table { margin-top: 1em; }</style>"
"<h3>%9</h3>"
"<table width=\"100%\">"
"<tr><th>%13 %10</th><th>%13 %11</th><th>%13 %12</th></tr>"
"<tr><td>%1x%2</td><td>%3</td><td>%4</td></tr>"
"<tr><td></td><td></td><td></td></tr>"
"<tr><th>%14 %10</th><th>%14 %11</th><th>%14 %12</th></tr>"
"<tr><td>%5x%6</td><td>%7</td><td>%8</td></tr>"
"</table>")
.arg(QString::number(specs.dim.width()),
QString::number(specs.dim.height()),
QString::number(specs.fps),
QString::number(specs.range.fMax),
QString::number(scene->getCanvasWidth()),
QString::number(scene->getCanvasHeight()),
QString::number(scene->getFps()),
QString::number(scene->getFrameRange().fMax),
tr("Adjust scene to clip?"),
tr("Dimension"),
tr("Fps"),
tr("Frames"),
tr("Clip"),
tr("Scene")));

const auto buttonYes = new QPushButton(tr("Yes"), this);
const auto buttonNo = new QPushButton(tr("No"), this);
const auto buttonAlways = new QPushButton(tr("Always"), this);
const auto buttonNever = new QPushButton(tr("Never"), this);

mLayout->addWidget(infoWidget);
mLayout->addStretch();
mLayout->addWidget(buttonsWidget);
infoLayout->addWidget(pixLabel);
infoLayout->addWidget(infoLabel);
buttonsLayout->addWidget(buttonAlways);
buttonsLayout->addWidget(buttonNever);
buttonsLayout->addStretch();
buttonsLayout->addWidget(buttonYes);
buttonsLayout->addWidget(buttonNo);

connect(buttonYes, &QPushButton::clicked,
this, [scene, &specs, this] {
scene->setCanvasSize(specs.dim.width(),
specs.dim.height());
scene->setFps(specs.fps);
scene->setFrameRange(specs.range);
accept();
});

connect(buttonAlways, &QPushButton::clicked,
this, [scene, &specs, this]() {
const auto settings = eSettings::sInstance;
settings->fAdjustSceneFromFirstClip = eSettings::AdjustSceneAlways;
settings->saveKeyToFile("AdjustSceneFromFirstClip");
scene->setCanvasSize(specs.dim.width(),
specs.dim.height());
scene->setFps(specs.fps);
scene->setFrameRange(specs.range);
accept();
});

connect(buttonNo, &QPushButton::clicked,
this, [this]() { reject(); });

connect(buttonNever, &QPushButton::clicked,
this, [this]() {
const auto settings = eSettings::sInstance;
settings->fAdjustSceneFromFirstClip = eSettings::AdjustSceneNever;
settings->saveKeyToFile("AdjustSceneFromFirstClip");
reject();
});
}
42 changes: 42 additions & 0 deletions src/ui/dialogs/adjustscenedialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
#
# Friction - https://friction.graphics
#
# Copyright (c) Friction contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# See 'README.md' for more information.
#
*/

#ifndef ADJUSTSCENEDIALOG_H
#define ADJUSTSCENEDIALOG_H

#include "ui_global.h"

#include <QDialog>

#include "canvas.h"
#include "Boxes/videobox.h"

class UI_EXPORT AdjustSceneDialog : public QDialog
{
public:
AdjustSceneDialog(Canvas *scene,
const VideoBox::VideoSpecs &specs,
QWidget *parent = nullptr);
};

#endif // ADJUSTSCENEDIALOG_H
22 changes: 22 additions & 0 deletions src/ui/widgets/canvassettingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ CanvasSettingsWidget::CanvasSettingsWidget(QWidget* const parent) :
mRtlSupport = new QCheckBox("RTL language support", this);
addWidget(mRtlSupport);

const auto mAdjustSceneWidget = new QWidget(this);
const auto mAdjustSceneLayout = new QHBoxLayout(mAdjustSceneWidget);
const auto mAdjustSceneLabel = new QLabel(tr("Adjust scene to first clip"), this);

mAdjustSceneFromFirstClip = new QComboBox(this);
mAdjustSceneFromFirstClip->addItem(tr("Ask"), eSettings::AdjustSceneAsk);
mAdjustSceneFromFirstClip->addItem(tr("Always"), eSettings::AdjustSceneAlways);
mAdjustSceneFromFirstClip->addItem(tr("Never"), eSettings::AdjustSceneNever);

mAdjustSceneLayout->addWidget(mAdjustSceneLabel);
mAdjustSceneLayout->addWidget(mAdjustSceneFromFirstClip);
addWidget(mAdjustSceneWidget);

eSizesUI::widget.add(mRtlSupport, [this](const int size) {
mRtlSupport->setFixedHeight(size);
mRtlSupport->setStyleSheet(QString("QCheckBox::indicator { width: %1px; height: %1px;}").arg(size/1.5));
Expand All @@ -96,6 +109,8 @@ void CanvasSettingsWidget::applySettings() {
mSett.fPathControlSelectedColor = mPathControlSelectedColor->color();

mSett.fCanvasRtlSupport = mRtlSupport->isChecked();

mSett.fAdjustSceneFromFirstClip = mAdjustSceneFromFirstClip->currentData().toInt();
}

void CanvasSettingsWidget::updateSettings(bool restore)
Expand All @@ -114,4 +129,11 @@ void CanvasSettingsWidget::updateSettings(bool restore)
mPathControlSelectedColor->setColor(mSett.fPathControlSelectedColor);

mRtlSupport->setChecked(mSett.fCanvasRtlSupport);

for (int i = 0; i < mAdjustSceneFromFirstClip->count(); i++) {
if (mAdjustSceneFromFirstClip->itemData(i).toInt() == mSett.fAdjustSceneFromFirstClip) {
mAdjustSceneFromFirstClip->setCurrentIndex(i);
return;
}
}
}
2 changes: 2 additions & 0 deletions src/ui/widgets/canvassettingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include <QDoubleSpinBox>
#include <QCheckBox>
#include <QComboBox>

class ColorAnimatorButton;
class QSlider;
Expand All @@ -54,6 +55,7 @@ class UI_EXPORT CanvasSettingsWidget : public SettingsWidget {
QSlider* mPathControlSize;
ColorAnimatorButton* mPathControlColor = nullptr;
ColorAnimatorButton* mPathControlSelectedColor = nullptr;
QComboBox* mAdjustSceneFromFirstClip = nullptr;
};

#endif // CANVASSETTINGSWIDGET_H

0 comments on commit 35a9244

Please sign in to comment.