Skip to content

Commit

Permalink
config refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolcha committed Sep 7, 2024
1 parent 0c410ce commit 5650cce
Show file tree
Hide file tree
Showing 72 changed files with 405 additions and 532 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
48 changes: 0 additions & 48 deletions app/config/config_sections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,8 @@

#include "config_sections.hpp"

#include <QFile>

// complex default values should be implemneted here

QBrush SectionAppearance::getTexture() const
{
switch (getTextureType()) {
case None:
return Qt::NoBrush;
case SolidColor:
return getTextureColor();
case Gradient:
return getTextureGradient();
case Pattern:
return getTexturePattern();
}
Q_UNREACHABLE();
return Qt::NoBrush;
}

QPixmap SectionAppearance::getTexturePattern() const
{
if (QFile::exists(getTexturePatternFile()))
return QPixmap(getTexturePatternFile());
return sample_pattern();
}

QBrush SectionAppearance::getBackground() const
{
switch (getBackgroundType()) {
case None:
return Qt::NoBrush;
case SolidColor:
return getBackgroundColor();
case Gradient:
return getBackgroundGradient();
case Pattern:
return getBackgroundPattern();
}
Q_UNREACHABLE();
return Qt::NoBrush;
}

QPixmap SectionAppearance::getBackgroundPattern() const
{
if (QFile::exists(getBackgroundPatternFile()))
return QPixmap(getBackgroundPatternFile());
return sample_pattern();
}

