123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- #include "SchemeFlowWidget.h"
- #include <dbService/ClassSet.h>
- #include <QGroupBox>
- #include <QCheckBox>
- #include <QBoxLayout>
- #include <QDebug>
- #include <QtNodes/GraphicsView>
- using QtNodes::GraphicsView;
- static std::shared_ptr<NodeDelegateModelRegistry> registerDataModels()
- {
- auto ret = std::make_shared<NodeDelegateModelRegistry>();
- ret->registerModel<FlowTemplateDataModel>();
- 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() { }
|