#include "drawingPanel.h" #include "ui_drawingPanel.h" #include "designerView.h" #include "dataFlowGraphModel.h" #include "nodeDelegateModelRegistry.h" #include "util/selectorManager.h" #include "statusBar.h" DrawingPanel::DrawingPanel(QWidget *parent) : QWidget(parent) , ui(new Ui::drawingPanel) { ui->setupUi(this); QSharedPointer registry = registerDataModels(); DataFlowGraphModel dataFlowGraphModel(registry); m_pSelectorManager = new SelectorManager(this); m_pGraphicsScene = new DesignerScene(dataFlowGraphModel,this); //设置场景大小.前两个参数为scene的坐标远点,设置到view的中心点后,无论view如何缩放,secne的坐标原点都不会动,方便后续的位置计算 m_pGraphicsScene->setSceneRect(-g_dGriaphicsScene_Width / 2, -g_dGriaphicsScene_Height / 2, g_dGriaphicsScene_Width, g_dGriaphicsScene_Height); m_pGraphicsScene->setGridVisible(true); m_pGraphicsView = new DesignerView(this); m_pGraphicsView->setScene(m_pGraphicsScene); m_pGraphicsScene->setView(m_pGraphicsView); ui->mainLayout->addWidget(m_pGraphicsView); m_pStatusBar = new StatusBar(this); ui->mainLayout->addWidget(m_pStatusBar); connect(m_pGraphicsView,&DesignerView::onScaleChanged,m_pStatusBar,&StatusBar::onScaleLevelChanged); } DrawingPanel::~DrawingPanel() { delete ui; } QGraphicsScene* DrawingPanel::getQGraphicsScene() { return m_pGraphicsView->scene(); } DesignerScene* DrawingPanel::getDesignerScene() { return m_pGraphicsScene; } void DrawingPanel::grahpicsViewZoomIn() { m_pGraphicsView->zoomIn(); } void DrawingPanel::grahpicsViewZoomOut() { m_pGraphicsView->zoomOut(); } void DrawingPanel::grahpicsViewZoomFit() { m_pGraphicsView->zoomFit(); } GraphicsItemGroup* DrawingPanel::createItemGroup() { return m_pGraphicsScene->createGroup(); } void DrawingPanel::destroyItemGroup() { m_pGraphicsScene->destroyGroup(); } SelectorManager* DrawingPanel::selectorManager() const { if(m_pSelectorManager) return m_pSelectorManager; else return NULL; } void DrawingPanel::onSignal_addGraphicsItem(GraphicsItemType& itemType) { if(m_pSelectorManager) { m_pSelectorManager->setWorkingSelector(ST_cerating); m_pSelectorManager->setDrawGraphicsItem(itemType); } } QSharedPointer DrawingPanel::registerDataModels() { auto ret = QSharedPointer(new NodeDelegateModelRegistry()); return ret; }