解耦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",
|
||||
"qtconcurrentrun": "cpp",
|
||||
"*.in": "cpp",
|
||||
"qactiongroup": "cpp"
|
||||
"qactiongroup": "cpp",
|
||||
"qprocess": "cpp",
|
||||
"qmessagebox": "cpp",
|
||||
"qdatetime": "cpp"
|
||||
},
|
||||
"Codegeex.RepoIndex": true,
|
||||
"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")
|
||||
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")
|
||||
|
||||
|
@ -2,10 +2,9 @@
|
||||
#include "xsteam_ui.h"
|
||||
#include <QTranslator>
|
||||
#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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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
|
@ -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 (sender() != nullptr)
|
||||
{
|
||||
if (_data.x_config.style_system != 0)
|
||||
if (_data.x_config.style_system==1)
|
||||
{
|
||||
_data.x_config.style_system = 0;
|
||||
m_style->state = _data.x_config.style_system;
|
||||
((QAction *)sender())->setChecked(false);
|
||||
m_style->state = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_data.x_config.style_system = 1;
|
||||
m_style->state = _data.x_config.style_system;
|
||||
((QAction *)sender())->setChecked(true);
|
||||
}
|
||||
m_style->state = 1;
|
||||
}
|
||||
}
|
||||
void sui_title::set_font_style()
|
||||
void sui_title::slots_change_font_bold(bool state)
|
||||
{
|
||||
slots_set_font_change();
|
||||
slots_set_style_change();
|
||||
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_set_style_change()
|
||||
void sui_title::slots_change_font()
|
||||
{
|
||||
if (sender() != nullptr)
|
||||
{
|
||||
_data.x_config.font = sender()->objectName().toInt();
|
||||
}
|
||||
init_font_style();
|
||||
}
|
||||
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)
|
||||
{
|
||||
if (sender()->objectName() == "font_bold")
|
||||
{
|
||||
QString style;
|
||||
QString qss_font = "QWidget { ";
|
||||
qss_font.append("font-family: '" + font_table[_data.x_config.font] + "';");
|
||||
if (_data.x_config.font_bold)
|
||||
{
|
||||
_data.x_config.font_bold = 0;
|
||||
((QAction *)sender())->setChecked(false);
|
||||
qss_font.append("font-weight: bold;");
|
||||
}
|
||||
else
|
||||
{
|
||||
_data.x_config.font_bold = 1;
|
||||
((QAction *)sender())->setChecked(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_data.x_config.font = sender()->objectName().toInt();
|
||||
}
|
||||
}
|
||||
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<QApplication *>(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)
|
||||
{
|
||||
|
@ -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;
|
||||
@ -61,10 +61,10 @@ private:
|
||||
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_change_font();
|
||||
void slots_change_style();
|
||||
void slots_change_font_bold(bool);
|
||||
void slots_style_system(bool);
|
||||
signals:
|
||||
void signals_close();
|
||||
};
|
||||
|
@ -21,9 +21,13 @@ void xsteam_init_opts()
|
||||
}
|
||||
}
|
||||
QFontDatabase database;
|
||||
QString temp_family_name;
|
||||
foreach (const QString &family, database.families(QFontDatabase::SimplifiedChinese))
|
||||
{
|
||||
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);
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user