From f0b8c4ec0202ace9cd959d4478ed0205bd487aed Mon Sep 17 00:00:00 2001 From: arm64v8a <48624112+arm64v8a@users.noreply.github.com> Date: Sun, 22 Jan 2023 17:53:51 +0900 Subject: [PATCH] improve edit chain --- res/icon/material/delete.svg | 1 + res/icon/material/swap-horizontal.svg | 1 + res/neko.qrc | 2 ++ translations/fa_IR.ts | 2 +- translations/zh_CN.ts | 2 +- ui/edit/edit_chain.cpp | 23 ++++++++++++++++++++--- ui/edit/edit_chain.h | 6 +++++- ui/widget/ProxyItem.cpp | 4 ++++ ui/widget/ProxyItem.h | 4 ++++ ui/widget/ProxyItem.ui | 23 ++++++++++++++++++++--- 10 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 res/icon/material/delete.svg create mode 100644 res/icon/material/swap-horizontal.svg diff --git a/res/icon/material/delete.svg b/res/icon/material/delete.svg new file mode 100644 index 0000000..21c80c2 --- /dev/null +++ b/res/icon/material/delete.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/res/icon/material/swap-horizontal.svg b/res/icon/material/swap-horizontal.svg new file mode 100644 index 0000000..3f30649 --- /dev/null +++ b/res/icon/material/swap-horizontal.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/res/neko.qrc b/res/neko.qrc index 4d1987d..af5501c 100644 --- a/res/neko.qrc +++ b/res/neko.qrc @@ -11,6 +11,8 @@ icon/material/cancel.svg icon/material/history.svg icon/material/swap-vertical.svg + icon/material/delete.svg + icon/material/swap-horizontal.svg public/nekobox.png diff --git a/translations/fa_IR.ts b/translations/fa_IR.ts index 29f7cc8..01f3c02 100644 --- a/translations/fa_IR.ts +++ b/translations/fa_IR.ts @@ -1237,7 +1237,7 @@ End: %2 ProxyItem Remove - حذف کردن + حذف کردن Confirmation diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index 9d16073..25f699c 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -1240,7 +1240,7 @@ Split by line. ProxyItem Remove - 删除 + 删除 Confirmation diff --git a/ui/edit/edit_chain.cpp b/ui/edit/edit_chain.cpp index 1a83e15..9d3f1e6 100644 --- a/ui/edit/edit_chain.cpp +++ b/ui/edit/edit_chain.cpp @@ -44,13 +44,30 @@ void EditChain::on_select_profile_clicked() { }); } -void EditChain::AddProfileToListIfExist(int id) { - auto _ent = NekoRay::profileManager->GetProfile(id); +void EditChain::AddProfileToListIfExist(int profileId) { + auto _ent = NekoRay::profileManager->GetProfile(profileId); if (_ent != nullptr && _ent->type != "chain") { auto wI = new QListWidgetItem(); + wI->setData(114514, profileId); auto w = new ProxyItem(this, _ent, wI); - wI->setData(114514, id); ui->listWidget->addItem(wI); ui->listWidget->setItemWidget(wI, w); + // change button + connect(w->get_change_button(), &QPushButton::clicked, w, [=] { + get_edit_dialog()->hide(); + GetMainWindow()->start_select_mode(w, [=](int newId) { + get_edit_dialog()->show(); + ReplaceProfile(w, newId); + }); + }); + } +} + +void EditChain::ReplaceProfile(ProxyItem *w, int profileId) { + auto _ent = NekoRay::profileManager->GetProfile(profileId); + if (_ent != nullptr && _ent->type != "chain") { + w->item->setData(114514, profileId); + w->ent = _ent; + w->refresh_data(); } } diff --git a/ui/edit/edit_chain.h b/ui/edit/edit_chain.h index 7edd884..03640ac 100644 --- a/ui/edit/edit_chain.h +++ b/ui/edit/edit_chain.h @@ -9,6 +9,8 @@ namespace Ui { } QT_END_NAMESPACE +class ProxyItem; + class EditChain : public QWidget, public ProfileEditor { Q_OBJECT @@ -25,7 +27,9 @@ private: Ui::EditChain *ui; QSharedPointer ent; - void AddProfileToListIfExist(int id); + void AddProfileToListIfExist(int profileId); + + static void ReplaceProfile(ProxyItem *w, int profileId); private slots: diff --git a/ui/widget/ProxyItem.cpp b/ui/widget/ProxyItem.cpp index 730ae78..edc2b47 100644 --- a/ui/widget/ProxyItem.cpp +++ b/ui/widget/ProxyItem.cpp @@ -42,3 +42,7 @@ void ProxyItem::on_remove_clicked() { delete item; } } + +QPushButton *ProxyItem::get_change_button() { + return ui->change; +} diff --git a/ui/widget/ProxyItem.h b/ui/widget/ProxyItem.h index c6e48cc..208c243 100644 --- a/ui/widget/ProxyItem.h +++ b/ui/widget/ProxyItem.h @@ -11,6 +11,8 @@ namespace Ui { } QT_END_NAMESPACE +class QPushButton; + class ProxyItem : public QWidget { Q_OBJECT @@ -21,6 +23,8 @@ public: void refresh_data(); + QPushButton *get_change_button(); + QSharedPointer ent; QListWidgetItem *item; bool remove_confirm = false; diff --git a/ui/widget/ProxyItem.ui b/ui/widget/ProxyItem.ui index 4f51e76..351dbae 100644 --- a/ui/widget/ProxyItem.ui +++ b/ui/widget/ProxyItem.ui @@ -35,6 +35,20 @@ + + + + + 0 + 0 + + + + + :/icon/material/swap-horizontal.svg:/icon/material/swap-horizontal.svg + + + @@ -43,8 +57,9 @@ 0 - - Remove + + + :/icon/material/delete.svg:/icon/material/delete.svg @@ -124,6 +139,8 @@ - + + +