Fixes cable behaviour
This commit is contained in:
@@ -45,7 +45,6 @@ void Cable::corner(QPoint point)
|
||||
{
|
||||
std::pair<QPoint, QPoint> restriced_points = getRestrictedCablePath(m_corner.last(), point);
|
||||
m_corner.append(restriced_points.first);
|
||||
m_corner.append(restriced_points.second);
|
||||
switchPlane();
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
|
||||
enum class DirectionalPlane { Horizontal, Vertical };
|
||||
|
||||
struct CableSegment {
|
||||
|
||||
};
|
||||
|
||||
class Cable : public QGraphicsItem
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -43,6 +43,13 @@ void NodeEditorScene::handlePadTrigger(Pad *pad)
|
||||
enableCableConnectionState(pad);
|
||||
}
|
||||
}
|
||||
void NodeEditorScene::handlePadHover(Pad *pad)
|
||||
{
|
||||
pad->setHover(true);
|
||||
if (isCableConnectionState()) {
|
||||
m_active_cable->previewCable(pad->getSceneDockPoint());
|
||||
}
|
||||
}
|
||||
|
||||
void NodeEditorScene::connectPads(Pad *first, Pad *second)
|
||||
{
|
||||
@@ -57,6 +64,15 @@ void NodeEditorScene::handleCornerTrigger(QPoint corner_pos)
|
||||
}
|
||||
}
|
||||
|
||||
void NodeEditorScene::removePadHoverStates()
|
||||
{
|
||||
for (QGraphicsItem *item : items()) {
|
||||
if (Pad *pad = qgraphicsitem_cast<Pad *>(item)) {
|
||||
pad->setHover(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NodeEditorScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
@@ -81,27 +97,18 @@ void NodeEditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
QPointF scene_pos = event->scenePos();
|
||||
QList<QGraphicsItem *> items_at_pos = items(scene_pos);
|
||||
|
||||
// Set all pads to no hover as it is the default value
|
||||
removePadHoverStates();
|
||||
|
||||
bool mouse_on_pad = false;
|
||||
for (QGraphicsItem *item : items_at_pos) {
|
||||
if (Pad *pad = qgraphicsitem_cast<Pad *>(item)) {
|
||||
pad->setHover(true);
|
||||
for (QGraphicsItem *other : items_at_pos) {
|
||||
if (Pad *other_pad = qgraphicsitem_cast<Pad *>(other)) {
|
||||
if (other_pad != pad) {
|
||||
other_pad->setHover(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
mouse_on_pad = true;
|
||||
handlePadHover(pad);
|
||||
}
|
||||
}
|
||||
|
||||
for (QGraphicsItem *item : items()) {
|
||||
if (Pad *pad = qgraphicsitem_cast<Pad *>(item)) {
|
||||
pad->setHover(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (isCableConnectionState()) {
|
||||
if (isCableConnectionState() && !mouse_on_pad) {
|
||||
m_active_cable->previewCable(event->scenePos().toPoint());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,10 +32,12 @@ protected:
|
||||
|
||||
private:
|
||||
void handlePadTrigger(Pad *);
|
||||
void handlePadHover(Pad *);
|
||||
void connectPads(Pad *first, Pad *second);
|
||||
void handleCornerTrigger(QPoint corner_pos);
|
||||
void disableCableConnectionState();
|
||||
void enableCableConnectionState(Pad *);
|
||||
void removePadHoverStates();
|
||||
|
||||
int m_debug_x = 0;
|
||||
QList<Node *> m_nodes;
|
||||
|
||||
Reference in New Issue
Block a user