mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
feat: manually column width
This commit is contained in:
@@ -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<Group> ProfileManager::LoadGroup(const QString &jsonPath) {
|
||||
|
||||
@@ -9,11 +9,15 @@ namespace NekoRay {
|
||||
int id = -1;
|
||||
bool archive = false;
|
||||
QString name = "";
|
||||
QList<int> order;
|
||||
QString url = "";
|
||||
QString info = "";
|
||||
qint64 last_update = 0;
|
||||
|
||||
// list ui
|
||||
bool manually_column_width = false;
|
||||
QList<int> column_width;
|
||||
QList<int> order;
|
||||
|
||||
Group();
|
||||
|
||||
// 按 id 顺序
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -280,6 +280,10 @@
|
||||
<source>Copied</source>
|
||||
<translation>کپی شده است</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Manually column width</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DialogEditProfile</name>
|
||||
|
||||
@@ -278,6 +278,10 @@
|
||||
<source>Copy profile share links (Neko Links)</source>
|
||||
<translation>复制分组内配置的分享链接 (Neko Links)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Manually column width</source>
|
||||
<translation>手动调节列宽</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DialogEditProfile</name>
|
||||
|
||||
@@ -18,6 +18,7 @@ DialogEditGroup::DialogEditGroup(const QSharedPointer<NekoRay::Group> &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<NekoRay::Group> &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();
|
||||
});
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="gridWidget" native="true">
|
||||
<widget class="QWidget" name="cat_common" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -35,13 +35,6 @@
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="name"/>
|
||||
</item>
|
||||
@@ -52,9 +45,32 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item row="3" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="manually_column_width">
|
||||
<property name="text">
|
||||
<string>Manually column width</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="archive">
|
||||
<property name="text">
|
||||
<string>Archive</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="type">
|
||||
<item>
|
||||
<property name="text">
|
||||
@@ -68,15 +84,6 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="archive">
|
||||
<property name="text">
|
||||
<string>Archive</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user