Skip to content

Commit

Permalink
config refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolcha committed Sep 8, 2024
1 parent b78f89c commit 22568ef
Show file tree
Hide file tree
Showing 74 changed files with 474 additions and 497 deletions.
3 changes: 2 additions & 1 deletion app/config/app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#pragma once

#include "config_sections.hpp"
#include "plugin_config.hpp"

class AppConfig;

Expand Down Expand Up @@ -48,7 +49,7 @@ class PluginConfig {
auto& state(size_t i) const { return _states[i]; }

private:
std::vector<SettingsClient> _configs;
std::vector<PluginSettingsStorage> _configs;
std::vector<StateClient> _states;
};

Expand Down
16 changes: 5 additions & 11 deletions app/config/config_sections.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
#pragma once

#include <QFont>
#include <QObject>

#include "config/settings_storage.hpp"
#include "config/appearance_base.hpp"

// even it may look as unnecessary and unused header,
// it is requeired due to some templates behind macro
Expand All @@ -29,7 +31,7 @@ class SectionAppGlobal : public SettingsStorageClient {
CONFIG_OPTION_Q(bool, CheckForBetaVersion, true)
CONFIG_OPTION_Q(int, UpdatePeriodDays, 7)

CONFIG_OPTION_Q(bool, TransparentOnHover, true)
CONFIG_OPTION_Q(bool, TransparentOnHover, false)
CONFIG_OPTION_Q(int, OpacityOnHover, 15)

CONFIG_OPTION_Q(QStringList, Plugins, QStringList())
Expand All @@ -51,9 +53,9 @@ class SectionLimits : public SettingsStorageClient {

// per-window settings

class SectionAppearance : public SettingsStorageClient {
class SectionAppearance : public AppearanceSectionBase {
public:
using SettingsStorageClient::SettingsStorageClient;
using AppearanceSectionBase::AppearanceSectionBase;

CONFIG_OPTION_Q(int, ScalingH, 100)
CONFIG_OPTION_Q(int, ScalingV, 100)
Expand All @@ -79,14 +81,6 @@ class SectionAppearance : public SettingsStorageClient {
CONFIG_OPTION_Q(QString, LayoutConfig, QString())
CONFIG_OPTION_Q(int, SecondsScaleFactor, 100)

CONFIG_OPTION_Q(QBrush, Texture, QColor(112, 96, 240))
CONFIG_OPTION_Q(bool, TextureStretch, false)
CONFIG_OPTION_Q(bool, TexturePerCharacter, true)

CONFIG_OPTION_Q(QBrush, Background, Qt::NoBrush)
CONFIG_OPTION_Q(bool, BackgroundStretch, false)
CONFIG_OPTION_Q(bool, BackgroundPerCharacter, false)

private:
static QFont default_font();
};
Expand Down
116 changes: 46 additions & 70 deletions app/gui/settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@
#include "core/application.hpp"
#include "platform/autostart.h"
#include "plugin_list_item_widget.hpp"
#include "common_appearance_state.hpp"

namespace {

class SettingsDialogState : public CommonAppearanceState {
public:
using CommonAppearanceState::CommonAppearanceState;
};

int setIndexByValue(QComboBox* box, const QVariant& value)
{
auto idx = box->findData(value);
Expand Down Expand Up @@ -413,46 +407,41 @@ void SettingsDialog::on_colorization_strength_edit_valueChanged(int arg1)

void SettingsDialog::on_texture_group_clicked(bool checked)
{
SettingsDialogState state(app->config().window(_curr_idx).state());

QBrush brush(Qt::NoBrush);
auto& acfg = app->config().window(_curr_idx).appearance();

if (checked) {
if (ui->tx_options_box->currentIndex() == 0)
brush = QBrush(state.getTextureColor());
acfg.setTextureType(SectionAppearance::SolidColor);

if (ui->tx_options_box->currentIndex() == 1)
brush = QBrush(state.getTextureGradient());
acfg.setTextureType(SectionAppearance::Gradient);

if (ui->tx_options_box->currentIndex() == 2)
brush = QBrush(state.getTexturePattern());
acfg.setTextureType(SectionAppearance::Pattern);
} else {
acfg.setTextureType(SectionAppearance::None);
}

app->config().window(_curr_idx).appearance().setTexture(brush);
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setTexture), brush);
notifyOptionChanged(&SettingsChangeTransmitter::setTexture, brush);
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setTexture), acfg.getTexture());
notifyOptionChanged(&SettingsChangeTransmitter::setTexture, acfg.getTexture());
}

void SettingsDialog::on_tx_options_box_activated(int index)
{
SettingsDialogState state(app->config().window(_curr_idx).state());
auto& acfg = app->config().window(_curr_idx).appearance();
switch (index) {
case 0: // color
app->config().window(_curr_idx).appearance().setTexture(state.getTextureColor());
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setTexture), state.getTextureColor());
notifyOptionChanged(&SettingsChangeTransmitter::setTexture, state.getTextureColor());
acfg.setTextureType(SectionAppearance::SolidColor);
break;
case 1: // gradient
app->config().window(_curr_idx).appearance().setTexture(state.getTextureGradient());
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setTexture), state.getTextureGradient());
notifyOptionChanged(&SettingsChangeTransmitter::setTexture, state.getTextureGradient());
acfg.setTextureType(SectionAppearance::Gradient);
break;
case 2: // pattern
app->config().window(_curr_idx).appearance().setTexture(state.getTexturePattern());
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setTexture), state.getTexturePattern());
notifyOptionChanged(&SettingsChangeTransmitter::setTexture, state.getTexturePattern());
acfg.setTextureType(SectionAppearance::Pattern);
break;
}
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setTexture), acfg.getTexture());
notifyOptionChanged(&SettingsChangeTransmitter::setTexture, acfg.getTexture());
}

