add: added ChainWidget components

This commit is contained in:
QwQ 2020-07-30 23:25:31 +08:00
parent c464499756
commit be17652bc4
No known key found for this signature in database
GPG Key ID: E7FAEFAFCD031D4B
21 changed files with 174 additions and 128 deletions

@ -1 +1 @@
Subproject commit 1a888b795971116dfe6855b6ef81bccd6cf81c37
Subproject commit da43b6742c2e67835ef8b29dd79354b3f379591b

View File

@ -1 +1 @@
5835
5836

View File

@ -80,7 +80,7 @@ namespace Qv2ray::base::objects::complex
ChainId chainId;
//
safetype::OUTBOUND realOutbound;
QString getTag() const
QString getDisplayName() const
{
if (metaType == METAOUTBOUND_ORIGINAL)
return realOutbound["tag"].toString();

View File

@ -28,7 +28,12 @@
using namespace QtNodes;
using namespace Qv2ray::ui::nodemodels;
//#define CurrentRule this->rules[this->currentRuleTag]
namespace
{
constexpr auto NODE_TAB_ROUTE_EDITOR = 0;
constexpr auto NODE_TAB_CHAIN_EDITOR = 1;
} // namespace
#define LOADINGCHECK \
if (isLoading) \
return;
@ -40,27 +45,31 @@ void RouteEditor::updateColorScheme()
// Setup icons according to the theme settings.
addInboundBtn->setIcon(QICON_R("add"));
addOutboundBtn->setIcon(QICON_R("add"));
//
const static auto darkConnectionStyle = R"({"ConnectionStyle": {"ConstructionColor": "gray","NormalColor": "black","SelectedColor": "gray",
"SelectedHaloColor": "deepskyblue","HoveredColor": "deepskyblue","LineWidth": 3.0,
"ConstructionLineWidth": 2.0,"PointDiameter": 10.0,"UseDataDefinedColors": true}})";
const static auto lightNodeStyle = R"({"NodeStyle": {"NormalBoundaryColor": "darkgray","SelectedBoundaryColor": "deepskyblue",
"GradientColor0": "mintcream","GradientColor1": "mintcream","GradientColor2": "mintcream",
"GradientColor3": "mintcream","ShadowColor": [200, 200, 200],"FontColor": [10, 10, 10],
"FontColorFaded": [100, 100, 100],"ConnectionPointColor": "white","PenWidth": 2.0,"HoveredPenWidth": 2.5,
"ConnectionPointDiameter": 10.0,"Opacity": 1.0}})";
const static auto lightViewStyle =
R"({"FlowViewStyle": {"BackgroundColor": [255, 255, 240],"FineGridColor": [245, 245, 230],"CoarseGridColor": [235, 235, 220]}})";
const static auto lightConnectionStyle = R"({"ConnectionStyle": {"ConstructionColor": "gray","NormalColor": "black","SelectedColor": "gray",
"SelectedHaloColor": "deepskyblue","HoveredColor": "deepskyblue","LineWidth": 3.0,"ConstructionLineWidth": 2.0,
"PointDiameter": 10.0,"UseDataDefinedColors": false}})";
if (GlobalConfig.uiConfig.useDarkTheme)
{
ConnectionStyle::setConnectionStyle(
R"({"ConnectionStyle": {"ConstructionColor": "gray","NormalColor": "black","SelectedColor": "gray",
"SelectedHaloColor": "deepskyblue","HoveredColor": "deepskyblue","LineWidth": 3.0,
"ConstructionLineWidth": 2.0,"PointDiameter": 10.0,"UseDataDefinedColors": true}})");
QtNodes::NodeStyle::reset();
QtNodes::FlowViewStyle::reset();
ConnectionStyle::setConnectionStyle(darkConnectionStyle);
}
else
{
QtNodes::NodeStyle::setNodeStyle(
R"({"NodeStyle": {"NormalBoundaryColor": "darkgray","SelectedBoundaryColor": "deepskyblue",
"GradientColor0": "mintcream","GradientColor1": "mintcream","GradientColor2": "mintcream",
"GradientColor3": "mintcream","ShadowColor": [200, 200, 200],"FontColor": [10, 10, 10],
"FontColorFaded": [100, 100, 100],"ConnectionPointColor": "white","PenWidth": 2.0,"HoveredPenWidth": 2.5,
"ConnectionPointDiameter": 10.0,"Opacity": 1.0}})");
QtNodes::FlowViewStyle::setStyle(
R"({"FlowViewStyle": {"BackgroundColor": [255, 255, 240],"FineGridColor": [245, 245, 230],"CoarseGridColor": [235, 235, 220]}})");
ConnectionStyle::setConnectionStyle(
R"({"ConnectionStyle": {"ConstructionColor": "gray","NormalColor": "black","SelectedColor": "gray",
"SelectedHaloColor": "deepskyblue","HoveredColor": "deepskyblue","LineWidth": 3.0,"ConstructionLineWidth": 2.0,
"PointDiameter": 10.0,"UseDataDefinedColors": false}})");
QtNodes::NodeStyle::setNodeStyle(lightNodeStyle);
QtNodes::FlowViewStyle::setStyle(lightViewStyle);
ConnectionStyle::setConnectionStyle(lightConnectionStyle);
}
}
@ -79,13 +88,13 @@ RouteEditor::RouteEditor(QJsonObject connection, QWidget *parent) : QvDialog(par
ruleWidget = new RoutingEditorWidget(nodeDispatcher, ruleEditorUIWidget);
chainWidget = new ChainEditorWidget(nodeDispatcher, chainEditorUIWidget);
nodeDispatcher->InitializeScenes(ruleWidget->getScene(), chainWidget->getScene());
connect(nodeDispatcher.get(), &NodeDispatcher::OnOutboundCreated, this, &RouteEditor::OnDispatcherOutboundCreated);
connect(nodeDispatcher.get(), &NodeDispatcher::OnOutboundDeleted, this, &RouteEditor::OnDispatcherOutboundDeleted);
connect(nodeDispatcher.get(), &NodeDispatcher::OnRuleCreated, this, &RouteEditor::OnDispatcherRuleCreated);
connect(nodeDispatcher.get(), &NodeDispatcher::OnInboundOutboundNodeHovered, this, &RouteEditor::OnDispatcherInboundOutboundHovered);
// connect(nodeDispatcher.get(), &NodeDispatcher::OnEditChainRequested, this, &RouteEditor::OnDispatcherEditChainRequested);
//
{
//
connect(nodeDispatcher.get(), &NodeDispatcher::OnOutboundCreated, this, &RouteEditor::OnDispatcherOutboundCreated);
connect(nodeDispatcher.get(), &NodeDispatcher::OnOutboundDeleted, this, &RouteEditor::OnDispatcherOutboundDeleted);
connect(nodeDispatcher.get(), &NodeDispatcher::OnRuleCreated, this, &RouteEditor::OnDispatcherRuleCreated);
connect(nodeDispatcher.get(), &NodeDispatcher::OnInboundOutboundNodeHovered, this, &RouteEditor::OnDispatcherInboundOutboundHovered);
//
if (!ruleEditorUIWidget->layout())
{
@ -157,7 +166,7 @@ void RouteEditor::OnDispatcherInboundOutboundHovered(const QString &tag, const P
void RouteEditor::OnDispatcherOutboundCreated(std::shared_ptr<OutboundObjectMeta> out, QtNodes::Node &)
{
defaultOutboundCombo->addItem(out->getTag());
defaultOutboundCombo->addItem(out->getDisplayName());
}
void RouteEditor::OnDispatcherRuleCreated(std::shared_ptr<RuleObject> rule, QtNodes::Node &)
@ -167,7 +176,7 @@ void RouteEditor::OnDispatcherRuleCreated(std::shared_ptr<RuleObject> rule, QtNo
void RouteEditor::OnDispatcherOutboundDeleted(const OutboundObjectMeta &data)
{
const auto id = defaultOutboundCombo->findText(data.getTag());
const auto id = defaultOutboundCombo->findText(data.getDisplayName());
if (id >= 0)
{
defaultOutboundCombo->removeItem(id);
@ -199,6 +208,12 @@ void RouteEditor::OnDispatcherObjectTagChanged(ComplexTagNodeMode t, const QStri
}
}
void RouteEditor::OnDispatcherEditChainRequested(const ChainId &id)
{
nodesTab->setCurrentIndex(NODE_TAB_CHAIN_EDITOR);
chainWidget->editChain(id);
}
CONFIGROOT RouteEditor::OpenEditor()
{
auto result = this->exec();

View File

@ -62,6 +62,7 @@ class RouteEditor
void on_linkExistingBtn_clicked();
private slots:
void OnDispatcherEditChainRequested(const ChainId &);
void OnDispatcherOutboundDeleted(const complex::OutboundObjectMeta &);
void OnDispatcherOutboundCreated(std::shared_ptr<complex::OutboundObjectMeta>, QtNodes::Node &);
void OnDispatcherRuleCreated(std::shared_ptr<RuleObject>, QtNodes::Node &);

View File

@ -224,9 +224,9 @@
</layout>
</item>
<item row="1" column="0">
<widget class="QTabWidget" name="tabWidget_3">
<widget class="QTabWidget" name="nodesTab">
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="tabWidget_3Page1">
<attribute name="title">
@ -255,6 +255,16 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>DNS Settings</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<widget class="QWidget" name="widget" native="true"/>
</item>
</layout>
</widget>
</widget>
</item>
<item row="1" column="1">

View File

@ -60,7 +60,7 @@ namespace Qv2ray::ui::nodemodels
DECL_NODE_DATA_TYPE(InboundNodeData, NODE_TYPE_INBOUND, INBOUND);
DECL_NODE_DATA_TYPE(OutboundNodeData, NODE_TYPE_OUTBOUND, OutboundObjectMeta);
DECL_NODE_DATA_TYPE(RuleNodeData, NODE_TYPE_RULE, RuleObject);
DECL_NODE_DATA_TYPE(ChainOutboundData, NODE_TYPE_CHAINED_OUTBOUND, QString);
DECL_NODE_DATA_TYPE(ChainOutboundData, NODE_TYPE_CHAINED_OUTBOUND, OutboundObjectMeta);
template<typename NODEMODEL_T>
NODEMODEL_T *convert_nodemodel(QtNodes::Node *node)
@ -135,7 +135,7 @@ namespace Qv2ray::ui::nodemodels
DECL_NODE_DATA_MODEL(InboundNodeModel, INBOUND);
DECL_NODE_DATA_MODEL(OutboundNodeModel, OutboundObjectMeta);
DECL_NODE_DATA_MODEL(RuleNodeModel, RuleObject);
DECL_NODE_DATA_MODEL(ChainOutboundNodeModel, QString);
DECL_NODE_DATA_MODEL(ChainOutboundNodeModel, OutboundObjectMeta);
} // namespace Qv2ray::ui::nodemodels

View File

@ -135,6 +135,10 @@ void NodeDispatcher::DeleteNode(const QtNodes::Node &node)
#undef CLEANUP
}
void NodeDispatcher::RequestEditChain(const ChainId &id)
{
}
QString NodeDispatcher::CreateInbound(INBOUND in)
{
auto tag = getTag(in);
@ -157,7 +161,7 @@ QString NodeDispatcher::CreateInbound(INBOUND in)
QString NodeDispatcher::CreateOutbound(OutboundObjectMeta out)
{
QString tag = out.getTag();
QString tag = out.getDisplayName();
// In case the tag is duplicated:
while (outbounds.contains(tag))
{
@ -175,6 +179,12 @@ QString NodeDispatcher::CreateOutbound(OutboundObjectMeta out)
outboundNodes.insert(tag, node.id());
emit OnOutboundCreated(dataPtr, node);
}
// Create node and emit signals.
{
// auto nodeData = std::make_unique<ChainOutboundNodeModel>(shared_from_this(), dataPtr->getDisplayName());
// auto &node = chainScene->createNode(std::move(nodeData));
// emit OnChainOutboundCreate(dataPtr, node);
}
return tag;
}

View File

@ -62,6 +62,15 @@ class NodeDispatcher
public:
void DeleteNode(const QtNodes::Node &node);
void RequestEditChain(const ChainId &id);
const QList<const std::shared_ptr<OutboundObjectMeta>> GetChainableOutboudns() const
{
for (const auto &outbound : outbounds.values())
{
//
}
return {};
}
template<ComplexTagNodeMode t>
inline bool RenameTag(const QString originalTag, const QString newTag)
@ -90,6 +99,10 @@ class NodeDispatcher
rules[newTag] = rules.take(originalTag);
ruleNodes[newTag] = ruleNodes.take(originalTag);
}
else
{
Q_UNREACHABLE();
}
emit OnObjectTagChanged(t, originalTag, newTag);
return true;
}
@ -100,6 +113,7 @@ class NodeDispatcher
void OnInboundCreated(std::shared_ptr<INBOUND>, QtNodes::Node &);
void OnOutboundCreated(std::shared_ptr<OutboundObjectMeta>, QtNodes::Node &);
void OnRuleCreated(std::shared_ptr<RuleObject>, QtNodes::Node &);
void OnChainOutboundCreate(std::shared_ptr<OutboundObjectMeta>, QtNodes::Node &);
//
void OnObjectTagChanged(ComplexTagNodeMode, const QString originalTag, const QString newTag);

View File

@ -48,10 +48,10 @@ void OutboundNodeModel::onNodeHoverEnter()
ProtocolSettingsInfoObject o;
if (dataptr->metaType == METAOUTBOUND_ORIGINAL)
{
emit dispatcher->OnInboundOutboundNodeHovered(dataptr->getTag(), GetOutboundInfo(dataptr->realOutbound));
emit dispatcher->OnInboundOutboundNodeHovered(dataptr->getDisplayName(), GetOutboundInfo(dataptr->realOutbound));
}
else if (dataptr->metaType == METAOUTBOUND_EXTERNAL)
{
emit dispatcher->OnInboundOutboundNodeHovered(dataptr->getTag(), GetConnectionInfo(dataptr->connectionId));
emit dispatcher->OnInboundOutboundNodeHovered(dataptr->getDisplayName(), GetConnectionInfo(dataptr->connectionId));
}
}

View File

@ -49,11 +49,11 @@ void RuleNodeModel::outputConnectionCreated(const QtNodes::Connection &c)
case METAOUTBOUND_ORIGINAL:
case METAOUTBOUND_BALANCER:
{
dataptr->outboundTag = outbound->GetData()->getTag();
dataptr->outboundTag = outbound->GetData()->getDisplayName();
break;
}
{
dataptr->balancerTag = outbound->GetData()->getTag();
dataptr->balancerTag = outbound->GetData()->getDisplayName();
break;
}
}

View File

@ -15,7 +15,7 @@ void ChainOutboundWidget::changeEvent(QEvent *e)
}
}
void ChainOutboundWidget::setValue(std::shared_ptr<QString> tag)
void ChainOutboundWidget::setValue(std::shared_ptr<OutboundObjectMeta> data)
{
tagLabel->setText(*tag);
tagLabel->setText(data->getDisplayName());
}

