refactor: separate network class from Qgraphics

This commit is contained in:
parker
2025-06-20 01:51:28 +01:00
parent 2feb6eb5b4
commit be9f3e27ea
6 changed files with 42 additions and 12 deletions

View File

@@ -0,0 +1,18 @@
#include "gui/network/Network.h"
#include "gui/network/NetworkGraphicsView.h"
#include "gui/network/NetworkGraphicsScene.h"
#include <qboxlayout.h>
#include <QPushButton>
Network::Network(QWidget* parent)
{
mainLayout_ = new QVBoxLayout(parent);
this->setLayout(mainLayout_);
NetworkGraphicsScene* scene = new NetworkGraphicsScene();
NetworkGraphicsView* view = new NetworkGraphicsView(parent, scene);
mainLayout_->addWidget(view);
}

11
src/gui/network/Network.h Normal file
View File

@@ -0,0 +1,11 @@
#pragma once
#include <QWidget>
class Network
: public QWidget
{
public:
Network(QWidget* parent = nullptr);
private:
QLayout* mainLayout_;
};

View File

@@ -1,14 +1,13 @@
#include "gui/network/NetworkView.h"
#include "gui/network/NetworkGraphicsView.h"
#include <QGraphicsItem>
#include "gui/network/NetworkGraphicsScene.h"
#include <iostream>
#include <QMouseEvent>
#include <QScrollBar>
NetworkView::NetworkView(QWidget *parent)
NetworkGraphicsView::NetworkGraphicsView(QWidget *parent, QGraphicsScene* scene)
: QGraphicsView(parent)
{
QGraphicsScene *scene = new NetworkGraphicsScene(this);
setScene(scene);
QPen greenPen = QPen(Qt::green);
@@ -24,7 +23,7 @@ NetworkView::NetworkView(QWidget *parent)
}
void NetworkView::mousePressEvent(QMouseEvent *event)
void NetworkGraphicsView::mousePressEvent(QMouseEvent *event)
{
if(
event->button() & Qt::MiddleButton
@@ -48,7 +47,7 @@ void NetworkView::mousePressEvent(QMouseEvent *event)
// }
// }
void NetworkView::mouseMoveEvent(QMouseEvent *mouseEvent)
void NetworkGraphicsView::mouseMoveEvent(QMouseEvent *mouseEvent)
{
if( mouseEvent->buttons() & Qt::MiddleButton)

View File

@@ -1,12 +1,13 @@
#pragma once
#include <qwidget.h>
#include <QGraphicsView>
#include <QGraphicsScene>
class NetworkView
class NetworkGraphicsView
: public QGraphicsView
{
public:
NetworkView(QWidget *parent = nullptr);
NetworkGraphicsView(QWidget *parent = nullptr, QGraphicsScene* scene = nullptr);
private:
QPointF panStartPos;