#include "xsteam_set_ui.h" xsteam_set_ui::xsteam_set_ui() { init_set(); load_data_set(); } xsteam_set_ui::~xsteam_set_ui() { } void xsteam_set_ui::init_set() { main_qwidget = new QWidget; main_layout = new QVBoxLayout; foot_layout = new QHBoxLayout; body_layout = new QVBoxLayout; set_group = new QGroupBox(tr("参数设置")); set_group->setObjectName("SET_GROUP"); steam_layout = new QHBoxLayout; steam_path_str = new QLabel(tr("Steam路径设置:")); steam_path_edit = new QLineEdit(); steam_path_btn = new QPushButton(tr("浏览")); steam_path_btn->setObjectName("STEAM_PATH_BTN"); steam_layout->addWidget(steam_path_str); steam_layout->addWidget(steam_path_edit); steam_layout->addWidget(steam_path_btn); steamtools_layout = new QHBoxLayout; steamtools_path_str = new QLabel(tr("SteamTools路径设置:")); steamtools_path_edit = new QLineEdit(); steamtools_path_btn = new QPushButton(tr("浏览")); steamtools_path_btn->setObjectName("STEAMTOOLS_PATH_BTN"); steamtools_layout->addWidget(steamtools_path_str); steamtools_layout->addWidget(steamtools_path_edit); steamtools_layout->addWidget(steamtools_path_btn); steamtools_st_layout = new QHBoxLayout; steamtools_st_path_str = new QLabel(tr("SteamTools .st路径设置(不建议修改):")); steamtools_st_path_edit = new QLineEdit(); steamtools_st_path_btn = new QPushButton(tr("浏览")); steamtools_st_path_btn->setObjectName("STEAMTOOLS_ST_PATH_BTN"); steamtools_st_layout->addWidget(steamtools_st_path_str); steamtools_st_layout->addWidget(steamtools_st_path_edit); steamtools_st_layout->addWidget(steamtools_st_path_btn); steam_api_layout = new QHBoxLayout; steaminfo_api_path_str = new QLabel(tr("Steam Info Api Url(不建议修改):")); steaminfo_api_path_edit = new QLineEdit(); steam_api_layout->addWidget(steaminfo_api_path_str); steam_api_layout->addWidget(steaminfo_api_path_edit); steam_head_api_layout = new QHBoxLayout; steaminfo_head_path_str = new QLabel(tr("Steam Logo Api Url(不建议修改):")); steaminfo_head_path_edit = new QLineEdit(); steam_head_api_layout->addWidget(steaminfo_head_path_str); steam_head_api_layout->addWidget(steaminfo_head_path_edit); body_layout->addLayout(steam_layout); body_layout->addLayout(steamtools_layout); body_layout->addLayout(steamtools_st_layout); body_layout->addLayout(steam_api_layout); body_layout->addLayout(steam_head_api_layout); body_layout->addWidget(new QWidget()); set_group->setLayout(body_layout); _pSaveData = new QPushButton(tr("保存")); foot_layout->addSpacerItem(sparcer_item); foot_layout->addWidget(_pSaveData); foot_layout->addSpacerItem(sparcer_item); main_layout->addWidget(set_group); main_layout->addLayout(foot_layout); main_layout->setStretch(0, 8); main_layout->setStretch(1, 2); main_layout->setContentsMargins(5, 5, 5, 5); main_qwidget->setLayout(main_layout); layout()->addWidget(main_qwidget); connect_slots(); } void xsteam_set_ui::connect_slots() { connect(_pSaveData, SIGNAL(clicked()), this, SLOT(slotsSaveDone())); connect(steam_path_btn, SIGNAL(clicked()), this, SLOT(slots_set_path_change())); connect(steamtools_path_btn, SIGNAL(clicked()), this, SLOT(slots_set_path_change())); connect(steamtools_st_path_btn, SIGNAL(clicked()), this, SLOT(slots_set_path_change())); } void xsteam_set_ui::load_data_set() { steam_path_edit->setText(QString::fromStdString(_data.x_config.steam_dir)); steamtools_path_edit->setText(QString::fromStdString(_data.x_config.steamtools_dir)); steamtools_st_path_edit->setText(QString::fromStdString(_data.x_config.steamtools_st_dir)); steaminfo_api_path_edit->setText(QString::fromStdString(_data.x_config.steam_api_url)); steaminfo_head_path_edit->setText(QString::fromStdString(_data.x_config.steam_logo_url)); } void xsteam_set_ui::slotsSaveDone() { _data.x_config.steam_dir = steam_path_edit->text().toStdString(); _data.x_config.steamtools_dir = steamtools_path_edit->text().toStdString(); _data.x_config.steamtools_st_dir = steamtools_st_path_edit->text().toStdString(); _data.x_config.steam_api_url = steaminfo_api_path_edit->text().toStdString(); _data.x_config.steam_logo_url = steaminfo_head_path_edit->text().toStdString(); xsteam_save_data_write(); xsteam_msg_tip(nullptr, "保存成功"); this->close(); } void xsteam_set_ui::slots_set_path_change() { auto select_dir = [=](QString sender_name) { QString default_dir; if (sender_name == "STEAM_PATH_BTN") { default_dir = steam_path_edit->text(); } else if (sender_name == "STEAMTOOLS_PATH_BTN") { default_dir = steamtools_path_edit->text(); } else if (sender_name == "STEAMTOOLS_ST_PATH_BTN") { default_dir = steamtools_st_path_edit->text(); } return QFileDialog::getExistingDirectory(new QWidget(), "选择目录", default_dir); }; auto set_dir = [=](QString sender_name,QString dir_str) { if (sender_name == "STEAM_PATH_BTN") { _data.x_config.steam_dir = dir_str.toStdString(); } else if (sender_name == "STEAMTOOLS_PATH_BTN") { _data.x_config.steamtools_dir = dir_str.toStdString(); } else if (sender_name == "STEAMTOOLS_ST_PATH_BTN") { _data.x_config.steamtools_st_dir = dir_str.toStdString(); } }; QString dir_str=select_dir(sender()->objectName()); if ( dir_str!= nullptr) { set_dir(sender()->objectName(),dir_str); load_data_set(); } }