loom
109 строк · 2.9 Кб
1#include <QtNodes/ConnectionStyle>
2#include <QtNodes/DataFlowGraphModel>
3#include <QtNodes/DataFlowGraphicsScene>
4#include <QtNodes/GraphicsView>
5#include <QtNodes/NodeData>
6#include <QtNodes/NodeDelegateModelRegistry>
7
8#include <QtGui/QScreen>
9#include <QtWidgets/QApplication>
10#include <QtWidgets/QMenuBar>
11#include <QtWidgets/QVBoxLayout>
12
13#include <QtGui/QScreen>
14
15#include "AdditionModel.hpp"
16#include "DivisionModel.hpp"
17#include "MultiplicationModel.hpp"
18#include "NumberDisplayDataModel.hpp"
19#include "NumberSourceDataModel.hpp"
20#include "SubtractionModel.hpp"
21
22using QtNodes::ConnectionStyle;
23using QtNodes::DataFlowGraphicsScene;
24using QtNodes::DataFlowGraphModel;
25using QtNodes::GraphicsView;
26using QtNodes::NodeDelegateModelRegistry;
27
28static std::shared_ptr<NodeDelegateModelRegistry> registerDataModels()
29{
30auto ret = std::make_shared<NodeDelegateModelRegistry>();
31ret->registerModel<NumberSourceDataModel>("Sources");
32
33ret->registerModel<NumberDisplayDataModel>("Displays");
34
35ret->registerModel<AdditionModel>("Operators");
36
37ret->registerModel<SubtractionModel>("Operators");
38
39ret->registerModel<MultiplicationModel>("Operators");
40
41ret->registerModel<DivisionModel>("Operators");
42
43return ret;
44}
45
46static void setStyle()
47{
48ConnectionStyle::setConnectionStyle(
49R"(
50{
51"ConnectionStyle": {
52"ConstructionColor": "gray",
53"NormalColor": "black",
54"SelectedColor": "gray",
55"SelectedHaloColor": "deepskyblue",
56"HoveredColor": "deepskyblue",
57
58"LineWidth": 3.0,
59"ConstructionLineWidth": 2.0,
60"PointDiameter": 10.0,
61
62"UseDataDefinedColors": true
63}
64}
65)");
66}
67
68int main(int argc, char *argv[])
69{
70QApplication app(argc, argv);
71
72setStyle();
73
74std::shared_ptr<NodeDelegateModelRegistry> registry = registerDataModels();
75
76QWidget mainWidget;
77
78auto menuBar = new QMenuBar();
79QMenu *menu = menuBar->addMenu("File");
80auto saveAction = menu->addAction("Save Scene");
81auto loadAction = menu->addAction("Load Scene");
82
83QVBoxLayout *l = new QVBoxLayout(&mainWidget);
84
85DataFlowGraphModel dataFlowGraphModel(registry);
86
87l->addWidget(menuBar);
88auto scene = new DataFlowGraphicsScene(dataFlowGraphModel, &mainWidget);
89
90auto view = new GraphicsView(scene);
91l->addWidget(view);
92l->setContentsMargins(0, 0, 0, 0);
93l->setSpacing(0);
94
95QObject::connect(saveAction, &QAction::triggered, scene, &DataFlowGraphicsScene::save);
96
97QObject::connect(loadAction, &QAction::triggered, scene, &DataFlowGraphicsScene::load);
98
99QObject::connect(scene, &DataFlowGraphicsScene::sceneLoaded, view, &GraphicsView::centerScene);
100
101mainWidget.setWindowTitle("Data Flow: simplest calculator");
102mainWidget.resize(800, 600);
103// Center window.
104mainWidget.move(QApplication::primaryScreen()->availableGeometry().center()
105- mainWidget.rect().center());
106mainWidget.showNormal();
107
108return app.exec();
109}
110