mirror of
https://github.com/feather-wallet/feather.git
synced 2024-12-23 12:09:50 +00:00
Nodes: double click to connect
This commit is contained in:
parent
bd4400a7f2
commit
3fbf58f64d
2 changed files with 63 additions and 88 deletions
|
@ -18,10 +18,10 @@
|
||||||
#include "utils/nodes.h"
|
#include "utils/nodes.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
NodeWidget::NodeWidget(QWidget *parent) :
|
NodeWidget::NodeWidget(QWidget *parent)
|
||||||
QWidget(parent),
|
: QWidget(parent)
|
||||||
ui(new Ui::NodeWidget),
|
, ui(new Ui::NodeWidget)
|
||||||
m_contextMenu(new QMenu(this)) {
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
connect(ui->btn_add_custom, &QPushButton::clicked, this, &NodeWidget::onCustomAddClicked);
|
connect(ui->btn_add_custom, &QPushButton::clicked, this, &NodeWidget::onCustomAddClicked);
|
||||||
|
@ -35,112 +35,91 @@ NodeWidget::NodeWidget(QWidget *parent) :
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
m_contextActionRemove = new QAction("Remove", this);
|
||||||
|
m_contextActionConnect = new QAction(QIcon(":/assets/images/connect.svg"), "Connect to node", this);
|
||||||
|
m_contextActionOpenStatusURL = new QAction(QIcon(":/assets/images/network.png"), "Visit status page", this);
|
||||||
|
m_contextActionCopy = new QAction(QIcon(":/assets/images/copy.png"), "Copy", this);
|
||||||
|
connect(m_contextActionConnect, &QAction::triggered, this, &NodeWidget::onContextConnect);
|
||||||
|
connect(m_contextActionRemove, &QAction::triggered, this, &NodeWidget::onContextCustomNodeRemove);
|
||||||
|
connect(m_contextActionOpenStatusURL, &QAction::triggered, this, &NodeWidget::onContextStatusURL);
|
||||||
|
connect(m_contextActionCopy, &QAction::triggered, this, &NodeWidget::onContextNodeCopy);
|
||||||
|
connect(m_contextActionRemove, &QAction::triggered, this, &NodeWidget::onContextCustomNodeRemove);
|
||||||
|
|
||||||
ui->wsView->setContextMenuPolicy(Qt::CustomContextMenu);
|
ui->wsView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
ui->customView->setContextMenuPolicy(Qt::CustomContextMenu);
|
ui->customView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(ui->wsView, &QTreeView::customContextMenuRequested, this, &NodeWidget::onShowWSContextMenu);
|
connect(ui->wsView, &QTreeView::customContextMenuRequested, this, &NodeWidget::onShowWSContextMenu);
|
||||||
connect(ui->customView, &QTreeView::customContextMenuRequested, this, &NodeWidget::onShowCustomContextMenu);
|
connect(ui->customView, &QTreeView::customContextMenuRequested, this, &NodeWidget::onShowCustomContextMenu);
|
||||||
|
|
||||||
|
connect(ui->customView, &QTreeView::doubleClicked, this, &NodeWidget::onContextConnect);
|
||||||
|
connect(ui->wsView, &QTreeView::doubleClicked, this, &NodeWidget::onContextConnect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeWidget::onShowWSContextMenu(const QPoint &pos) {
|
void NodeWidget::onShowWSContextMenu(const QPoint &pos) {
|
||||||
QModelIndex index = ui->wsView->indexAt(pos);
|
m_activeView = ui->wsView;
|
||||||
if (!index.isValid()) return;
|
FeatherNode node = this->selectedNode();
|
||||||
|
if (node.full.isEmpty()) return;
|
||||||
|
|
||||||
FeatherNode node = m_wsModel->node(index.row());
|
|
||||||
this->showContextMenu(pos, node);
|
this->showContextMenu(pos, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeWidget::onShowCustomContextMenu(const QPoint &pos) {
|
void NodeWidget::onShowCustomContextMenu(const QPoint &pos) {
|
||||||
QModelIndex index = ui->customView->indexAt(pos);
|
m_activeView = ui->customView;
|
||||||
if (!index.isValid()) return;
|
FeatherNode node = this->selectedNode();
|
||||||
|
if (node.full.isEmpty()) return;
|
||||||
|
|
||||||
FeatherNode node = m_customModel->node(index.row());
|
|
||||||
this->showContextMenu(pos, node);
|
this->showContextMenu(pos, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void NodeWidget::showContextMenu(const QPoint &pos, const FeatherNode &node) {
|
void NodeWidget::showContextMenu(const QPoint &pos, const FeatherNode &node) {
|
||||||
bool custom = node.custom;
|
QMenu menu(this);
|
||||||
m_activeView = custom ? ui->customView : ui->wsView;
|
|
||||||
|
|
||||||
m_contextActionRemove = new QAction("Remove");
|
|
||||||
m_contextActionConnect = new QAction("Connect to node");
|
|
||||||
m_contextActionConnect->setIcon(QIcon(":/assets/images/connect.svg"));
|
|
||||||
m_contextActionOpenStatusURL = new QAction("Visit status page");
|
|
||||||
m_contextActionOpenStatusURL->setIcon(QIcon(":/assets/images/network.png"));
|
|
||||||
m_contextActionCopy = new QAction("Copy");
|
|
||||||
m_contextActionCopy->setIcon(QIcon(":/assets/images/copy.png"));
|
|
||||||
|
|
||||||
if (!node.isActive) {
|
if (!node.isActive) {
|
||||||
connect(m_contextActionConnect, &QAction::triggered, this, &NodeWidget::onContextConnect);
|
menu.addAction(m_contextActionConnect);
|
||||||
m_contextMenu->addAction(m_contextActionConnect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_contextMenu->addAction(m_contextActionOpenStatusURL);
|
menu.addAction(m_contextActionOpenStatusURL);
|
||||||
m_contextMenu->addAction(m_contextActionCopy);
|
menu.addAction(m_contextActionCopy);
|
||||||
|
|
||||||
if(custom) {
|
if (m_activeView == ui->customView)
|
||||||
connect(m_contextActionRemove, &QAction::triggered, this, &NodeWidget::onContextCustomNodeRemove);
|
menu.addAction(m_contextActionRemove);
|
||||||
m_contextMenu->addAction(m_contextActionRemove);
|
|
||||||
|
|
||||||
connect(m_contextActionOpenStatusURL, &QAction::triggered, this, &NodeWidget::onContextCustomStatusURL);
|
menu.exec(m_activeView->viewport()->mapToGlobal(pos));
|
||||||
connect(m_contextActionCopy, &QAction::triggered, this, &NodeWidget::onContextCustomNodeCopy);
|
|
||||||
} else {
|
|
||||||
connect(m_contextActionOpenStatusURL, &QAction::triggered, this, &NodeWidget::onContextWSStatusURL);
|
|
||||||
connect(m_contextActionCopy, &QAction::triggered, this, &NodeWidget::onContextWSNodeCopy);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_contextMenu->exec(m_activeView->viewport()->mapToGlobal(pos));
|
|
||||||
m_contextActionRemove->deleteLater();
|
|
||||||
m_contextActionConnect->deleteLater();
|
|
||||||
m_contextActionOpenStatusURL->deleteLater();
|
|
||||||
m_contextActionCopy->deleteLater();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeWidget::onContextConnect() {
|
void NodeWidget::onContextConnect() {
|
||||||
|
QObject *obj = sender();
|
||||||
|
if (obj == ui->customView)
|
||||||
|
m_activeView = ui->customView;
|
||||||
|
else
|
||||||
|
m_activeView = ui->wsView;
|
||||||
|
|
||||||
|
FeatherNode node = this->selectedNode();
|
||||||
|
if (!node.full.isEmpty())
|
||||||
|
emit connectToNode(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeWidget::onContextStatusURL() {
|
||||||
|
FeatherNode node = this->selectedNode();
|
||||||
|
if (!node.full.isEmpty())
|
||||||
|
Utils::externalLinkWarning(this, node.as_url());
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeWidget::onContextNodeCopy() {
|
||||||
|
FeatherNode node = this->selectedNode();
|
||||||
|
Utils::copyToClipboard(node.full);
|
||||||
|
}
|
||||||
|
|
||||||
|
FeatherNode NodeWidget::selectedNode() {
|
||||||
QModelIndex index = m_activeView->currentIndex();
|
QModelIndex index = m_activeView->currentIndex();
|
||||||
if (!index.isValid()) return;
|
if (!index.isValid()) return FeatherNode();
|
||||||
|
|
||||||
if(m_activeView->objectName() == "wsView"){
|
FeatherNode node;
|
||||||
FeatherNode node = m_wsModel->node(index.row());
|
if (m_activeView == ui->customView) {
|
||||||
emit connectToNode(node);
|
node = m_customModel->node(index.row());
|
||||||
} else {
|
} else {
|
||||||
FeatherNode node = m_customModel->node(index.row());
|
node = m_wsModel->node(index.row());
|
||||||
emit connectToNode(node);
|
|
||||||
}
|
}
|
||||||
}
|
return node;
|
||||||
|
|
||||||
void NodeWidget::onContextWSStatusURL() {
|
|
||||||
QModelIndex index = ui->wsView->currentIndex();
|
|
||||||
if (!index.isValid()) return;
|
|
||||||
FeatherNode node = m_wsModel->node(index.row());
|
|
||||||
Utils::externalLinkWarning(this, node.as_url());
|
|
||||||
}
|
|
||||||
|
|
||||||
void NodeWidget::onContextCustomStatusURL() {
|
|
||||||
QModelIndex index = ui->customView->currentIndex();
|
|
||||||
if (!index.isValid()) return;
|
|
||||||
FeatherNode node = m_customModel->node(index.row());
|
|
||||||
Utils::externalLinkWarning(this, node.as_url());
|
|
||||||
}
|
|
||||||
|
|
||||||
void NodeWidget::onContextDisconnect() {
|
|
||||||
QModelIndex index = ui->customView->currentIndex();
|
|
||||||
if (!index.isValid()) return;
|
|
||||||
FeatherNode node = m_customModel->node(index.row());
|
|
||||||
|
|
||||||
Utils::copyToClipboard(node.full);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NodeWidget::onContextWSNodeCopy() {
|
|
||||||
QModelIndex index = ui->wsView->currentIndex();
|
|
||||||
if (!index.isValid()) return;
|
|
||||||
FeatherNode node = m_wsModel->node(index.row());
|
|
||||||
|
|
||||||
Utils::copyToClipboard(node.full);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NodeWidget::onContextCustomNodeCopy() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeWidget::onContextCustomNodeRemove() {
|
void NodeWidget::onContextCustomNodeRemove() {
|
||||||
|
|
|
@ -35,12 +35,9 @@ public slots:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onContextConnect();
|
void onContextConnect();
|
||||||
void onContextDisconnect();
|
|
||||||
void onContextCustomNodeRemove();
|
void onContextCustomNodeRemove();
|
||||||
void onContextWSStatusURL();
|
void onContextStatusURL();
|
||||||
void onContextCustomStatusURL();
|
void onContextNodeCopy();
|
||||||
void onContextWSNodeCopy();
|
|
||||||
void onContextCustomNodeCopy();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void connectToNode(FeatherNode node);
|
void connectToNode(FeatherNode node);
|
||||||
|
@ -54,14 +51,13 @@ private:
|
||||||
|
|
||||||
QTreeView *m_activeView;
|
QTreeView *m_activeView;
|
||||||
|
|
||||||
QMenu *m_contextMenu;
|
|
||||||
QAction *m_contextActionConnect;
|
QAction *m_contextActionConnect;
|
||||||
QAction *m_contextActionDisconnect;
|
|
||||||
QAction *m_contextActionRemove;
|
QAction *m_contextActionRemove;
|
||||||
QAction *m_contextActionOpenStatusURL;
|
QAction *m_contextActionOpenStatusURL;
|
||||||
QAction *m_contextActionCopy;
|
QAction *m_contextActionCopy;
|
||||||
|
|
||||||
void showContextMenu(const QPoint &pos, const FeatherNode &node);
|
void showContextMenu(const QPoint &pos, const FeatherNode &node);
|
||||||
|
FeatherNode selectedNode();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NODEWIDGET_H
|
#endif // NODEWIDGET_H
|
||||||
|
|
Loading…
Reference in a new issue