#include "SchemeFlowWidget.h" #include #include #include #include #include #include using QtNodes::GraphicsView; static std::shared_ptr registerDataModels() { auto ret = std::make_shared(); ret->registerModel(); return ret; } static void setStyle_() { GraphicsViewStyle::setStyle( R"( { "GraphicsViewStyle": { "BackgroundColor": [255, 255, 255], "FineGridColor": [255, 255, 255], "CoarseGridColor": [255, 255, 255] } } )"); NodeStyle::setNodeStyle( R"( { "NodeStyle": { "NormalBoundaryColor": "darkgray", "SelectedBoundaryColor": "deepskyblue", "GradientColor0": "mintcream", "GradientColor1": "mintcream", "GradientColor2": "mintcream", "GradientColor3": "mintcream", "ShadowColor": [200, 200, 200], "FontColor": [10, 10, 10], "FontColorFaded": [100, 100, 100], "ConnectionPointColor": "white", "PenWidth": 2.0, "HoveredPenWidth": 2.5, "ConnectionPointDiameter": 10.0, "Opacity": 1.0 } } )"); ConnectionStyle::setConnectionStyle( R"( { "ConnectionStyle": { "ConstructionColor": "gray", "NormalColor": "black", "SelectedColor": "gray", "SelectedHaloColor": "deepskyblue", "HoveredColor": "deepskyblue", "LineWidth": 3.0, "ConstructionLineWidth": 2.0, "PointDiameter": 10.0, "UseDataDefinedColors": false } } )"); } SchemeFlowWidget::SchemeFlowWidget(ProjectInfo *proj, int indexType, QWidget *parent) : QWidget(parent) { setStyle_(); initWidgets(); initLayout(); } SchemeFlowWidget::~SchemeFlowWidget() { delete graphModel; } void SchemeFlowWidget::initWidgets() { graphModel = new DataFlowModel(registerDataModels()); // Initialize and connect two nodes. { NodeId id1 = graphModel->addNode(FlowTemplateData().type().id); graphModel->setNodeData(id1, NodeRole::Position, QPointF(0, 0)); NodeId id2 = graphModel->addNode(FlowTemplateData().type().id); graphModel->setNodeData(id2, NodeRole::Position, QPointF(200, 0)); graphModel->addConnection(ConnectionId { id1, 0, id2, 0 }); NodeId id3 = graphModel->addNode(FlowTemplateData().type().id); graphModel->setNodeData(id3, NodeRole::Position, QPointF(400, 0)); graphModel->addConnection(ConnectionId { id2, 0, id3, 0 }); } auto scene = new DataFlowGraphicsScene(*graphModel); QHBoxLayout *l = new QHBoxLayout(this); GraphicsView *view = new GraphicsView(scene); l->addWidget(view); QGroupBox *groupBox = new QGroupBox("Options"); QCheckBox *cb1 = new QCheckBox("Nodes are locked"); QCheckBox *cb2 = new QCheckBox("Connections detachable"); cb2->setChecked(true); QVBoxLayout *vbl = new QVBoxLayout; vbl->addWidget(cb1); vbl->addWidget(cb2); vbl->addStretch(); groupBox->setLayout(vbl); QObject::connect(cb1, &QCheckBox::stateChanged, [this](int state) { graphModel->setNodesLocked(state == Qt::Checked); }); QObject::connect(cb2, &QCheckBox::stateChanged, [this](int state) { graphModel->setDetachPossible(state == Qt::Checked); }); l->addWidget(groupBox); this->setWindowTitle("Locked Nodes and Connections"); this->resize(800, 600); } void SchemeFlowWidget::initLayout() { }