2929#include " settings.h"
3030#include " themeconverter.h"
3131
32- #include < QScreen>
3332#include < QFontDatabase>
33+ #include < QJsonArray>
3434#include < QJsonDocument>
3535#include < QJsonObject>
36- #include < QJsonArray>
36+ #include < QScreen>
37+ #include < QSettings>
3738
3839#ifdef Q_OS_WIN
3940#include < QOperatingSystemVersion>
4344
4445#include " log.h"
4546
47+ using namespace Qt ::Literals;
4648using namespace muse ;
4749using namespace muse ::ui;
4850using namespace muse ::async;
4951
5052static const Settings::Key UI_THEMES_KEY (" ui" , " ui/application/themes" );
5153static const Settings::Key UI_CURRENT_THEME_CODE_KEY (" ui" , " ui/application/currentThemeCode" );
54+ static const Settings::Key UI_CUSTOM_COLORS_KEY (" ui" , " ui/application/customColors" );
5255static const Settings::Key UI_FOLLOW_SYSTEM_THEME_KEY (" ui" , " ui/application/followSystemTheme" );
5356static const Settings::Key UI_FONT_FAMILY_KEY (" ui" , " ui/theme/fontFamily" );
5457static const Settings::Key UI_FONT_SIZE_KEY (" ui" , " ui/theme/fontSize" );
@@ -64,11 +67,30 @@ static const int FLICKABLE_MAX_VELOCITY = 4000;
6467
6568static const int TOOLTIP_DELAY = 500 ;
6669
70+ // read custom colors saved by Qt < 6.9
71+ // see: https://github.com/qt/qtbase/blob/v6.2.4/src/gui/kernel/qplatformdialoghelper.cpp#L292-L302
72+ static std::vector<Val> readLegacyCustomColors ()
73+ {
74+ constexpr size_t customColorCount = 16 ;
75+
76+ QSettings settings (QSettings::UserScope, u" QtProject" _s);
77+ std::vector<Val> legacyValues (customColorCount, Val (QColorConstants::White));
78+ for (size_t i = 0 ; i < customColorCount; ++i) {
79+ const QVariant value = settings.value (u" Qt/customColors/" _s + QString::number (i));
80+ if (value.isValid ()) {
81+ legacyValues[i] = Val (QColor::fromRgb (value.toUInt ()));
82+ }
83+ }
84+
85+ return legacyValues;
86+ }
87+
6788void UiConfiguration::init ()
6889{
6990 m_config = ConfigReader::read (" :/configs/ui.cfg" );
7091
7192 settings ()->setDefaultValue (UI_CURRENT_THEME_CODE_KEY, Val (LIGHT_THEME_CODE));
93+ settings ()->setDefaultValue (UI_CUSTOM_COLORS_KEY, Val (readLegacyCustomColors ()));
7294 settings ()->setDefaultValue (UI_FOLLOW_SYSTEM_THEME_KEY, Val (false ));
7395 settings ()->setDefaultValue (UI_FONT_FAMILY_KEY, Val (defaultFontFamily ()));
7496 settings ()->setDefaultValue (UI_FONT_SIZE_KEY, Val (defaultFontSize ()));
@@ -906,3 +928,27 @@ int UiConfiguration::tooltipDelay() const
906928{
907929 return TOOLTIP_DELAY;
908930}
931+
932+ std::vector<QColor> UiConfiguration::colorDialogCustomColors () const
933+ {
934+ const ValList colorVals = settings ()->value (UI_CUSTOM_COLORS_KEY).toList ();
935+
936+ std::vector<QColor> customColors;
937+ customColors.reserve (colorVals.size ());
938+ for (const auto & colorVal : colorVals) {
939+ customColors.push_back (colorVal.toQColor ());
940+ }
941+
942+ return customColors;
943+ }
944+
945+ void UiConfiguration::setColorDialogCustomColors (const std::vector<QColor>& customColors)
946+ {
947+ ValList colorVals;
948+ colorVals.reserve (customColors.size ());
949+ for (const auto & color: customColors) {
950+ colorVals.emplace_back (color);
951+ }
952+
953+ settings ()->setLocalValue (UI_CUSTOM_COLORS_KEY, Val (colorVals));
954+ }
0 commit comments