解耦sui框架的部分设置
This commit is contained in:
parent
bb6266fd1b
commit
9e4ce3fe4e
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -111,7 +111,10 @@
|
|||||||
"qabstractlistmodel": "cpp",
|
"qabstractlistmodel": "cpp",
|
||||||
"qtconcurrentrun": "cpp",
|
"qtconcurrentrun": "cpp",
|
||||||
"*.in": "cpp",
|
"*.in": "cpp",
|
||||||
"qactiongroup": "cpp"
|
"qactiongroup": "cpp",
|
||||||
|
"qprocess": "cpp",
|
||||||
|
"qmessagebox": "cpp",
|
||||||
|
"qdatetime": "cpp"
|
||||||
},
|
},
|
||||||
"Codegeex.RepoIndex": true,
|
"Codegeex.RepoIndex": true,
|
||||||
"editor.gotoLocation.alternativeDeclarationCommand": "editor.action.revealDefinition",
|
"editor.gotoLocation.alternativeDeclarationCommand": "editor.action.revealDefinition",
|
||||||
|
@ -52,7 +52,9 @@ else()
|
|||||||
SET(QT_DIR "D:/Dev/Qt/6.8.0/mingw1310_static_x64/lib/cmake")
|
SET(QT_DIR "D:/Dev/Qt/6.8.0/mingw1310_static_x64/lib/cmake")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
#JSON库
|
||||||
SET(JSON ${PROJECT_SOURCE_DIR}/3rdparty/json)
|
SET(JSON ${PROJECT_SOURCE_DIR}/3rdparty/json)
|
||||||
|
include_directories(${JSON}/include)
|
||||||
|
|
||||||
LIST(APPEND CMAKE_PREFIX_PATH ${QT_DIR} ${MSYS})
|
LIST(APPEND CMAKE_PREFIX_PATH ${QT_DIR} ${MSYS})
|
||||||
|
|
||||||
@ -105,9 +107,6 @@ else()
|
|||||||
message(STATUS "CURL_FOUND=NOT")
|
message(STATUS "CURL_FOUND=NOT")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
#JSON库
|
|
||||||
include_directories(${JSON}/include)
|
|
||||||
|
|
||||||
#增加XSteam的cpp
|
#增加XSteam的cpp
|
||||||
FILE(GLOB src_xsteam "${PROJECT_SOURCE_DIR}/src/*.cpp" "${PROJECT_SOURCE_DIR}/src/*.h")
|
FILE(GLOB src_xsteam "${PROJECT_SOURCE_DIR}/src/*.cpp" "${PROJECT_SOURCE_DIR}/src/*.h")
|
||||||
|
|
||||||
|
@ -2,10 +2,9 @@
|
|||||||
#include "xsteam_ui.h"
|
#include "xsteam_ui.h"
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
#include "xsteam_base_ex.h"
|
#include "xsteam_base_ex.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
qputenv("QT_QPA_PLATFORM","windows:fontengine=freetype");
|
qputenv("QT_QPA_PLATFORM", "windows:fontengine=freetype");
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
QTranslator qtBaseTranslator;
|
QTranslator qtBaseTranslator;
|
||||||
if (!qtBaseTranslator.load(QStringLiteral(":/res/translator/qtbase_zh_CN.qm")))
|
if (!qtBaseTranslator.load(QStringLiteral(":/res/translator/qtbase_zh_CN.qm")))
|
||||||
@ -18,11 +17,10 @@ int main(int argc, char *argv[])
|
|||||||
xsteam_init_opts();
|
xsteam_init_opts();
|
||||||
xsteam_ui x;
|
xsteam_ui x;
|
||||||
x.xsteam_init_layout();
|
x.xsteam_init_layout();
|
||||||
//仅限于windows平台
|
// 仅限于windows平台
|
||||||
#if defined(__WIN32__)
|
#if defined(__WIN32__)
|
||||||
x.title()->set_type(QD_TYPE::QD_EXIT);
|
x.title()->set_type(QD_TYPE::QD_EXIT);
|
||||||
#endif
|
#endif
|
||||||
x.title()->set_font_style();
|
|
||||||
x.show();
|
x.show();
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,11 @@ void sui_sys_style::slots_sys_style_thread()
|
|||||||
//判断当前临时isDark状态是否和系统主题一致&不一致则更新当前软件主题
|
//判断当前临时isDark状态是否和系统主题一致&不一致则更新当前软件主题
|
||||||
if (cDark != QGuiApplication::styleHints()->colorScheme())
|
if (cDark != QGuiApplication::styleHints()->colorScheme())
|
||||||
{
|
{
|
||||||
int style;
|
bool style;
|
||||||
if(QGuiApplication::styleHints()->colorScheme()==Qt::ColorScheme::Light){
|
if(QGuiApplication::styleHints()->colorScheme()==Qt::ColorScheme::Light){
|
||||||
style=1;
|
style=true;
|
||||||
}else if(QGuiApplication::styleHints()->colorScheme()==Qt::ColorScheme::Dark){
|
}else if(QGuiApplication::styleHints()->colorScheme()==Qt::ColorScheme::Dark){
|
||||||
style=0;
|
style=false;
|
||||||
}
|
}
|
||||||
emit signals_sys_style_change(style);
|
emit signals_sys_style_change(style);
|
||||||
cDark = QGuiApplication::styleHints()->colorScheme();
|
cDark = QGuiApplication::styleHints()->colorScheme();
|
||||||
|
@ -16,6 +16,6 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void slots_sys_style_thread();
|
void slots_sys_style_thread();
|
||||||
signals:
|
signals:
|
||||||
void signals_sys_style_change(int);
|
void signals_sys_style_change(bool);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
@ -10,7 +10,7 @@ sui_title::sui_title(QWidget *parent)
|
|||||||
setObjectName(tr("sui_title"));
|
setObjectName(tr("sui_title"));
|
||||||
for (int i = 0; i <= m_btn_obj_str.count() - 1; i++)
|
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->setAutoFillBackground(true);
|
||||||
btn->setFlat(true);
|
btn->setFlat(true);
|
||||||
btn->setObjectName(m_btn_obj_str[i]);
|
btn->setObjectName(m_btn_obj_str[i]);
|
||||||
@ -76,7 +76,7 @@ void sui_title::btn_ico_menu()
|
|||||||
}
|
}
|
||||||
else
|
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)
|
if (i == _data.x_config.style)
|
||||||
{
|
{
|
||||||
@ -95,7 +95,7 @@ void sui_title::btn_ico_menu()
|
|||||||
{
|
{
|
||||||
t_action->setChecked(true);
|
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);
|
s_menu->addAction(t_action);
|
||||||
}
|
}
|
||||||
// 字体
|
// 字体
|
||||||
@ -112,7 +112,7 @@ void sui_title::btn_ico_menu()
|
|||||||
{
|
{
|
||||||
f_Action->setChecked(true);
|
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);
|
f_menu->addAction(f_Action);
|
||||||
}
|
}
|
||||||
QAction *separator = new QAction(nullptr);
|
QAction *separator = new QAction(nullptr);
|
||||||
@ -126,7 +126,7 @@ void sui_title::btn_ico_menu()
|
|||||||
{
|
{
|
||||||
b_Action->setChecked(true);
|
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);
|
f_menu->addAction(b_Action);
|
||||||
}
|
}
|
||||||
m_menu->addMenu(s_menu);
|
m_menu->addMenu(s_menu);
|
||||||
@ -139,94 +139,69 @@ void sui_title::btn_ico_menu()
|
|||||||
s_menu = nullptr;
|
s_menu = nullptr;
|
||||||
f_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 (sender() != nullptr)
|
||||||
{
|
{
|
||||||
if (_data.x_config.style_system != 0)
|
_data.x_config.font = sender()->objectName().toInt();
|
||||||
{
|
|
||||||
_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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
init_font_style();
|
||||||
}
|
}
|
||||||
void sui_title::set_font_style()
|
void sui_title::slots_change_style()
|
||||||
{
|
|
||||||
slots_set_font_change();
|
|
||||||
slots_set_style_change();
|
|
||||||
}
|
|
||||||
void sui_title::slots_set_style_change()
|
|
||||||
{
|
{
|
||||||
if (sender() != nullptr)
|
if (sender() != nullptr)
|
||||||
{
|
{
|
||||||
_data.x_config.style = sender()->objectName().toInt();
|
_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")
|
qss_font.append("font-weight: 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
QFont font;
|
qss_font.append("}");
|
||||||
if (!font_table[_data.x_config.font].isEmpty())
|
|
||||||
{
|
QString style_file = tr(":/res/qss/") + style_table[_data.x_config.style];
|
||||||
font.setFamily(font_table[_data.x_config.font]);
|
QFile qss(style_file);
|
||||||
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);
|
|
||||||
if (qss.open(QFile::ReadOnly))
|
if (qss.open(QFile::ReadOnly))
|
||||||
{
|
{
|
||||||
QString _styleSheet = QLatin1String(qss.readAll());
|
style= QLatin1String(qss.readAll());
|
||||||
m_parent->setStyleSheet("");
|
style.append(qss_font);
|
||||||
m_parent->setStyleSheet(_styleSheet);
|
|
||||||
// QApplication::setStyle("Fusion");
|
|
||||||
}
|
}
|
||||||
qss.close();
|
qss.close();
|
||||||
// m_parent->update();
|
QApplication *main_app = static_cast<QApplication *>(QCoreApplication::instance());
|
||||||
|
main_app->setStyleSheet(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 双击标题栏进行界面的最大化/还原
|
// 双击标题栏进行界面的最大化/还原
|
||||||
@ -292,14 +267,14 @@ void sui_title::up_maximize()
|
|||||||
void sui_title::set_type(QD_TYPE _type)
|
void sui_title::set_type(QD_TYPE _type)
|
||||||
{
|
{
|
||||||
m_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 = new sui_sys_style();
|
||||||
|
m_style->state = _data.x_config.style_system;
|
||||||
m_thread = new QThread();
|
m_thread = new QThread();
|
||||||
m_style->moveToThread(m_thread);
|
m_style->moveToThread(m_thread);
|
||||||
m_style->state = _data.x_config.style_system;
|
connect(m_style, SIGNAL(signals_sys_style_change(bool)), this, SLOT(slots_style_system(bool)));
|
||||||
connect(m_style, SIGNAL(signals_sys_style_change(int)), this, SLOT(change_style(int)));
|
|
||||||
connect(m_thread, SIGNAL(started()), m_style, SLOT(slots_sys_style_thread()));
|
connect(m_thread, SIGNAL(started()), m_style, SLOT(slots_sys_style_thread()));
|
||||||
m_thread->start();
|
m_thread->start();
|
||||||
}
|
}
|
||||||
@ -309,6 +284,7 @@ void sui_title::set_type(QD_TYPE _type)
|
|||||||
m_btn_vectors[1]->setVisible(false);
|
m_btn_vectors[1]->setVisible(false);
|
||||||
m_btn_vectors[2]->setVisible(false);
|
m_btn_vectors[2]->setVisible(false);
|
||||||
}
|
}
|
||||||
|
init_font_style();
|
||||||
}
|
}
|
||||||
void sui_title::set_title(QString str)
|
void sui_title::set_title(QString str)
|
||||||
{
|
{
|
||||||
|
@ -36,7 +36,6 @@ public:
|
|||||||
~sui_title();
|
~sui_title();
|
||||||
void set_title(QString str);
|
void set_title(QString str);
|
||||||
void set_type(QD_TYPE _type);
|
void set_type(QD_TYPE _type);
|
||||||
void set_font_style();
|
|
||||||
protected:
|
protected:
|
||||||
//双击标题栏进行界面的最大化/还原
|
//双击标题栏进行界面的最大化/还原
|
||||||
void mouseDoubleClickEvent(QMouseEvent *event);
|
void mouseDoubleClickEvent(QMouseEvent *event);
|
||||||
@ -45,6 +44,7 @@ private:
|
|||||||
void up_maximize();
|
void up_maximize();
|
||||||
void connect_slots();
|
void connect_slots();
|
||||||
void btn_ico_menu();
|
void btn_ico_menu();
|
||||||
|
void init_font_style();
|
||||||
private:
|
private:
|
||||||
QWidget *m_parent;
|
QWidget *m_parent;
|
||||||
QHBoxLayout *m_layout;
|
QHBoxLayout *m_layout;
|
||||||
@ -60,11 +60,11 @@ private:
|
|||||||
QStringList m_btn_obj_str={"btn_opt","btn_min","btn_max","btn_close"};
|
QStringList m_btn_obj_str={"btn_opt","btn_min","btn_max","btn_close"};
|
||||||
QStringList m_btn_tips_str={"功能","最小化","最大化","关闭"};
|
QStringList m_btn_tips_str={"功能","最小化","最大化","关闭"};
|
||||||
public slots:
|
public slots:
|
||||||
void slots_on_clicked();
|
void slots_on_clicked();
|
||||||
void slots_set_style_change();
|
void slots_change_font();
|
||||||
void slots_set_font_change();
|
void slots_change_style();
|
||||||
void slots_style_system();
|
void slots_change_font_bold(bool);
|
||||||
void change_style(int);
|
void slots_style_system(bool);
|
||||||
signals:
|
signals:
|
||||||
void signals_close();
|
void signals_close();
|
||||||
};
|
};
|
||||||
|
@ -21,9 +21,13 @@ void xsteam_init_opts()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
QFontDatabase database;
|
QFontDatabase database;
|
||||||
|
QString temp_family_name;
|
||||||
foreach (const QString &family, database.families(QFontDatabase::SimplifiedChinese))
|
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/");
|
QDir *styleDir = new QDir(":/res/qss/");
|
||||||
style_table = styleDir->entryList(QDir::Files);
|
style_table = styleDir->entryList(QDir::Files);
|
||||||
|
@ -508,7 +508,6 @@ void xsteam_ui::slots_open_server_edit()
|
|||||||
xs_src_edit_ui->setMaximumSize(width(), height()- 30);
|
xs_src_edit_ui->setMaximumSize(width(), height()- 30);
|
||||||
xs_src_edit_ui->setGeometry(geometry());
|
xs_src_edit_ui->setGeometry(geometry());
|
||||||
connect(xs_src_edit_ui, SIGNAL(signals_update()), this, SLOT(slots_server_combobox_load_data()));
|
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();
|
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->setMaximumSize(width() / 2, height());
|
||||||
xs_update_ui->setGeometry(geometry());
|
xs_update_ui->setGeometry(geometry());
|
||||||
xs_update_ui->title()->set_font_style();
|
|
||||||
xs_update_ui->show();
|
xs_update_ui->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -530,7 +528,6 @@ void xsteam_ui::slots_open_setting()
|
|||||||
{
|
{
|
||||||
xs_sets_ui->setMaximumSize(width(), height()- 30);
|
xs_sets_ui->setMaximumSize(width(), height()- 30);
|
||||||
xs_sets_ui->setGeometry(geometry());
|
xs_sets_ui->setGeometry(geometry());
|
||||||
xs_sets_ui->title()->set_font_style();
|
|
||||||
xs_sets_ui->show();
|
xs_sets_ui->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -541,7 +538,6 @@ void xsteam_ui::slots_open_about()
|
|||||||
{
|
{
|
||||||
xs_about_ui->setMaximumSize(width() / 2, height());
|
xs_about_ui->setMaximumSize(width() / 2, height());
|
||||||
xs_about_ui->setGeometry(geometry());
|
xs_about_ui->setGeometry(geometry());
|
||||||
xs_about_ui->title()->set_font_style();
|
|
||||||
xs_about_ui->show();
|
xs_about_ui->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user