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