From 856dc2b031877cb2a36f453d556abb0ca83dad5b Mon Sep 17 00:00:00 2001
From: arm64v8a <48624112+arm64v8a@users.noreply.github.com>
Date: Fri, 19 Aug 2022 12:48:56 +0800
Subject: [PATCH] improve scroll
---
ui/GroupSort.hpp | 1 +
ui/mainwindow.cpp | 15 ++++++++++++++-
ui/mainwindow.ui | 3 ---
3 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/ui/GroupSort.hpp b/ui/GroupSort.hpp
index 99e6e0588..b3bb299e0 100644
--- a/ui/GroupSort.hpp
+++ b/ui/GroupSort.hpp
@@ -17,5 +17,6 @@ namespace NekoRay {
GroupSortMethod::GroupSortMethod method = GroupSortMethod::Raw;
bool save_sort = false; //保存到文件
bool descending = false; //默认升序,开这个就是降序
+ bool scroll_to_started = false;
};
}
diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp
index 5809e3620..2e7af3d01 100644
--- a/ui/mainwindow.cpp
+++ b/ui/mainwindow.cpp
@@ -467,12 +467,16 @@ void MainWindow::show_group(int gid) {
MessageBoxWarning(tr("Error"), QString("No such group: %1").arg(gid));
return;
}
+
if (NekoRay::dataStore->current_group != gid) {
NekoRay::dataStore->current_group = gid;
NekoRay::dataStore->Save();
}
ui->tabWidget->widget(groupId2TabIndex(gid))->layout()->addWidget(ui->proxyListTable);
- refresh_proxy_list();
+
+ NekoRay::GroupSortAction gsa;
+ gsa.scroll_to_started = true;
+ refresh_proxy_list_impl(-1, gsa);
}
// callback
@@ -727,6 +731,8 @@ void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction
ui->proxyListTable->setRowCount(0);
}
+ QTableWidgetItem *started_item = nullptr;
+
// 绘制或更新item(s)
int row = -1;
for (const auto &profile: NekoRay::profileManager->profiles) {
@@ -751,6 +757,7 @@ void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction
auto f = f0->clone();
if (profile->id == NekoRay::dataStore->started_id) {
f->setText("✓");
+ if (groupSortAction.scroll_to_started) started_item = f;
} else {
f->setText(" ");
}
@@ -851,6 +858,12 @@ void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction
}
ui->proxyListTable->update_order(groupSortAction.save_sort);
}
+
+ if (started_item != nullptr) {
+ runOnUiThread([=] {
+ ui->proxyListTable->verticalScrollBar()->setSliderPosition(started_item->row());
+ });
+ }
}
// table菜单相关
diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui
index 9429994f1..bc7b6c7fa 100644
--- a/ui/mainwindow.ui
+++ b/ui/mainwindow.ui
@@ -242,9 +242,6 @@
QAbstractItemView::SelectRows
-
- QAbstractItemView::ScrollPerPixel
-
QAbstractItemView::ScrollPerPixel