使主题色依照DDE主题色改变

因为AUTOMOC不会在编译主程序的时候再对插件接口类进行MOC,所以需要在主程序内加一份一模一样的插件接口类定义。
This commit is contained in:
RigoLigo
2021-07-08 00:38:11 +08:00
parent 6536d3230f
commit 0a6e86dba7
9 changed files with 88 additions and 22 deletions

View File

@@ -2,6 +2,7 @@
#include <QGuiApplication>
#include <QScreen>
#include <QJsonArray>
#include "spkmsgbox.h"
#include "spkmainwindow.h"
#include "spklogging.h"
#include "spkuimsg.h"

View File

@@ -22,6 +22,8 @@
namespace SpkUi
{
UiMetaObject SpkUiMetaObject;
SpkUiStyle CurrentStyle;
QString StylesheetBase, CurrentStylesheet;
QColor ColorLine, ColorBack;
@@ -100,6 +102,13 @@ namespace SpkUi
DtkPlugin = i;
States::IsUsingDtkPlugin = true;
}
i->Initialize();
SpkUiMetaObject.SetAccentColor(i->GetAccentColor()); // Match OS accent color
QObject::connect(i, &SpkDtkPlugin::AccentColorChanged,
&SpkUiMetaObject, &UiMetaObject::SetAccentColor);
}
}
@@ -130,10 +139,12 @@ namespace SpkUi
{
case Light:
static auto LightColor = QList<QColor>{
0x353535, 0x353535, 0xff0000, 0x0070ff, 0x2987ff,
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
ColorTextOnBackground(0x0070ff)
};
0x282828, 0x282828, 0xff0000, 0x0070ff, QColor(0x70ff).lighter(120),
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
ColorTextOnBackground(0x0070ff),
ColorTextOnBackground(0x282828),
ColorTextOnBackground(0x282828)
};
CurrentStylesheet = StylesheetFromColors(LightColor);
qApp->setStyleSheet(CurrentStylesheet);
// TODO
@@ -141,10 +152,12 @@ namespace SpkUi
break;
case Dark:
static auto DarkColor = QList<QColor>{
0x353535, 0x353535, 0xff0000, 0x0070ff, 0x2987ff,
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
ColorTextOnBackground(0x0070ff)
};
0x282828, 0x282828, 0xff0000, 0x0070ff, QColor(0x70ff).lighter(120),
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
ColorTextOnBackground(0x0070ff),
ColorTextOnBackground(0x282828),
ColorTextOnBackground(0x282828)
};
CurrentStylesheet = StylesheetFromColors(DarkColor);
CurrentColorSet = DarkColor;
qApp->setStyleSheet(CurrentStylesheet);
@@ -248,4 +261,12 @@ namespace SpkUi
return gray > 0.5 ? Qt::black : Qt::white;
}
void UiMetaObject::SetAccentColor(QColor aColor)
{
CurrentColorSet[3] = aColor.lighter(80);
CurrentColorSet[4] = aColor;
CurrentColorSet[10] = ColorTextOnBackground(aColor);
qApp->setStyleSheet(StylesheetFromColors(CurrentColorSet));
}
}