Improve Features

Support save current theme setting when exit;
Use QScreen::primaryScreen() instead of QDesktopWidget to get desktop size;
Ensure only one instance will be running at the same time.
This commit is contained in:
zty199 2021-04-20 18:49:17 +08:00
parent e5fe80cb76
commit 9a3d32ee11
5 changed files with 92 additions and 73 deletions

View File

@ -1,15 +1,15 @@
#include <DApplication>
#include <DApplicationSettings>
#include <DWidgetUtil> // Dtk::Widget::moveToCenter(&w); 要调用它,就得引用 DWidgetUtil
#include <QDesktopWidget>
#include <widget.h>
#include <QTranslator>
#include <DAboutDialog>
#include "appitem.h"
#include <QScreen>
#include "widget.h"
DWIDGET_USE_NAMESPACE
int main(int argc, char *argv[])
{
DApplication::loadDXcbPlugin(); //让bar处在标题栏中
// DApplication::loadDXcbPlugin(); // 让 bar 处在标题栏中
DApplication a(argc, argv);
a.setAttribute(Qt::AA_UseHighDpiPixmaps);
@ -52,35 +52,48 @@ int main(int argc, char *argv[])
)
);
// 限制单实例运行
if(!a.setSingleInstance("spark-store"))
{
return -1;
}
// 保存窗口主题设置
DApplicationSettings settings;
Widget w;
QDesktopWidget *s=DApplication::desktop();
int d_w=s->width();
int d_h=s->height();
if(d_w<=1366){
QScreen *s = DApplication::primaryScreen();
int d_w = s->geometry().width();
int d_h = s->geometry().height();
if(d_w <= 1366)
{
w.setMinimumWidth(925);
w.resize(925,650);
}else if(d_w<=1920){
w.setMinimumWidth(1180);
w.resize(1180,760);
}else {
}
else
{
w.setMinimumWidth(1180);
w.resize(1180,760);
}
if(d_h<=768){
if(d_h <= 768)
{
w.setMinimumHeight(650);
w.resize(925,650);
}else if(d_h<=1080){
w.setMinimumHeight(760);
w.resize(1180,760);
}else {
}
else
{
w.setMinimumHeight(760);
w.resize(1180,760);
}
QString arg1 = argv[1];
if(arg1.left(6)=="spk://"){
if(arg1.left(6)=="spk://")
{
w.openUrl(QUrl(argv[1]));
}
// 让打开时界面显示在正中
Dtk::Widget::moveToCenter(&w);

View File

@ -1,5 +1,7 @@
#include "progressload.h"
#include <DApplicationHelper>
ProgressLoad::ProgressLoad(QWidget *parent) :
QWidget(parent),
m_progess(new QWidget(this)),
@ -28,7 +30,7 @@ void ProgressLoad::setTheme(bool dark, QColor color)
{
if(dark)
{
plt.setColor(QPalette::Background, QColor(28,28,28));
plt.setColor(QPalette::Background, QColor(40, 40, 40));
setAutoFillBackground(true);
setPalette(plt);
}

View File

@ -44,8 +44,6 @@ Widget::Widget(DBlurEffectWidget *parent) :
initConfig();
manager = new QNetworkAccessManager(this); // 下载管理
m_loadweb=ui->progressload;
m_loadweb->show();
httpClient = new AeaQt::HttpClient;
downloadController = new DownloadController(this); // 并发下载
@ -68,19 +66,21 @@ Widget::Widget(DBlurEffectWidget *parent) :
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [=](DGuiApplicationHelper::ColorType themeType)
{
// 获取系统活动色
QColor main_color;
main_color = DGuiApplicationHelper::instance()->applicationPalette().highlight().color();
if(themeType == DGuiApplicationHelper::DarkType)
{
qDebug() << "Dark";
setTheme(true, main_color);
themeIsDark = true;
}
else
else if(themeType == DGuiApplicationHelper::LightType)
{
qDebug() << "Light";
setTheme(false, main_color);
themeIsDark = false;
}
// 设置 UI 主题
setTheme(themeIsDark, main_color);
});
connect(&appinfoLoadThread, SIGNAL(requestResetUi()), this, SLOT(sltAppinfoResetUi()), Qt::ConnectionType::BlockingQueuedConnection);
@ -152,7 +152,7 @@ Widget::~Widget()
void Widget::initUI()
{
// ui初始化
setMaskAlpha(220);
setMaskAlpha(200);
ui->webfoot->setFixedHeight(0);
ui->stackedWidget->setCurrentIndex(0);
ui->listWidget->hide();
@ -160,7 +160,9 @@ void Widget::initUI()
ui->pushButton_uninstall->hide();
ui->line1_widget->setStyleSheet("background-color:#808080");
ui->icon->setPixmap(QIcon::fromTheme("spark-store").pixmap(36,36));
ui->titlebar->setFixedHeight(50);
ui->titlebar->setFixedHeight(48);
m_loadweb = ui->progressload;
label_screen << ui->screen_0 << ui->screen_1 << ui->screen_2 << ui->screen_3 << ui->screen_4;
@ -196,11 +198,11 @@ void Widget::initUI()
menu->addAction(actionSubmission);
titlebar->setMenu(menu);
connect(actionSubmission, &QAction::triggered, this, [=](){QDesktopServices::openUrl(QUrl("https://upload.spark-app.store/"));});
connect(actionSubmission, &QAction::triggered, this, [=]{QDesktopServices::openUrl(QUrl("https://upload.spark-app.store/"));});
connect(setting, &QAction::triggered, this, &Widget::opensetting);
// 载入自定义字体
int loadedFontID = QFontDatabase::addApplicationFont(":/fonts/fonts/华康少女字体.ttf");
int loadedFontID = QFontDatabase::addApplicationFont(":/fonts/fonts/hksnzt.ttf");
QStringList loadedFontFamilies = QFontDatabase::applicationFontFamilies(loadedFontID);
if(!loadedFontFamilies.isEmpty())
{
@ -237,7 +239,8 @@ void Widget::initUI()
ui->applist_scrollAreaWidget->setLayout(main);
spinner->setFixedSize(80, 80);
// 初始化主题颜色
// 初始化系统活动色和主题颜色
main_color = DGuiApplicationHelper::instance()->applicationPalette().highlight().color();
if(DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType)
{
themeIsDark = true;
@ -246,6 +249,7 @@ void Widget::initUI()
{
themeIsDark = false;
}
setTheme(themeIsDark, main_color);
}
void Widget::initConfig()
@ -341,12 +345,12 @@ void Widget::setTheme(bool isDark, QColor color)
{
// 黑色模式
themeIsDark = true;
ui->webEngineView->setStyleSheet("background-color:#282828");
ui->btn_openDir->setStyleSheet("color: #8B91A1; background-color: #2E2F30; border: 0px");
ui->webfoot->setStyleSheet("background-color:#252525");
ui->label->setStyleSheet("background-color:#252525");
// ui->scrollArea->setStyleSheet("background-color:#252525");
ui->label_show->setStyleSheet("background-color:#252525");
ui->webEngineView->setStyleSheet("background-color: #252525;");
ui->webfoot->setStyleSheet("background-color: #252525;");
ui->btn_openDir->setStyleSheet("color: #AFAFAF; background-color: #2C2C2C; border: 0px;");
ui->label->setStyleSheet("background-color: #252525;");
// ui->scrollArea->setStyleSheet("background-color: #2C2C2C;");
ui->label_show->setStyleSheet("background-color: #2C2C2C;");
ui->pushButton_return->setIcon(DStyle().standardIcon(DStyle::SP_ArrowLeft));
ui->pushButton_refresh->setIcon(QIcon(":/icons/icons/refresh-page-dark.svg"));
}
@ -354,12 +358,12 @@ void Widget::setTheme(bool isDark, QColor color)
{
// 亮色模式
themeIsDark = false;
ui->webEngineView->setStyleSheet("background-color:#FFFFFF");
ui->webfoot->setStyleSheet("background-color:#FFFFFF");
ui->btn_openDir->setStyleSheet("color: #505050; background-color: #FBFBFB; border: 0px");
ui->label->setStyleSheet("background-color:#FFFFFF");
// ui->scrollArea->setStyleSheet("background-color:#F8F8F8");
ui->label_show->setStyleSheet("background-color:#F8F8F8");
ui->webEngineView->setStyleSheet("background-color: #FFFFFF;");
ui->webfoot->setStyleSheet("background-color: #FFFFFF;");
ui->btn_openDir->setStyleSheet("color: #505050; background-color: #F8F8F8; border: 0px;");
ui->label->setStyleSheet("background-color: #FFFFFF;");
// ui->scrollArea->setStyleSheet("background-color: #F8F8F8;");
ui->label_show->setStyleSheet("background-color: #F8F8F8;");
ui->pushButton_return->setIcon(DStyle().standardIcon(DStyle::SP_ArrowLeft));
ui->pushButton_refresh->setIcon(QIcon(":/icons/icons/refresh-page.svg"));
}
@ -369,7 +373,7 @@ void Widget::setTheme(bool isDark, QColor color)
m_loadweb->setTheme(themeIsDark, color);
updateUI();
// 刷新页主题颜色
// 刷新页主题颜色
if(ui->stackedWidget->currentIndex() == 0)
{
chooseLeftMenu(nowMenu);

View File

@ -489,8 +489,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>606</width>
<height>854</height>
<width>582</width>
<height>849</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_17">
@ -984,8 +984,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>568</width>
<height>323</height>
<width>98</width>
<height>28</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
@ -1114,8 +1114,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>743</width>
<height>902</height>
<width>738</width>
<height>886</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_23">