| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2020 Mathias Wein <[email protected]> |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
#ifndef WGCONFIG_H |
| 8 |
#define WGCONFIG_H |
| 9 |
|
| 10 |
#include <KisColorSelectorConfiguration.h> |
| 11 |
|
| 12 |
#include <ksharedconfig.h> |
| 13 |
#include <kconfiggroup.h> |
| 14 |
|
| 15 |
#include <QVector4D> |
| 16 |
|
| 17 |
#include <type_traits> |
| 18 |
|
| 19 |
class KoColorSpace; |
| 20 |
|
| 21 |
namespace WGConfig { |
| 22 |
|
| 23 |
template<class T> struct GenericSetting |
| 24 |
{ |
| 25 |
typedef T ValueType; |
| 26 |
|
| 27 |
T readValue(const KConfigGroup &group) const |
| 28 |
{ |
| 29 |
return group.readEntry(name, defaultValue); |
| 30 |
} |
| 31 |
|
| 32 |
void writeValue(KConfigGroup &group, const T &value) const |
| 33 |
{ |
| 34 |
group.writeEntry(name, value); |
| 35 |
} |
| 36 |
|
| 37 |
QString name; |
| 38 |
T defaultValue; |
| 39 |
}; |
| 40 |
|
| 41 |
template<class T> struct NumericSetting |
| 42 |
{ |
| 43 |
typedef T ValueType; |
| 44 |
// the storage type, for enums it's the underlying integral type, otherwise T |
| 45 |
// NOTE: The use of std::remove_cv is because std::type_identity is C++20 |
| 46 |
using ST = typename std::conditional_t<std::is_enum<T>::value, std::underlying_type<T>, std::remove_cv<T>>::type; |
| 47 |
|
| 48 |
T readValue(const KConfigGroup &group) const |
| 49 |
{ |
| 50 |
T value = static_cast<T>(group.readEntry(name, static_cast<ST>(defaultValue))); |
| 51 |
return applyLimits(value); |
| 52 |
} |
| 53 |
|
| 54 |
void writeValue(KConfigGroup &group, const T &value) const |
| 55 |
{ |
| 56 |
group.writeEntry(name, static_cast<ST>(value)); |
| 57 |
} |
| 58 |
|
| 59 |
T boundFunc(const T &min, const T &val, const T &max) const |
| 60 |
{ |
| 61 |
return qBound(min, val, max); |
| 62 |
} |
| 63 |
|
| 64 |
T applyLimits(T value) const { |
| 65 |
if (enforceLimits) { |
| 66 |
return boundFunc(minValue, value, maxValue); |
| 67 |
} |
| 68 |
return value; |
| 69 |
} |
| 70 |
QString name; |
| 71 |
T defaultValue; |
| 72 |
T minValue; |
| 73 |
T maxValue; |
| 74 |
bool enforceLimits {false}; |
| 75 |
}; |
| 76 |
|
| 77 |
template<> |
| 78 |
inline QSize NumericSetting<QSize>::boundFunc(const QSize &min, const QSize &val, const QSize &max) const |
| 79 |
{ |
| 80 |
return val.expandedTo(min).boundedTo(max); |
| 81 |
} |
| 82 |
|
| 83 |
struct ShadeLine { |
| 84 |
ShadeLine() = default; |
| 85 |
explicit ShadeLine(QVector4D grad, QVector4D offs=QVector4D(), int patchC=-1) |
| 86 |
: gradient(grad), offset(offs), patchCount(patchC) {} |
| 87 |
QVector4D gradient; |
| 88 |
QVector4D offset; |
| 89 |
int patchCount {-1}; // negative value means slider mode |
| 90 |
}; |
| 91 |
|
| 92 |
class WGConfig |
| 93 |
{ |
| 94 |
public: |
| 95 |
|
| 96 |
explicit WGConfig(bool readOnly = true); |
| 97 |
~WGConfig(); |
| 98 |
|
| 99 |
template<class T> |
| 100 |
typename T::ValueType get(const T &setting, bool defaultValue = false) const |
| 101 |
{ |
| 102 |
if (defaultValue) { |
| 103 |
return setting.defaultValue; |
| 104 |
} |
| 105 |
return setting.readValue(m_cfg); |
| 106 |
} |
| 107 |
|
| 108 |
template<class T> |
| 109 |
void set(const T &setting, const typename T::ValueType &value) { setting.writeValue(m_cfg, value); } |
| 110 |
|
| 111 |
static QString configGroupName(); |
| 112 |
|
| 113 |
KisColorSelectorConfiguration colorSelectorConfiguration() const; |
| 114 |
void setColorSelectorConfiguration(const KisColorSelectorConfiguration &config); |
| 115 |
|
| 116 |
QVector<KisColorSelectorConfiguration> favoriteConfigurations(bool defaultValue = false) const; |
| 117 |
static QVector<KisColorSelectorConfiguration> defaultFavoriteConfigurations(); |
| 118 |
void setFavoriteConfigurations(const QVector<KisColorSelectorConfiguration> &favoriteConfigs); |
| 119 |
|
| 120 |
// shade selector |
| 121 |
static QVector<ShadeLine> defaultShadeSelectorLines(); |
| 122 |
QVector<ShadeLine> shadeSelectorLines(bool defaultValue = false) const; |
| 123 |
void setShadeSelectorLines(const QVector<ShadeLine> &shadeLines); |
| 124 |
|
| 125 |
const KoColorSpace* customSelectionColorSpace(bool defaultValue = false) const; |
| 126 |
void setCustomSelectionColorSpace(const KoColorSpace *cs); |
| 127 |
|
| 128 |
template<class T> |
| 129 |
void writeEntry(const QString& name, const T& value) { |
| 130 |
m_cfg.writeEntry(name, value); |
| 131 |
} |
| 132 |
|
| 133 |
template<class T> |
| 134 |
T readEntry(const QString& name, const T& defaultValue=T()) { |
| 135 |
return m_cfg.readEntry(name, defaultValue); |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
static const KisColorSelectorConfiguration defaultColorSelectorConfiguration; |
| 141 |
|
| 142 |
private: |
| 143 |
/*mutable*/ KConfigGroup m_cfg; |
| 144 |
bool m_readOnly; |
| 145 |
}; |
| 146 |
|
| 147 |
typedef WGConfig Accessor; |
| 148 |
|
| 149 |
class WGConfigNotifier : public QObject |
| 150 |
{ |
| 151 |
Q_OBJECT |
| 152 |
public: |
| 153 |
WGConfigNotifier() = default; |
| 154 |
WGConfigNotifier(const WGConfigNotifier&) = delete; |
| 155 |
~WGConfigNotifier() override = default; |
| 156 |
|
| 157 |
WGConfigNotifier operator=(const WGConfigNotifier&) = delete; |
| 158 |
|
| 159 |
/** |
| 160 |
* Notify that the plugin configuration has changed. This will cause the |
| 161 |
* configChanged() signal to be emitted. |
| 162 |
*/ |
| 163 |
void notifyConfigChanged(); |
| 164 |
/** |
| 165 |
* Notify that a setting which affects KisVisualColorSelector or the |
| 166 |
* KisVisualColorModel it uses has changed. |
| 167 |
*/ |
| 168 |
void notifySelectorConfigChanged(); |
| 169 |
|
| 170 |
Q_SIGNALS: |
| 171 |
/** |
| 172 |
* This signal is emitted whenever notifyConfigChanged() is called. |
| 173 |
*/ |
| 174 |
void configChanged(); |
| 175 |
void selectorConfigChanged(); |
| 176 |
}; |
| 177 |
|
| 178 |
/** |
| 179 |
* @return the WGConfigNotifier singleton |
| 180 |
*/ |
| 181 |
WGConfigNotifier* notifier(); |
| 182 |
|
| 183 |
/* ======== Configuration object definitions ======== |
| 184 |
/ TODO: Think about splitting this off into individual headers |
| 185 |
/ to prevent full recompile on every change. |
| 186 |
*/ |
| 187 |
|
| 188 |
enum Scrolling { |
| 189 |
ScrollNone, |
| 190 |
ScrollLongitudinal, |
| 191 |
ScrollLaterally |
| 192 |
}; |
| 193 |
|
| 194 |
struct ColorPatches |
| 195 |
{ |
| 196 |
NumericSetting<Qt::Orientation> orientation; |
| 197 |
NumericSetting<QSize> patchSize; |
| 198 |
NumericSetting<int> maxCount; |
| 199 |
NumericSetting<int> rows; |
| 200 |
NumericSetting<Scrolling> scrolling; |
| 201 |
}; |
| 202 |
|
| 203 |
extern const ColorPatches colorHistory; |
| 204 |
extern const ColorPatches commonColors; |
| 205 |
extern const ColorPatches popupPatches; |
| 206 |
|
| 207 |
extern const GenericSetting<bool> proofToPaintingColors; |
| 208 |
extern const GenericSetting<bool> colorHistoryEnabled; |
| 209 |
extern const GenericSetting<bool> commonColorsEnabled; |
| 210 |
extern const GenericSetting<bool> colorHistoryShowClearButton; |
| 211 |
extern const GenericSetting<bool> commonColorsAutoUpdate; |
| 212 |
|
| 213 |
extern const GenericSetting<bool> quickSettingsEnabled; |
| 214 |
extern const NumericSetting<int> popupSize; |
| 215 |
|
| 216 |
// Shade Selector |
| 217 |
extern const GenericSetting<bool> minimalShadeSelectorEnabled; |
| 218 |
extern const NumericSetting<int> shadeSelectorLineHeight; |
| 219 |
extern const GenericSetting<bool> shadeSelectorUpdateOnExternalChanges; |
| 220 |
extern const GenericSetting<bool> shadeSelectorUpdateOnInteractionEnd; |
| 221 |
extern const GenericSetting<bool> shadeSelectorUpdateOnRightClick; |
| 222 |
|
| 223 |
} // namespace WGConfig |
| 224 |
|
| 225 |
#endif // WGCONFIG_H |