更新部分样式

增加样式同系统深浅色保持同步
This commit is contained in:
JackLee_CN 2024-11-03 19:18:41 +08:00
parent 8ac8985bd4
commit 04aafbe408
22 changed files with 230 additions and 80 deletions

View File

@ -3,6 +3,7 @@
<file>res/img/btn/btn_setting.png</file>
<file>res/img/btn/btn_about.png</file>
<file>res/img/btn/btn_update.png</file>
<file>res/img/btn/btn_download.png</file>
<file>res/img/btn/net_ok.png</file>
<file>res/img/btn/net_error.png</file>
<file>res/img/btn/net_wait.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 439 B

View File

@ -12,6 +12,11 @@ QLabel{
color:#F2F2F2;
}
QPushButton#BTN_DOWNLOAD{
width:25px;
height:25px;
image:url(":/res/img/btn/btn_download.png");
}
QPushButton#BTN_SETS{
width:25px;
height:25px;

View File

@ -1,7 +1,3 @@
QWidget#m_widget{
background-color: #F3F3F3;
color:#2F4F4F;
}
QWidget#m_widget{
border-radius:10px;
background-color: #F3F3F3;
@ -22,6 +18,11 @@ QPushButton:hover{
padding-top:1px;
}
QPushButton#BTN_DOWNLOAD{
width:25px;
height:25px;
image:url(":/res/img/btn/btn_download.png");
}
QPushButton#BTN_SETS{
width:25px;
height:25px;

View File

@ -18,6 +18,10 @@ int main(int argc, char *argv[])
xsteam_init_opts();
xsteam_ui x;
x.xsteam_init_layout();
//仅限于windows平台
#if defined(__WIN32__)
x.title()->set_type(QD_TYPE::QD_EXIT);
#endif
x.show();
return a.exec();
}

View File

@ -1,6 +1,6 @@
#include "sui.h"
sui::sui(QDialog *parent)
: QDialog(parent),
sui::sui(QWidget *parent)
: QWidget(parent),
m_widget(new QDialog),
m_layout(new QVBoxLayout),
m_press(false),

View File

