feat: add node selection
This commit is contained in:
@@ -408,6 +408,15 @@ void Network::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
moveNodeBuffer.clear();
|
||||
state_=State::DEFAULT;
|
||||
if(
|
||||
QGraphicsItem* clickedNode = itemOfType<NodeGraphic>(hoverItems);
|
||||
clickedNode &&
|
||||
QLineF(event->pos(), leftMouseStart).length()<5.0f)
|
||||
{
|
||||
NodeGraphic* node = static_cast<NodeGraphic*>(clickedNode);
|
||||
node->toggleSelected();
|
||||
}
|
||||
|
||||
}
|
||||
else if(floatingEdge_ && hoverSocket)
|
||||
{
|
||||
|
||||
@@ -154,6 +154,21 @@ QRectF NodeGraphic::boundingRect() const
|
||||
return boundRect;
|
||||
}
|
||||
|
||||
void NodeGraphic::setSelected(bool selected)
|
||||
{
|
||||
selected_=selected;
|
||||
update();
|
||||
}
|
||||
|
||||
bool NodeGraphic::toggleSelected()
|
||||
{
|
||||
bool selected = !selected_;
|
||||
|
||||
setSelected(selected);
|
||||
return selected;
|
||||
}
|
||||
|
||||
|
||||
void NodeGraphic::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
// default outline
|
||||
@@ -169,6 +184,7 @@ void NodeGraphic::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
|
||||
QBrush whiteBrush = QBrush("white");
|
||||
painter->setBrush(QBrush(QColor("#1b1b1b")));
|
||||
|
||||
if(selected_) painter->setPen(QPen(QColor("#fee046"), 2));
|
||||
painter->drawRoundedRect(bodyRect_, 5, 5);
|
||||
|
||||
painter->setPen(QPen(QColor("white")));
|
||||
|
||||
@@ -22,14 +22,12 @@ public:
|
||||
QPointF getSocketScenePosition(int socketIndex, enzo::nt::SocketIOType socketType);
|
||||
QRectF getBodyRect();
|
||||
void setDisplayFlag(bool state);
|
||||
void setSelected(bool selected);
|
||||
bool toggleSelected();
|
||||
|
||||
// void addEdge(NodeEdgeGraphic* edge);
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
|
||||
// void setInputEdge(NodeEdgeGraphic* edge, int indx);
|
||||
// void setOutputEdge(NodeEdgeGraphic* edge, int indx);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +42,7 @@ private:
|
||||
std::vector<SocketGraphic*> outputs_;
|
||||
|
||||
// std::vector<NodeEdgeGraphic*> edges_;
|
||||
|
||||
bool selected_=false;
|
||||
std::string titleText_="";
|
||||
std::string subTitleText_="";
|
||||
int maxTitleLen_=10;
|
||||
|
||||
Reference in New Issue
Block a user