✨ feat: add defaultPalette options; rename "palettes" config section to "theme"
This commit is contained in:
@@ -19,11 +19,12 @@
|
|||||||
// wallpaper.dirs[].recursive boolean false Whether to search the directory recursively.
|
// wallpaper.dirs[].recursive boolean false Whether to search the directory recursively.
|
||||||
// wallpaper.excludes array [] Exclude patterns (regex)
|
// wallpaper.excludes array [] Exclude patterns (regex)
|
||||||
//
|
//
|
||||||
// palettes array []
|
// theme.defaultPalette string "" Name of the default palette to use
|
||||||
// palettes[].name string "" Name of the palette
|
// theme.palettes array []
|
||||||
// palettes[].colors array [] List of colors in the palette
|
// theme.palettes[].name string "" Name of the palette
|
||||||
// palettes[].colors[].name string "" Name of the color
|
// theme.palettes[].colors array [] List of colors in the palette
|
||||||
// palettes[].colors[].value string "" Color value in hex format, e.g. "#ff0000" for red
|
// theme.palettes[].colors[].name string "" Name of the color
|
||||||
|
// theme.palettes[].colors[].value string "" Color value in hex format, e.g. "#ff0000" for red
|
||||||
//
|
//
|
||||||
// action.previewDebounceTime number 300 Debounce time for preview action in milliseconds
|
// action.previewDebounceTime number 300 Debounce time for preview action in milliseconds
|
||||||
// action.printSelected boolean true Whether to print the selected wallpaper path to stdout on confirm
|
// action.printSelected boolean true Whether to print the selected wallpaper path to stdout on confirm
|
||||||
@@ -73,7 +74,7 @@ struct WallpaperConfigItems {
|
|||||||
QList<QRegularExpression> excludes;
|
QList<QRegularExpression> excludes;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PaletteConfigItems {
|
struct ThemeConfigItems {
|
||||||
struct PaletteColorConfigItem {
|
struct PaletteColorConfigItem {
|
||||||
QString name;
|
QString name;
|
||||||
QColor value;
|
QColor value;
|
||||||
@@ -85,6 +86,7 @@ struct PaletteConfigItems {
|
|||||||
};
|
};
|
||||||
|
|
||||||
QList<PaletteConfigItem> palettes;
|
QList<PaletteConfigItem> palettes;
|
||||||
|
QString defaultPalette;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ActionConfigItems {
|
struct ActionConfigItems {
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ void WallReel::Core::Config::Manager::_loadConfig(const QString& configPath) {
|
|||||||
const auto jsonObj = jsonDoc.object();
|
const auto jsonObj = jsonDoc.object();
|
||||||
|
|
||||||
_loadWallpaperConfig(jsonObj);
|
_loadWallpaperConfig(jsonObj);
|
||||||
_loadPaletteConfig(jsonObj);
|
_loadThemeConfig(jsonObj);
|
||||||
_loadActionConfig(jsonObj);
|
_loadActionConfig(jsonObj);
|
||||||
_loadStyleConfig(jsonObj);
|
_loadStyleConfig(jsonObj);
|
||||||
_loadSortConfig(jsonObj);
|
_loadSortConfig(jsonObj);
|
||||||
@@ -112,22 +112,30 @@ void WallReel::Core::Config::Manager::_loadWallpaperConfig(const QJsonObject& ro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WallReel::Core::Config::Manager::_loadPaletteConfig(const QJsonObject& root) {
|
void WallReel::Core::Config::Manager::_loadThemeConfig(const QJsonObject& root) {
|
||||||
if (!root.contains("palettes") || !root["palettes"].isArray()) {
|
if (!root.contains("theme") || !root["theme"].isObject()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const QJsonArray& palettes = root["palettes"].toArray();
|
const QJsonObject& theme = root["theme"].toObject();
|
||||||
|
if (theme.contains("defaultPalette") && theme["defaultPalette"].isString()) {
|
||||||
|
m_themeConfig.defaultPalette = theme["defaultPalette"].toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!theme.contains("palettes") || !theme["palettes"].isArray()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QJsonArray& palettes = theme["palettes"].toArray();
|
||||||
|
|
||||||
for (const auto& palItem : palettes) {
|
for (const auto& palItem : palettes) {
|
||||||
if (palItem.isObject()) {
|
if (palItem.isObject()) {
|
||||||
QJsonObject palObj = palItem.toObject();
|
QJsonObject palObj = palItem.toObject();
|
||||||
PaletteConfigItems::PaletteConfigItem palette;
|
ThemeConfigItems::PaletteConfigItem palette;
|
||||||
if (palObj.contains("name") && palObj["name"].isString()) {
|
if (palObj.contains("name") && palObj["name"].isString()) {
|
||||||
palette.name = palObj["name"].toString();
|
palette.name = palObj["name"].toString();
|
||||||
}
|
}
|
||||||
if (palObj.contains("colors") && palObj["colors"].isArray()) {
|
if (palObj.contains("colors") && palObj["colors"].isArray()) {
|
||||||
for (const auto& colorItem : palObj["colors"].toArray()) {
|
for (const auto& colorItem : palObj["colors"].toArray()) {
|
||||||
PaletteConfigItems::PaletteColorConfigItem colorConfig;
|
ThemeConfigItems::PaletteColorConfigItem colorConfig;
|
||||||
if (colorItem.isObject()) {
|
if (colorItem.isObject()) {
|
||||||
QJsonObject colorObj = colorItem.toObject();
|
QJsonObject colorObj = colorItem.toObject();
|
||||||
if (colorObj.contains("name") && colorObj["name"].isString()) {
|
if (colorObj.contains("name") && colorObj["name"].isString()) {
|
||||||
@@ -154,7 +162,7 @@ void WallReel::Core::Config::Manager::_loadPaletteConfig(const QJsonObject& root
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_paletteConfig.palettes.append(palette);
|
m_themeConfig.palettes.append(palette);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class Manager : public QObject {
|
|||||||
|
|
||||||
const WallpaperConfigItems& getWallpaperConfig() const { return m_wallpaperConfig; }
|
const WallpaperConfigItems& getWallpaperConfig() const { return m_wallpaperConfig; }
|
||||||
|
|
||||||
const PaletteConfigItems& getPaletteConfig() const { return m_paletteConfig; }
|
const ThemeConfigItems& getThemeConfig() const { return m_themeConfig; }
|
||||||
|
|
||||||
const ActionConfigItems& getActionConfig() const { return m_actionConfig; }
|
const ActionConfigItems& getActionConfig() const { return m_actionConfig; }
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ class Manager : public QObject {
|
|||||||
// Parse config
|
// Parse config
|
||||||
void _loadConfig(const QString& configPath);
|
void _loadConfig(const QString& configPath);
|
||||||
void _loadWallpaperConfig(const QJsonObject& config);
|
void _loadWallpaperConfig(const QJsonObject& config);
|
||||||
void _loadPaletteConfig(const QJsonObject& config);
|
void _loadThemeConfig(const QJsonObject& config);
|
||||||
void _loadActionConfig(const QJsonObject& config);
|
void _loadActionConfig(const QJsonObject& config);
|
||||||
void _loadStyleConfig(const QJsonObject& config);
|
void _loadStyleConfig(const QJsonObject& config);
|
||||||
void _loadSortConfig(const QJsonObject& config);
|
void _loadSortConfig(const QJsonObject& config);
|
||||||
@@ -108,7 +108,7 @@ class Manager : public QObject {
|
|||||||
private:
|
private:
|
||||||
const QDir m_configDir;
|
const QDir m_configDir;
|
||||||
WallpaperConfigItems m_wallpaperConfig;
|
WallpaperConfigItems m_wallpaperConfig;
|
||||||
PaletteConfigItems m_paletteConfig;
|
ThemeConfigItems m_themeConfig;
|
||||||
ActionConfigItems m_actionConfig;
|
ActionConfigItems m_actionConfig;
|
||||||
StyleConfigItems m_styleConfig;
|
StyleConfigItems m_styleConfig;
|
||||||
SortConfigItems m_sortConfig;
|
SortConfigItems m_sortConfig;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include "predefined.hpp"
|
#include "predefined.hpp"
|
||||||
|
|
||||||
WallReel::Core::Palette::Manager::Manager(
|
WallReel::Core::Palette::Manager::Manager(
|
||||||
const Config::PaletteConfigItems& config,
|
const Config::ThemeConfigItems& config,
|
||||||
Image::Model& imageModel,
|
Image::Model& imageModel,
|
||||||
QObject* parent) : QObject(parent), m_imageModel(imageModel) {
|
QObject* parent) : QObject(parent), m_imageModel(imageModel) {
|
||||||
connect(&m_imageModel, &Image::Model::focusedImageChanged, this, &Manager::updateColor);
|
connect(&m_imageModel, &Image::Model::focusedImageChanged, this, &Manager::updateColor);
|
||||||
@@ -45,6 +45,19 @@ WallReel::Core::Palette::Manager::Manager(
|
|||||||
m_palettes.append(newP);
|
m_palettes.append(newP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set default palette if specified
|
||||||
|
if (!config.defaultPalette.isEmpty()) {
|
||||||
|
for (const auto& p : m_palettes) {
|
||||||
|
if (p.name == config.defaultPalette) {
|
||||||
|
m_selectedColor = std::nullopt;
|
||||||
|
m_selectedPalette = p;
|
||||||
|
emit selectedColorChanged();
|
||||||
|
emit selectedPaletteChanged();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WallReel::Core::Palette::Manager::updateColor() {
|
void WallReel::Core::Palette::Manager::updateColor() {
|
||||||
|
|||||||
@@ -12,11 +12,13 @@ namespace WallReel::Core::Palette {
|
|||||||
class Manager : public QObject {
|
class Manager : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QList<PaletteItem> availablePalettes READ availablePalettes CONSTANT)
|
Q_PROPERTY(QList<PaletteItem> availablePalettes READ availablePalettes CONSTANT)
|
||||||
|
Q_PROPERTY(QVariant selectedPalette READ selectedPalette WRITE setSelectedPalette NOTIFY selectedPaletteChanged)
|
||||||
|
Q_PROPERTY(QVariant selectedColor READ selectedColor WRITE setSelectedColor NOTIFY selectedColorChanged)
|
||||||
Q_PROPERTY(QColor color READ color NOTIFY colorChanged)
|
Q_PROPERTY(QColor color READ color NOTIFY colorChanged)
|
||||||
Q_PROPERTY(QString colorName READ colorName NOTIFY colorNameChanged)
|
Q_PROPERTY(QString colorName READ colorName NOTIFY colorNameChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Manager(const Config::PaletteConfigItems& config,
|
Manager(const Config::ThemeConfigItems& config,
|
||||||
Image::Model& imageModel,
|
Image::Model& imageModel,
|
||||||
QObject* parent = nullptr);
|
QObject* parent = nullptr);
|
||||||
|
|
||||||
@@ -28,7 +30,19 @@ class Manager : public QObject {
|
|||||||
|
|
||||||
const QString& colorName() const { return m_displayColorName; }
|
const QString& colorName() const { return m_displayColorName; }
|
||||||
|
|
||||||
// Setters
|
QVariant selectedPalette() const {
|
||||||
|
if (m_selectedPalette) {
|
||||||
|
return QVariant::fromValue(*m_selectedPalette);
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant selectedColor() const {
|
||||||
|
if (m_selectedColor) {
|
||||||
|
return QVariant::fromValue(*m_selectedColor);
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
Q_INVOKABLE void setSelectedPalette(const QVariant& paletteVar) {
|
Q_INVOKABLE void setSelectedPalette(const QVariant& paletteVar) {
|
||||||
if (paletteVar.isNull() || !paletteVar.isValid()) {
|
if (paletteVar.isNull() || !paletteVar.isValid()) {
|
||||||
@@ -36,6 +50,9 @@ class Manager : public QObject {
|
|||||||
} else {
|
} else {
|
||||||
m_selectedPalette = paletteVar.value<PaletteItem>();
|
m_selectedPalette = paletteVar.value<PaletteItem>();
|
||||||
}
|
}
|
||||||
|
m_selectedColor = std::nullopt;
|
||||||
|
emit selectedPaletteChanged();
|
||||||
|
emit selectedColorChanged();
|
||||||
updateColor();
|
updateColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +62,7 @@ class Manager : public QObject {
|
|||||||
} else {
|
} else {
|
||||||
m_selectedColor = colorVar.value<ColorItem>();
|
m_selectedColor = colorVar.value<ColorItem>();
|
||||||
}
|
}
|
||||||
|
emit selectedColorChanged();
|
||||||
updateColor();
|
updateColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +102,8 @@ class Manager : public QObject {
|
|||||||
void updateColor(); // <- Image::Model::focusedImageChanged
|
void updateColor(); // <- Image::Model::focusedImageChanged
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void selectedPaletteChanged();
|
||||||
|
void selectedColorChanged();
|
||||||
void colorChanged();
|
void colorChanged();
|
||||||
void colorNameChanged();
|
void colorNameChanged();
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,14 @@ Item {
|
|||||||
|
|
||||||
implicitWidth: row.implicitWidth
|
implicitWidth: row.implicitWidth
|
||||||
implicitHeight: row.implicitHeight
|
implicitHeight: row.implicitHeight
|
||||||
|
Component.onCompleted: {
|
||||||
|
paletteCombo.currentIndex = selectedPalette ? availablePalettes.findIndex((p) => {
|
||||||
|
return p.name === selectedPalette.name;
|
||||||
|
}) : -1;
|
||||||
|
colorCombo.currentIndex = selectedColor ? availableColors.findIndex((c) => {
|
||||||
|
return c.name === selectedColor.name;
|
||||||
|
}) + 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
id: row
|
id: row
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ QtObject {
|
|||||||
property bool isSortReverse: ImageModel.currentSortReverse
|
property bool isSortReverse: ImageModel.currentSortReverse
|
||||||
//// Palette / Color
|
//// Palette / Color
|
||||||
readonly property var availablePalettes: PaletteManager.availablePalettes
|
readonly property var availablePalettes: PaletteManager.availablePalettes
|
||||||
property var selectedPalette: null // PaletteItem | null
|
property var selectedPalette: PaletteManager.selectedPalette // PaletteItem | null
|
||||||
readonly property var availableColors: selectedPalette ? selectedPalette.colors : []
|
readonly property var availableColors: selectedPalette ? selectedPalette.colors : []
|
||||||
property var selectedColor: null // ColorItem | null (null means "auto")
|
property var selectedColor: PaletteManager.selectedColor // ColorItem | null (null means "auto")
|
||||||
readonly property string colorName: PaletteManager.colorName
|
readonly property string colorName: PaletteManager.colorName
|
||||||
readonly property string colorHex: PaletteManager.color
|
readonly property string colorHex: PaletteManager.color
|
||||||
readonly property color colorValue: PaletteManager.color
|
readonly property color colorValue: PaletteManager.color
|
||||||
@@ -58,12 +58,11 @@ QtObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function selectPalette(palette) {
|
function selectPalette(palette) {
|
||||||
selectedPalette = palette;
|
PaletteManager.selectedPalette = palette;
|
||||||
selectedColor = null; // reset color when palette changes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectColor(colorItem) {
|
function selectColor(colorItem) {
|
||||||
selectedColor = colorItem;
|
PaletteManager.selectedColor = colorItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setSearchText(text) {
|
function setSearchText(text) {
|
||||||
@@ -83,10 +82,4 @@ QtObject {
|
|||||||
ImageModel.focusOnIndex(currentIndex);
|
ImageModel.focusOnIndex(currentIndex);
|
||||||
|
|
||||||
}
|
}
|
||||||
onSelectedPaletteChanged: () => {
|
|
||||||
PaletteManager.setSelectedPalette(selectedPalette);
|
|
||||||
}
|
|
||||||
onSelectedColorChanged: () => {
|
|
||||||
PaletteManager.setSelectedColor(selectedColor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ int main(int argc, char* argv[]) {
|
|||||||
imageModel);
|
imageModel);
|
||||||
|
|
||||||
auto paletteMgr = new Palette::Manager(
|
auto paletteMgr = new Palette::Manager(
|
||||||
config->getPaletteConfig(),
|
config->getThemeConfig(),
|
||||||
*imageModel,
|
*imageModel,
|
||||||
imageModel);
|
imageModel);
|
||||||
engine.rootContext()->setContextProperty("PaletteManager", paletteMgr);
|
engine.rootContext()->setContextProperty("PaletteManager", paletteMgr);
|
||||||
|
|||||||
Reference in New Issue
Block a user