Skip to content

Commit

Permalink
Setting can be edited, and are saved in file.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlamhauge committed Mar 6, 2024
1 parent 569a54e commit 84b8322
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 9 deletions.
5 changes: 4 additions & 1 deletion app/app.pro
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ HEADERS += \
src/commandlineexporter.h \
src/statusbar.h \
src/elidedlabel.h \
src/cameraoptionswidget.h
src/cameraoptionswidget.h \
src/layerpropertiesdialog.h

SOURCES += \
src/importlayersdialog.cpp \
src/importpositiondialog.cpp \
src/layeropacitydialog.cpp \
src/layerpropertiesdialog.cpp \
src/main.cpp \
src/mainwindow2.cpp \
src/onionskinwidget.cpp \
Expand Down Expand Up @@ -169,6 +171,7 @@ FORMS += \
ui/importlayersdialog.ui \
ui/importpositiondialog.ui \
ui/layeropacitydialog.ui \
ui/layerpropertiesdialog.ui \
ui/mainwindow2.ui \
ui/onionskin.ui \
ui/pegbaralignmentdialog.ui \
Expand Down
36 changes: 36 additions & 0 deletions app/src/layerpropertiesdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "layerpropertiesdialog.h"
#include "ui_layerpropertiesdialog.h"

#include <QPushButton>
#include <QMessageBox>

layerPropertiesDialog::layerPropertiesDialog(QString name, qreal distance) :
QDialog(),
ui(new Ui::layerPropertiesDialog)
{
ui->setupUi(this);
ui->lineEditName->setText(name);
ui->doubleSpinBoxDistance->setValue(distance);
connect(ui->btnInstructions, &QPushButton::clicked, this, &layerPropertiesDialog::showInstructions);
}

layerPropertiesDialog::~layerPropertiesDialog()
{
delete ui;
}

void layerPropertiesDialog::showInstructions()
{
QMessageBox mBox;
}

QString layerPropertiesDialog::updateName()
{
return ui->lineEditName->text();
}

qreal layerPropertiesDialog::updateDistance()
{
return ui->doubleSpinBoxDistance->value();
}

26 changes: 26 additions & 0 deletions app/src/layerpropertiesdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef LAYERPROPERTIESDIALOG_H
#define LAYERPROPERTIESDIALOG_H

#include <QDialog>

namespace Ui {
class layerPropertiesDialog;
}

class layerPropertiesDialog : public QDialog
{
Q_OBJECT

public:
explicit layerPropertiesDialog( QString name, qreal distance);
~layerPropertiesDialog();

void showInstructions();
QString updateName();
qreal updateDistance();

private:
Ui::layerPropertiesDialog *ui;
};

#endif // LAYERPROPERTIESDIALOG_H
35 changes: 32 additions & 3 deletions app/src/timelinecells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ GNU General Public License for more details.
#include <QSettings>

#include "camerapropertiesdialog.h"
#include "layerpropertiesdialog.h"
#include "editor.h"
#include "keyframe.h"
#include "layermanager.h"
Expand All @@ -33,6 +34,8 @@ GNU General Public License for more details.
#include "playbackmanager.h"
#include "preferencemanager.h"
#include "timeline.h"
#include "layerbitmap.h"
#include "layervector.h"

#include "cameracontextmenu.h"

Expand Down Expand Up @@ -1145,16 +1148,19 @@ void TimeLineCells::editLayerProperties(Layer *layer) const
{
if (layer->type() != Layer::CAMERA)
{
editLayerName(layer);
if (layer->type() == Layer::SOUND)
editLayerName(layer); // soundlayer can only change name
else
editLayerSettings(layer); // bitmap and vector layers can also change distance
return;
}

auto cameraLayer = dynamic_cast<LayerCamera*>(layer);
Q_ASSERT(cameraLayer);
editLayerProperties(cameraLayer);
editCameraLayerProperties(cameraLayer);
}

void TimeLineCells::editLayerProperties(LayerCamera* cameraLayer) const
void TimeLineCells::editCameraLayerProperties(LayerCamera* cameraLayer) const
{
QRegularExpression regex("([\\x{FFEF}-\\x{FFFF}])+");

Expand Down Expand Up @@ -1199,6 +1205,29 @@ void TimeLineCells::editLayerName(Layer* layer) const
mEditor->layers()->renameLayer(layer, name);
}

