diff --git a/effects/effect.cpp b/effects/effect.cpp index a7476f1dc..a94e9bb6a 100644 --- a/effects/effect.cpp +++ b/effects/effect.cpp @@ -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;iField(j); if (!field->id().isEmpty()) { switch (field->type()) { - case EffectField::EFFECT_FIELD_DOUBLE: + case olive::nodes::kFloat: { DoubleField* double_field = static_cast(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(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; } } diff --git a/effects/effectfield.cpp b/effects/effectfield.cpp index 7446fbc5f..a9abd46c6 100644 --- a/effects/effectfield.cpp +++ b/effects/effectfield.cpp @@ -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; diff --git a/effects/effectfield.h b/effects/effectfield.h index 30b74e53e..1e97a074e 100644 --- a/effects/effectfield.h +++ b/effects/effectfield.h @@ -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(). diff --git a/effects/fields/boolfield.cpp b/effects/fields/boolfield.cpp index 13c958912..1cd44a96b 100644 --- a/effects/fields/boolfield.cpp +++ b/effects/fields/boolfield.cpp @@ -23,7 +23,7 @@ #include BoolField::BoolField(EffectRow *parent, const QString &id) : - EffectField(parent, id, EFFECT_FIELD_BOOL) + EffectField(parent, id, olive::nodes::kBoolean) {} bool BoolField::GetBoolAt(double timecode) diff --git a/effects/fields/buttonfield.cpp b/effects/fields/buttonfield.cpp index 77025b17a..3cb5f1e23 100644 --- a/effects/fields/buttonfield.cpp +++ b/effects/fields/buttonfield.cpp @@ -23,7 +23,7 @@ #include ButtonField::ButtonField(EffectRow *parent, const QString &string) : - EffectField(parent, nullptr, EFFECT_FIELD_UI), + EffectField(parent, nullptr, olive::nodes::kUI), button_text_(string) {} diff --git a/effects/fields/colorfield.cpp b/effects/fields/colorfield.cpp index b294f9e78..109a4b4c1 100644 --- a/effects/fields/colorfield.cpp +++ b/effects/fields/colorfield.cpp @@ -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) diff --git a/effects/fields/combofield.cpp b/effects/fields/combofield.cpp index 133e704d3..08c6a52a5 100644 --- a/effects/fields/combofield.cpp +++ b/effects/fields/combofield.cpp @@ -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) diff --git a/effects/fields/doublefield.cpp b/effects/fields/doublefield.cpp index 58603d4b0..537b2bebb 100644 --- a/effects/fields/doublefield.cpp +++ b/effects/fields/doublefield.cpp @@ -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), diff --git a/effects/fields/filefield.cpp b/effects/fields/filefield.cpp index b40eede59..89e74d119 100644 --- a/effects/fields/filefield.cpp +++ b/effects/fields/filefield.cpp @@ -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, ""); diff --git a/effects/fields/fontfield.cpp b/effects/fields/fontfield.cpp index 5876bdd78..6618c683d 100644 --- a/effects/fields/fontfield.cpp +++ b/effects/fields/fontfield.cpp @@ -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(); diff --git a/effects/fields/labelfield.cpp b/effects/fields/labelfield.cpp index 231c1ee08..459ec10dc 100644 --- a/effects/fields/labelfield.cpp +++ b/effects/fields/labelfield.cpp @@ -23,7 +23,7 @@ #include LabelField::LabelField(EffectRow *parent, const QString &string) : - EffectField(parent, nullptr, EFFECT_FIELD_UI), + EffectField(parent, nullptr, olive::nodes::kUI), label_text_(string) {} diff --git a/effects/fields/stringfield.cpp b/effects/fields/stringfield.cpp index 57439473a..fcdc65cf4 100644 --- a/effects/fields/stringfield.cpp +++ b/effects/fields/stringfield.cpp @@ -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 diff --git a/nodes/medianode.h b/nodes/medianode.h index 96dd94ecc..7fb634375 100644 --- a/nodes/medianode.h +++ b/nodes/medianode.h @@ -1,9 +1,7 @@ #ifndef MEDIANODE_H #define MEDIANODE_H -#include "node.h" - -class MediaNode : public Node +class MediaNode { public: MediaNode(); diff --git a/nodes/nodedatatypes.cpp b/nodes/nodedatatypes.cpp new file mode 100644 index 000000000..53636cc7d --- /dev/null +++ b/nodes/nodedatatypes.cpp @@ -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; +} diff --git a/nodes/nodedatatypes.h b/nodes/nodedatatypes.h new file mode 100644 index 000000000..ebf20eadf --- /dev/null +++ b/nodes/nodedatatypes.h @@ -0,0 +1,102 @@ +#ifndef NODEDATATYPES_H +#define NODEDATATYPES_H + +#include + +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 diff --git a/olive.pro b/olive.pro index fe3afc66e..cde79eb5e 100644 --- a/olive.pro +++ b/olive.pro @@ -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 += diff --git a/panels/grapheditor.cpp b/panels/grapheditor.cpp index e664b8aba..6430a80fd 100644 --- a/panels/grapheditor.cpp +++ b/panels/grapheditor.cpp @@ -149,7 +149,7 @@ void GraphEditor::update_panel() { int slider_index = 0; for (int i=0;iFieldCount();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;iFieldCount();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()); diff --git a/panels/nodeeditor.cpp b/panels/nodeeditor.cpp index 1d6ba9cfd..a4e8823d3 100644 --- a/panels/nodeeditor.cpp +++ b/panels/nodeeditor.cpp @@ -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); - } -} diff --git a/panels/nodeeditor.h b/panels/nodeeditor.h index 2da7260e2..a404629c3 100644 --- a/panels/nodeeditor.h +++ b/panels/nodeeditor.h @@ -23,9 +23,6 @@ private: NodeView view_; QVector nodes_; -private slots: - void Scroll(qreal x, qreal y); - }; #endif // NODEEDITOR_H diff --git a/ui/graphview.cpp b/ui/graphview.cpp index 5885d7f76..72b91848e 100644 --- a/ui/graphview.cpp +++ b/ui/graphview.cpp @@ -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 sorted_keys = sort_keys_from_field(field); @@ -386,7 +386,7 @@ void GraphView::mousePressEvent(QMouseEvent *event) { } else { for (int i=0;iFieldCount();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;jkeyframes.size();j++) { const EffectKeyframe& key = field->keyframes.at(j); int key_x = get_screen_x(key.time); diff --git a/ui/nodeview.cpp b/ui/nodeview.cpp index d4b780ce0..25b40ef36 100644 --- a/ui/nodeview.cpp +++ b/ui/nodeview.cpp @@ -1,6 +1,7 @@ #include "nodeview.h" #include +#include #include 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); diff --git a/ui/nodeview.h b/ui/nodeview.h index 61ef0ccdb..bd751aa4c 100644 --- a/ui/nodeview.h +++ b/ui/nodeview.h @@ -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;