diff --git a/src/framework/ui/internal/uiconfiguration.cpp b/src/framework/ui/internal/uiconfiguration.cpp index 2c3e36744a717..4e8507754c4f2 100644 --- a/src/framework/ui/internal/uiconfiguration.cpp +++ b/src/framework/ui/internal/uiconfiguration.cpp @@ -29,11 +29,12 @@ #include "settings.h" #include "themeconverter.h" -#include #include +#include #include #include -#include +#include +#include #ifdef Q_OS_WIN #include @@ -43,12 +44,14 @@ #include "log.h" +using namespace Qt::Literals; using namespace muse; using namespace muse::ui; using namespace muse::async; static const Settings::Key UI_THEMES_KEY("ui", "ui/application/themes"); static const Settings::Key UI_CURRENT_THEME_CODE_KEY("ui", "ui/application/currentThemeCode"); +static const Settings::Key UI_CUSTOM_COLORS_KEY("ui", "ui/application/customColors"); static const Settings::Key UI_FOLLOW_SYSTEM_THEME_KEY("ui", "ui/application/followSystemTheme"); static const Settings::Key UI_FONT_FAMILY_KEY("ui", "ui/theme/fontFamily"); static const Settings::Key UI_FONT_SIZE_KEY("ui", "ui/theme/fontSize"); @@ -64,11 +67,30 @@ static const int FLICKABLE_MAX_VELOCITY = 4000; static const int TOOLTIP_DELAY = 500; +// read custom colors saved by Qt < 6.9 +// see: https://github.com/qt/qtbase/blob/v6.2.4/src/gui/kernel/qplatformdialoghelper.cpp#L292-L302 +static std::vector readLegacyCustomColors() +{ + constexpr size_t customColorCount = 16; + + QSettings settings(QSettings::UserScope, u"QtProject"_s); + std::vector legacyValues(customColorCount, Val(QColorConstants::White)); + for (size_t i = 0; i < customColorCount; ++i) { + const QVariant value = settings.value(u"Qt/customColors/"_s + QString::number(i)); + if (value.isValid()) { + legacyValues[i] = Val(QColor::fromRgb(value.toUInt())); + } + } + + return legacyValues; +} + void UiConfiguration::init() { m_config = ConfigReader::read(":/configs/ui.cfg"); settings()->setDefaultValue(UI_CURRENT_THEME_CODE_KEY, Val(LIGHT_THEME_CODE)); + settings()->setDefaultValue(UI_CUSTOM_COLORS_KEY, Val(readLegacyCustomColors())); settings()->setDefaultValue(UI_FOLLOW_SYSTEM_THEME_KEY, Val(false)); settings()->setDefaultValue(UI_FONT_FAMILY_KEY, Val(defaultFontFamily())); settings()->setDefaultValue(UI_FONT_SIZE_KEY, Val(defaultFontSize())); @@ -906,3 +928,27 @@ int UiConfiguration::tooltipDelay() const { return TOOLTIP_DELAY; } + +std::vector UiConfiguration::colorDialogCustomColors() const +{ + const ValList colorVals = settings()->value(UI_CUSTOM_COLORS_KEY).toList(); + + std::vector customColors; + customColors.reserve(colorVals.size()); + for (const auto& colorVal : colorVals) { + customColors.push_back(colorVal.toQColor()); + } + + return customColors; +} + +void UiConfiguration::setColorDialogCustomColors(const std::vector& customColors) +{ + ValList colorVals; + colorVals.reserve(customColors.size()); + for (const auto& color: customColors) { + colorVals.emplace_back(color); + } + + settings()->setLocalValue(UI_CUSTOM_COLORS_KEY, Val(colorVals)); +} diff --git a/src/framework/ui/internal/uiconfiguration.h b/src/framework/ui/internal/uiconfiguration.h index e87af01543695..79e6a4793ce23 100644 --- a/src/framework/ui/internal/uiconfiguration.h +++ b/src/framework/ui/internal/uiconfiguration.h @@ -131,6 +131,9 @@ class UiConfiguration : public IUiConfiguration, public Injectable, public async int tooltipDelay() const override; + std::vector colorDialogCustomColors() const override; + void setColorDialogCustomColors(const std::vector&) override; + private: void initThemes(); void correctUserFontIfNeeded(); diff --git a/src/framework/ui/iuiconfiguration.h b/src/framework/ui/iuiconfiguration.h index 3a3214e289ea2..bbd6285999004 100644 --- a/src/framework/ui/iuiconfiguration.h +++ b/src/framework/ui/iuiconfiguration.h @@ -24,6 +24,8 @@ #include +#include + #include "modularity/imoduleinterface.h" #include "global/types/retval.h" @@ -124,5 +126,8 @@ class IUiConfiguration : MODULE_EXPORT_INTERFACE virtual int flickableMaxVelocity() const = 0; virtual int tooltipDelay() const = 0; + + virtual std::vector colorDialogCustomColors() const = 0; + virtual void setColorDialogCustomColors(const std::vector&) = 0; }; } diff --git a/src/framework/ui/tests/mocks/uiconfigurationmock.h b/src/framework/ui/tests/mocks/uiconfigurationmock.h index 91b8bf9149430..b0247791ec9ae 100644 --- a/src/framework/ui/tests/mocks/uiconfigurationmock.h +++ b/src/framework/ui/tests/mocks/uiconfigurationmock.h @@ -108,5 +108,8 @@ class UiConfigurationMock : public IUiConfiguration MOCK_METHOD(int, flickableMaxVelocity, (), (const, override)); MOCK_METHOD(int, tooltipDelay, (), (const, override)); + + MOCK_METHOD(std::vector, colorDialogCustomColors, (), (const, override)); + MOCK_METHOD(void, setColorDialogCustomColors, (const std::vector&), (override)); }; } diff --git a/src/framework/ui/view/interactiveprovider.cpp b/src/framework/ui/view/interactiveprovider.cpp index 7905076da7cb8..78a07fd9ba6d7 100644 --- a/src/framework/ui/view/interactiveprovider.cpp +++ b/src/framework/ui/view/interactiveprovider.cpp @@ -79,6 +79,26 @@ void InteractiveProvider::raiseWindowInStack(QObject* newActiveWindow) } } +static std::vector getCustomColors() +{ + const int customColorCount = QColorDialog::customCount(); + std::vector customColors; + customColors.reserve(customColorCount); + for (int i = 0; i < customColorCount; ++i) { + customColors.push_back(QColorDialog::customColor(i)); + } + + return customColors; +} + +static void setCustomColors(const std::vector& customColors) +{ + const int customColorCount = std::min(QColorDialog::customCount(), static_cast(customColors.size())); + for (int i = 0; i < customColorCount; ++i) { + QColorDialog::setCustomColor(i, customColors[i]); + } +} + async::Promise InteractiveProvider::selectColor(const Color& color, const std::string& title) { if (m_isSelectColorOpened) { @@ -91,6 +111,8 @@ async::Promise InteractiveProvider::selectColor(const Color& color, const m_isSelectColorOpened = true; + setCustomColors(config()->colorDialogCustomColors()); + return async::make_promise([this, color, title](auto resolve, auto reject) { //! FIX https://github.com/musescore/MuseScore/issues/23208 shortcutsRegister()->setActive(false); @@ -105,6 +127,8 @@ async::Promise InteractiveProvider::selectColor(const Color& color, const QObject::connect(dlg, &QColorDialog::finished, [this, dlg, resolve, reject](int result) { dlg->deleteLater(); + config()->setColorDialogCustomColors(getCustomColors()); + m_isSelectColorOpened = false; shortcutsRegister()->setActive(true); diff --git a/src/framework/ui/view/interactiveprovider.h b/src/framework/ui/view/interactiveprovider.h index 71acf9ca63a06..17296f1bceba5 100644 --- a/src/framework/ui/view/interactiveprovider.h +++ b/src/framework/ui/view/interactiveprovider.h @@ -19,8 +19,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef MUSE_UI_INTERACTIVEPROVIDER_H -#define MUSE_UI_INTERACTIVEPROVIDER_H +#pragma once #include #include @@ -30,6 +29,7 @@ #include "global/async/asyncable.h" #include "modularity/ioc.h" +#include "ui/iuiconfiguration.h" #include "../iinteractiveprovider.h" #include "../iinteractiveuriregister.h" #include "../imainwindow.h" @@ -56,6 +56,7 @@ class InteractiveProvider : public QObject, public IInteractiveProvider, public { Q_OBJECT + Inject config = { this }; Inject uriRegister = { this }; Inject mainWindow = { this }; Inject extensionsProvider = { this }; @@ -149,5 +150,3 @@ class InteractiveProvider : public QObject, public IInteractiveProvider, public bool m_isSelectColorOpened = false; }; } - -#endif // MUSE_UI_INTERACTIVEPROVIDER_H