void TimeLineCells::editLayerSettings(Layer *layer) const
{
auto artLayer = dynamic_cast<LayerBitmap*>(layer);
Q_ASSERT(artLayer);
if (layer->type() == Layer::VECTOR)
{
auto artLayer = dynamic_cast<LayerVector*>(layer);
Q_ASSERT(artLayer);
}
QRegularExpression regex("([\\x{FFEF}-\\x{FFFF}])+");

layerPropertiesDialog dialog(artLayer->name(),
artLayer->getDistance());
if (dialog.exec() != QDialog::Accepted)
{
return;
}
QString name = dialog.updateName().replace(regex, "");
artLayer->setName(name);
artLayer->setDistance(dialog.updateDistance());

}

void TimeLineCells::hScrollChange(int x)
{
mFrameOffset = x;
Expand Down
6 changes: 5 additions & 1 deletion app/src/timelinecells.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ GNU General Public License for more details.
#include <QString>
#include <QWidget>
#include "layercamera.h"
#include "layerbitmap.h"
#include "layervector.h"
#include "layersound.h"

class Layer;
enum class LayerVisibility;
Expand Down Expand Up @@ -113,8 +116,9 @@ private slots:
void paintHighlightedFrame(QPainter& painter, int framePos, int recTop, int recWidth, int recHeight) const;

void editLayerProperties(Layer* layer) const;
void editLayerProperties(LayerCamera *layer) const;
void editCameraLayerProperties(LayerCamera *layer) const;
void editLayerName(Layer* layer) const;
void editLayerSettings(Layer* layer) const;

TimeLine* mTimeLine;
Editor* mEditor; // the editor for which this timeLine operates
Expand Down
136 changes: 136 additions & 0 deletions app/ui/layerpropertiesdialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>layerPropertiesDialog</class>
<widget class="QDialog" name="layerPropertiesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>338</width>
<height>157</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="labName">
<property name="text">
<string>Layer name: </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labDistance">
<property name="text">
<string>Distance to camera:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLineEdit" name="lineEditName"/>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBoxDistance">
<property name="suffix">
<string> m.</string>
</property>
<property name="minimum">
<double>1.000000000000000</double>
</property>
<property name="maximum">
<double>50000.000000000000000</double>
</property>
<property name="singleStep">
<double>0.500000000000000</double>
</property>
<property name="value">
<double>10.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnInstructions">
<property name="text">
<string>Instructions</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>layerPropertiesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>layerPropertiesDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
6 changes: 3 additions & 3 deletions core_lib/src/structure/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ class Layer : public QObject
void clearDirtyFrames() { mDirtyFrames.clear(); }

// for depth of field
void setDistance(qreal dist) { mDistance = dist; }
qreal getDistance() { return mDistance; }
void setDistance(qreal dist) const { mDistance = dist; }
qreal getDistance() const { return mDistance; }
void setNearDistance(qreal dist) { mNearDistance = dist; }
qreal getNearDistance() { return mNearDistance; }
void setFarDistance(qreal dist) { mFarDistance = dist; }
Expand All @@ -189,7 +189,7 @@ public slots:
QString mName;

// vars for depth of field
qreal mDistance = 10.0f; // standard distance from camera to layer
mutable qreal mDistance = 10.0f; // standard distance from camera to layer
qreal mNearDistance = 10.0f; // nearest distance, where the object will be i "acceptable" focus
qreal mFarDistance = 10.0f; // farthest distance, where the object will be i "acceptable" focus

Expand Down
9 changes: 8 additions & 1 deletion core_lib/src/structure/layerbitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ bool LayerBitmap::needSaveFrame(KeyFrame* key, const QString& savePath)
QDomElement LayerBitmap::createDomElement(QDomDocument& doc) const
{
QDomElement layerElem = createBaseDomElement(doc);
layerElem.setAttribute("distance", getDistance());

foreachKeyFrame([&](KeyFrame* pKeyFrame)
{
Expand All @@ -195,13 +196,19 @@ QDomElement LayerBitmap::createDomElement(QDomDocument& doc) const

Q_ASSERT(QFileInfo(pKeyFrame->fileName()).fileName() == fileName(pKeyFrame));
});

/*
// Here we append a new element to the end of the document
QDomElement distance = doc.createElement("dist");
distance.setAttribute("dist", getDistance());
layerElem.appendChild(distance);
*/
return layerElem;
}

void LayerBitmap::loadDomElement(const QDomElement& element, QString dataDirPath, ProgressCallback progressStep)
{
this->loadBaseDomElement(element);
setDistance(element.attribute("distance").toDouble());

QDomNode imageTag = element.firstChild();
while (!imageTag.isNull())
Expand Down

0 comments on commit 84b8322

Please sign in to comment.