feat: destroy floating edge from emtpy click
This commit is contained in:
@@ -53,6 +53,23 @@ Network::Network(QWidget* parent)
|
||||
mainLayout_->addWidget(view_);
|
||||
}
|
||||
|
||||
void Network::leftMousePress(QMouseEvent *event)
|
||||
{
|
||||
QGraphicsItem* itemClicked = view_->itemAt(event->pos());
|
||||
bool isSocket = itemClicked && typeid(*itemClicked)==typeid(SocketGraphic);
|
||||
if(isSocket)
|
||||
{
|
||||
std::cout << "SOCKET!\n";
|
||||
socketClicked(static_cast<SocketGraphic*>(itemClicked), event);
|
||||
}
|
||||
else
|
||||
{
|
||||
destroyFloatingEdge();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Network::socketClicked(SocketGraphic* socket, QMouseEvent *event)
|
||||
{
|
||||
std::cout << "socket clicked\n";
|
||||
@@ -65,6 +82,17 @@ void Network::socketClicked(SocketGraphic* socket, QMouseEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void Network::destroyFloatingEdge()
|
||||
{
|
||||
if(floatingEdge_)
|
||||
{
|
||||
scene_->removeItem(floatingEdge_);
|
||||
delete floatingEdge_;
|
||||
floatingEdge_=nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Network::mouseMoved(QMouseEvent *event)
|
||||
{
|
||||
@@ -80,12 +108,6 @@ void Network::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if(event->key() == Qt::Key_Escape)
|
||||
{
|
||||
// delete floating edge
|
||||
if(floatingEdge_)
|
||||
{
|
||||
scene_->removeItem(floatingEdge_);
|
||||
delete floatingEdge_;
|
||||
floatingEdge_=nullptr;
|
||||
}
|
||||
destroyFloatingEdge();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,12 +12,14 @@ public:
|
||||
Network(QWidget* parent = nullptr);
|
||||
void socketClicked(SocketGraphic* socket, QMouseEvent *event);
|
||||
void mouseMoved(QMouseEvent *event);
|
||||
void leftMousePress(QMouseEvent *event);
|
||||
private:
|
||||
QLayout* mainLayout_;
|
||||
NetworkGraphicsScene* scene_;
|
||||
NetworkGraphicsView* view_;
|
||||
FloatingEdgeGraphic* floatingEdge_=nullptr;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
void destroyFloatingEdge();
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
@@ -56,13 +56,14 @@ void NetworkGraphicsView::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
void NetworkGraphicsView::leftMousePress(QMouseEvent *event)
|
||||
{
|
||||
QGraphicsItem* itemClicked = itemAt(event->pos());
|
||||
bool isSocket = itemClicked && typeid(*itemClicked)==typeid(SocketGraphic);
|
||||
if(isSocket)
|
||||
{
|
||||
std::cout << "SOCKET!\n";
|
||||
network_->socketClicked(static_cast<SocketGraphic*>(itemClicked), event);
|
||||
}
|
||||
network_->leftMousePress(event);
|
||||
// QGraphicsItem* itemClicked = itemAt(event->pos());
|
||||
// bool isSocket = itemClicked && typeid(*itemClicked)==typeid(SocketGraphic);
|
||||
// if(isSocket)
|
||||
// {
|
||||
// std::cout << "SOCKET!\n";
|
||||
// network_->socketClicked(static_cast<SocketGraphic*>(itemClicked), event);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user