Skip to content

Commit

Permalink
improve edit chain
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Jan 22, 2023
1 parent 8fa966a commit f0b8c4e
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 9 deletions.
1 change: 1 addition & 0 deletions res/icon/material/delete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions res/icon/material/swap-horizontal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions res/neko.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<file>icon/material/cancel.svg</file>
<file>icon/material/history.svg</file>
<file>icon/material/swap-vertical.svg</file>
<file>icon/material/delete.svg</file>
<file>icon/material/swap-horizontal.svg</file>
</qresource>
<qresource prefix="/neko">
<file alias="nekobox.png">public/nekobox.png</file>
Expand Down
2 changes: 1 addition & 1 deletion translations/fa_IR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ End: %2</source>
<name>ProxyItem</name>
<message>
<source>Remove</source>
<translation>حذف کردن</translation>
<translation type="vanished">حذف کردن</translation>
</message>
<message>
<source>Confirmation</source>
Expand Down
2 changes: 1 addition & 1 deletion translations/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ Split by line.</source>
<name>ProxyItem</name>
<message>
<source>Remove</source>
<translation>删除</translation>
<translation type="vanished">删除</translation>
</message>
<message>
<source>Confirmation</source>
Expand Down
23 changes: 20 additions & 3 deletions ui/edit/edit_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
6 changes: 5 additions & 1 deletion ui/edit/edit_chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Ui {
}
QT_END_NAMESPACE

class ProxyItem;

class EditChain : public QWidget, public ProfileEditor {
Q_OBJECT

Expand All @@ -25,7 +27,9 @@ class EditChain : public QWidget, public ProfileEditor {
Ui::EditChain *ui;
QSharedPointer<NekoRay::ProxyEntity> ent;

void AddProfileToListIfExist(int id);
void AddProfileToListIfExist(int profileId);

static void ReplaceProfile(ProxyItem *w, int profileId);

private slots:

Expand Down
4 changes: 4 additions & 0 deletions ui/widget/ProxyItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ void ProxyItem::on_remove_clicked() {
delete item;
}
}

QPushButton *ProxyItem::get_change_button() {
return ui->change;
}
4 changes: 4 additions & 0 deletions ui/widget/ProxyItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Ui {
}
QT_END_NAMESPACE

class QPushButton;

class ProxyItem : public QWidget {
Q_OBJECT

Expand All @@ -21,6 +23,8 @@ class ProxyItem : public QWidget {

void refresh_data();

QPushButton *get_change_button();

QSharedPointer<NekoRay::ProxyEntity> ent;
QListWidgetItem *item;
bool remove_confirm = false;
Expand Down
23 changes: 20 additions & 3 deletions ui/widget/ProxyItem.ui
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="change">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="../../res/neko.qrc">
<normaloff>:/icon/material/swap-horizontal.svg</normaloff>:/icon/material/swap-horizontal.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="remove">
<property name="sizePolicy">
Expand All @@ -43,8 +57,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Remove</string>
<property name="icon">
<iconset resource="../../res/neko.qrc">
<normaloff>:/icon/material/delete.svg</normaloff>:/icon/material/delete.svg</iconset>
</property>
</widget>
</item>
Expand Down Expand Up @@ -124,6 +139,8 @@
</item>
</layout>
</widget>
<resources/>
<resources>
<include location="../../res/neko.qrc"/>
</resources>
<connections/>
</ui>

0 comments on commit f0b8c4e

Please sign in to comment.