You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

85 lines
2.9 KiB

// settingsdialog.cpp — Settings dialog with category list
#include "settingsdialog.h"
#include "networksettingspage.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QLabel>
SettingsDialog::SettingsDialog(const QString& configPath, QWidget* parent)
: QDialog(parent)
, m_configPath(configPath)
{
setWindowTitle("Settings");
setMinimumSize(560, 380);
setModal(true);
auto* mainLayout = new QHBoxLayout(this);
mainLayout->setSpacing(0);
mainLayout->setContentsMargins(0, 0, 0, 0);
// --- Left sidebar: category list ---
m_categoryList = new QListWidget(this);
m_categoryList->setFixedWidth(150);
m_categoryList->setStyleSheet(
"QListWidget { border: none; border-right: 1px solid palette(mid);"
" background: palette(window); font-size: 13px; }"
"QListWidget::item { padding: 10px 14px; }"
"QListWidget::item:selected { background: #3390EC; color: white; }");
m_categoryList->addItem("Network");
mainLayout->addWidget(m_categoryList);
// --- Right panel: stacked pages ---
auto* rightPanel = new QWidget(this);
auto* rightLayout = new QVBoxLayout(rightPanel);
rightLayout->setContentsMargins(20, 16, 20, 16);
rightLayout->setSpacing(0);
m_pages = new QStackedWidget(rightPanel);
m_networkPage = new NetworkSettingsPage(m_pages);
m_pages->addWidget(m_networkPage);
rightLayout->addWidget(m_pages, 1);
// --- Bottom buttons ---
auto* btnLayout = new QHBoxLayout();
btnLayout->setSpacing(8);
btnLayout->addStretch();
auto* cancelBtn = new QPushButton("Cancel", rightPanel);
cancelBtn->setFixedWidth(90);
cancelBtn->setStyleSheet(
"QPushButton { border: 1px solid palette(mid); border-radius: 4px;"
" padding: 6px 16px; font-size: 13px; background: palette(button); }"
"QPushButton:hover { background: palette(light); }");
connect(cancelBtn, &QPushButton::clicked, this, &QDialog::reject);
btnLayout->addWidget(cancelBtn);
m_saveBtn = new QPushButton("Save", rightPanel);
m_saveBtn->setFixedWidth(90);
m_saveBtn->setDefault(true);
m_saveBtn->setStyleSheet(
"QPushButton { border: none; border-radius: 4px;"
" padding: 6px 16px; font-size: 13px; font-weight: bold;"
" background: #3390EC; color: white; }"
"QPushButton:hover { background: #2B7ED4; }");
connect(m_saveBtn, &QPushButton::clicked, this, &SettingsDialog::onSave);
btnLayout->addWidget(m_saveBtn);
rightLayout->addLayout(btnLayout);
mainLayout->addWidget(rightPanel, 1);
connect(m_categoryList, &QListWidget::currentRowChanged,
this, &SettingsDialog::onCategoryChanged);
m_networkPage->loadFromConfig(m_configPath);
m_categoryList->setCurrentRow(0);
}
void SettingsDialog::onCategoryChanged(int row) {
m_pages->setCurrentIndex(row);
}
void SettingsDialog::onSave() {
m_networkPage->saveToConfig(m_configPath);
accept();
}