Skip to content

Commit

Permalink
Settings can be changed, and they are saved properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlamhauge committed Mar 4, 2024
1 parent 5ea52b6 commit 569a54e
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 11 deletions.
14 changes: 12 additions & 2 deletions app/src/camerapropertiesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GNU General Public License for more details.
#include "camerapropertiesdialog.h"
#include "ui_camerapropertiesdialog.h"

CameraPropertiesDialog::CameraPropertiesDialog(const QString& name, int width, int height) :
CameraPropertiesDialog::CameraPropertiesDialog(const QString &name, int width, int height, qreal aperture, qreal distance) :
QDialog(),
ui(new Ui::CameraPropertiesDialog)
{
Expand All @@ -27,6 +27,10 @@ CameraPropertiesDialog::CameraPropertiesDialog(const QString& name, int width, i
ui->nameBox->setText(name);
ui->widthBox->setValue(width);
ui->heightBox->setValue(height);
ui->apertureBox->setCurrentText(QString::number(aperture));
ui->distanceSpinBox->setValue(distance);

connect(ui->btnResetSettings, &QPushButton::clicked, this, &CameraPropertiesDialog::resetDialog);
}

CameraPropertiesDialog::~CameraPropertiesDialog()
Expand Down Expand Up @@ -76,10 +80,16 @@ void CameraPropertiesDialog::setDistance(qreal dist)

qreal CameraPropertiesDialog::getAperture()
{
return ui->apertureBox->itemData(ui->apertureBox->currentIndex()).toDouble();
return ui->apertureBox->itemText(ui->apertureBox->currentIndex()).toDouble();
}

void CameraPropertiesDialog::setAperture(qreal aperture)
{
ui->apertureBox->setCurrentText(QString::number(aperture));
}

void CameraPropertiesDialog::resetDialog()
{
ui->apertureBox->setCurrentText(QString::number(8.0f));
ui->distanceSpinBox->setValue(10.0f);
}
6 changes: 5 additions & 1 deletion app/src/camerapropertiesdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CameraPropertiesDialog : public QDialog
{
Q_OBJECT
public:
CameraPropertiesDialog(const QString& name, int width, int height);
CameraPropertiesDialog(const QString& name, int width, int height, qreal aperture, qreal distance);
~CameraPropertiesDialog() override;
QString getName();
void setName(const QString& name);
Expand All @@ -40,6 +40,10 @@ class CameraPropertiesDialog : public QDialog
void setDistance(qreal dist);
qreal getAperture();
void setAperture(qreal aperture);
void resetDialog();

signals:
void propertiesChanged();

private:
Ui::CameraPropertiesDialog* ui = nullptr;
Expand Down
11 changes: 7 additions & 4 deletions app/src/timelinecells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,8 +1158,11 @@ void TimeLineCells::editLayerProperties(LayerCamera* cameraLayer) const
{
QRegularExpression regex("([\\x{FFEF}-\\x{FFFF}])+");

CameraPropertiesDialog dialog(cameraLayer->name(), cameraLayer->getViewRect().width(),
cameraLayer->getViewRect().height());
CameraPropertiesDialog dialog(cameraLayer->name(),
cameraLayer->getViewRect().width(),
cameraLayer->getViewRect().height(),
cameraLayer->getAperture(),
cameraLayer->getDistance());
if (dialog.exec() != QDialog::Accepted)
{
return;
Expand All @@ -1173,9 +1176,9 @@ void TimeLineCells::editLayerProperties(LayerCamera* cameraLayer) const
QSettings settings(PENCIL2D, PENCIL2D);
settings.setValue(SETTING_FIELD_W, dialog.getWidth());
settings.setValue(SETTING_FIELD_H, dialog.getHeight());
settings.setValue(SETTING_CAM_DISTANCE, dialog.getDistance());
settings.setValue(SETTING_APERTURE, dialog.getAperture());
cameraLayer->setViewRect(QRect(-dialog.getWidth() / 2, -dialog.getHeight() / 2, dialog.getWidth(), dialog.getHeight()));
cameraLayer->setAperture(dialog.getAperture());
cameraLayer->setDistance(dialog.getDistance());
mEditor->view()->forceUpdateViewTransform();
}

Expand Down
20 changes: 18 additions & 2 deletions app/ui/camerapropertiesdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
</item>
<item>
<property name="text">
<string>2,8</string>
<string>2.8</string>
</property>
</item>
<item>
Expand All @@ -96,7 +96,7 @@
</item>
<item>
<property name="text">
<string>5,6</string>
<string>5.6</string>
</property>
</item>
<item>
Expand Down Expand Up @@ -231,5 +231,21 @@
</hint>
</hints>
</connection>
<connection>
<sender>btnResetSettings</sender>
<signal>clicked()</signal>
<receiver>CameraPropertiesDialog</receiver>
<slot>exec()</slot>
<hints>
<hint type="sourcelabel">
<x>73</x>
<y>194</y>
</hint>
<hint type="destinationlabel">
<x>126</x>
<y>134</y>
</hint>
</hints>
</connection>
</connections>
</ui>
6 changes: 6 additions & 0 deletions core_lib/src/structure/layercamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,8 @@ QDomElement LayerCamera::createDomElement(QDomDocument& doc) const
QDomElement layerElem = createBaseDomElement(doc);
layerElem.setAttribute("width", viewRect.width());
layerElem.setAttribute("height", viewRect.height());
layerElem.setAttribute("aperture", mAperture);
layerElem.setAttribute("distance", mDistance);

if (mShowPath) {
layerElem.setAttribute("showPath", mShowPath);
Expand Down Expand Up @@ -596,6 +598,10 @@ void LayerCamera::loadDomElement(const QDomElement& element, QString dataDirPath

int width = element.attribute("width").toInt();
int height = element.attribute("height").toInt();
qreal aperture = element.attribute("aperture", "8").toDouble();
setAperture(aperture);
qreal distance = element.attribute("distance", "10").toDouble();
setDistance(distance);
mShowPath = element.attribute("showPath").toInt();
updateDotColor(static_cast<DotColorType>(element.attribute("pathColorType").toInt()));
viewRect = QRect(-width / 2, -height / 2, width, height);
Expand Down
10 changes: 10 additions & 0 deletions core_lib/src/structure/layercamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ GNU General Public License for more details.
#ifndef LAYERCAMERA_H
#define LAYERCAMERA_H

#include <QDebug>
#include <QRect>
#include <QColor>
#include "layer.h"
Expand Down Expand Up @@ -68,6 +69,11 @@ class LayerCamera : public Layer
void splitControlPointIfNeeded(int frame) const;
void mergeControlPointIfNeeded(int frame) const;

void setAperture(qreal aper) { mAperture = aper; }
qreal getAperture() { return mAperture; }
void setDistance(qreal dist) { mDistance = dist; }
qreal getDistance() { return mDistance; }

protected:
Status saveKeyFrameFile(KeyFrame*, QString path) override;
KeyFrame* createKeyFrame(int position) override;
Expand All @@ -77,6 +83,10 @@ class LayerCamera : public Layer
qreal getInterpolationPercent(CameraEasingType type, qreal percent) const;
QPointF getBezierPoint(const QPointF& first, const QPointF& last, const QPointF& pathPoint, qreal percent) const;

// values specific for camera depth of field
qreal mAperture = 8.0f;
qreal mDistance = 10.0f;

int mFieldW = 800;
int mFieldH = 600;
QRect viewRect;
Expand Down
2 changes: 0 additions & 2 deletions core_lib/src/util/pencildef.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@ const static float RotationHandleOffset = 50;
#define SETTING_FPS "Fps"
#define SETTING_FIELD_W "FieldW"
#define SETTING_FIELD_H "FieldH"
#define SETTING_APERTURE "Aperture"
#define SETTING_CAM_DISTANCE "CamDistance"
#define SETTING_FRAME_SIZE "FrameSize"
#define SETTING_TIMELINE_SIZE "TimelineSize"
#define SETTING_LABEL_FONT_SIZE "LabelFontSize"
Expand Down

0 comments on commit 569a54e

Please sign in to comment.