@ -9,11 +9,11 @@
#pragma execution_character_set("utf-8")
#endif
#include "sui_title.h"
class sui : public QDialog
class sui : public QWidget
{
Q_OBJECT
public:
explicit sui(QDialog *parent = 0);
explicit sui(QWidget *parent = 0);
~sui();
sui_title* title() { return m_title; }
private:

30
src/sui_sys_style.cpp Normal file
View File

@ -0,0 +1,30 @@
#include "sui_sys_style.h"
sui_sys_style::sui_sys_style(QObject *parent) : QObject(parent)
{
}
sui_sys_style::~sui_sys_style()
{
}
void sui_sys_style::slots_sys_style_thread()
{
//获取系统注册表信息
QSettings style_set(QSettings::UserScope, "Microsoft", "Windows\\CurrentVersion\\Themes\\Personalize");
//当前系统主题状态,默认0-深色主题,1-浅色主题
bool isDark=true;
while (true)
{
//跟随功能是否开启,0-关闭,1-开启 采用bool类型
if (state)
{
//判断当前临时isDark状态是否和系统主题一致&不一致则更新当前软件主题
if (isDark != !style_set.value("AppsUseLightTheme").toBool())
{
emit signals_sys_style_change(!style_set.value("AppsUseLightTheme").toInt());
isDark = !style_set.value("AppsUseLightTheme").toBool();
}
}
//刷新间隔5秒
QThread::sleep(5);
}
}

20
src/sui_sys_style.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef SUI_SYS_STYLE_H
#define SUI_SYS_STYLE_H
#include<QObject>
#include<QThread>
#include<QSettings>
class sui_sys_style:public QObject
{
Q_OBJECT
public:
explicit sui_sys_style(QObject *parent = nullptr);
~sui_sys_style();
bool state;
public slots:
void slots_sys_style_thread();
signals:
void signals_sys_style_change(int);
};
#endif

View File

@ -3,10 +3,10 @@ sui_title::sui_title(QWidget *parent)
: QWidget(parent),
m_menu(nullptr),
s_menu(nullptr),
f_menu(nullptr)
f_menu(nullptr),
m_type(QD_TYPE::QD_EXIT)
{
m_parent = parent;
m_type = QD_TYPE::QD_EXIT;
// 给成员变量申请内存
m_icon_button = new QPushButton(/*this*/);
m_min_button = new QPushButton(this);
@ -65,25 +65,12 @@ sui_title::sui_title(QWidget *parent)
}
sui_title::~sui_title()
{
if(m_thread){
m_thread->quit();
m_thread->exit();
}
}
void sui_title::auto_style()
{
QFuture<void> future = QtConcurrent::run([=]()
{
QSettings style_set(QSettings::UserScope, "Microsoft", "Windows\\CurrentVersion\\Themes\\Personalize");
bool isDark;
while (true)
{
isDark= !style_set.value("AppsUseLightTheme").toBool();
if(isDark){
change_style(0);
}else{
change_style(1);
}
QThread::sleep(5);
}
});
}
void sui_title::connect_slots()
{
// 连接三个按钮的信号槽3
@ -106,13 +93,33 @@ void sui_title::slots_ico_menu()
QAction *s_Action = new QAction(sName, s_QGroup);
s_Action->setObjectName(QString::number(i));
s_Action->setCheckable(true);
if (_data.x_config.style_system)
{
s_Action->setEnabled(false);
}
else
{
connect(s_Action, SIGNAL(triggered(bool)), this, SLOT(slots_set_style_change()));
}
if (i == _data.x_config.style)
{
s_Action->setChecked(true);
}
connect(s_Action, SIGNAL(triggered(bool)), this, SLOT(slots_set_style_change()));
s_menu->addAction(s_Action);
}
QAction *separator = new QAction(nullptr);
separator->setSeparator(true);
s_menu->addAction(separator);
QActionGroup *t_group = new QActionGroup(this);
QAction *t_action = new QAction("跟随系统", t_group);
t_action->setObjectName("track_system");
t_action->setCheckable(true);
if (_data.x_config.style_system)
{
t_action->setChecked(true);
}
connect(t_action, SIGNAL(triggered(bool)), this, SLOT(slots_style_system()));
s_menu->addAction(t_action);
}
// 字体
if (!f_menu)
@ -149,7 +156,29 @@ void sui_title::slots_ico_menu()
m_menu->addMenu(f_menu);
m_menu->exec(QCursor::pos());
delete m_menu;
delete s_menu;
delete f_menu;
m_menu = nullptr;
s_menu = nullptr;
f_menu = nullptr;
}
void sui_title::slots_style_system()
{
if (sender() != nullptr)
{
if (_data.x_config.style_system)
{
_data.x_config.style_system = 0;
m_style->state=0;
((QAction *)sender())->setChecked(false);
}
else
{
_data.x_config.style_system = 1;
m_style->state=1;
((QAction *)sender())->setChecked(true);
}
}
}
void sui_title::set_font_style()
{
@ -205,7 +234,6 @@ void sui_title::slots_set_font_change()
{
qDebug() << "Failed to load font.";
}
change_style(_data.x_config.style);
}
void sui_title::change_style(int index)
@ -215,12 +243,13 @@ void sui_title::change_style(int index)
QFile qss(style);
if (qss.open(QFile::ReadOnly))
{
QString styleSheet = this->styleSheet();
styleSheet += QLatin1String(qss.readAll());
m_parent->setStyleSheet(styleSheet);
QString _styleSheet = QLatin1String(qss.readAll());
m_parent->setStyleSheet("");
m_parent->setStyleSheet(_styleSheet);
QApplication::setStyle("Fusion");
}
qss.close();
m_parent->update();
//m_parent->update();
}
// 双击标题栏进行界面的最大化/还原
@ -287,7 +316,20 @@ void sui_title::up_maximize()
void sui_title::set_type(QD_TYPE _type)
{
m_type = _type;
disconnect(m_icon_button, SIGNAL(clicked(bool)), this, SLOT(slots_ico_menu()));
if (m_type)
{
//启动系统主题监听线程
m_style = new sui_sys_style();
m_thread=new QThread();
m_style->moveToThread(m_thread);
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()));
m_thread->start();
}
else
{
disconnect(m_icon_button, SIGNAL(clicked(bool)), this, SLOT(slots_ico_menu()));
}
}
void sui_title::set_title(QString str)
{

View File

@ -19,7 +19,10 @@
#include <QStyleFactory>
#include <QtConcurrent/QtConcurrent>
#include "xsteam_ex.h"
#include "sui_sys_style.h"
//QD_CLOSE->表示子窗口状态
//QD_EXIT->表示主窗口状态
typedef enum{
QD_CLOSE,
QD_EXIT
@ -43,9 +46,7 @@ private slots:
private:
//最大化/还原
void up_maximize();
void change_style(int);
void connect_slots();
void auto_style();
private:
QWidget *m_parent;
QHBoxLayout *m_layout;
@ -59,10 +60,14 @@ private:
QMenu* s_menu;
QMenu* f_menu;
QD_TYPE m_type;
QThread* m_thread=nullptr;
sui_sys_style* m_style=nullptr;
public slots:
void slots_ico_menu();
void slots_set_style_change();
void slots_set_font_change();
void slots_style_system();
void change_style(int);
signals:
void signals_close();
};

View File

@ -25,6 +25,7 @@ public:
_instance = new xsteam_about_ui();
_instance->title()->set_type(QD_CLOSE);
_instance->title()->set_title(tr("XSteam关于"));
_instance->setWindowTitle(tr("XSteam关于"));
}
mutex.unlock();
}

