diff --git a/.vscode/settings.json b/.vscode/settings.json index 05298a6..7c626a1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -111,7 +111,10 @@ "qabstractlistmodel": "cpp", "qtconcurrentrun": "cpp", "*.in": "cpp", - "qactiongroup": "cpp" + "qactiongroup": "cpp", + "qprocess": "cpp", + "qmessagebox": "cpp", + "qdatetime": "cpp" }, "Codegeex.RepoIndex": true, "editor.gotoLocation.alternativeDeclarationCommand": "editor.action.revealDefinition", diff --git a/CMakeLists.txt b/CMakeLists.txt index f2fe07c..2e14e88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,9 @@ else() SET(QT_DIR "D:/Dev/Qt/6.8.0/mingw1310_static_x64/lib/cmake") endif() +#JSON库 SET(JSON ${PROJECT_SOURCE_DIR}/3rdparty/json) +include_directories(${JSON}/include) LIST(APPEND CMAKE_PREFIX_PATH ${QT_DIR} ${MSYS}) @@ -105,9 +107,6 @@ else() message(STATUS "CURL_FOUND=NOT") endif() -#JSON库 -include_directories(${JSON}/include) - #增加XSteam的cpp FILE(GLOB src_xsteam "${PROJECT_SOURCE_DIR}/src/*.cpp" "${PROJECT_SOURCE_DIR}/src/*.h") diff --git a/src/main.cpp b/src/main.cpp index 9fc3e2e..7be71ec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,10 +2,9 @@ #include "xsteam_ui.h" #include #include "xsteam_base_ex.h" - int main(int argc, char *argv[]) { - qputenv("QT_QPA_PLATFORM","windows:fontengine=freetype"); + qputenv("QT_QPA_PLATFORM", "windows:fontengine=freetype"); QApplication a(argc, argv); QTranslator qtBaseTranslator; if (!qtBaseTranslator.load(QStringLiteral(":/res/translator/qtbase_zh_CN.qm"))) @@ -18,11 +17,10 @@ int main(int argc, char *argv[]) xsteam_init_opts(); xsteam_ui x; x.xsteam_init_layout(); - //仅限于windows平台 + // 仅限于windows平台 #if defined(__WIN32__) x.title()->set_type(QD_TYPE::QD_EXIT); #endif - x.title()->set_font_style(); x.show(); return a.exec(); } diff --git a/src/sui_sys_style.cpp b/src/sui_sys_style.cpp index 08c425c..d6bc6ec 100644 --- a/src/sui_sys_style.cpp +++ b/src/sui_sys_style.cpp @@ -18,11 +18,11 @@ void sui_sys_style::slots_sys_style_thread() //判断当前临时isDark状态是否和系统主题一致&不一致则更新当前软件主题 if (cDark != QGuiApplication::styleHints()->colorScheme()) { - int style; + bool style; if(QGuiApplication::styleHints()->colorScheme()==Qt::ColorScheme::Light){ - style=1; + style=true; }else if(QGuiApplication::styleHints()->colorScheme()==Qt::ColorScheme::Dark){ - style=0; + style=false; } emit signals_sys_style_change(style); cDark = QGuiApplication::styleHints()->colorScheme(); diff --git a/src/sui_sys_style.h b/src/sui_sys_style.h index cf7cae4..307ba65 100644 --- a/src/sui_sys_style.h +++ b/src/sui_sys_style.h @@ -16,6 +16,6 @@ public: public slots: void slots_sys_style_thread(); signals: - void signals_sys_style_change(int); + void signals_sys_style_change(bool); }; #endif \ No newline at end of file diff --git a/src/sui_title.cpp b/src/sui_title.cpp index c34aaf3..366b686 100644 --- a/src/sui_title.cpp +++ b/src/sui_title.cpp @@ -10,7 +10,7 @@ sui_title::sui_title(QWidget *parent) setObjectName(tr("sui_title")); for (int i = 0; i <= m_btn_obj_str.count() - 1; i++) { - QPushButton *btn=new QPushButton(this); + QPushButton *btn = new QPushButton(this); btn->setAutoFillBackground(true); btn->setFlat(true); btn->setObjectName(m_btn_obj_str[i]); @@ -76,7 +76,7 @@ void sui_title::btn_ico_menu() } else { - connect(s_Action, SIGNAL(triggered(bool)), this, SLOT(slots_set_style_change())); + connect(s_Action, SIGNAL(triggered(bool)), this, SLOT(slots_change_style())); } if (i == _data.x_config.style) { @@ -95,7 +95,7 @@ void sui_title::btn_ico_menu() { t_action->setChecked(true); } - connect(t_action, SIGNAL(triggered(bool)), this, SLOT(slots_style_system())); + connect(t_action, SIGNAL(triggered(bool)), this, SLOT(slots_style_system(bool))); s_menu->addAction(t_action); } // 字体 @@ -112,7 +112,7 @@ void sui_title::btn_ico_menu() { f_Action->setChecked(true); } - connect(f_Action, SIGNAL(triggered(bool)), this, SLOT(slots_set_font_change())); + connect(f_Action, SIGNAL(triggered(bool)), this, SLOT(slots_change_font())); f_menu->addAction(f_Action); } QAction *separator = new QAction(nullptr); @@ -126,7 +126,7 @@ void sui_title::btn_ico_menu() { b_Action->setChecked(true); } - connect(b_Action, SIGNAL(triggered(bool)), this, SLOT(slots_set_font_change())); + connect(b_Action, SIGNAL(triggered(bool)), this, SLOT(slots_change_font_bold(bool))); f_menu->addAction(b_Action); } m_menu->addMenu(s_menu); @@ -139,94 +139,69 @@ void sui_title::btn_ico_menu() s_menu = nullptr; f_menu = nullptr; } -void sui_title::slots_style_system() +void sui_title::slots_style_system(bool state) +{ + if (_data.x_config.style_system==1) + { + _data.x_config.style_system = 0; + m_style->state = 0; + } + else + { + _data.x_config.style_system = 1; + m_style->state = 1; + } +} +void sui_title::slots_change_font_bold(bool state) +{ + if (_data.x_config.font_bold) + { + _data.x_config.font_bold = 0; + } + else + { + _data.x_config.font_bold = 1; + } + init_font_style(); +} +void sui_title::slots_change_font() { if (sender() != nullptr) { - if (_data.x_config.style_system != 0) - { - _data.x_config.style_system = 0; - m_style->state = _data.x_config.style_system; - ((QAction *)sender())->setChecked(false); - } - else - { - _data.x_config.style_system = 1; - m_style->state = _data.x_config.style_system; - ((QAction *)sender())->setChecked(true); - } + _data.x_config.font = sender()->objectName().toInt(); } + init_font_style(); } -void sui_title::set_font_style() -{ - slots_set_font_change(); - slots_set_style_change(); -} -void sui_title::slots_set_style_change() +void sui_title::slots_change_style() { if (sender() != nullptr) { _data.x_config.style = sender()->objectName().toInt(); } - change_style(_data.x_config.style); + init_font_style(); } -void sui_title::slots_set_font_change() + +void sui_title::init_font_style() { - if (sender() != nullptr) + QString style; + QString qss_font = "QWidget { "; + qss_font.append("font-family: '" + font_table[_data.x_config.font] + "';"); + if (_data.x_config.font_bold) { - if (sender()->objectName() == "font_bold") - { - if (_data.x_config.font_bold) - { - _data.x_config.font_bold = 0; - ((QAction *)sender())->setChecked(false); - } - else - { - _data.x_config.font_bold = 1; - ((QAction *)sender())->setChecked(true); - } - } - else - { - _data.x_config.font = sender()->objectName().toInt(); - } + qss_font.append("font-weight: bold;"); } - QFont font; - if (!font_table[_data.x_config.font].isEmpty()) - { - font.setFamily(font_table[_data.x_config.font]); - font.setPointSize(10); - if (_data.x_config.font_bold) - { - font.setBold(true); - } - else - { - font.setBold(false); - } - QApplication::setFont(font); - } - else - { - qDebug() << "Failed to load font."; - } - change_style(_data.x_config.style); -} -void sui_title::change_style(int index) -{ - _data.x_config.style = index; - QString style = tr(":/res/qss/") + style_table[index]; - QFile qss(style); + qss_font.append("}"); + + QString style_file = tr(":/res/qss/") + style_table[_data.x_config.style]; + QFile qss(style_file); if (qss.open(QFile::ReadOnly)) { - QString _styleSheet = QLatin1String(qss.readAll()); - m_parent->setStyleSheet(""); - m_parent->setStyleSheet(_styleSheet); - // QApplication::setStyle("Fusion"); + style= QLatin1String(qss.readAll()); + style.append(qss_font); } qss.close(); - // m_parent->update(); + QApplication *main_app = static_cast(QCoreApplication::instance()); + main_app->setStyleSheet(style); } // 双击标题栏进行界面的最大化/还原 @@ -292,14 +267,14 @@ void sui_title::up_maximize() void sui_title::set_type(QD_TYPE _type) { m_type = _type; - if (m_type==QD_TYPE::QD_EXIT) + if (m_type == QD_TYPE::QD_EXIT) { - // 启动系统主题监听线程 + // 启动系统主题监听线程 m_style = new sui_sys_style(); + m_style->state = _data.x_config.style_system; m_thread = new QThread(); m_style->moveToThread(m_thread); - m_style->state = _data.x_config.style_system; - connect(m_style, SIGNAL(signals_sys_style_change(int)), this, SLOT(change_style(int))); + connect(m_style, SIGNAL(signals_sys_style_change(bool)), this, SLOT(slots_style_system(bool))); connect(m_thread, SIGNAL(started()), m_style, SLOT(slots_sys_style_thread())); m_thread->start(); } @@ -309,6 +284,7 @@ void sui_title::set_type(QD_TYPE _type) m_btn_vectors[1]->setVisible(false); m_btn_vectors[2]->setVisible(false); } + init_font_style(); } void sui_title::set_title(QString str) { diff --git a/src/sui_title.h b/src/sui_title.h index 648145b..722daf8 100644 --- a/src/sui_title.h +++ b/src/sui_title.h @@ -36,7 +36,6 @@ public: ~sui_title(); void set_title(QString str); void set_type(QD_TYPE _type); - void set_font_style(); protected: //双击标题栏进行界面的最大化/还原 void mouseDoubleClickEvent(QMouseEvent *event); @@ -45,6 +44,7 @@ private: void up_maximize(); void connect_slots(); void btn_ico_menu(); + void init_font_style(); private: QWidget *m_parent; QHBoxLayout *m_layout; @@ -60,11 +60,11 @@ private: QStringList m_btn_obj_str={"btn_opt","btn_min","btn_max","btn_close"}; QStringList m_btn_tips_str={"功能","最小化","最大化","关闭"}; public slots: - void slots_on_clicked(); - void slots_set_style_change(); - void slots_set_font_change(); - void slots_style_system(); - void change_style(int); + void slots_on_clicked(); + void slots_change_font(); + void slots_change_style(); + void slots_change_font_bold(bool); + void slots_style_system(bool); signals: void signals_close(); }; diff --git a/src/xsteam_ex.cpp b/src/xsteam_ex.cpp index a4ae460..e955038 100644 --- a/src/xsteam_ex.cpp +++ b/src/xsteam_ex.cpp @@ -21,9 +21,13 @@ void xsteam_init_opts() } } QFontDatabase database; + QString temp_family_name; foreach (const QString &family, database.families(QFontDatabase::SimplifiedChinese)) { - font_table.append(family); + if(temp_family_name!=family){ + font_table.append(family); + temp_family_name=family; + } } QDir *styleDir = new QDir(":/res/qss/"); style_table = styleDir->entryList(QDir::Files); diff --git a/src/xsteam_ui.cpp b/src/xsteam_ui.cpp index 004b294..f8b3e08 100644 --- a/src/xsteam_ui.cpp +++ b/src/xsteam_ui.cpp @@ -508,7 +508,6 @@ void xsteam_ui::slots_open_server_edit() xs_src_edit_ui->setMaximumSize(width(), height()- 30); xs_src_edit_ui->setGeometry(geometry()); connect(xs_src_edit_ui, SIGNAL(signals_update()), this, SLOT(slots_server_combobox_load_data())); - xs_src_edit_ui->title()->set_font_style(); xs_src_edit_ui->show(); } } @@ -519,7 +518,6 @@ void xsteam_ui::slots_open_update() { xs_update_ui->setMaximumSize(width() / 2, height()); xs_update_ui->setGeometry(geometry()); - xs_update_ui->title()->set_font_style(); xs_update_ui->show(); } } @@ -530,7 +528,6 @@ void xsteam_ui::slots_open_setting() { xs_sets_ui->setMaximumSize(width(), height()- 30); xs_sets_ui->setGeometry(geometry()); - xs_sets_ui->title()->set_font_style(); xs_sets_ui->show(); } } @@ -541,7 +538,6 @@ void xsteam_ui::slots_open_about() { xs_about_ui->setMaximumSize(width() / 2, height()); xs_about_ui->setGeometry(geometry()); - xs_about_ui->title()->set_font_style(); xs_about_ui->show(); } }