Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions src/framework/ui/internal/uiconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
#include "settings.h"
#include "themeconverter.h"

#include <QScreen>
#include <QFontDatabase>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QScreen>
#include <QSettings>

#ifdef Q_OS_WIN
#include <QOperatingSystemVersion>
Expand All @@ -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");
Expand All @@ -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<Val> readLegacyCustomColors()
{
constexpr size_t customColorCount = 16;

QSettings settings(QSettings::UserScope, u"QtProject"_s);
std::vector<Val> 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()));
Expand Down Expand Up @@ -906,3 +928,27 @@ int UiConfiguration::tooltipDelay() const
{
return TOOLTIP_DELAY;
}

std::vector<QColor> UiConfiguration::colorDialogCustomColors() const
{
const ValList colorVals = settings()->value(UI_CUSTOM_COLORS_KEY).toList();

std::vector<QColor> customColors;
customColors.reserve(colorVals.size());
for (const auto& colorVal : colorVals) {
customColors.push_back(colorVal.toQColor());
}

return customColors;
}

void UiConfiguration::setColorDialogCustomColors(const std::vector<QColor>& customColors)
{
ValList colorVals;
colorVals.reserve(customColors.size());
for (const auto& color: customColors) {
colorVals.emplace_back(color);
}

settings()->setLocalValue(UI_CUSTOM_COLORS_KEY, Val(colorVals));
}
3 changes: 3 additions & 0 deletions src/framework/ui/internal/uiconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ class UiConfiguration : public IUiConfiguration, public Injectable, public async

int tooltipDelay() const override;

std::vector<QColor> colorDialogCustomColors() const override;
void setColorDialogCustomColors(const std::vector<QColor>&) override;

private:
void initThemes();
void correctUserFontIfNeeded();
Expand Down
5 changes: 5 additions & 0 deletions src/framework/ui/iuiconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include <optional>

#include <QColor>

#include "modularity/imoduleinterface.h"

#include "global/types/retval.h"
Expand Down Expand Up @@ -124,5 +126,8 @@ class IUiConfiguration : MODULE_EXPORT_INTERFACE
virtual int flickableMaxVelocity() const = 0;

virtual int tooltipDelay() const = 0;

virtual std::vector<QColor> colorDialogCustomColors() const = 0;
virtual void setColorDialogCustomColors(const std::vector<QColor>&) = 0;
};
}
3 changes: 3 additions & 0 deletions src/framework/ui/tests/mocks/uiconfigurationmock.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,8 @@ class UiConfigurationMock : public IUiConfiguration
MOCK_METHOD(int, flickableMaxVelocity, (), (const, override));

MOCK_METHOD(int, tooltipDelay, (), (const, override));

MOCK_METHOD(std::vector<QColor>, colorDialogCustomColors, (), (const, override));
MOCK_METHOD(void, setColorDialogCustomColors, (const std::vector<QColor>&), (override));
};
}
24 changes: 24 additions & 0 deletions src/framework/ui/view/interactiveprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,26 @@ void InteractiveProvider::raiseWindowInStack(QObject* newActiveWindow)
}
}

static std::vector<QColor> getCustomColors()
{
const int customColorCount = QColorDialog::customCount();
std::vector<QColor> 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<QColor>& customColors)
{
const int customColorCount = std::min(QColorDialog::customCount(), static_cast<int>(customColors.size()));
for (int i = 0; i < customColorCount; ++i) {
QColorDialog::setCustomColor(i, customColors[i]);
}
}

async::Promise<Color> InteractiveProvider::selectColor(const Color& color, const std::string& title)
{
if (m_isSelectColorOpened) {
Expand All @@ -91,6 +111,8 @@ async::Promise<Color> InteractiveProvider::selectColor(const Color& color, const

m_isSelectColorOpened = true;

setCustomColors(config()->colorDialogCustomColors());

return async::make_promise<Color>([this, color, title](auto resolve, auto reject) {
//! FIX https://github.com/musescore/MuseScore/issues/23208
shortcutsRegister()->setActive(false);
Expand All @@ -105,6 +127,8 @@ async::Promise<Color> 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);

Expand Down
7 changes: 3 additions & 4 deletions src/framework/ui/view/interactiveprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MUSE_UI_INTERACTIVEPROVIDER_H
#define MUSE_UI_INTERACTIVEPROVIDER_H
#pragma once

#include <QObject>
#include <QVariant>
Expand All @@ -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"
Expand All @@ -56,6 +56,7 @@ class InteractiveProvider : public QObject, public IInteractiveProvider, public
{
Q_OBJECT

Inject<IUiConfiguration> config = { this };
Inject<IInteractiveUriRegister> uriRegister = { this };
Inject<IMainWindow> mainWindow = { this };
Inject<muse::extensions::IExtensionsProvider> extensionsProvider = { this };
Expand Down Expand Up @@ -149,5 +150,3 @@ class InteractiveProvider : public QObject, public IInteractiveProvider, public
bool m_isSelectColorOpened = false;
};
}

#endif // MUSE_UI_INTERACTIVEPROVIDER_H
Loading