View File

@ -11,7 +11,7 @@ class ChainOutboundWidget
public:
explicit ChainOutboundWidget(std::shared_ptr<NodeDispatcher> _dispatcher, QWidget *parent = nullptr);
void setValue(std::shared_ptr<QString>);
void setValue(std::shared_ptr<OutboundObjectMeta>);
protected:
void changeEvent(QEvent *e);

View File

@ -1,14 +1,18 @@
#include "ChainWidget.hpp"
#include "base/Qv2rayBase.hpp"
#include "ui/common/UIBase.hpp"
ChainWidget::ChainWidget(std::shared_ptr<NodeDispatcher> _dispatcher, QWidget *parent) : QvNodeWidget(_dispatcher, parent)
{
setupUi(this);
editChainBtn->setIcon(QICON_R("edit"));
}
void ChainWidget::setValue(std::shared_ptr<OutboundObjectMeta> data)
{
dataptr = data;
displayNameTxt->setText(data->getDisplayName());
}
void ChainWidget::changeEvent(QEvent *e)
@ -20,3 +24,22 @@ void ChainWidget::changeEvent(QEvent *e)
default: break;
}
}
void ChainWidget::on_displayNameTxt_textEdited(const QString &arg1)
{
const auto originalTag = dataptr->getDisplayName();
if (originalTag == arg1 || dispatcher->RenameTag<NODE_OUTBOUND>(originalTag, arg1))
{
dataptr->displayName = arg1;
BLACK(displayNameTxt);
}
else
{
RED(displayNameTxt);
}
}
void ChainWidget::on_editChainBtn_clicked()
{
emit dispatcher->RequestEditChain(dataptr->chainId);
}