void SettingsDialog::on_tx_options_box_currentIndexChanged(int index)
Expand Down Expand Up @@ -483,45 +472,41 @@ void SettingsDialog::on_tx_options_box_currentIndexChanged(int index)

void SettingsDialog::tx_select_color()
{
SettingsDialogState state(app->config().window(_curr_idx).state());
auto color = QColorDialog::getColor(state.getTextureColor(),
auto& acfg = app->config().window(_curr_idx).appearance();
auto color = QColorDialog::getColor(acfg.getTextureColor(),
this,
QString(),
QColorDialog::ShowAlphaChannel);
if (!color.isValid()) return;
app->config().window(_curr_idx).appearance().setTexture(color);
state.setTextureColor(color);
acfg.setTextureColor(color);
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setTexture), color);
notifyOptionChanged(&SettingsChangeTransmitter::setTexture, color);
}

void SettingsDialog::tx_select_gradient()
{
SettingsDialogState state(app->config().window(_curr_idx).state());
auto& acfg = app->config().window(_curr_idx).appearance();
bool ok = false;
auto gradient = GradientDialog::getGradient(&ok,
state.getTextureGradient(),
acfg.getTextureGradient(),
this);
if (!ok) return;
gradient.setCoordinateMode(QGradient::ObjectMode);
app->config().window(_curr_idx).appearance().setTexture(gradient);
state.setTextureGradient(gradient);
acfg.setTextureGradient(gradient);
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setTexture), gradient);
notifyOptionChanged(&SettingsChangeTransmitter::setTexture, gradient);
}

void SettingsDialog::tx_select_pattern()
{
SettingsDialogState state(app->config().window(_curr_idx).state());
auto& acfg = app->config().window(_curr_idx).appearance();
auto file = QFileDialog::getOpenFileName(this,
QString(),
_last_path,
acfg.getTexturePatternFile(),
tr("Images (*.png *.bmp *.jpg)"));
if (file.isEmpty()) return;
_last_path = file;
QPixmap pxm(file);
app->config().window(_curr_idx).appearance().setTexture(pxm);
state.setTexturePattern(pxm);
acfg.setTexturePatternFile(file);
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setTexture), pxm);
notifyOptionChanged(&SettingsChangeTransmitter::setTexture, pxm);
}
Expand All @@ -542,46 +527,41 @@ void SettingsDialog::on_tx_per_element_cb_clicked(bool checked)

void SettingsDialog::on_background_group_clicked(bool checked)
{
SettingsDialogState state(app->config().window(_curr_idx).state());

QBrush brush(Qt::NoBrush);
auto& acfg = app->config().window(_curr_idx).appearance();

if (checked) {
if (ui->bg_options_box->currentIndex() == 0)
brush = QBrush(state.getBackgroundColor());
acfg.setBackgroundType(SectionAppearance::SolidColor);

if (ui->bg_options_box->currentIndex() == 1)
brush = QBrush(state.getBackgroundGradient());
acfg.setBackgroundType(SectionAppearance::Gradient);

if (ui->bg_options_box->currentIndex() == 2)
brush = QBrush(state.getBackgroundPattern());
acfg.setBackgroundType(SectionAppearance::Pattern);
} else {
acfg.setBackgroundType(SectionAppearance::None);
}

app->config().window(_curr_idx).appearance().setBackground(brush);
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setBackground), brush);
notifyOptionChanged(&SettingsChangeTransmitter::setBackground, brush);
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setBackground), acfg.getBackground());
notifyOptionChanged(&SettingsChangeTransmitter::setBackground, acfg.getBackground());
}