View File

@ -61,6 +61,7 @@ typedef struct
typedef struct
{
int style = 0;
int style_system=0;
int font = 0;
int font_bold=0;
std::string steam_dir={};

View File

@ -23,7 +23,7 @@ QStringList ex_default_src_name = {QStringLiteral("ikun0014"),
QStringLiteral("fast_ManifestHub ")
};
QStringList ex_default_src_url = {QStringLiteral("https://github.com/ikun0014/ManifestHub"),
QStringList ex_default_src_url = {QStringLiteral("https://github.com/ikun0014/ManifestHub.git"),
QStringLiteral("https://github.com/ManifestHub/ManifestHub.git"),
QStringLiteral("https://githubfast.com/ikun0014/ManifestHub.git"),
QStringLiteral("https://githubfast.com/ManifestHub/ManifestHub.git"),

View File

@ -347,6 +347,7 @@ void xsteam_data_unserialize()
}
}
_data.x_config.style = j3.at("xsteam_sets").at("style");
_data.x_config.style_system = j3.at("xsteam_sets").at("style_system");
_data.x_config.font = j3.at("xsteam_sets").at("font");
_data.x_config.font_bold = j3.at("xsteam_sets").at("font_bold");
_data.x_config.steam_dir = j3.at("xsteam_sets").at("steam_dir");
@ -372,6 +373,7 @@ void xsteam_data_unserialize()
_data.x_config.font = 0;
_data.x_config.font_bold = 0;
_data.x_config.style = 1;
_data.x_config.style_system = 0;
QSettings settings("HKEY_CURRENT_USER\\Software\\Valve\\Steam", QSettings::NativeFormat);
_data.x_config.steam_dir = (settings.value("SteamPath", "").toString()).toStdString();
_data.x_config.steam_api_url = "https://store.steampowered.com/api/appdetails/?appids=";
@ -432,6 +434,7 @@ json xsteam_data_serialize(json jsonData)
}
jsonData[toStr(xsteam_sets)][toStr(style)] = _data.x_config.style;
jsonData[toStr(xsteam_sets)][toStr(font)] = _data.x_config.font;
jsonData[toStr(xsteam_sets)][toStr(style_system)] = _data.x_config.style_system;
jsonData[toStr(xsteam_sets)][toStr(font_bold)] = _data.x_config.font_bold;
jsonData[toStr(xsteam_sets)][toStr(steam_dir)] = _data.x_config.steam_dir;
jsonData[toStr(xsteam_sets)][toStr(steamtools_dir)] = _data.x_config.steamtools_dir;

View File

@ -29,6 +29,7 @@ public:
_instance = new xsteam_set_ui();
_instance->title()->set_type(QD_CLOSE);
_instance->title()->set_title(tr("XSteam设置"));
_instance->setWindowTitle(tr("XSteam设置"));
}
mutex.unlock();
}

View File