View File

@ -15,8 +15,16 @@ class ChainWidget
signals:
void OnSizeUpdated();
void OnEditChainRequested(const ChainId &id);
protected:
void changeEvent(QEvent *e);
QStringList targetList;
private slots:
void on_displayNameTxt_textEdited(const QString &arg1);
void on_editChainBtn_clicked();
private:
std::shared_ptr<OutboundObjectMeta> dataptr;
};

View File

@ -6,14 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>127</width>
<height>51</height>
<width>240</width>
<height>27</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
@ -26,18 +26,38 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>C H A I N!</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="outboundsLabel">
<property name="text">
<string>Chained</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="displayNameTxt"/>
</item>
<item>
<widget class="QToolButton" name="editChainBtn">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../../resources.new.qrc">
<normaloff>:/assets/icons/ui_light/edit.svg</normaloff>:/assets/icons/ui_light/edit.svg</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<resources>
<include location="../../../../resources.new.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -28,7 +28,7 @@ void InboundOutboundWidget::setValue(std::shared_ptr<OutboundObjectMeta> data)
{
assert(workingMode == NODE_OUTBOUND);
outboundObject = data;
tagTxt->setText(outboundObject->getTag());
tagTxt->setText(outboundObject->getDisplayName());
isExternalOutbound = outboundObject->metaType == METAOUTBOUND_EXTERNAL;
statusLabel->setText(isExternalOutbound ? tr("External Config") : "");
tagTxt->setEnabled(!isExternalOutbound);
@ -149,7 +149,7 @@ void InboundOutboundWidget::on_tagTxt_textEdited(const QString &arg1)
}
else
{
const auto originalTag = outboundObject->getTag();
const auto originalTag = outboundObject->getDisplayName();
if (originalTag == arg1 || dispatcher->RenameTag<NODE_OUTBOUND>(originalTag, arg1))
{
BLACK(tagTxt);

View File

@ -31,6 +31,10 @@ QvMessageBusSlotImpl(ChainEditorWidget)
}
}
void ChainEditorWidget::editChain(const ChainId &id)
{
}
void ChainEditorWidget::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
@ -40,3 +44,7 @@ void ChainEditorWidget::changeEvent(QEvent *e)
default: break;
}
}
void ChainEditorWidget::on_chainComboBox_currentIndexChanged(const QString &arg1)
{
}

