From 64b45e2dbdb16c732b79bda736214210f80fe212 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Mon, 19 Jun 2017 14:38:54 +0200 Subject: [PATCH] feat(Colors): provide a way to get colors (without alpha) --- src/components/other/colors/Colors.cpp | 24 ++++++++++++++++++++---- src/components/other/colors/Colors.hpp | 4 ++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/components/other/colors/Colors.cpp b/src/components/other/colors/Colors.cpp index d5d0433e4..f0bbaf71b 100644 --- a/src/components/other/colors/Colors.cpp +++ b/src/components/other/colors/Colors.cpp @@ -37,17 +37,33 @@ Colors::Colors (QObject *parent) : QObject(parent) { QObject::connect(CoreManager::getInstance(), &CoreManager::coreCreated, this, &Colors::overrideColors); } +// ----------------------------------------------------------------------------- + void Colors::overrideColors () { shared_ptr config = CoreManager::getInstance()->getCore()->getConfig(); const QMetaObject *info = metaObject(); for (int i = info->propertyOffset(); i < info->propertyCount(); ++i) { - const QMetaProperty &metaProperty = info->property(i); - - string colorName = metaProperty.name(); - string colorValue = config->getString(COLORS_SECTION, colorName, ""); + const QMetaProperty metaProperty = info->property(i); + const string colorName = metaProperty.name(); + const string colorValue = config->getString(COLORS_SECTION, colorName, ""); if (!colorValue.empty()) setProperty(colorName.c_str(), QColor(::Utils::coreStringToAppString(colorValue))); } } + +QStringList Colors::getColorNames () const { + static QStringList colorNames; + if (!colorNames.isEmpty()) + return colorNames; + + const QMetaObject *info = metaObject(); + for (int i = info->propertyOffset(); i < info->propertyCount(); ++i) { + const QMetaProperty metaProperty = info->property(i); + if (metaProperty.isWritable()) + colorNames << QString::fromLatin1(metaProperty.name()); + } + + return colorNames; +} diff --git a/src/components/other/colors/Colors.hpp b/src/components/other/colors/Colors.hpp index e59a96d68..f7d3c3395 100644 --- a/src/components/other/colors/Colors.hpp +++ b/src/components/other/colors/Colors.hpp @@ -50,6 +50,8 @@ class Colors : public QObject { Q_OBJECT; + Q_PROPERTY(QStringList colorNames READ getColorNames CONSTANT); + ADD_COLOR(a, "transparent"); ADD_COLOR(b, "#5E5E5F"); ADD_COLOR(c, "#CBCBCB"); @@ -124,6 +126,8 @@ signals: private: void overrideColors (); + + QStringList getColorNames () const; }; // -----------------------------------------------------------------------------