mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-13 20:32:05 +08:00
使主题色依照DDE主题色改变
因为AUTOMOC不会在编译主程序的时候再对插件接口类进行MOC,所以需要在主程序内加一份一模一样的插件接口类定义。
This commit is contained in:
@@ -44,7 +44,6 @@ add_library(gitver STATIC ${POST_CONFIGURE_FILE})
|
||||
#target_include_directories(gitver PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_dependencies(gitver check_git)
|
||||
|
||||
|
||||
set(SOURCE_FILES
|
||||
src/main.cpp
|
||||
resource/resource.qrc
|
||||
@@ -103,6 +102,7 @@ add_executable(${EXECUTABLE_NAME} ${SOURCE_FILES})
|
||||
|
||||
if(SPARK_BUILD_DTK_PLUGIN)
|
||||
add_subdirectory(plugin/dtkplugin)
|
||||
add_dependencies(${EXECUTABLE_NAME} spkdtkplugin)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${EXECUTABLE_NAME} ${REQUIRED_LIBS_QUALIFIED} ${LIBLINKING})
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QScreen>
|
||||
#include <QJsonArray>
|
||||
#include "spkmsgbox.h"
|
||||
#include "spkmainwindow.h"
|
||||
#include "spklogging.h"
|
||||
#include "spkuimsg.h"
|
||||
|
||||
@@ -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,9 +139,11 @@ namespace SpkUi
|
||||
{
|
||||
case Light:
|
||||
static auto LightColor = QList<QColor>{
|
||||
0x353535, 0x353535, 0xff0000, 0x0070ff, 0x2987ff,
|
||||
0x282828, 0x282828, 0xff0000, 0x0070ff, QColor(0x70ff).lighter(120),
|
||||
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
|
||||
ColorTextOnBackground(0x0070ff)
|
||||
ColorTextOnBackground(0x0070ff),
|
||||
ColorTextOnBackground(0x282828),
|
||||
ColorTextOnBackground(0x282828)
|
||||
};
|
||||
CurrentStylesheet = StylesheetFromColors(LightColor);
|
||||
qApp->setStyleSheet(CurrentStylesheet);
|
||||
@@ -141,9 +152,11 @@ namespace SpkUi
|
||||
break;
|
||||
case Dark:
|
||||
static auto DarkColor = QList<QColor>{
|
||||
0x353535, 0x353535, 0xff0000, 0x0070ff, 0x2987ff,
|
||||
0x282828, 0x282828, 0xff0000, 0x0070ff, QColor(0x70ff).lighter(120),
|
||||
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
|
||||
ColorTextOnBackground(0x0070ff)
|
||||
ColorTextOnBackground(0x0070ff),
|
||||
ColorTextOnBackground(0x282828),
|
||||
ColorTextOnBackground(0x282828)
|
||||
};
|
||||
CurrentStylesheet = StylesheetFromColors(DarkColor);
|
||||
CurrentColorSet = DarkColor;
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,12 +3,17 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class SpkDtkPlugin
|
||||
class SpkDtkPlugin : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual ~SpkDtkPlugin() = default;
|
||||
|
||||
virtual void Initialize() = 0;
|
||||
virtual void addWindow(QWidget* w, QObject* parent) = 0;
|
||||
virtual QColor GetAccentColor() = 0;
|
||||
|
||||
signals:
|
||||
void AccentColorChanged(QColor);
|
||||
};
|
||||
QT_BEGIN_NAMESPACE
|
||||
Q_DECLARE_INTERFACE(SpkDtkPlugin, "org.spark-store.client.dtkplugin")
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <QSize>
|
||||
#include <QColor>
|
||||
|
||||
#include "dtkplugin/spkdtkplugin.h"
|
||||
#include "dtk/spkdtkplugin.h"
|
||||
|
||||
namespace SpkUi
|
||||
{
|
||||
@@ -19,6 +19,19 @@ namespace SpkUi
|
||||
constexpr int StackTraceArraySize = 64;
|
||||
constexpr const char * const StoreIconName = "spark-store";
|
||||
|
||||
class UiMetaObject : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
static UiMetaObject *sGlobalInstance;
|
||||
public:
|
||||
UiMetaObject() {}
|
||||
UiMetaObject *Instance() {return nullptr;} //FIXME!!
|
||||
public slots:
|
||||
void SetAccentColor(QColor);
|
||||
};
|
||||
|
||||
extern UiMetaObject SpkUiMetaObject;
|
||||
extern SpkUiStyle CurrentStyle;
|
||||
extern QString StylesheetBase, CurrentStylesheet;
|
||||
extern QColor ColorLine, ColorBack;
|
||||
|
||||
@@ -1,11 +1,25 @@
|
||||
#include <DGuiApplicationHelper>
|
||||
#include <DPlatformWindowHandle>
|
||||
#include <DPlatformTheme>
|
||||
#include "spkdtkplugin_impl.h"
|
||||
|
||||
using Dtk::Widget::DPlatformWindowHandle;
|
||||
|
||||
void SpkDtkPluginImpl::Initialize()
|
||||
{
|
||||
connect(DGuiApplicationHelper::instance()->systemTheme(),
|
||||
&DPlatformTheme::activeColorChanged,
|
||||
this,
|
||||
&SpkDtkPluginImpl::AccentColorChanged);
|
||||
}
|
||||
|
||||
void SpkDtkPluginImpl::addWindow(QWidget *w, QObject *parent)
|
||||
{
|
||||
DPlatformWindowHandle *h = new DPlatformWindowHandle(w, parent);
|
||||
Q_UNUSED(h);
|
||||
}
|
||||
|
||||
QColor SpkDtkPluginImpl::GetAccentColor()
|
||||
{
|
||||
return DGuiApplicationHelper::instance()->systemTheme()->activeColor();
|
||||
}
|
||||
|
||||
@@ -3,12 +3,17 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class SpkDtkPlugin
|
||||
class SpkDtkPlugin : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual ~SpkDtkPlugin() = default;
|
||||
|
||||
virtual void Initialize() = 0;
|
||||
virtual void addWindow(QWidget* w, QObject* parent) = 0;
|
||||
virtual QColor GetAccentColor() = 0;
|
||||
|
||||
signals:
|
||||
void AccentColorChanged(QColor);
|
||||
};
|
||||
QT_BEGIN_NAMESPACE
|
||||
Q_DECLARE_INTERFACE(SpkDtkPlugin, "org.spark-store.client.dtkplugin")
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <QtPlugin>
|
||||
#include "spkdtkplugin.h"
|
||||
|
||||
class SpkDtkPluginImpl : public QObject, SpkDtkPlugin
|
||||
class SpkDtkPluginImpl : public SpkDtkPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.spark-store.client.dtkplugin")
|
||||
@@ -13,4 +13,6 @@ class SpkDtkPluginImpl : public QObject, SpkDtkPlugin
|
||||
|
||||
public:
|
||||
void addWindow(QWidget* w, QObject* parent) override;
|
||||
void Initialize() override;
|
||||
QColor GetAccentColor() override;
|
||||
};
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
%9 : Dark controls gradient light
|
||||
%10: Dark controls gradient dark
|
||||
%11: Text on Selection/Activation
|
||||
%12: Text on Global background
|
||||
%13: Text on controls background
|
||||
*/
|
||||
|
||||
QWidget
|
||||
@@ -21,19 +23,20 @@ QWidget
|
||||
QTreeWidget[objectName=spk_mw_category]
|
||||
{
|
||||
border: none;
|
||||
font-size: 16px;
|
||||
font-size: 14px;
|
||||
show-decoration-selected: 1;
|
||||
}
|
||||
|
||||
QTreeWidget[objectName=spk_mw_category]::item
|
||||
{
|
||||
height: 50px;
|
||||
height: 35px;
|
||||
border: none;
|
||||
color: %11;
|
||||
color: %13;
|
||||
}
|
||||
|
||||
QTreeWidget[objectName=spk_mw_category]::item:selected
|
||||
{
|
||||
color: %11;
|
||||
background-color: %4;
|
||||
}
|
||||
|
||||
@@ -44,7 +47,7 @@ QTreeWidget[objectName=spk_mw_category]::branch:selected
|
||||
|
||||
QLabel
|
||||
{
|
||||
font-size: 16px
|
||||
font-size: 14px
|
||||
}
|
||||
|
||||
QScrollArea
|
||||
@@ -56,9 +59,9 @@ QScrollArea
|
||||
QPushButton
|
||||
{
|
||||
border-width: 1px;
|
||||
padding: 4px;
|
||||
border-radius: 7px;
|
||||
font-size: 16px;
|
||||
padding: 2px;
|
||||
border-radius: 11px;
|
||||
font-size: 14px;
|
||||
font-weight: 300;
|
||||
border-top-color: #7b7b7b;
|
||||
border-style: solid;
|
||||
@@ -127,6 +130,8 @@ SpkTitleBarDefaultButton:pressed
|
||||
background-color: %8;
|
||||
}
|
||||
|
||||
SpkTitleBar, QWidget[objectName="spk_mw_"]
|
||||
|
||||
QScrollBar::handle
|
||||
{
|
||||
border: 0px;
|
||||
|
||||
Reference in New Issue
Block a user