Skip to content

Commit

Permalink
added option to use system theme bg/fg colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolcha committed Sep 14, 2024
1 parent aba0ad6 commit 6569d62
Show file tree
Hide file tree
Showing 16 changed files with 166 additions and 20 deletions.
4 changes: 4 additions & 0 deletions app/core/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions app/core/settings_change_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions app/core/settings_change_listener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
42 changes: 36 additions & 6 deletions app/gui/settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,9 @@ void SettingsDialog::on_texture_group_clicked(bool checked)
}

applyClockOption(qOverload<QBrush>(&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)
Expand All @@ -476,8 +478,11 @@ void SettingsDialog::on_tx_options_box_activated(int index)
acfg.setTextureType(SectionAppearance::Pattern);
break;
}

applyClockOption(qOverload<QBrush>(&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)
Expand All @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -579,7 +595,9 @@ void SettingsDialog::on_background_group_clicked(bool checked)
}

applyClockOption(qOverload<QBrush>(&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)
Expand All @@ -596,8 +614,11 @@ void SettingsDialog::on_bg_options_box_activated(int index)
acfg.setBackgroundType(SectionAppearance::Pattern);
break;
}

applyClockOption(qOverload<QBrush>(&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)
Expand All @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions app/gui/settings_dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
4 changes: 0 additions & 4 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions clock_common/config/appearance_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -53,3 +58,8 @@ QPixmap AppearanceSectionBase::getBackgroundPattern() const
return QPixmap(getBackgroundPatternFile());
return sample_pattern();
}

bool AppearanceSectionBase::shouldUseSystemBackground() const
{
return getBackgroundType() == SolidColor && getUseSystemBackground();
}
4 changes: 4 additions & 0 deletions clock_common/config/appearance_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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;
};
44 changes: 34 additions & 10 deletions plugin_core/impl/appearance_settings_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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(),
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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(),
Expand Down
Loading

0 comments on commit 6569d62

Please sign in to comment.