/* * SPDX-FileCopyrightText: 2020 Mathias Wein * * SPDX-License-Identifier: GPL-3.0-or-later */ #ifndef WGCONFIG_H #define WGCONFIG_H #include #include #include #include #include class KoColorSpace; namespace WGConfig { template struct GenericSetting { typedef T ValueType; T readValue(const KConfigGroup &group) const { return group.readEntry(name, defaultValue); } void writeValue(KConfigGroup &group, const T &value) const { group.writeEntry(name, value); } QString name; T defaultValue; }; template struct NumericSetting { typedef T ValueType; // the storage type, for enums it's the underlying integral type, otherwise T // NOTE: The use of std::remove_cv is because std::type_identity is C++20 using ST = typename std::conditional_t::value, std::underlying_type, std::remove_cv>::type; T readValue(const KConfigGroup &group) const { T value = static_cast(group.readEntry(name, static_cast(defaultValue))); return applyLimits(value); } void writeValue(KConfigGroup &group, const T &value) const { group.writeEntry(name, static_cast(value)); } T boundFunc(const T &min, const T &val, const T &max) const { return qBound(min, val, max); } T applyLimits(T value) const { if (enforceLimits) { return boundFunc(minValue, value, maxValue); } return value; } QString name; T defaultValue; T minValue; T maxValue; bool enforceLimits {false}; }; template<> inline QSize NumericSetting::boundFunc(const QSize &min, const QSize &val, const QSize &max) const { return val.expandedTo(min).boundedTo(max); } struct ShadeLine { ShadeLine() = default; explicit ShadeLine(QVector4D grad, QVector4D offs=QVector4D(), int patchC=-1) : gradient(grad), offset(offs), patchCount(patchC) {} QVector4D gradient; QVector4D offset; int patchCount {-1}; // negative value means slider mode }; class WGConfig { public: explicit WGConfig(bool readOnly = true); ~WGConfig(); template typename T::ValueType get(const T &setting, bool defaultValue = false) const { if (defaultValue) { return setting.defaultValue; } return setting.readValue(m_cfg); } template void set(const T &setting, const typename T::ValueType &value) { setting.writeValue(m_cfg, value); } static QString configGroupName(); KisColorSelectorConfiguration colorSelectorConfiguration() const; void setColorSelectorConfiguration(const KisColorSelectorConfiguration &config); QVector favoriteConfigurations(bool defaultValue = false) const; static QVector defaultFavoriteConfigurations(); void setFavoriteConfigurations(const QVector &favoriteConfigs); // shade selector static QVector defaultShadeSelectorLines(); QVector shadeSelectorLines(bool defaultValue = false) const; void setShadeSelectorLines(const QVector &shadeLines); const KoColorSpace* customSelectionColorSpace(bool defaultValue = false) const; void setCustomSelectionColorSpace(const KoColorSpace *cs); template void writeEntry(const QString& name, const T& value) { m_cfg.writeEntry(name, value); } template T readEntry(const QString& name, const T& defaultValue=T()) { return m_cfg.readEntry(name, defaultValue); } static const KisColorSelectorConfiguration defaultColorSelectorConfiguration; private: /*mutable*/ KConfigGroup m_cfg; bool m_readOnly; }; typedef WGConfig Accessor; class WGConfigNotifier : public QObject { Q_OBJECT public: WGConfigNotifier() = default; WGConfigNotifier(const WGConfigNotifier&) = delete; ~WGConfigNotifier() override = default; WGConfigNotifier operator=(const WGConfigNotifier&) = delete; /** * Notify that the plugin configuration has changed. This will cause the * configChanged() signal to be emitted. */ void notifyConfigChanged(); /** * Notify that a setting which affects KisVisualColorSelector or the * KisVisualColorModel it uses has changed. */ void notifySelectorConfigChanged(); Q_SIGNALS: /** * This signal is emitted whenever notifyConfigChanged() is called. */ void configChanged(); void selectorConfigChanged(); }; /** * @return the WGConfigNotifier singleton */ WGConfigNotifier* notifier(); /* ======== Configuration object definitions ======== / TODO: Think about splitting this off into individual headers / to prevent full recompile on every change. */ enum Scrolling { ScrollNone, ScrollLongitudinal, ScrollLaterally }; struct ColorPatches { NumericSetting orientation; NumericSetting patchSize; NumericSetting maxCount; NumericSetting rows; NumericSetting scrolling; }; extern const ColorPatches colorHistory; extern const ColorPatches commonColors; extern const ColorPatches popupPatches; extern const GenericSetting proofToPaintingColors; extern const GenericSetting colorHistoryEnabled; extern const GenericSetting commonColorsEnabled; extern const GenericSetting colorHistoryShowClearButton; extern const GenericSetting commonColorsAutoUpdate; extern const GenericSetting quickSettingsEnabled; extern const NumericSetting popupSize; // Shade Selector extern const GenericSetting minimalShadeSelectorEnabled; extern const NumericSetting shadeSelectorLineHeight; extern const GenericSetting shadeSelectorUpdateOnExternalChanges; extern const GenericSetting shadeSelectorUpdateOnInteractionEnd; extern const GenericSetting shadeSelectorUpdateOnRightClick; } // namespace WGConfig #endif // WGCONFIG_H