From 0a6e86dba7dccc2303955acfcced3dd89c718c60 Mon Sep 17 00:00:00 2001 From: RigoLigo Date: Thu, 8 Jul 2021 00:38:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E4=B8=BB=E9=A2=98=E8=89=B2=E4=BE=9D?= =?UTF-8?q?=E7=85=A7DDE=E4=B8=BB=E9=A2=98=E8=89=B2=E6=94=B9=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 因为AUTOMOC不会在编译主程序的时候再对插件接口类进行MOC,所以需要在主程序内加一份一模一样的插件接口类定义。 --- CMakeLists.txt | 2 +- gui/spkmainwindow.cpp | 1 + gui/spkui_general.cpp | 37 +++++++++++++++++++----- inc/dtk/spkdtkplugin.h | 9 ++++-- inc/spkui_general.h | 15 +++++++++- plugin/dtkplugin/spkdtkplugin.cpp | 14 +++++++++ plugin/dtkplugin/spkdtkplugin.h | 9 ++++-- plugin/dtkplugin/spkdtkplugin_impl.h | 4 ++- resource/stylesheets/mainwindow_dark.css | 19 +++++++----- 9 files changed, 88 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4716dd4..22a6c7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/gui/spkmainwindow.cpp b/gui/spkmainwindow.cpp index 246abc7..8ef6c80 100644 --- a/gui/spkmainwindow.cpp +++ b/gui/spkmainwindow.cpp @@ -2,6 +2,7 @@ #include #include #include +#include "spkmsgbox.h" #include "spkmainwindow.h" #include "spklogging.h" #include "spkuimsg.h" diff --git a/gui/spkui_general.cpp b/gui/spkui_general.cpp index 92f6827..cad5f0f 100644 --- a/gui/spkui_general.cpp +++ b/gui/spkui_general.cpp @@ -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{ - 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{ - 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)); + } + } diff --git a/inc/dtk/spkdtkplugin.h b/inc/dtk/spkdtkplugin.h index 8929b73..8d3bc40 100644 --- a/inc/dtk/spkdtkplugin.h +++ b/inc/dtk/spkdtkplugin.h @@ -3,12 +3,17 @@ #include -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") diff --git a/inc/spkui_general.h b/inc/spkui_general.h index 8c53be1..0165a50 100644 --- a/inc/spkui_general.h +++ b/inc/spkui_general.h @@ -9,7 +9,7 @@ #include #include -#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; diff --git a/plugin/dtkplugin/spkdtkplugin.cpp b/plugin/dtkplugin/spkdtkplugin.cpp index d9891fe..b9cd119 100644 --- a/plugin/dtkplugin/spkdtkplugin.cpp +++ b/plugin/dtkplugin/spkdtkplugin.cpp @@ -1,11 +1,25 @@ #include #include +#include #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(); +} diff --git a/plugin/dtkplugin/spkdtkplugin.h b/plugin/dtkplugin/spkdtkplugin.h index 8929b73..8d3bc40 100644 --- a/plugin/dtkplugin/spkdtkplugin.h +++ b/plugin/dtkplugin/spkdtkplugin.h @@ -3,12 +3,17 @@ #include -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") diff --git a/plugin/dtkplugin/spkdtkplugin_impl.h b/plugin/dtkplugin/spkdtkplugin_impl.h index 9bbe7aa..75dd248 100644 --- a/plugin/dtkplugin/spkdtkplugin_impl.h +++ b/plugin/dtkplugin/spkdtkplugin_impl.h @@ -5,7 +5,7 @@ #include #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; }; diff --git a/resource/stylesheets/mainwindow_dark.css b/resource/stylesheets/mainwindow_dark.css index f98f0d3..afe5567 100644 --- a/resource/stylesheets/mainwindow_dark.css +++ b/resource/stylesheets/mainwindow_dark.css @@ -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;