diff --git a/db/Database.cpp b/db/Database.cpp index 1e9f9fe..0a69ebe 100644 --- a/db/Database.cpp +++ b/db/Database.cpp @@ -213,6 +213,8 @@ namespace NekoRay { _add(new configItem("url", &url, itemType::string)); _add(new configItem("info", &info, itemType::string)); _add(new configItem("lastup", &last_update, itemType::integer64)); + _add(new configItem("manually_column_width", &manually_column_width, itemType::boolean)); + _add(new configItem("column_width", &column_width, itemType::integerList)); } QSharedPointer ProfileManager::LoadGroup(const QString &jsonPath) { diff --git a/db/Group.hpp b/db/Group.hpp index bc82479..64ae678 100644 --- a/db/Group.hpp +++ b/db/Group.hpp @@ -9,11 +9,15 @@ namespace NekoRay { int id = -1; bool archive = false; QString name = ""; - QList order; QString url = ""; QString info = ""; qint64 last_update = 0; + // list ui + bool manually_column_width = false; + QList column_width; + QList order; + Group(); // 按 id 顺序 diff --git a/main/NekoRay_DataStore.hpp b/main/NekoRay_DataStore.hpp index 4bb6144..3d7d5c3 100644 --- a/main/NekoRay_DataStore.hpp +++ b/main/NekoRay_DataStore.hpp @@ -60,6 +60,7 @@ namespace NekoRay { Routing *routing = new Routing; int imported_count = 0; bool refreshing_group_list = false; + bool refreshing_group = false; int resolve_count = 0; // Flags diff --git a/translations/fa_IR.ts b/translations/fa_IR.ts index 64902fb..29f7cc8 100644 --- a/translations/fa_IR.ts +++ b/translations/fa_IR.ts @@ -280,6 +280,10 @@ Copied کپی شده است + + Manually column width + + DialogEditProfile diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index ff8b0b1..9d16073 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -278,6 +278,10 @@ Copy profile share links (Neko Links) 复制分组内配置的分享链接 (Neko Links) + + Manually column width + 手动调节列宽 + DialogEditProfile diff --git a/ui/edit/dialog_edit_group.cpp b/ui/edit/dialog_edit_group.cpp index 235b416..6c07fd5 100644 --- a/ui/edit/dialog_edit_group.cpp +++ b/ui/edit/dialog_edit_group.cpp @@ -18,6 +18,7 @@ DialogEditGroup::DialogEditGroup(const QSharedPointer &ent, QWid ui->url->setText(ent->url); ui->type->setCurrentIndex(ent->url.isEmpty() ? 0 : 1); ui->type->currentIndexChanged(ui->type->currentIndex()); + ui->manually_column_width->setChecked(ent->manually_column_width); ui->copy_links->setVisible(false); ui->copy_links_nkr->setVisible(false); if (ent->id >= 0) { // already a group @@ -38,6 +39,7 @@ DialogEditGroup::DialogEditGroup(const QSharedPointer &ent, QWid ent->name = ui->name->text(); ent->url = ui->url->text(); ent->archive = ui->archive->isChecked(); + ent->manually_column_width = ui->manually_column_width->isChecked(); QDialog::accept(); }); diff --git a/ui/edit/dialog_edit_group.ui b/ui/edit/dialog_edit_group.ui index b068daf..ae920e6 100644 --- a/ui/edit/dialog_edit_group.ui +++ b/ui/edit/dialog_edit_group.ui @@ -15,7 +15,7 @@ - + 0 @@ -35,13 +35,6 @@ 0 - - - - Type - - - @@ -52,20 +45,13 @@ - - + + - - - - Basic - - - - - Subscription - - + + + Manually column width + @@ -77,6 +63,27 @@ + + + + Type + + + + + + + + Basic + + + + + Subscription + + + + diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index f2608d8..0897d36 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -175,11 +175,17 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi } refresh_proxy_list_impl(-1, action); }); - ui->proxyListTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); - ui->proxyListTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); - ui->proxyListTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); - ui->proxyListTable->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents); - ui->proxyListTable->horizontalHeader()->setSectionResizeMode(4, QHeaderView::ResizeToContents); + connect(ui->proxyListTable->horizontalHeader(), &QHeaderView::sectionResized, this, [=](int logicalIndex, int oldSize, int newSize) { + auto group = NekoRay::profileManager->CurrentGroup(); + if (NekoRay::dataStore->refreshing_group || group == nullptr || !group->manually_column_width) return; + // save manually column width + group->column_width.clear(); + for (int i = 0; i < ui->proxyListTable->horizontalHeader()->count(); i++) { + group->column_width.push_back(ui->proxyListTable->horizontalHeader()->sectionSize(i)); + } + group->column_width[logicalIndex] = newSize; + group->Save(); + }); ui->tableWidget_conn->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); ui->tableWidget_conn->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents); ui->tableWidget_conn->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); @@ -417,9 +423,13 @@ void MainWindow::on_tabWidget_currentChanged(int index) { } void MainWindow::show_group(int gid) { + if (NekoRay::dataStore->refreshing_group) return; + NekoRay::dataStore->refreshing_group = true; + auto group = NekoRay::profileManager->GetGroup(gid); if (group == nullptr) { MessageBoxWarning(tr("Error"), QString("No such group: %1").arg(gid)); + NekoRay::dataStore->refreshing_group = false; return; } @@ -429,9 +439,28 @@ void MainWindow::show_group(int gid) { } ui->tabWidget->widget(groupId2TabIndex(gid))->layout()->addWidget(ui->proxyListTable); + // 列宽是否可调 + if (group->manually_column_width) { + for (int i = 0; i <= 4; i++) { + ui->proxyListTable->horizontalHeader()->setSectionResizeMode(i, QHeaderView::Interactive); + auto size = group->column_width.value(i); + if (size <= 0) size = ui->proxyListTable->horizontalHeader()->defaultSectionSize(); + ui->proxyListTable->horizontalHeader()->resizeSection(i, size); + } + } else { + ui->proxyListTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); + ui->proxyListTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); + ui->proxyListTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); + ui->proxyListTable->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents); + ui->proxyListTable->horizontalHeader()->setSectionResizeMode(4, QHeaderView::ResizeToContents); + } + + // show proxies NekoRay::GroupSortAction gsa; gsa.scroll_to_started = true; refresh_proxy_list_impl(-1, gsa); + + NekoRay::dataStore->refreshing_group = false; } // callback