QFont SectionAppearance::default_font()
{
#ifdef Q_OS_WINDOWS
Expand Down
35 changes: 4 additions & 31 deletions app/config/config_sections.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <QObject>

#include "config/settings_storage.hpp"
#include "config/sample_brushes.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 @@ -31,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 @@ -53,18 +53,9 @@ class SectionLimits : public SettingsStorageClient {

// per-window settings

class SectionAppearance : public SettingsStorageClient {
Q_GADGET
class SectionAppearance : public AppearanceSectionBase {
public:
enum CustomizationType {
None,
SolidColor,
Gradient,
Pattern,
};
Q_ENUM(CustomizationType)

using SettingsStorageClient::SettingsStorageClient;
using AppearanceSectionBase::AppearanceSectionBase;

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

QBrush getTexture() const;
CONFIG_OPTION_Q(CustomizationType, TextureType, SolidColor)
CONFIG_OPTION_Q(QColor, TextureColor, QColor(112, 96, 240))
CONFIG_OPTION_Q(QGradient, TextureGradient, sample_conical_gradient())
QPixmap getTexturePattern() const;
CONFIG_OPTION_Q(QString, TexturePatternFile, QString())
CONFIG_OPTION_Q(bool, TextureStretch, false)
CONFIG_OPTION_Q(bool, TexturePerCharacter, true)

QBrush getBackground() const;
CONFIG_OPTION_Q(CustomizationType, BackgroundType, None)
CONFIG_OPTION_Q(QColor, BackgroundColor, QColor(0, 0, 0, 160))
CONFIG_OPTION_Q(QGradient, BackgroundGradient, sample_linear_gradient())
QPixmap getBackgroundPattern() const;
CONFIG_OPTION_Q(QString, BackgroundPatternFile, QString())
CONFIG_OPTION_Q(bool, BackgroundStretch, false)
CONFIG_OPTION_Q(bool, BackgroundPerCharacter, false)

private:
static QFont default_font();
};
Expand Down
5 changes: 3 additions & 2 deletions clock_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
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
43 changes: 0 additions & 43 deletions clock_common/common_appearance_state.cpp

This file was deleted.

29 changes: 0 additions & 29 deletions clock_common/common_appearance_state.hpp

This file was deleted.

55 changes: 55 additions & 0 deletions clock_common/config/appearance_base.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* SPDX-FileCopyrightText: 2024 Nick Korotysh <[email protected]>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#include "appearance_base.hpp"

#include <QFile>

QBrush AppearanceSectionBase::getTexture() const
{
switch (getTextureType()) {
case None:
return Qt::NoBrush;
case SolidColor:
return getTextureColor();
case Gradient:
return getTextureGradient();
case Pattern:
return getTexturePattern();
}
Q_UNREACHABLE();
return Qt::NoBrush;
}

QPixmap AppearanceSectionBase::getTexturePattern() const
{
if (QFile::exists(getTexturePatternFile()))
return QPixmap(getTexturePatternFile());
return sample_pattern();
}

QBrush AppearanceSectionBase::getBackground() const
{
switch (getBackgroundType()) {
case None:
return Qt::NoBrush;
case SolidColor:
return getBackgroundColor();
case Gradient:
return getBackgroundGradient();
case Pattern:
return getBackgroundPattern();
}
Q_UNREACHABLE();
return Qt::NoBrush;
}

QPixmap AppearanceSectionBase::getBackgroundPattern() const
{
if (QFile::exists(getBackgroundPatternFile()))
return QPixmap(getBackgroundPatternFile());
return sample_pattern();
}
46 changes: 46 additions & 0 deletions clock_common/config/appearance_base.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* SPDX-FileCopyrightText: 2024 Nick Korotysh <[email protected]>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#pragma once

#include "settings_storage.hpp"

#include <QtCore/qtmetamacros.h>

#include "custom_converters.hpp"
#include "sample_brushes.hpp"

class CLOCK_COMMON_EXPORT AppearanceSectionBase : public SettingsStorageClient {
Q_GADGET
public:
enum CustomizationType {
None,
SolidColor,
Gradient,
Pattern,
};
Q_ENUM(CustomizationType)

using SettingsStorageClient::SettingsStorageClient;

QBrush getTexture() const;
CONFIG_OPTION_Q(CustomizationType, TextureType, SolidColor)
CONFIG_OPTION_Q(QColor, TextureColor, QColor(112, 96, 240))
CONFIG_OPTION_Q(QGradient, TextureGradient, sample_conical_gradient())
QPixmap getTexturePattern() const;
CONFIG_OPTION_Q(QString, TexturePatternFile, QString())
CONFIG_OPTION_Q(bool, TextureStretch, false)
CONFIG_OPTION_Q(bool, TexturePerCharacter, true)

QBrush getBackground() const;
CONFIG_OPTION_Q(CustomizationType, BackgroundType, None)
CONFIG_OPTION_Q(QColor, BackgroundColor, QColor(0, 0, 0, 160))
CONFIG_OPTION_Q(QGradient, BackgroundGradient, sample_linear_gradient())
QPixmap getBackgroundPattern() const;
CONFIG_OPTION_Q(QString, BackgroundPatternFile, QString())
CONFIG_OPTION_Q(bool, BackgroundStretch, false)
CONFIG_OPTION_Q(bool, BackgroundPerCharacter, false)
};
19 changes: 4 additions & 15 deletions clock_common/config/settings_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ void SettingsStorage::importSettings(const QVariantHash& s)
}


SettingsStorageClient::SettingsStorageClient(QString title, SettingsStorage& st)
SettingsStorageClient::SettingsStorageClient(QString title, ISettingsStorage& st)
: _st(st)
, _title(std::move(title))
{
}

void SettingsStorageClient::commit()
{
keysOperation(&SettingsStorage::commitValue);
keysOperation(&ISettingsStorage::commitValue);
}

void SettingsStorageClient::discard()
{
keysOperation(&SettingsStorage::discardValue);
keysOperation(&ISettingsStorage::discardValue);
}

void SettingsStorageClient::setValue(QString key, QVariant val)
Expand All @@ -100,18 +100,7 @@ void SettingsStorageClient::keysOperation(op_type op)
}


void SettingsClient::setValue(QString key, QVariant val)
{
SettingsStorageClient::setValue(std::move(key), std::move(val));
}

QVariant SettingsClient::value(QString key, QVariant def) const
{
return SettingsStorageClient::value(std::move(key), std::move(def));
}


StateClient::StateClient(QString title, SettingsStorage& st)
StateClient::StateClient(QString title, ISettingsStorage& st)
: _st(st)
, _title(title)
{
Expand Down
Loading

0 comments on commit 5650cce

Please sign in to comment.