void SettingsDialog::on_bg_options_box_activated(int index)
{
SettingsDialogState state(app->config().window(_curr_idx).state());
auto& acfg = app->config().window(_curr_idx).appearance();
switch (index) {
case 0: // color
app->config().window(_curr_idx).appearance().setBackground(state.getBackgroundColor());
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setBackground), state.getBackgroundColor());
notifyOptionChanged(&SettingsChangeTransmitter::setBackground, state.getBackgroundColor());
acfg.setBackgroundType(SectionAppearance::SolidColor);
break;
case 1: // gradient
app->config().window(_curr_idx).appearance().setBackground(state.getBackgroundGradient());
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setBackground), state.getBackgroundGradient());
notifyOptionChanged(&SettingsChangeTransmitter::setBackground, state.getBackgroundGradient());
acfg.setBackgroundType(SectionAppearance::Gradient);
break;
case 2: // pattern
app->config().window(_curr_idx).appearance().setBackground(state.getBackgroundPattern());
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setBackground), state.getBackgroundPattern());
notifyOptionChanged(&SettingsChangeTransmitter::setBackground, state.getBackgroundPattern());
acfg.setBackgroundType(SectionAppearance::Pattern);
break;
}
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setBackground), acfg.getBackground());
notifyOptionChanged(&SettingsChangeTransmitter::setBackground, acfg.getBackground());
}

void SettingsDialog::on_bg_options_box_currentIndexChanged(int index)
Expand Down Expand Up @@ -612,45 +592,41 @@ void SettingsDialog::on_bg_options_box_currentIndexChanged(int index)

void SettingsDialog::bg_select_color()
{
SettingsDialogState state(app->config().window(_curr_idx).state());
auto color = QColorDialog::getColor(state.getBackgroundColor(),
auto& acfg = app->config().window(_curr_idx).appearance();
auto color = QColorDialog::getColor(acfg.getBackgroundColor(),
this,
QString(),
QColorDialog::ShowAlphaChannel);
if (!color.isValid()) return;
app->config().window(_curr_idx).appearance().setBackground(color);
state.setBackgroundColor(color);
acfg.setBackgroundColor(color);
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setBackground), color);
notifyOptionChanged(&SettingsChangeTransmitter::setBackground, color);
}

void SettingsDialog::bg_select_gradient()
{
SettingsDialogState state(app->config().window(_curr_idx).state());
auto& acfg = app->config().window(_curr_idx).appearance();
bool ok = false;
auto gradient = GradientDialog::getGradient(&ok,
state.getBackgroundGradient(),
acfg.getBackgroundGradient(),
this);
if (!ok) return;
gradient.setCoordinateMode(QGradient::ObjectMode);
app->config().window(_curr_idx).appearance().setBackground(gradient);
state.setBackgroundGradient(gradient);
acfg.setBackgroundGradient(gradient);
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setBackground), gradient);
notifyOptionChanged(&SettingsChangeTransmitter::setBackground, gradient);
}

void SettingsDialog::bg_select_pattern()
{
SettingsDialogState state(app->config().window(_curr_idx).state());
auto& acfg = app->config().window(_curr_idx).appearance();
auto file = QFileDialog::getOpenFileName(this,
QString(),
_last_path,
acfg.getBackgroundPatternFile(),
tr("Images (*.png *.bmp *.jpg)"));
if (file.isEmpty()) return;
_last_path = file;
QPixmap pxm(file);
app->config().window(_curr_idx).appearance().setBackground(pxm);
state.setBackgroundPattern(pxm);
acfg.setBackgroundPatternFile(file);
applyClockOption(qOverload<QBrush>(&GraphicsDateTimeWidget::setBackground), pxm);
notifyOptionChanged(&SettingsChangeTransmitter::setBackground, pxm);
}
Expand Down
1 change: 0 additions & 1 deletion app/gui/settings_dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,4 @@ private slots:
Ui::SettingsDialog* ui;
Application* app;
int _curr_idx;
QString _last_path;
};
9 changes: 6 additions & 3 deletions clock_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later

project(ClockCommon VERSION 2.0.0 LANGUAGES CXX)
project(ClockCommon VERSION 2.0.1 LANGUAGES CXX)

qt_add_library(${PROJECT_NAME} SHARED
config/appearance_base.cpp
config/appearance_base.hpp
config/settings_storage.hpp
config/settings_storage.cpp
config/custom_converters.hpp
config/sample_brushes.cpp
config/sample_brushes.hpp
clock_common_global.hpp
state.cpp
state.hpp
common_appearance_state.cpp
common_appearance_state.hpp
)

add_win_rc_file(${PROJECT_NAME} clock_common.rc)
Expand Down
29 changes: 0 additions & 29 deletions clock_common/common_appearance_state.hpp

This file was deleted.

Loading

0 comments on commit 22568ef

Please sign in to comment.