@ -33,6 +33,7 @@ public:
_instance = new xsteam_src_edit_ui();
_instance->title()->set_type(QD_CLOSE);
_instance->title()->set_title(tr("XSteam源地址管理"));
_instance->setWindowTitle(tr("XSteam源地址管理"));
}
mutex.unlock();
}

View File

@ -1,12 +1,12 @@
#include "xsteam_ui.h"
xsteam_ui::xsteam_ui()
{
}
xsteam_ui::~xsteam_ui()
{
}
void xsteam_ui::xsteam_init_layout(){
void xsteam_ui::xsteam_init_layout()
{
xsteam_init_info_layout();
xsteam_init_mind_layout();
xsteam_init_foot_layout();
@ -31,7 +31,7 @@ void xsteam_ui::xsteam_init_main_layout()
{
layout()->addWidget(mind_widget);
layout()->addWidget(foot_widget);
layout()->setSpacing(0);
layout()->setSpacing(2);
layout()->setContentsMargins(5, 5, 5, 5);
}
void xsteam_ui::xsteam_init_info_layout()
@ -45,13 +45,13 @@ void xsteam_ui::xsteam_init_info_layout()
}
void xsteam_ui::xsteam_init_mind_layout()
{
mind_widget=new QWidget();
mind_layout=new QVBoxLayout();
mind_widget = new QWidget();
mind_layout = new QVBoxLayout();
server_layout = new QHBoxLayout();
server_tag = new QLabel(tr("源数据:"));
server_tag->setObjectName("SRC_SERVER");
server_txt = new QComboBox();
server_state=new QLabel();
server_state = new QLabel();
btn_server_edit = new QPushButton(tr("编辑源"));
btn_server_edit->setObjectName("EDIT");
btn_fetch_src_data = new QPushButton(tr("拉取"));
@ -149,8 +149,8 @@ void xsteam_ui::xsteam_init_mind_layout()
}
void xsteam_ui::xsteam_init_foot_layout()
{
foot_widget=new QWidget();
foot_layout=new QHBoxLayout();
foot_widget = new QWidget();
foot_layout = new QHBoxLayout();
foot_status_data_layout = new QHBoxLayout();
version_tips = new QLabel(tr("version:"));
version_tips->setObjectName("VERSION_TIPS");
@ -160,6 +160,10 @@ void xsteam_ui::xsteam_init_foot_layout()
state_tips_txt->setObjectName("STATE_TIPS");
state_tips_txt->setAlignment(Qt::AlignCenter);
btn_xs_download = new QPushButton();
btn_xs_download->setMaximumSize(25, 25);
btn_xs_download->setObjectName(tr("BTN_DOWNLOAD"));
btn_xs_sets = new QPushButton();
btn_xs_sets->setMaximumSize(25, 25);
btn_xs_sets->setObjectName(tr("BTN_SETS"));
@ -179,11 +183,12 @@ void xsteam_ui::xsteam_init_foot_layout()
foot_status_data_layout->addWidget(state_tips_txt);
foot_status_data_layout->addItem(sparcer_item);
foot_status_data_layout->addWidget(btn_xs_download);
foot_status_data_layout->addWidget(btn_xs_sets);
foot_status_data_layout->addWidget(btn_xs_update);
foot_status_data_layout->addWidget(btn_xs_about);
foot_layout->addLayout(foot_status_data_layout);
foot_layout->setContentsMargins(10, 0, 10, 0);
foot_layout->setContentsMargins(5, 0, 5, 0);
foot_widget->setLayout(foot_layout);
xs_git_fetch = new xsteam_git_fetch();
}
@ -218,7 +223,7 @@ void xsteam_ui::slots_change_src_state(int index)
QPixmap xs_pixmap;
std::string url;
xs_pixmap.load(":res/img/btn/net_wait.png");
xs_pixmap = xs_pixmap.scaled(20,20,Qt::KeepAspectRatio,Qt::SmoothTransformation);
xs_pixmap = xs_pixmap.scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation);
server_state->setPixmap(xs_pixmap);
for (auto &i : _data.s_data)
{
@ -230,7 +235,8 @@ void xsteam_ui::slots_change_src_state(int index)
}
if (url != "")
{
QFuture<void> future = QtConcurrent::run([=](std::string _url,QPixmap _pixmap) {
QFuture<void> future = QtConcurrent::run([=](std::string _url, QPixmap _pixmap)
{
xsteam_curl* xs_curl=new xsteam_curl();
if(xs_curl->get_url_state(_url)){
_pixmap.load(":/res/img/btn/net_ok.png");
@ -240,8 +246,7 @@ void xsteam_ui::slots_change_src_state(int index)
_pixmap=_pixmap.scaled(20,20,Qt::KeepAspectRatio,Qt::SmoothTransformation);
server_state->setPixmap(_pixmap);
delete xs_curl;
xs_curl=nullptr;
},url,xs_pixmap);
xs_curl=nullptr; }, url, xs_pixmap);
}
}
void xsteam_ui::slots_get_uid_dlcs()
@ -485,42 +490,57 @@ void xsteam_ui::slots_run_steam_steamtools()
void xsteam_ui::slots_push_manifest()
{
xs_push_manifest = xsteam_push_manifest::Instance();
xs_push_manifest->setMaximumSize(width(),height() - 25);
xs_push_manifest->setGeometry(geometry());
xs_push_manifest->exec();
if (!xs_push_manifest->isVisible())
{
xs_push_manifest->setMaximumSize(width(), height() - 25);
xs_push_manifest->setGeometry(geometry());
xs_push_manifest->show();
}
}
void xsteam_ui::slots_open_server_edit()
{
xs_src_edit_ui = xsteam_src_edit_ui::Instance();
xs_src_edit_ui->setMaximumSize(width(), height());
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->exec();
if (!xs_src_edit_ui->isVisible())
{
xs_src_edit_ui->setMaximumSize(width(), height());
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();
}
}
void xsteam_ui::slots_open_update()
{
xs_update_ui = xsteam_update_ui::Instance();
xs_update_ui->setMaximumSize(width()/2, height());
xs_update_ui->setGeometry(geometry());
xs_update_ui->title()->set_font_style();
xs_update_ui->exec();
if (!xs_update_ui->isVisible())
{
xs_update_ui->setMaximumSize(width() / 2, height());
xs_update_ui->setGeometry(geometry());
xs_update_ui->title()->set_font_style();
xs_update_ui->show();
}
}
void xsteam_ui::slots_open_setting()
{
xs_sets_ui = xsteam_set_ui::Instance();
xs_sets_ui->setMaximumSize(width(), height());
xs_sets_ui->setGeometry(geometry());
xs_sets_ui->title()->set_font_style();
xs_sets_ui->exec();
if (!xs_sets_ui->isVisible())
{
xs_sets_ui->setMaximumSize(width(), height());
xs_sets_ui->setGeometry(geometry());
xs_sets_ui->title()->set_font_style();
xs_sets_ui->show();
}
}
void xsteam_ui::slots_open_about()
{
xs_about_ui = xsteam_about_ui::Instance();
xs_about_ui->setMaximumSize(width()/2, height());
xs_about_ui->setGeometry(geometry());
xs_about_ui->title()->set_font_style();
xs_about_ui->exec();
if (!xs_about_ui->isVisible())
{
xs_about_ui->setMaximumSize(width() / 2, height());
xs_about_ui->setGeometry(geometry());
xs_about_ui->title()->set_font_style();
xs_about_ui->show();
}
}
void xsteam_ui::slots_table_append(UidData u_data)

View File

@ -80,9 +80,11 @@ private:
QLabel* version_tips;
QLabel* version_tips_txt;
QLabel* state_tips_txt;
QPushButton* btn_xs_download;
QPushButton* btn_xs_sets;
QPushButton* btn_xs_update;
QPushButton* btn_xs_about;
xsteam_src_edit_ui* xs_src_edit_ui;
xsteam_set_ui * xs_sets_ui;
xsteam_about_ui* xs_about_ui;

View File

@ -24,6 +24,7 @@ public:
_instance = new xsteam_update_ui();
_instance->title()->set_type(QD_CLOSE);
_instance->title()->set_title(tr("XSteam更新"));
_instance->setWindowTitle(tr("XSteam更新"));
}
mutex.unlock();
}

12
vcpkg1.json Normal file
View File

@ -0,0 +1,12 @@
{
"dependencies": [
{
"name":"curl",
"version>=":"8.10.1"
},
{
"name":"libgit2",
"version>=":"1.8.0"
}
]
}