nodeparamview: allow disconnecting nodes by right clicking the "connected to" label

This commit is contained in:
itsmattkc
2020-06-16 17:48:10 +10:00
parent f107c9bba1
commit 67ee78ac9a
3 changed files with 27 additions and 4 deletions
+8 -4
View File
@@ -20,6 +20,8 @@
#include "clickablelabel.h"
#include <QMouseEvent>
OLIVE_NAMESPACE_ENTER
ClickableLabel::ClickableLabel(const QString &text, QWidget *parent) :
@@ -32,16 +34,18 @@ ClickableLabel::ClickableLabel(QWidget *parent) :
{
}
void ClickableLabel::mouseReleaseEvent(QMouseEvent *)
void ClickableLabel::mouseReleaseEvent(QMouseEvent *event)
{
if (underMouse()) {
if (event->button() == Qt::LeftButton && underMouse()) {
emit MouseClicked();
}
}
void ClickableLabel::mouseDoubleClickEvent(QMouseEvent *)
void ClickableLabel::mouseDoubleClickEvent(QMouseEvent *event)
{
emit MouseDoubleClicked();
if (event->button() == Qt::LeftButton) {
emit MouseDoubleClicked();
}
}
OLIVE_NAMESPACE_EXIT
@@ -23,7 +23,10 @@
#include <QHBoxLayout>
#include "common/qtutils.h"
#include "core.h"
#include "node/node.h"
#include "widget/menu/menu.h"
#include "widget/nodeview/nodeviewundo.h"
OLIVE_NAMESPACE_ENTER
@@ -39,7 +42,9 @@ NodeParamViewConnectedLabel::NodeParamViewConnectedLabel(NodeInput *input, QWidg
connected_to_lbl_ = new ClickableLabel();
connected_to_lbl_->setCursor(Qt::PointingHandCursor);
connected_to_lbl_->setContextMenuPolicy(Qt::CustomContextMenu);
connect(connected_to_lbl_, &ClickableLabel::MouseClicked, this, &NodeParamViewConnectedLabel::ConnectionClicked);
connect(connected_to_lbl_, &ClickableLabel::customContextMenuRequested, this, &NodeParamViewConnectedLabel::ShowLabelContextMenu);
layout->addWidget(connected_to_lbl_);
layout->addStretch();
@@ -69,4 +74,16 @@ void NodeParamViewConnectedLabel::UpdateConnected()
connected_to_lbl_->setText(connection_str);
}
void NodeParamViewConnectedLabel::ShowLabelContextMenu()
{
Menu m(this);
QAction* disconnect_action = m.addAction(tr("Disconnect"));
connect(disconnect_action, &QAction::triggered, this, [this](){
Core::instance()->undo_stack()->push(new NodeEdgeRemoveCommand(input_->get_connected_output(), input_));
});
m.exec(QCursor::pos());
}
OLIVE_NAMESPACE_EXIT
@@ -37,6 +37,8 @@ signals:
private slots:
void UpdateConnected();
void ShowLabelContextMenu();
private:
ClickableLabel* connected_to_lbl_;