feat: add delete hover animation
This commit is contained in:
@@ -4,10 +4,13 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <qgraphicsitem.h>
|
#include <qgraphicsitem.h>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsSceneHoverEvent>
|
||||||
|
|
||||||
NodeEdgeGraphic::NodeEdgeGraphic(SocketGraphic* socket1, SocketGraphic* socket2, QGraphicsItem *parent)
|
NodeEdgeGraphic::NodeEdgeGraphic(SocketGraphic* socket1, SocketGraphic* socket2, QGraphicsItem *parent)
|
||||||
: QGraphicsItem(parent), socket1_{socket1}, socket2_{socket2}, defaultColor_{QColor("white")}
|
: QGraphicsItem(parent), socket1_{socket1}, socket2_{socket2}, defaultColor_{QColor("white")}
|
||||||
{
|
{
|
||||||
|
setAcceptHoverEvents(true);
|
||||||
|
|
||||||
setZValue(-1);
|
setZValue(-1);
|
||||||
color_=defaultColor_;
|
color_=defaultColor_;
|
||||||
defaultPen_=QPen(defaultColor_);
|
defaultPen_=QPen(defaultColor_);
|
||||||
@@ -24,10 +27,10 @@ NodeEdgeGraphic::NodeEdgeGraphic(SocketGraphic* socket1, SocketGraphic* socket2,
|
|||||||
|
|
||||||
void NodeEdgeGraphic::updateDeleteHighlightPen()
|
void NodeEdgeGraphic::updateDeleteHighlightPen()
|
||||||
{
|
{
|
||||||
QLinearGradient gradient(pos1_, pos2_);
|
QLinearGradient gradient(pos1_, hoverPos_);
|
||||||
gradient.setColorAt(0.0, QColor(255, 74, 74, 200));
|
gradient.setColorAt(0.0, QColor(255, 74, 74, 200));
|
||||||
gradient.setColorAt(0.5, QColor(255, 74, 74, 50));
|
gradient.setColorAt(1, QColor(255, 74, 74, 50));
|
||||||
gradient.setColorAt(1.0, QColor(255, 74, 74, 200));
|
// gradient.setColorAt(1.0, QColor(255, 74, 74, 200));
|
||||||
|
|
||||||
deleteHighlightPen_.setBrush(QBrush(gradient));
|
deleteHighlightPen_.setBrush(QBrush(gradient));
|
||||||
}
|
}
|
||||||
@@ -39,6 +42,16 @@ NodeEdgeGraphic::~NodeEdgeGraphic()
|
|||||||
std::cout << "destructor finished\n";
|
std::cout << "destructor finished\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NodeEdgeGraphic::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
|
{
|
||||||
|
hoverPos_ = event->scenePos();
|
||||||
|
if(deleteHighlight_)
|
||||||
|
{
|
||||||
|
updateDeleteHighlightPen();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void NodeEdgeGraphic::updatePath()
|
void NodeEdgeGraphic::updatePath()
|
||||||
{
|
{
|
||||||
qreal cubicStrength = 40;
|
qreal cubicStrength = 40;
|
||||||
|
|||||||
@@ -37,7 +37,10 @@ private:
|
|||||||
QPainterPath path_;
|
QPainterPath path_;
|
||||||
QRectF boundRect_;
|
QRectF boundRect_;
|
||||||
qreal padding_=40;
|
qreal padding_=40;
|
||||||
|
QPointF hoverPos_;
|
||||||
|
|
||||||
void updatePath();
|
void updatePath();
|
||||||
|
protected:
|
||||||
|
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user