created enum for more node data types

This commit is contained in:
itsmattkc
2019-04-09 20:55:25 +10:00
parent 433ae494ad
commit 7cbcb20543
22 changed files with 237 additions and 114 deletions
+18 -30
View File
@@ -159,21 +159,7 @@ Effect::Effect(Clip* c, const EffectMeta *em) :
const QXmlStreamAttribute& attr = attributes.at(i);
if (attr.name() == "type") {
QString comp = attr.value().toString().toUpper();
if (comp == "DOUBLE") {
type = EffectField::EFFECT_FIELD_DOUBLE;
} else if (comp == "BOOL") {
type = EffectField::EFFECT_FIELD_BOOL;
} else if (comp == "COLOR") {
type = EffectField::EFFECT_FIELD_COLOR;
} else if (comp == "COMBO") {
type = EffectField::EFFECT_FIELD_COMBO;
} else if (comp == "FONT") {
type = EffectField::EFFECT_FIELD_FONT;
} else if (comp == "STRING") {
type = EffectField::EFFECT_FIELD_STRING;
} else if (comp == "FILE") {
type = EffectField::EFFECT_FIELD_FILE;
}
type = olive::nodes::StringToDataType(comp);
} else if (attr.name() == "id") {
id = attr.value().toString();
}
@@ -181,11 +167,13 @@ Effect::Effect(Clip* c, const EffectMeta *em) :
if (id.isEmpty()) {
qCritical() << "Couldn't load field from" << em->filename << "- ID cannot be empty.";
} else if (type == olive::nodes::kInvalid) {
qWarning() << "Invalid field type found";
} else {
EffectField* field = nullptr;
switch (type) {
case EffectField::EFFECT_FIELD_DOUBLE:
case olive::nodes::kFloat:
{
DoubleField* double_field = new DoubleField(row, id);
@@ -204,7 +192,7 @@ Effect::Effect(Clip* c, const EffectMeta *em) :
field = double_field;
}
break;
case EffectField::EFFECT_FIELD_COLOR:
case olive::nodes::kColor:
{
QColor color;
@@ -232,7 +220,7 @@ Effect::Effect(Clip* c, const EffectMeta *em) :
field->SetValueAt(0, color);
}
break;
case EffectField::EFFECT_FIELD_STRING:
case olive::nodes::kString:
field = new StringField(row, id);
for (int i=0;i<attributes.size();i++) {
const QXmlStreamAttribute& attr = attributes.at(i);
@@ -241,7 +229,7 @@ Effect::Effect(Clip* c, const EffectMeta *em) :
}
}
break;
case EffectField::EFFECT_FIELD_BOOL:
case olive::nodes::kBoolean:
field = new BoolField(row, id);
for (int i=0;i<attributes.size();i++) {
const QXmlStreamAttribute& attr = attributes.at(i);
@@ -250,7 +238,7 @@ Effect::Effect(Clip* c, const EffectMeta *em) :
}
}
break;
case EffectField::EFFECT_FIELD_COMBO:
case olive::nodes::kCombo:
{
ComboField* combo_field = new ComboField(row, id);
int combo_default_index = 0;
@@ -274,7 +262,7 @@ Effect::Effect(Clip* c, const EffectMeta *em) :
field = combo_field;
}
break;
case EffectField::EFFECT_FIELD_FONT:
case olive::nodes::kFont:
field = new FontField(row, id);
for (int i=0;i<attributes.size();i++) {
const QXmlStreamAttribute& attr = attributes.at(i);
@@ -283,7 +271,7 @@ Effect::Effect(Clip* c, const EffectMeta *em) :
}
}
break;
case EffectField::EFFECT_FIELD_FILE:
case olive::nodes::kFile:
field = new FileField(row, id);
for (int i=0;i<attributes.size();i++) {
const QXmlStreamAttribute& attr = attributes.at(i);
@@ -864,14 +852,14 @@ void Effect::process_shader(double timecode, GLTextureCoords&, int iteration) {
EffectField* field = row->Field(j);
if (!field->id().isEmpty()) {
switch (field->type()) {
case EffectField::EFFECT_FIELD_DOUBLE:
case olive::nodes::kFloat:
{
DoubleField* double_field = static_cast<DoubleField*>(field);
shader_program_->setUniformValue(double_field->id().toUtf8().constData(),
GLfloat(double_field->GetDoubleAt(timecode)));
}
break;
case EffectField::EFFECT_FIELD_COLOR:
case olive::nodes::kColor:
{
ColorField* color_field = static_cast<ColorField*>(field);
shader_program_->setUniformValue(
@@ -882,18 +870,18 @@ void Effect::process_shader(double timecode, GLTextureCoords&, int iteration) {
);
}
break;
case EffectField::EFFECT_FIELD_BOOL:
case olive::nodes::kBoolean:
shader_program_->setUniformValue(field->id().toUtf8().constData(), field->GetValueAt(timecode).toBool());
break;
case EffectField::EFFECT_FIELD_COMBO:
case olive::nodes::kCombo:
shader_program_->setUniformValue(field->id().toUtf8().constData(), field->GetValueAt(timecode).toInt());
break;
// can you even send a string to a uniform value?
case EffectField::EFFECT_FIELD_STRING:
case EffectField::EFFECT_FIELD_FONT:
case EffectField::EFFECT_FIELD_FILE:
case EffectField::EFFECT_FIELD_UI:
case olive::nodes::kString:
case olive::nodes::kFont:
case olive::nodes::kFile:
case olive::nodes::kUI:
break;
}
}
+11 -11
View File
@@ -34,7 +34,7 @@
#include "global/math.h"
#include "global/debug.h"
EffectField::EffectField(EffectRow* parent, const QString &i, EffectFieldType t) :
EffectField::EffectField(EffectRow* parent, const QString &i, olive::nodes::DataType t) :
QObject(parent),
type_(t),
id_(i),
@@ -43,7 +43,7 @@ EffectField::EffectField(EffectRow* parent, const QString &i, EffectFieldType t)
{
// EffectField MUST be created with a parent.
Q_ASSERT(parent != nullptr);
Q_ASSERT(!i.isEmpty() || t == EFFECT_FIELD_UI);
Q_ASSERT(!i.isEmpty() || t == olive::nodes::kUI);
// Add this field to the parent row specified
parent->AddField(this);
@@ -93,7 +93,7 @@ QVariant EffectField::GetValueAt(double timecode)
const QVariant& before_data = keyframes.at(before_keyframe).data;
switch (type_) {
case EFFECT_FIELD_DOUBLE:
case olive::nodes::kFloat:
{
double value;
if (before_keyframe == after_keyframe) {
@@ -163,7 +163,7 @@ QVariant EffectField::GetValueAt(double timecode)
persistent_data_ = value;
break;
}
case EFFECT_FIELD_COLOR:
case olive::nodes::kColor:
{
QColor value;
if (before_keyframe == after_keyframe) {
@@ -178,11 +178,11 @@ QVariant EffectField::GetValueAt(double timecode)
persistent_data_ = value;
break;
}
case EFFECT_FIELD_STRING:
case EFFECT_FIELD_BOOL:
case EFFECT_FIELD_COMBO:
case EFFECT_FIELD_FONT:
case EFFECT_FIELD_FILE:
case olive::nodes::kString:
case olive::nodes::kBoolean:
case olive::nodes::kCombo:
case olive::nodes::kFont:
case olive::nodes::kFile:
persistent_data_ = before_data;
break;
default:
@@ -274,7 +274,7 @@ void EffectField::PrepareDataForKeyframing(bool enabled, ComboAction *ca)
}
}
const EffectField::EffectFieldType &EffectField::type()
const olive::nodes::DataType &EffectField::type()
{
return type_;
}
@@ -360,7 +360,7 @@ void EffectField::GetKeyframeData(double timecode, int &before, int &after, doub
}
}
if ((type_ == EFFECT_FIELD_DOUBLE || type_ == EFFECT_FIELD_COLOR)
if ((type_ == olive::nodes::kFloat || type_ == olive::nodes::kColor)
&& (before_keyframe_index > -1 && after_keyframe_index > -1)) {
// interpolate
before = before_keyframe_index;
+5 -37
View File
@@ -28,6 +28,7 @@
#include "effects/keyframe.h"
#include "undo/undo.h"
#include "undo/undostack.h"
#include "nodes/nodedatatypes.h"
class EffectRow;
class ComboAction;
@@ -56,39 +57,6 @@ class ComboAction;
class EffectField : public QObject {
Q_OBJECT
public:
/**
* @brief The EffectFieldType enum
*
* Predetermined types of fields. Used throughout Olive to identify what kind of data to expect from GetValueAt().
*
* This enum is also currently used to match an external XML effect's fields with the correct derived class (e.g.
* EFFECT_FIELD_DOUBLE matches to DoubleField).
*/
enum EffectFieldType {
/** Values are doubles. Also corresponds to DoubleField. */
EFFECT_FIELD_DOUBLE,
/** Values are colors. Also corresponds to ColorField. */
EFFECT_FIELD_COLOR,
/** Values are strings. Also corresponds to StringField. */
EFFECT_FIELD_STRING,
/** Values are booleans. Also corresponds to BoolField. */
EFFECT_FIELD_BOOL,
/** Values are arbitrary data. Also corresponds to ComboField. */
EFFECT_FIELD_COMBO,
/** Values are font family names (in string). Also corresponds to FontField. */
EFFECT_FIELD_FONT,
/** Values are filenames (in string). Also corresponds to FileField. */
EFFECT_FIELD_FILE,
/** Values is a UI object with no data. Corresponds to nothing. */
EFFECT_FIELD_UI
};
/**
* @brief EffectField Constructor
@@ -112,7 +80,7 @@ public:
*
* The type of data contained within this field. This is expected to be filled by a derived class.
*/
EffectField(EffectRow* parent, const QString& i, EffectFieldType t);
EffectField(EffectRow* parent, const QString& i, olive::nodes::DataType t);
/**
* @brief Get the EffectRow that this field is a member of.
@@ -130,9 +98,9 @@ public:
*
* @return
*
* A member of the EffectFieldType enum.
* A member of the olive::nodes::DataType enum.
*/
const EffectFieldType& type();
const olive::nodes::DataType& type();
/**
* @brief Get the unique identifier of this field set in the constructor
@@ -430,7 +398,7 @@ private:
/**
* @brief Internal type variable set in the constructor. Access with type().
*/
EffectFieldType type_;
olive::nodes::DataType type_;
/**
* @brief Internal unique identifier for this field set in the constructor. Access with id().
+1 -1
View File
@@ -23,7 +23,7 @@
#include <QCheckBox>
BoolField::BoolField(EffectRow *parent, const QString &id) :
EffectField(parent, id, EFFECT_FIELD_BOOL)
EffectField(parent, id, olive::nodes::kBoolean)
{}
bool BoolField::GetBoolAt(double timecode)
+1 -1
View File
@@ -23,7 +23,7 @@
#include <QPushButton>
ButtonField::ButtonField(EffectRow *parent, const QString &string) :
EffectField(parent, nullptr, EFFECT_FIELD_UI),
EffectField(parent, nullptr, olive::nodes::kUI),
button_text_(string)
{}
+1 -1
View File
@@ -25,7 +25,7 @@
#include "ui/colorbutton.h"
ColorField::ColorField(EffectRow* parent, const QString& id) :
EffectField(parent, id, EFFECT_FIELD_COLOR)
EffectField(parent, id, olive::nodes::kColor)
{}
QColor ColorField::GetColorAt(double timecode)
+1 -1
View File
@@ -25,7 +25,7 @@
#include "ui/comboboxex.h"
ComboField::ComboField(EffectRow* parent, const QString& id) :
EffectField(parent, id, EFFECT_FIELD_COMBO)
EffectField(parent, id, olive::nodes::kCombo)
{}
void ComboField::AddItem(const QString &text, const QVariant &data)
+1 -1
View File
@@ -23,7 +23,7 @@
#include "effects/effectrow.h"
DoubleField::DoubleField(EffectRow* parent, const QString& id) :
EffectField(parent, id, EFFECT_FIELD_DOUBLE),
EffectField(parent, id, olive::nodes::kFloat),
min_(qSNaN()),
max_(qSNaN()),
default_(0),
+1 -1
View File
@@ -25,7 +25,7 @@
#include "ui/embeddedfilechooser.h"
FileField::FileField(EffectRow* parent, const QString &id) :
EffectField(parent, id, EFFECT_FIELD_FILE)
EffectField(parent, id, olive::nodes::kFile)
{
// Set default value to an empty string
SetValueAt(0, "");
+1 -1
View File
@@ -28,7 +28,7 @@
// NOTE/TODO: This shares a lot of similarity with ComboField, and could probably be a derived class of it
FontField::FontField(EffectRow* parent, const QString &id) :
EffectField(parent, id, EFFECT_FIELD_FONT)
EffectField(parent, id, olive::nodes::kFont)
{
font_list = QFontDatabase().families();
+1 -1
View File
@@ -23,7 +23,7 @@
#include <QLabel>
LabelField::LabelField(EffectRow *parent, const QString &string) :
EffectField(parent, nullptr, EFFECT_FIELD_UI),
EffectField(parent, nullptr, olive::nodes::kUI),
label_text_(string)
{}
+1 -1
View File
@@ -27,7 +27,7 @@
#include "global/config.h"
StringField::StringField(EffectRow* parent, const QString& id, bool rich_text) :
EffectField(parent, id, EFFECT_FIELD_STRING),
EffectField(parent, id, olive::nodes::kString),
rich_text_(rich_text)
{
// Set default value to an empty string
+1 -3
View File
@@ -1,9 +1,7 @@
#ifndef MEDIANODE_H
#define MEDIANODE_H
#include "node.h"
class MediaNode : public Node
class MediaNode
{
public:
MediaNode();
+74
View File
@@ -0,0 +1,74 @@
#include "nodedatatypes.h"
QString olive::nodes::DataTypeToString(DataType type) {
switch (type) {
case kFloat:
return "DOUBLE";
case kVec2:
return "VEC2";
case kVec3:
return "VEC3";
case kVec4:
return "VEC4";
case kArray:
return "ARRAY";
case kColor:
return "COLOR";
case kString:
return "STRING";
case kBoolean:
return "BOOL";
case kCombo:
return "COMBO";
case kFont:
return "FONT";
case kFile:
return "FILE";
case kInteger:
return "INTEGER";
case kTexture:
return "TEXTURE";
case kMatrix:
return "MATRIX";
case kUI:
return "UI";
default:
return QString();
}
}
olive::nodes::DataType olive::nodes::StringToDataType(const QString &s)
{
if (s == "DOUBLE") {
return kFloat;
} else if (s == "VEC2") {
return kVec2;
} else if (s == "VEC3") {
return kVec3;
} else if (s == "VEC4") {
return kVec4;
} else if (s == "ARRAY") {
return kArray;
} else if (s == "COLOR") {
return kColor;
} else if (s == "STRING") {
return kString;
} else if (s == "BOOL") {
return kBoolean;
} else if (s == "COMBO") {
return kCombo;
} else if (s == "FONT") {
return kFont;
} else if (s == "FILE") {
return kFile;
} else if (s == "INTEGER") {
return kInteger;
} else if (s == "TEXTURE") {
return kTexture;
} else if (s == "MATRIX") {
return kMatrix;
} else if (s == "UI") {
return kUI;
}
return kInvalid;
}
+102
View File
@@ -0,0 +1,102 @@
#ifndef NODEDATATYPES_H
#define NODEDATATYPES_H
#include <QString>
namespace olive {
namespace nodes {
/**
* @brief The EffectFieldType enum
*
* Predetermined types of fields. Used throughout Olive to identify what kind of data to expect from GetValueAt().
*
* This enum is also currently used to match an external XML effect's fields with the correct derived class (e.g.
* EFFECT_FIELD_DOUBLE matches to DoubleField).
*/
enum DataType {
/** Invalid data type. Used only for error handling. */
kInvalid,
/** Values are doubles. Also corresponds to DoubleField. */
kFloat,
/** Value is an 2-component vector of floats. */
kVec2,
/** Value is an 3-component vector of floats. */
kVec3,
/** Value is an 4-component vector of floats. */
kVec4,
/** Value is an array of floats. This cannot be an input field, and can only be passed between nodes. */
kArray,
/** Values are colors. Equivalent to kVec4 but represents as a color. Corresponds to ColorField. */
kColor,
/** Values are strings. Also corresponds to StringField. */
kString,
/** Values are booleans. Also corresponds to BoolField. */
kBoolean,
/** Values are arbitrary data. Also corresponds to ComboField. */
kCombo,
/** Values are font family names (in string). Also corresponds to FontField. */
kFont,
/** Values are filenames (in string). Also corresponds to FileField. */
kFile,
/** Values are integers. */
kInteger,
/** Value is a texture. This cannot be an input field, and can only be passed between nodes. */
kTexture,
/** Value is a 4x4 matrix. This cannot be an input field, and can only be passed between nodes. */
kMatrix,
/** Values is a UI object with no data. Corresponds to nothing. */
kUI,
/** Total count of valid node data types. Never use this as an actual data type. */
kDataTypeCount
};
/**
* @brief Convert a node data type to a unique string that can be saved to an XML file
*
* @param type
*
* The data type to convert to string
*
* @return
*
* The unique string identifier for this data type.
*/
QString DataTypeToString(DataType type);
/**
* @brief Convert a string to a node data type.
*
* Generally this string should be a string that was received from DataTypeToString() to ensure compatibility and
* correctness.
*
* @param s
*
* The string to convert to a data type
*
* @return
*
* The data type that this string represents
*/
DataType StringToDataType(const QString& s);
}
}
#endif // NODEDATATYPES_H
+4 -2
View File
@@ -191,7 +191,8 @@ SOURCES += \
ui/nodeview.cpp \
nodes/medianode.cpp \
ui/nodeui.cpp \
panels/effectspanel.cpp
panels/effectspanel.cpp \
nodes/nodedatatypes.cpp
HEADERS += \
ui/mainwindow.h \
@@ -337,7 +338,8 @@ HEADERS += \
ui/nodeview.h \
nodes/medianode.h \
ui/nodeui.h \
panels/effectspanel.h
panels/effectspanel.h \
nodes/nodedatatypes.h
FORMS +=
+2 -2
View File
@@ -149,7 +149,7 @@ void GraphEditor::update_panel() {
int slider_index = 0;
for (int i=0;i<row->FieldCount();i++) {
EffectField* field = row->Field(i);
if (field->type() == EffectField::EFFECT_FIELD_DOUBLE) {
if (field->type() == olive::nodes::kFloat) {
field->UpdateWidgetValue(field_sliders_.at(slider_index), field->Now());
slider_index++;
}
@@ -186,7 +186,7 @@ void GraphEditor::set_row(EffectRow *r) {
if (r != nullptr && r->IsKeyframing()) {
for (int i=0;i<r->FieldCount();i++) {
EffectField* field = r->Field(i);
if (field->type() == EffectField::EFFECT_FIELD_DOUBLE) {
if (field->type() == olive::nodes::kFloat) {
QPushButton* slider_button = new QPushButton();
slider_button->setCheckable(true);
slider_button->setChecked(field->IsEnabled());
-10
View File
@@ -21,7 +21,6 @@ NodeEditor::NodeEditor(QWidget *parent) :
view_.setInteractive(true);
view_.setDragMode(QGraphicsView::RubberBandDrag);
connect(&view_, SIGNAL(ScrollChanged(qreal, qreal)), this, SLOT(Scroll(qreal, qreal)));
}
void NodeEditor::Retranslate()
@@ -57,12 +56,3 @@ void NodeEditor::ClearEvent()
nodes_.clear();
}
void NodeEditor::Scroll(qreal x, qreal y)
{
NodeUI* node;
foreach (node, nodes_) {
node->moveBy(x, y);
}
}
-3
View File
@@ -23,9 +23,6 @@ private:
NodeView view_;
QVector<NodeUI*> nodes_;
private slots:
void Scroll(qreal x, qreal y);
};
#endif // NODEEDITOR_H
+2 -2
View File
@@ -244,7 +244,7 @@ void GraphView::paintEvent(QPaintEvent *) {
for (int i=row->FieldCount()-1;i>=0;i--) {
EffectField* field = row->Field(i);
if (field->type() == EffectField::EFFECT_FIELD_DOUBLE && field_visibility.at(i)) {
if (field->type() == olive::nodes::kFloat && field_visibility.at(i)) {
// sort keyframes by time
QVector<int> sorted_keys = sort_keys_from_field(field);
@@ -386,7 +386,7 @@ void GraphView::mousePressEvent(QMouseEvent *event) {
} else {
for (int i=0;i<row->FieldCount();i++) {
EffectField* field = row->Field(i);
if (field->type() == EffectField::EFFECT_FIELD_DOUBLE && field_visibility.at(i)) {
if (field->type() == olive::nodes::kFloat && field_visibility.at(i)) {
for (int j=0;j<field->keyframes.size();j++) {
const EffectKeyframe& key = field->keyframes.at(j);
int key_x = get_screen_x(key.time);
+9 -2
View File
@@ -1,6 +1,7 @@
#include "nodeview.h"
#include <QWheelEvent>
#include <QScrollBar>
#include <QDebug>
NodeView::NodeView(QGraphicsScene *scene, QWidget *parent) :
@@ -27,8 +28,14 @@ void NodeView::mousePressEvent(QMouseEvent *event)
void NodeView::mouseMoveEvent(QMouseEvent *event)
{
if (hand_moving_) {
QPointF scene_delta = mapToScene(event->pos() - drag_start_) - mapToScene(0.0, 0.0);
emit ScrollChanged(scene_delta.x(), scene_delta.y());
//QPointF scene_delta = mapToScene(event->pos() - drag_start_) - mapToScene(0.0, 0.0);
//emit ScrollChanged(scene_delta.x(), scene_delta.y());
QPoint delta = event->pos() - drag_start_;
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + delta.x());
verticalScrollBar()->setValue(verticalScrollBar()->value() + delta.y());
drag_start_ = event->pos();
} else {
QGraphicsView::mouseMoveEvent(event);
-3
View File
@@ -8,9 +8,6 @@ class NodeView : public QGraphicsView {
public:
NodeView(QGraphicsScene *scene, QWidget* parent = nullptr);
signals:
void ScrollChanged(qreal x, qreal y);
protected:
virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseMoveEvent(QMouseEvent *event) override;