node socket UI

This commit is contained in:
itsmattkc
2019-04-11 11:48:20 +10:00
parent 358d1ba16a
commit 1285d70c62
14 changed files with 103 additions and 11 deletions
+10
View File
@@ -60,6 +60,11 @@ void EffectRow::AddField(EffectField *field)
fields_.append(field);
}
void EffectRow::AddNodeInput(olive::nodes::DataType type)
{
accepted_datatypes_.append(type);
}
bool EffectRow::IsKeyframing() {
return keyframing_;
}
@@ -102,6 +107,11 @@ void EffectRow::SetEnabled(bool enabled)
}
}
bool EffectRow::CanConnectNodes()
{
return !accepted_datatypes_.isEmpty();
}
void EffectRow::SetKeyframingEnabled(bool enabled) {
if (enabled == keyframing_) {
return;
+28
View File
@@ -211,6 +211,17 @@ public:
*/
void SetEnabled(bool enabled);
/**
* @brief Check if nodes can be connected to this input.
*
* Connecting is enabled by adding an accepted node input using AddNodeInput().
*
* @return
*
* TRUE if nodes can be connected.
*/
bool CanConnectNodes();
protected:
/**
* @brief Add a field to this row
@@ -224,6 +235,18 @@ protected:
*/
void AddField(EffectField* Field);
/**
* @brief Adds a node data type that can be accepted by this input
*
* Allows this input to take a node connection from a data type specified by type. An input can take several data
* types.
*
* @param type
*
* The data type to add
*/
void AddNodeInput(olive::nodes::DataType type);
public slots:
/**
* @brief Go to previous keyframe
@@ -340,6 +363,11 @@ private:
* get freed automatically.
*/
QVector<EffectField*> fields_;
/**
* @brief Internal array of accepted node data types
*/
QVector<olive::nodes::DataType> accepted_datatypes_;
};
#endif // EFFECTROW_H
+2
View File
@@ -6,6 +6,8 @@ BoolInput::BoolInput(Effect* parent, const QString& id, const QString& name, boo
BoolField* bool_field = new BoolField(this);
connect(bool_field, SIGNAL(Toggled(bool)), this, SIGNAL(Toggled(bool)));
AddField(bool_field);
AddNodeInput(olive::nodes::kBoolean);
}
bool BoolInput::GetBoolAt(double timecode)
+2
View File
@@ -4,6 +4,8 @@ ColorInput::ColorInput(Effect* parent, const QString& id, const QString& name, b
EffectRow(parent, id, name, savable, keyframable)
{
AddField(new ColorField(this));
AddNodeInput(olive::nodes::kColor);
}
QColor ColorInput::GetColorAt(double timecode)
+2
View File
@@ -6,6 +6,8 @@ ComboInput::ComboInput(Effect* parent, const QString& id, const QString& name, b
ComboField* combo_field = new ComboField(this);
connect(combo_field, SIGNAL(DataChanged(const QVariant&)), this, SIGNAL(DataChanged(const QVariant&)));
AddField(combo_field);
AddNodeInput(olive::nodes::kCombo);
}
void ComboInput::AddItem(const QString &text, const QVariant &data)
+2
View File
@@ -4,6 +4,8 @@ FileInput::FileInput(Effect* parent, const QString& id, const QString& name, boo
EffectRow(parent, id, name, savable, keyframable)
{
AddField(new FileField(this));
AddNodeInput(olive::nodes::kFile);
}
QString FileInput::GetFileAt(double timecode)
+2
View File
@@ -4,6 +4,8 @@ FontInput::FontInput(Effect* parent, const QString& id, const QString& name, boo
EffectRow(parent, id, name, savable, keyframable)
{
AddField(new FontField(this));
AddNodeInput(olive::nodes::kFont);
}
QString FontInput::GetFontAt(double timecode)
+2
View File
@@ -4,6 +4,8 @@ StringInput::StringInput(Effect* parent, const QString& id, const QString& name,
EffectRow(parent, id, name, savable, keyframable)
{
AddField(new StringField(this, rich_text));
AddNodeInput(olive::nodes::kString);
}
QString StringInput::GetStringAt(double timecode)
+11
View File
@@ -14,6 +14,17 @@ VecInput::VecInput(Effect* parent, const QString& id, const QString& name, int v
for (int i=0;i<values_;i++) {
AddField(new DoubleField(this));
}
AddNodeInput(olive::nodes::kFloat);
if (values > 1) {
AddNodeInput(olive::nodes::kVec2);
}
if (values > 2) {
AddNodeInput(olive::nodes::kVec3);
}
if (values > 3) {
AddNodeInput(olive::nodes::kVec4);
}
}
void VecInput::SetMinimum(double minimum)
-1
View File
@@ -9,7 +9,6 @@ public:
NodeGraph();
private:
Effect* end_node_;
};
#endif // NODEGRAPH_H
+10 -2
View File
@@ -202,11 +202,19 @@ int EffectUI::GetRowY(int row, QWidget* mapToWidget) {
QLabel* row_label = labels_.at(row);
int mapped_coord;
if (mapToWidget == nullptr) {
mapped_coord = contents->pos().y();
} else {
// FIXME Problematic now that EffectUIs are used outside of EffectControls
mapped_coord = mapToWidget->mapFrom(panel_effect_controls, contents->mapTo(panel_effect_controls, contents->pos())).y();
mapped_coord -= title_bar->height();
}
// Get center point of label (label->rect()->center()->y() - instead of y()+height/2 - produces an inaccurate result)
return row_label->y()
+ row_label->height() / 2
+ mapToWidget->mapFrom(panel_effect_controls, contents->mapTo(panel_effect_controls, contents->pos())).y()
- title_bar->height();
+ mapped_coord;
}
void EffectUI::UpdateFromEffect()
+1 -1
View File
@@ -95,7 +95,7 @@ public:
*
* The row's Y position.
*/
int GetRowY(int row, QWidget *mapToWidget);
int GetRowY(int row, QWidget *mapToWidget = nullptr);
/**
* @brief Update widgets with the current Effect's values.
+27 -5
View File
@@ -10,7 +10,10 @@
#include <QStyleOptionGraphicsItem>
#include <QPainter>
#include "ui/effectui.h"
const int kRoundedRectRadius = 5;
const int kNodePlugSize = 6;
NodeUI::NodeUI() :
central_widget_(nullptr)
@@ -33,24 +36,29 @@ void NodeUI::AddToScene(QGraphicsScene *scene)
if (central_widget_ != nullptr) {
proxy_ = scene->addWidget(central_widget_);
proxy_->setPos(pos() + QPoint(kRoundedRectRadius, kRoundedRectRadius));
proxy_->setPos(pos() + QPoint(1 + kRoundedRectRadius, 1 + kRoundedRectRadius));
proxy_->setParentItem(this);
}
}
void NodeUI::Resize(const QSize &s)
{
QRectF rectangle = rect();
QRectF rectangle;
rectangle.setTopLeft(pos());
rectangle.setSize(s + 2 * QSize(kRoundedRectRadius, kRoundedRectRadius));
QRectF inner_rect = rectangle;
inner_rect.translate(kNodePlugSize / 2, 0);
rectangle.setWidth(rectangle.width() + kNodePlugSize);
path_ = QPainterPath();
path_.addRoundedRect(rectangle, kRoundedRectRadius, kRoundedRectRadius);
path_.addRoundedRect(inner_rect, kRoundedRectRadius, kRoundedRectRadius);
setRect(rectangle);
}
void NodeUI::SetWidget(QWidget *widget)
void NodeUI::SetWidget(EffectUI *widget)
{
central_widget_ = widget;
}
@@ -59,6 +67,20 @@ void NodeUI::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QW
{
Q_UNUSED(widget)
if (proxy_ != nullptr) {
Effect* e = central_widget_->GetEffect();
for (int i=0;i<e->row_count();i++) {
if (e->row(i)->CanConnectNodes()) {
int y = central_widget_->GetRowY(i);
painter->setPen(Qt::black);
painter->setBrush(Qt::gray);
painter->drawEllipse(QPointF(rect().x() + kNodePlugSize / 2, proxy_->pos().y() + y), kNodePlugSize, kNodePlugSize);
}
}
}
QPalette palette = qApp->palette();
if (option->state & QStyle::State_Selected) {
+4 -2
View File
@@ -4,6 +4,8 @@
#include <QWidget>
#include <QGraphicsItem>
class EffectUI;
class NodeUI : public QGraphicsRectItem {
public:
NodeUI();
@@ -11,11 +13,11 @@ public:
void AddToScene(QGraphicsScene* scene);
void Resize(const QSize& s);
void SetWidget(QWidget* widget);
void SetWidget(EffectUI* widget);
protected:
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
private:
QWidget* central_widget_;
EffectUI* central_widget_;
QGraphicsProxyWidget* proxy_;
QPainterPath path_;
};