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})
|
#target_include_directories(gitver PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
add_dependencies(gitver check_git)
|
add_dependencies(gitver check_git)
|
||||||
|
|
||||||
|
|
||||||
set(SOURCE_FILES
|
set(SOURCE_FILES
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
resource/resource.qrc
|
resource/resource.qrc
|
||||||
@@ -103,6 +102,7 @@ add_executable(${EXECUTABLE_NAME} ${SOURCE_FILES})
|
|||||||
|
|
||||||
if(SPARK_BUILD_DTK_PLUGIN)
|
if(SPARK_BUILD_DTK_PLUGIN)
|
||||||
add_subdirectory(plugin/dtkplugin)
|
add_subdirectory(plugin/dtkplugin)
|
||||||
|
add_dependencies(${EXECUTABLE_NAME} spkdtkplugin)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(${EXECUTABLE_NAME} ${REQUIRED_LIBS_QUALIFIED} ${LIBLINKING})
|
target_link_libraries(${EXECUTABLE_NAME} ${REQUIRED_LIBS_QUALIFIED} ${LIBLINKING})
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
#include "spkmsgbox.h"
|
||||||
#include "spkmainwindow.h"
|
#include "spkmainwindow.h"
|
||||||
#include "spklogging.h"
|
#include "spklogging.h"
|
||||||
#include "spkuimsg.h"
|
#include "spkuimsg.h"
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
namespace SpkUi
|
namespace SpkUi
|
||||||
{
|
{
|
||||||
|
UiMetaObject SpkUiMetaObject;
|
||||||
|
|
||||||
SpkUiStyle CurrentStyle;
|
SpkUiStyle CurrentStyle;
|
||||||
QString StylesheetBase, CurrentStylesheet;
|
QString StylesheetBase, CurrentStylesheet;
|
||||||
QColor ColorLine, ColorBack;
|
QColor ColorLine, ColorBack;
|
||||||
@@ -100,6 +102,13 @@ namespace SpkUi
|
|||||||
DtkPlugin = i;
|
DtkPlugin = i;
|
||||||
States::IsUsingDtkPlugin = true;
|
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:
|
case Light:
|
||||||
static auto LightColor = QList<QColor>{
|
static auto LightColor = QList<QColor>{
|
||||||
0x353535, 0x353535, 0xff0000, 0x0070ff, 0x2987ff,
|
0x282828, 0x282828, 0xff0000, 0x0070ff, QColor(0x70ff).lighter(120),
|
||||||
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
|
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
|
||||||
ColorTextOnBackground(0x0070ff)
|
ColorTextOnBackground(0x0070ff),
|
||||||
};
|
ColorTextOnBackground(0x282828),
|
||||||
|
ColorTextOnBackground(0x282828)
|
||||||
|
};
|
||||||
CurrentStylesheet = StylesheetFromColors(LightColor);
|
CurrentStylesheet = StylesheetFromColors(LightColor);
|
||||||
qApp->setStyleSheet(CurrentStylesheet);
|
qApp->setStyleSheet(CurrentStylesheet);
|
||||||
// TODO
|
// TODO
|
||||||
@@ -141,10 +152,12 @@ namespace SpkUi
|
|||||||
break;
|
break;
|
||||||
case Dark:
|
case Dark:
|
||||||
static auto DarkColor = QList<QColor>{
|
static auto DarkColor = QList<QColor>{
|
||||||
0x353535, 0x353535, 0xff0000, 0x0070ff, 0x2987ff,
|
0x282828, 0x282828, 0xff0000, 0x0070ff, QColor(0x70ff).lighter(120),
|
||||||
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
|
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
|
||||||
ColorTextOnBackground(0x0070ff)
|
ColorTextOnBackground(0x0070ff),
|
||||||
};
|
ColorTextOnBackground(0x282828),
|
||||||
|
ColorTextOnBackground(0x282828)
|
||||||
|
};
|
||||||
CurrentStylesheet = StylesheetFromColors(DarkColor);
|
CurrentStylesheet = StylesheetFromColors(DarkColor);
|
||||||
CurrentColorSet = DarkColor;
|
CurrentColorSet = DarkColor;
|
||||||
qApp->setStyleSheet(CurrentStylesheet);
|
qApp->setStyleSheet(CurrentStylesheet);
|
||||||
@@ -248,4 +261,12 @@ namespace SpkUi
|
|||||||
return gray > 0.5 ? Qt::black : Qt::white;
|
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>
|
#include <QWidget>
|
||||||
|
|
||||||
class SpkDtkPlugin
|
class SpkDtkPlugin : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
virtual ~SpkDtkPlugin() = default;
|
virtual ~SpkDtkPlugin() = default;
|
||||||
|
virtual void Initialize() = 0;
|
||||||
virtual void addWindow(QWidget* w, QObject* parent) = 0;
|
virtual void addWindow(QWidget* w, QObject* parent) = 0;
|
||||||
|
virtual QColor GetAccentColor() = 0;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void AccentColorChanged(QColor);
|
||||||
};
|
};
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
Q_DECLARE_INTERFACE(SpkDtkPlugin, "org.spark-store.client.dtkplugin")
|
Q_DECLARE_INTERFACE(SpkDtkPlugin, "org.spark-store.client.dtkplugin")
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include <QSize>
|
#include <QSize>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
|
||||||
#include "dtkplugin/spkdtkplugin.h"
|
#include "dtk/spkdtkplugin.h"
|
||||||
|
|
||||||
namespace SpkUi
|
namespace SpkUi
|
||||||
{
|
{
|
||||||
@@ -19,6 +19,19 @@ namespace SpkUi
|
|||||||
constexpr int StackTraceArraySize = 64;
|
constexpr int StackTraceArraySize = 64;
|
||||||
constexpr const char * const StoreIconName = "spark-store";
|
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 SpkUiStyle CurrentStyle;
|
||||||
extern QString StylesheetBase, CurrentStylesheet;
|
extern QString StylesheetBase, CurrentStylesheet;
|
||||||
extern QColor ColorLine, ColorBack;
|
extern QColor ColorLine, ColorBack;
|
||||||
|
|||||||
@@ -1,11 +1,25 @@
|
|||||||
#include <DGuiApplicationHelper>
|
#include <DGuiApplicationHelper>
|
||||||
#include <DPlatformWindowHandle>
|
#include <DPlatformWindowHandle>
|
||||||
|
#include <DPlatformTheme>
|
||||||
#include "spkdtkplugin_impl.h"
|
#include "spkdtkplugin_impl.h"
|
||||||
|
|
||||||
using Dtk::Widget::DPlatformWindowHandle;
|
using Dtk::Widget::DPlatformWindowHandle;
|
||||||
|
|
||||||
|
void SpkDtkPluginImpl::Initialize()
|
||||||
|
{
|
||||||
|
connect(DGuiApplicationHelper::instance()->systemTheme(),
|
||||||
|
&DPlatformTheme::activeColorChanged,
|
||||||
|
this,
|
||||||
|
&SpkDtkPluginImpl::AccentColorChanged);
|
||||||
|
}
|
||||||
|
|
||||||
void SpkDtkPluginImpl::addWindow(QWidget *w, QObject *parent)
|
void SpkDtkPluginImpl::addWindow(QWidget *w, QObject *parent)
|
||||||
{
|
{
|
||||||
DPlatformWindowHandle *h = new DPlatformWindowHandle(w, parent);
|
DPlatformWindowHandle *h = new DPlatformWindowHandle(w, parent);
|
||||||
Q_UNUSED(h);
|
Q_UNUSED(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QColor SpkDtkPluginImpl::GetAccentColor()
|
||||||
|
{
|
||||||
|
return DGuiApplicationHelper::instance()->systemTheme()->activeColor();
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,12 +3,17 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
class SpkDtkPlugin
|
class SpkDtkPlugin : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
virtual ~SpkDtkPlugin() = default;
|
virtual ~SpkDtkPlugin() = default;
|
||||||
|
virtual void Initialize() = 0;
|
||||||
virtual void addWindow(QWidget* w, QObject* parent) = 0;
|
virtual void addWindow(QWidget* w, QObject* parent) = 0;
|
||||||
|
virtual QColor GetAccentColor() = 0;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void AccentColorChanged(QColor);
|
||||||
};
|
};
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
Q_DECLARE_INTERFACE(SpkDtkPlugin, "org.spark-store.client.dtkplugin")
|
Q_DECLARE_INTERFACE(SpkDtkPlugin, "org.spark-store.client.dtkplugin")
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <QtPlugin>
|
#include <QtPlugin>
|
||||||
#include "spkdtkplugin.h"
|
#include "spkdtkplugin.h"
|
||||||
|
|
||||||
class SpkDtkPluginImpl : public QObject, SpkDtkPlugin
|
class SpkDtkPluginImpl : public SpkDtkPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PLUGIN_METADATA(IID "org.spark-store.client.dtkplugin")
|
Q_PLUGIN_METADATA(IID "org.spark-store.client.dtkplugin")
|
||||||
@@ -13,4 +13,6 @@ class SpkDtkPluginImpl : public QObject, SpkDtkPlugin
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
void addWindow(QWidget* w, QObject* parent) override;
|
void addWindow(QWidget* w, QObject* parent) override;
|
||||||
|
void Initialize() override;
|
||||||
|
QColor GetAccentColor() override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
%9 : Dark controls gradient light
|
%9 : Dark controls gradient light
|
||||||
%10: Dark controls gradient dark
|
%10: Dark controls gradient dark
|
||||||
%11: Text on Selection/Activation
|
%11: Text on Selection/Activation
|
||||||
|
%12: Text on Global background
|
||||||
|
%13: Text on controls background
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QWidget
|
QWidget
|
||||||
@@ -21,19 +23,20 @@ QWidget
|
|||||||
QTreeWidget[objectName=spk_mw_category]
|
QTreeWidget[objectName=spk_mw_category]
|
||||||
{
|
{
|
||||||
border: none;
|
border: none;
|
||||||
font-size: 16px;
|
font-size: 14px;
|
||||||
show-decoration-selected: 1;
|
show-decoration-selected: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTreeWidget[objectName=spk_mw_category]::item
|
QTreeWidget[objectName=spk_mw_category]::item
|
||||||
{
|
{
|
||||||
height: 50px;
|
height: 35px;
|
||||||
border: none;
|
border: none;
|
||||||
color: %11;
|
color: %13;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTreeWidget[objectName=spk_mw_category]::item:selected
|
QTreeWidget[objectName=spk_mw_category]::item:selected
|
||||||
{
|
{
|
||||||
|
color: %11;
|
||||||
background-color: %4;
|
background-color: %4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +47,7 @@ QTreeWidget[objectName=spk_mw_category]::branch:selected
|
|||||||
|
|
||||||
QLabel
|
QLabel
|
||||||
{
|
{
|
||||||
font-size: 16px
|
font-size: 14px
|
||||||
}
|
}
|
||||||
|
|
||||||
QScrollArea
|
QScrollArea
|
||||||
@@ -56,9 +59,9 @@ QScrollArea
|
|||||||
QPushButton
|
QPushButton
|
||||||
{
|
{
|
||||||
border-width: 1px;
|
border-width: 1px;
|
||||||
padding: 4px;
|
padding: 2px;
|
||||||
border-radius: 7px;
|
border-radius: 11px;
|
||||||
font-size: 16px;
|
font-size: 14px;
|
||||||
font-weight: 300;
|
font-weight: 300;
|
||||||
border-top-color: #7b7b7b;
|
border-top-color: #7b7b7b;
|
||||||
border-style: solid;
|
border-style: solid;
|
||||||
@@ -127,6 +130,8 @@ SpkTitleBarDefaultButton:pressed
|
|||||||
background-color: %8;
|
background-color: %8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SpkTitleBar, QWidget[objectName="spk_mw_"]
|
||||||
|
|
||||||
QScrollBar::handle
|
QScrollBar::handle
|
||||||
{
|
{
|
||||||
border: 0px;
|
border: 0px;
|
||||||
|
|||||||
Reference in New Issue
Block a user