View File

@ -1,6 +1,7 @@
#pragma once
#include "ui/messaging/QvMessageBus.hpp"
#include "ui/node/NodeBase.hpp"
#include "ui_ChainEditorWidget.h"
#include <nodes/FlowScene>
@ -16,6 +17,7 @@ class ChainEditorWidget
public:
explicit ChainEditorWidget(std::shared_ptr<NodeDispatcher> dispatcher, QWidget *parent = nullptr);
void editChain(const ChainId &id);
auto getScene()
{
return scene;
@ -24,6 +26,9 @@ class ChainEditorWidget
protected:
void changeEvent(QEvent *e);
private slots:
void on_chainComboBox_currentIndexChanged(const QString &arg1);
private:
void updateColorScheme(){};
QvMessageBusSlotDecl;

View File

@ -13,82 +13,18 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1">
<item>
<widget class="QLabel" name="label">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Chains</string>
<string>Back</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="chainList"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="toolButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../../resources.new.qrc">
<normaloff>:/assets/icons/ui_light/add.svg</normaloff>:/assets/icons/ui_light/add.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_2">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../../resources.new.qrc">
<normaloff>:/assets/icons/ui_light/minus.svg</normaloff>:/assets/icons/ui_light/minus.svg</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
<widget class="QComboBox" name="chainComboBox"/>
</item>
</layout>
</item>
@ -97,8 +33,6 @@
</item>
</layout>
</widget>
<resources>
<include location="../../../../resources.new.qrc"/>
</resources>
<resources/>
<connections/>
</ui>

View File

@ -30,9 +30,7 @@ class RoutingEditorWidget
void OnDispatcherInboundCreated(std::shared_ptr<INBOUND>, QtNodes::Node &);
void OnDispatcherOutboundCreated(std::shared_ptr<complex::OutboundObjectMeta>, QtNodes::Node &);
void OnDispatcherRuleCreated(std::shared_ptr<RuleObject>, QtNodes::Node &);
void on_addRouteBtn_clicked();
void on_delBtn_clicked();
private: