Skip to content

Commit

Permalink
improve scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Aug 19, 2022
1 parent bf7e3c5 commit 856dc2b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions ui/GroupSort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ namespace NekoRay {
GroupSortMethod::GroupSortMethod method = GroupSortMethod::Raw;
bool save_sort = false; //保存到文件
bool descending = false; //默认升序,开这个就是降序
bool scroll_to_started = false;
};
}
15 changes: 14 additions & 1 deletion ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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(" ");
}
Expand Down Expand Up @@ -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菜单相关
Expand Down
3 changes: 0 additions & 3 deletions ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,6 @@
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="horizontalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
Expand Down

0 comments on commit 856dc2b

Please sign in to comment.