diff --git a/app/core/application.cpp b/app/core/application.cpp index 2000426..3f23824 100644 --- a/app/core/application.cpp +++ b/app/core/application.cpp @@ -78,9 +78,13 @@ void Application::configureWindow(size_t i) clock->setTexture(acfg.getTexture(), acfg.getTextureStretch(), acfg.getTexturePerCharacter()); + clock->setUseSystemForeground(acfg.getTextureType() == SectionAppearance::SolidColor && + acfg.getUseSystemForeground()); clock->setBackground(acfg.getBackground(), acfg.getBackgroundStretch(), acfg.getBackgroundPerCharacter()); + clock->setUseSystemBackground(acfg.getBackgroundType() == SectionAppearance::SolidColor && + acfg.getUseSystemBackground()); if (acfg.getApplyColorization()) { auto effect = new QGraphicsColorizeEffect; diff --git a/app/core/settings_change_listener.cpp b/app/core/settings_change_listener.cpp index 3d406de..dc659c7 100644 --- a/app/core/settings_change_listener.cpp +++ b/app/core/settings_change_listener.cpp @@ -148,6 +148,11 @@ void SettingsChangeListener::onSecondsScaleFactorChanged(int s) _wnd->clock()->setSecondsScaleFactor(s/100.); } +void SettingsChangeListener::onUseSystemForegroundChanged(bool use) +{ + _wnd->clock()->setUseSystemForeground(use); +} + void SettingsChangeListener::onTextureChanged(const QBrush& tx) { _wnd->clock()->setTexture(tx); @@ -163,6 +168,11 @@ void SettingsChangeListener::onTexturePerCharacterChanged(bool en) _wnd->clock()->setTexturePerChar(en); } +void SettingsChangeListener::onUseSystemBackgroundChanged(bool use) +{ + _wnd->clock()->setUseSystemBackground(use); +} + void SettingsChangeListener::onBackgroundChanged(const QBrush& bg) { _wnd->clock()->setBackground(bg); diff --git a/app/core/settings_change_listener.hpp b/app/core/settings_change_listener.hpp index 09be450..23a5cdf 100644 --- a/app/core/settings_change_listener.hpp +++ b/app/core/settings_change_listener.hpp @@ -44,10 +44,12 @@ class SettingsChangeListener : public SettingsChangeReceiver void onTimeFormatChanged(const QString& s) override; void onSecondsScaleFactorChanged(int s) override; + void onUseSystemForegroundChanged(bool use) override; void onTextureChanged(const QBrush& tx) override; void onTextureStretchChanged(bool en) override; void onTexturePerCharacterChanged(bool en) override; + void onUseSystemBackgroundChanged(bool use) override; void onBackgroundChanged(const QBrush& bg) override; void onBackgroundStretchChanged(bool en) override; void onBackgroundPerCharacterChanged(bool en) override; diff --git a/app/gui/settings_dialog.cpp b/app/gui/settings_dialog.cpp index bece9ef..cae2fd6 100644 --- a/app/gui/settings_dialog.cpp +++ b/app/gui/settings_dialog.cpp @@ -459,7 +459,9 @@ void SettingsDialog::on_texture_group_clicked(bool checked) } applyClockOption(qOverload(&GraphicsDateTimeWidget::setTexture), acfg.getTexture()); + applyClockOption(&GraphicsDateTimeWidget::setUseSystemForeground, acfg.shouldUseSystemForeground()); notifyOptionChanged(&SettingsChangeTransmitter::setTexture, acfg.getTexture()); + notifyOptionChanged(&SettingsChangeTransmitter::setUseSystemForeground, acfg.shouldUseSystemForeground()); } void SettingsDialog::on_tx_options_box_activated(int index) @@ -476,8 +478,11 @@ void SettingsDialog::on_tx_options_box_activated(int index) acfg.setTextureType(SectionAppearance::Pattern); break; } + applyClockOption(qOverload(&GraphicsDateTimeWidget::setTexture), acfg.getTexture()); + applyClockOption(&GraphicsDateTimeWidget::setUseSystemForeground, acfg.shouldUseSystemForeground()); notifyOptionChanged(&SettingsChangeTransmitter::setTexture, acfg.getTexture()); + notifyOptionChanged(&SettingsChangeTransmitter::setUseSystemForeground, acfg.shouldUseSystemForeground()); } void SettingsDialog::on_tx_options_box_currentIndexChanged(int index) @@ -486,12 +491,15 @@ void SettingsDialog::on_tx_options_box_currentIndexChanged(int index) disconnect(ui->tx_option, &QCheckBox::clicked, nullptr, nullptr); ui->tx_option->hide(); + SectionAppearance& acfg = app->config().window(_curr_idx).appearance(); + switch (index) { case 0: // color connect(ui->tx_btn, &QToolButton::clicked, this, &SettingsDialog::tx_select_color); ui->tx_option->setText(tr("follow system theme")); - // ui->tx_option->show(); - // connect(ui->tx_option, &QCheckBox::clicked, this, &SettingsDialog::applySystemColor); + ui->tx_option->show(); + ui->tx_option->setChecked(acfg.getUseSystemForeground()); + connect(ui->tx_option, &QCheckBox::clicked, this, &SettingsDialog::tx_use_system_color); break; case 1: // gradient connect(ui->tx_btn, &QToolButton::clicked, this, &SettingsDialog::tx_select_gradient); @@ -501,11 +509,19 @@ void SettingsDialog::on_tx_options_box_currentIndexChanged(int index) connect(ui->tx_btn, &QToolButton::clicked, this, &SettingsDialog::tx_select_pattern); ui->tx_option->setText(tr("stretch instead of tile")); ui->tx_option->show(); + ui->tx_option->setChecked(acfg.getTextureStretch()); connect(ui->tx_option, &QCheckBox::clicked, this, &SettingsDialog::tx_pattern_stretch); break; } } +void SettingsDialog::tx_use_system_color(bool use) +{ + app->config().window(_curr_idx).appearance().setUseSystemForeground(use); + applyClockOption(&GraphicsDateTimeWidget::setUseSystemForeground, use); + notifyOptionChanged(&SettingsChangeTransmitter::setUseSystemForeground, use); +} + void SettingsDialog::tx_select_color() { auto& acfg = app->config().window(_curr_idx).appearance(); @@ -579,7 +595,9 @@ void SettingsDialog::on_background_group_clicked(bool checked) } applyClockOption(qOverload(&GraphicsDateTimeWidget::setBackground), acfg.getBackground()); + applyClockOption(&GraphicsDateTimeWidget::setUseSystemBackground, acfg.shouldUseSystemBackground()); notifyOptionChanged(&SettingsChangeTransmitter::setBackground, acfg.getBackground()); + notifyOptionChanged(&SettingsChangeTransmitter::setUseSystemBackground, acfg.shouldUseSystemBackground()); } void SettingsDialog::on_bg_options_box_activated(int index) @@ -596,8 +614,11 @@ void SettingsDialog::on_bg_options_box_activated(int index) acfg.setBackgroundType(SectionAppearance::Pattern); break; } + applyClockOption(qOverload(&GraphicsDateTimeWidget::setBackground), acfg.getBackground()); + applyClockOption(&GraphicsDateTimeWidget::setUseSystemBackground, acfg.shouldUseSystemBackground()); notifyOptionChanged(&SettingsChangeTransmitter::setBackground, acfg.getBackground()); + notifyOptionChanged(&SettingsChangeTransmitter::setUseSystemBackground, acfg.shouldUseSystemBackground()); } void SettingsDialog::on_bg_options_box_currentIndexChanged(int index) @@ -606,12 +627,15 @@ void SettingsDialog::on_bg_options_box_currentIndexChanged(int index) disconnect(ui->bg_option, &QCheckBox::clicked, nullptr, nullptr); ui->bg_option->hide(); + SectionAppearance& acfg = app->config().window(_curr_idx).appearance(); + switch (index) { case 0: // color connect(ui->bg_btn, &QToolButton::clicked, this, &SettingsDialog::bg_select_color); ui->bg_option->setText(tr("follow system theme")); - // ui->bg_option->show(); - // connect(ui->bg_option, &QCheckBox::clicked, this, &SettingsDialog::applySystemColor); + ui->bg_option->show(); + ui->bg_option->setChecked(acfg.getUseSystemBackground()); + connect(ui->bg_option, &QCheckBox::clicked, this, &SettingsDialog::bg_use_system_color); break; case 1: // gradient connect(ui->bg_btn, &QToolButton::clicked, this, &SettingsDialog::bg_select_gradient); @@ -621,11 +645,19 @@ void SettingsDialog::on_bg_options_box_currentIndexChanged(int index) connect(ui->bg_btn, &QToolButton::clicked, this, &SettingsDialog::bg_select_pattern); ui->bg_option->setText(tr("stretch instead of tile")); ui->bg_option->show(); + ui->bg_option->setChecked(acfg.getBackgroundStretch()); connect(ui->bg_option, &QCheckBox::clicked, this, &SettingsDialog::bg_pattern_stretch); break; } } +void SettingsDialog::bg_use_system_color(bool use) +{ + app->config().window(_curr_idx).appearance().setUseSystemBackground(use); + applyClockOption(&GraphicsDateTimeWidget::setUseSystemBackground, use); + notifyOptionChanged(&SettingsChangeTransmitter::setUseSystemBackground, use); +} + void SettingsDialog::bg_select_color() { auto& acfg = app->config().window(_curr_idx).appearance(); @@ -884,7 +916,6 @@ void SettingsDialog::initAppearanceTab(int idx) } if (tx.style() == Qt::TexturePattern) { ui->tx_options_box->setCurrentIndex(2); - ui->tx_option->setChecked(acfg.getTextureStretch()); } ui->tx_per_element_cb->setChecked(acfg.getTexturePerCharacter()); on_tx_options_box_currentIndexChanged(ui->tx_options_box->currentIndex()); @@ -899,7 +930,6 @@ void SettingsDialog::initAppearanceTab(int idx) } if (bg.style() == Qt::TexturePattern) { ui->bg_options_box->setCurrentIndex(2); - ui->bg_option->setChecked(acfg.getBackgroundStretch()); } ui->bg_per_element_cb->setChecked(acfg.getBackgroundPerCharacter()); on_bg_options_box_currentIndexChanged(ui->bg_options_box->currentIndex()); diff --git a/app/gui/settings_dialog.hpp b/app/gui/settings_dialog.hpp index 050c24c..208a5b8 100644 --- a/app/gui/settings_dialog.hpp +++ b/app/gui/settings_dialog.hpp @@ -97,6 +97,7 @@ private slots: void on_texture_group_clicked(bool checked); void on_tx_options_box_activated(int index); void on_tx_options_box_currentIndexChanged(int index); + void tx_use_system_color(bool use); void tx_select_color(); void tx_select_gradient(); void tx_select_pattern(); @@ -106,6 +107,7 @@ private slots: void on_background_group_clicked(bool checked); void on_bg_options_box_activated(int index); void on_bg_options_box_currentIndexChanged(int index); + void bg_use_system_color(bool use); void bg_select_color(); void bg_select_gradient(); void bg_select_pattern(); diff --git a/app/main.cpp b/app/main.cpp index 4dac22c..0ff1175 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -28,11 +28,7 @@ int main(int argc, char *argv[]) QApplication::setAttribute(Qt::AA_DontShowIconsInMenus); #endif QApplication::setQuitOnLastWindowClosed(false); -#ifdef Q_OS_WINDOWS - QApplication::setStyle(u"windowsvista"_s); -#else QApplication::setStyle(u"fusion"_s); -#endif Application app(argc, argv); return app.exec(); diff --git a/clock_common/config/appearance_base.cpp b/clock_common/config/appearance_base.cpp index 655f3d1..5534793 100644 --- a/clock_common/config/appearance_base.cpp +++ b/clock_common/config/appearance_base.cpp @@ -31,6 +31,11 @@ QPixmap AppearanceSectionBase::getTexturePattern() const return sample_pattern(); } +bool AppearanceSectionBase::shouldUseSystemForeground() const +{ + return getTextureType() == SolidColor && getUseSystemForeground(); +} + QBrush AppearanceSectionBase::getBackground() const { switch (getBackgroundType()) { @@ -53,3 +58,8 @@ QPixmap AppearanceSectionBase::getBackgroundPattern() const return QPixmap(getBackgroundPatternFile()); return sample_pattern(); } + +bool AppearanceSectionBase::shouldUseSystemBackground() const +{ + return getBackgroundType() == SolidColor && getUseSystemBackground(); +} diff --git a/clock_common/config/appearance_base.hpp b/clock_common/config/appearance_base.hpp index a26c13f..cae9556 100644 --- a/clock_common/config/appearance_base.hpp +++ b/clock_common/config/appearance_base.hpp @@ -26,6 +26,7 @@ class CLOCK_COMMON_EXPORT AppearanceSectionBase : public SettingsStorageClient { using SettingsStorageClient::SettingsStorageClient; + CONFIG_OPTION_Q(bool, UseSystemForeground, false) QBrush getTexture() const; CONFIG_OPTION_Q(CustomizationType, TextureType, SolidColor) CONFIG_OPTION_Q(QColor, TextureColor, QColor(112, 96, 240)) @@ -34,7 +35,9 @@ class CLOCK_COMMON_EXPORT AppearanceSectionBase : public SettingsStorageClient { CONFIG_OPTION_Q(QString, TexturePatternFile, QString()) CONFIG_OPTION_Q(bool, TextureStretch, false) CONFIG_OPTION_Q(bool, TexturePerCharacter, true) + bool shouldUseSystemForeground() const; + CONFIG_OPTION_Q(bool, UseSystemBackground, false) QBrush getBackground() const; CONFIG_OPTION_Q(CustomizationType, BackgroundType, None) CONFIG_OPTION_Q(QColor, BackgroundColor, QColor(0, 0, 0, 160)) @@ -43,4 +46,5 @@ class CLOCK_COMMON_EXPORT AppearanceSectionBase : public SettingsStorageClient { CONFIG_OPTION_Q(QString, BackgroundPatternFile, QString()) CONFIG_OPTION_Q(bool, BackgroundStretch, false) CONFIG_OPTION_Q(bool, BackgroundPerCharacter, false) + bool shouldUseSystemBackground() const; }; diff --git a/plugin_core/impl/appearance_settings_widget.cpp b/plugin_core/impl/appearance_settings_widget.cpp index cfd9692..93ef88a 100644 --- a/plugin_core/impl/appearance_settings_widget.cpp +++ b/plugin_core/impl/appearance_settings_widget.cpp @@ -47,7 +47,6 @@ AppearanceSettingsWidget::AppearanceSettingsWidget(WidgetPluginBaseImpl* w, Plug } if (tx.style() == Qt::TexturePattern) { ui->tx_options_box->setCurrentIndex(2); - ui->tx_option->setChecked(cfg.getTextureStretch()); } ui->tx_per_char->setChecked(cfg.getTexturePerCharacter()); on_tx_options_box_currentIndexChanged(ui->tx_options_box->currentIndex()); @@ -62,7 +61,6 @@ AppearanceSettingsWidget::AppearanceSettingsWidget(WidgetPluginBaseImpl* w, Plug } if (bg.style() == Qt::TexturePattern) { ui->bg_options_box->setCurrentIndex(2); - ui->bg_option->setChecked(cfg.getBackgroundStretch()); } ui->bg_per_char->setChecked(cfg.getBackgroundPerCharacter()); on_bg_options_box_currentIndexChanged(ui->bg_options_box->currentIndex()); @@ -238,8 +236,10 @@ void AppearanceSettingsWidget::on_tx_group_clicked(bool checked) impl->tx = cfg.getTexture(); - if (widget) + if (widget) { widget->setTexture(cfg.getTexture()); + widget->setUseSystemForeground(cfg.shouldUseSystemForeground()); + } } void AppearanceSettingsWidget::on_tx_options_box_activated(int index) @@ -258,8 +258,10 @@ void AppearanceSettingsWidget::on_tx_options_box_activated(int index) impl->tx = cfg.getTexture(); - if (widget) + if (widget) { widget->setTexture(cfg.getTexture()); + widget->setUseSystemForeground(cfg.shouldUseSystemForeground()); + } } void AppearanceSettingsWidget::on_tx_options_box_currentIndexChanged(int index) @@ -272,8 +274,9 @@ void AppearanceSettingsWidget::on_tx_options_box_currentIndexChanged(int index) case 0: // color connect(ui->tx_btn, &QToolButton::clicked, this, &AppearanceSettingsWidget::tx_select_color); ui->tx_option->setText(tr("follow system theme")); - // ui->tx_option->show(); - // connect(ui->tx_option, &QCheckBox::clicked, this, &AppearanceSettingsWidget::applySystemColor); + ui->tx_option->show(); + ui->tx_option->setChecked(cfg.getUseSystemForeground()); + connect(ui->tx_option, &QCheckBox::clicked, this, &AppearanceSettingsWidget::tx_use_system_color); break; case 1: // gradient connect(ui->tx_btn, &QToolButton::clicked, this, &AppearanceSettingsWidget::tx_select_gradient); @@ -283,11 +286,19 @@ void AppearanceSettingsWidget::on_tx_options_box_currentIndexChanged(int index) connect(ui->tx_btn, &QToolButton::clicked, this, &AppearanceSettingsWidget::tx_select_pattern); ui->tx_option->setText(tr("stretch instead of tile")); ui->tx_option->show(); + ui->tx_option->setChecked(cfg.getTextureStretch()); connect(ui->tx_option, &QCheckBox::clicked, this, &AppearanceSettingsWidget::tx_pattern_stretch); break; } } +void AppearanceSettingsWidget::tx_use_system_color(bool use) +{ + cfg.setUseSystemForeground(use); + if (widget) + widget->setUseSystemForeground(use); +} + void AppearanceSettingsWidget::tx_select_color() { auto color = QColorDialog::getColor(cfg.getTextureColor(), @@ -370,8 +381,10 @@ void AppearanceSettingsWidget::on_bg_group_clicked(bool checked) impl->bg = cfg.getBackground(); - if (widget) + if (widget) { widget->setBackground(cfg.getBackground()); + widget->setUseSystemBackground(cfg.shouldUseSystemBackground()); + } } void AppearanceSettingsWidget::on_bg_options_box_activated(int index) @@ -390,8 +403,10 @@ void AppearanceSettingsWidget::on_bg_options_box_activated(int index) impl->bg = cfg.getBackground(); - if (widget) + if (widget) { widget->setBackground(cfg.getBackground()); + widget->setUseSystemBackground(cfg.shouldUseSystemBackground()); + } } void AppearanceSettingsWidget::on_bg_options_box_currentIndexChanged(int index) @@ -404,8 +419,9 @@ void AppearanceSettingsWidget::on_bg_options_box_currentIndexChanged(int index) case 0: // color connect(ui->bg_btn, &QToolButton::clicked, this, &AppearanceSettingsWidget::bg_select_color); ui->bg_option->setText(tr("follow system theme")); - // ui->bg_option->show(); - // connect(ui->bg_option, &QCheckBox::clicked, this, &AppearanceSettingsWidget::applySystemColor); + ui->bg_option->show(); + ui->bg_option->setChecked(cfg.getUseSystemBackground()); + connect(ui->bg_option, &QCheckBox::clicked, this, &AppearanceSettingsWidget::bg_use_system_color); break; case 1: // gradient connect(ui->bg_btn, &QToolButton::clicked, this, &AppearanceSettingsWidget::bg_select_gradient); @@ -415,11 +431,19 @@ void AppearanceSettingsWidget::on_bg_options_box_currentIndexChanged(int index) connect(ui->bg_btn, &QToolButton::clicked, this, &AppearanceSettingsWidget::bg_select_pattern); ui->bg_option->setText(tr("stretch instead of tile")); ui->bg_option->show(); + ui->bg_option->setChecked(cfg.getBackgroundStretch()); connect(ui->bg_option, &QCheckBox::clicked, this, &AppearanceSettingsWidget::bg_pattern_stretch); break; } } +void AppearanceSettingsWidget::bg_use_system_color(bool use) +{ + cfg.setUseSystemBackground(use); + if (widget) + widget->setUseSystemBackground(use); +} + void AppearanceSettingsWidget::bg_select_color() { auto color = QColorDialog::getColor(cfg.getBackgroundColor(), diff --git a/plugin_core/impl/appearance_settings_widget.hpp b/plugin_core/impl/appearance_settings_widget.hpp index d7e836b..5f92c23 100644 --- a/plugin_core/impl/appearance_settings_widget.hpp +++ b/plugin_core/impl/appearance_settings_widget.hpp @@ -47,6 +47,7 @@ private slots: void on_tx_group_clicked(bool checked); void on_tx_options_box_activated(int index); void on_tx_options_box_currentIndexChanged(int index); + void tx_use_system_color(bool use); void tx_select_color(); void tx_select_gradient(); void tx_select_pattern(); @@ -56,6 +57,7 @@ private slots: void on_bg_group_clicked(bool checked); void on_bg_options_box_activated(int index); void on_bg_options_box_currentIndexChanged(int index); + void bg_use_system_color(bool use); void bg_select_color(); void bg_select_gradient(); void bg_select_pattern(); diff --git a/plugin_core/settings_bridge.cpp b/plugin_core/settings_bridge.cpp index 42d106f..8ce28f3 100644 --- a/plugin_core/settings_bridge.cpp +++ b/plugin_core/settings_bridge.cpp @@ -69,10 +69,12 @@ OPTION_CHANGE_NOTIFIER_R(CustomSeparators, QString) OPTION_CHANGE_NOTIFIER_R(TimeFormat, QString) OPTION_CHANGE_NOTIFIER_V(SecondsScaleFactor, int) +OPTION_CHANGE_NOTIFIER_V(UseSystemForeground, bool) OPTION_CHANGE_NOTIFIER_R(Texture, QBrush) OPTION_CHANGE_NOTIFIER_V(TextureStretch, bool) OPTION_CHANGE_NOTIFIER_V(TexturePerCharacter, bool) +OPTION_CHANGE_NOTIFIER_V(UseSystemBackground, bool) OPTION_CHANGE_NOTIFIER_R(Background, QBrush) OPTION_CHANGE_NOTIFIER_V(BackgroundStretch, bool) OPTION_CHANGE_NOTIFIER_V(BackgroundPerCharacter, bool) @@ -108,10 +110,12 @@ void SettingsChangeReceiver::onOptionChanged(cs::SharedConfigKeys opt, const QVa HANDLE_OPTION_CHANGE(val, TimeFormat, QString) HANDLE_OPTION_CHANGE(val, SecondsScaleFactor, int) + HANDLE_OPTION_CHANGE(val, UseSystemForeground, bool) HANDLE_OPTION_CHANGE(val, Texture, QBrush) HANDLE_OPTION_CHANGE(val, TextureStretch, bool) HANDLE_OPTION_CHANGE(val, TexturePerCharacter, bool) + HANDLE_OPTION_CHANGE(val, UseSystemBackground, bool) HANDLE_OPTION_CHANGE(val, Background, QBrush) HANDLE_OPTION_CHANGE(val, BackgroundStretch, bool) HANDLE_OPTION_CHANGE(val, BackgroundPerCharacter, bool) diff --git a/plugin_core/settings_bridge.hpp b/plugin_core/settings_bridge.hpp index 82d538e..3d04773 100644 --- a/plugin_core/settings_bridge.hpp +++ b/plugin_core/settings_bridge.hpp @@ -42,10 +42,12 @@ public slots: void setTimeFormat(const QString& s); void setSecondsScaleFactor(int s); + void setUseSystemForeground(bool use); void setTexture(const QBrush& tx); void setTextureStretch(bool en); void setTexturePerCharacter(bool en); + void setUseSystemBackground(bool use); void setBackground(const QBrush& bg); void setBackgroundStretch(bool en); void setBackgroundPerCharacter(bool en); @@ -89,10 +91,12 @@ public slots: virtual void onTimeFormatChanged(const QString& s) = 0; virtual void onSecondsScaleFactorChanged(int s) = 0; + virtual void onUseSystemForegroundChanged(bool use) = 0; virtual void onTextureChanged(const QBrush& tx) = 0; virtual void onTextureStretchChanged(bool en) = 0; virtual void onTexturePerCharacterChanged(bool en) = 0; + virtual void onUseSystemBackgroundChanged(bool use) = 0; virtual void onBackgroundChanged(const QBrush& bg) = 0; virtual void onBackgroundStretchChanged(bool en) = 0; virtual void onBackgroundPerCharacterChanged(bool en) = 0; diff --git a/plugin_core/shared_config_keys.hpp b/plugin_core/shared_config_keys.hpp index 3a9d4fa..09b1506 100644 --- a/plugin_core/shared_config_keys.hpp +++ b/plugin_core/shared_config_keys.hpp @@ -44,6 +44,9 @@ enum SharedConfigKeys { Background, BackgroundStretch, BackgroundPerCharacter, + + UseSystemForeground, + UseSystemBackground, }; Q_ENUM_NS(SharedConfigKeys) diff --git a/plugin_core/widget_plugin_base.cpp b/plugin_core/widget_plugin_base.cpp index 2044d90..b1ff23e 100644 --- a/plugin_core/widget_plugin_base.cpp +++ b/plugin_core/widget_plugin_base.cpp @@ -90,6 +90,9 @@ void WidgetPluginBase::onOptionChanged(clock_settings::SharedConfigKeys opt, con // handle only minimal set of settings switch (opt) { + case cs::UseSystemForeground: + _impl->widget->setUseSystemForeground(val.toBool()); + break; case cs::Texture: _impl->widget->setTexture(val.value()); break; @@ -99,6 +102,9 @@ void WidgetPluginBase::onOptionChanged(clock_settings::SharedConfigKeys opt, con case cs::TexturePerCharacter: _impl->widget->setTexturePerChar(val.toBool()); break; + case cs::UseSystemBackground: + _impl->widget->setUseSystemBackground(val.toBool()); + break; case cs::Background: _impl->widget->setBackground(val.value()); break; diff --git a/skin_engine/skin/graphics_widgets.cpp b/skin_engine/skin/graphics_widgets.cpp index 24603ed..f8c945e 100644 --- a/skin_engine/skin/graphics_widgets.cpp +++ b/skin_engine/skin/graphics_widgets.cpp @@ -6,6 +6,7 @@ #include "graphics_widgets.hpp" +#include #include GraphicsWidgetBase::GraphicsWidgetBase(std::shared_ptr gr, QWidget* parent) @@ -113,16 +114,32 @@ void GraphicsWidgetBase::setLayoutConfig(QString lcfg) void GraphicsWidgetBase::setBackground(QBrush b, bool stretch, bool per_char) { + _last_bg = b; _gt->setBackground(std::move(b), stretch, per_char); update(); } void GraphicsWidgetBase::setTexture(QBrush b, bool stretch, bool per_char) { + _last_tx = b; _gt->setTexture(std::move(b), stretch, per_char); update(); } +void GraphicsWidgetBase::setUseSystemBackground(bool use) +{ + _sys_bg = use; + _gt->setBackground(use ? palette().window() : _last_bg); + update(); +} + +void GraphicsWidgetBase::setUseSystemForeground(bool use) +{ + _sys_fg = use; + _gt->setTexture(use ? palette().windowText() : _last_tx); + update(); +} + void GraphicsWidgetBase::paintEvent(QPaintEvent* event) { const auto& sz = _gt->rect().size(); @@ -163,6 +180,18 @@ void GraphicsWidgetBase::paintEvent(QPaintEvent* event) _gt->draw(&p); } +bool GraphicsWidgetBase::event(QEvent* e) +{ + if (e->type() == QEvent::PaletteChange) { + if (_sys_bg) + _gt->setBackground(palette().window()); + if (_sys_fg) + _gt->setTexture(palette().windowText()); + update(); + } + return QWidget::event(e); +} + GraphicsTextWidget::GraphicsTextWidget(QWidget* parent) : GraphicsTextWidget(std::make_shared(), parent) diff --git a/skin_engine/skin/graphics_widgets.hpp b/skin_engine/skin/graphics_widgets.hpp index bb5830a..c8a56a0 100644 --- a/skin_engine/skin/graphics_widgets.hpp +++ b/skin_engine/skin/graphics_widgets.hpp @@ -59,6 +59,9 @@ class SKIN_ENGINE_EXPORT GraphicsWidgetBase : public QWidget bool backgroundPerChar() const { return _gt->backgroundPerChar(); } bool texturePerChar() const { return _gt->texturePerChar(); } + bool useSystemBackground() const { return _sys_bg; } + bool useSystemForeground() const { return _sys_fg; } + // --------------------- void setSkin(std::shared_ptr skin); @@ -79,6 +82,8 @@ public slots: void setAlignment(Qt::Alignment a); void setLayoutConfig(QString lcfg); + // --------------------- + void setBackground(QBrush b, bool stretch, bool per_char); inline void setBackground(QBrush b) @@ -115,8 +120,14 @@ public slots: setTexture(texture(), textureStretch(), en); } + // --------------------- + + void setUseSystemBackground(bool use); + void setUseSystemForeground(bool use); + protected: void paintEvent(QPaintEvent* event) override; + bool event(QEvent* e) override; private: std::shared_ptr _gt; @@ -127,6 +138,11 @@ public slots: qreal _sy = 1.0; QString _lcfg; + + QBrush _last_bg; + QBrush _last_tx; + bool _sys_bg = false; + bool _sys_fg = false; };