Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/modlistviewactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,10 @@ void ModListViewActions::setColor(const QModelIndexList& indices,
return;

settings.colors().setPreviousSeparatorColor(currentColor);
for (int i = 0; i < QColorDialog::customCount(); ++i) {
const auto customColor = dialog.customColor(i);
settings.colors().setCustomColor(i, customColor);
}

for (auto& idx : indices) {
ModInfo::Ptr info = ModInfo::getByIndex(idx.data(ModList::IndexRole).toInt());
Expand Down
39 changes: 38 additions & 1 deletion src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ void Settings::processUpdates(const QVersionNumber& currentVersion,
remove(m_Settings, "Settings", "load_mechanism");
});

version({2, 6, 0}, [&] {
m_Colors.copyGlobalCustomColors();
});

// save version in all case
set(m_Settings, "General", "version", currentVersion.toString());

Expand Down Expand Up @@ -1259,7 +1263,13 @@ void WidgetSettings::resetQuestionButtons()
removeSection(m_Settings, "DialogChoices");
}

ColorSettings::ColorSettings(QSettings& s) : m_Settings(s) {}
ColorSettings::ColorSettings(QSettings& s) : m_Settings(s)
{
for (int i = 0; i < QColorDialog::customCount(); ++i) {
const auto color = customColor(i);
QColorDialog::setCustomColor(i, color);
}
}

QColor ColorSettings::modlistOverwrittenLoose() const
{
Expand Down Expand Up @@ -1356,6 +1366,33 @@ void ColorSettings::removePreviousSeparatorColor()
remove(m_Settings, "General", "previousSeparatorColor");
}

QColor ColorSettings::customColor(const int index) const
{
return get<QColor>(m_Settings, "Settings", QString("customColor%1").arg(index),
QColor(255, 255, 255));
}

void ColorSettings::setCustomColor(const int index, const QColor& c)
{
set(m_Settings, "Settings", QString("customColor%1").arg(index), c);
}

void ColorSettings::copyGlobalCustomColors()
{
// see:
// https://codereview.qt-project.org/c/qt/qtbase/+/626629/3/src/gui/kernel/qplatformdialoghelper.cpp#b263
QSettings globalSettings(QSettings::UserScope, QStringLiteral("QtProject"));
for (int i = 0; i < QColorDialog::customCount(); ++i) {
const QVariant v = globalSettings.value(QLatin1StringView("Qt/customColors/") +
QString::number(i));

if (v.isValid()) {
const QRgb rgba = v.toUInt();
setCustomColor(i, QColor::fromRgba(rgba));
}
}
}

bool ColorSettings::colorSeparatorScrollbar() const
{
return get<bool>(m_Settings, "Settings", "colorSeparatorScrollbars", true);
Expand Down
8 changes: 8 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ class ColorSettings
void setPreviousSeparatorColor(const QColor& c) const;
void removePreviousSeparatorColor();

// custom colors set in QColorDialog (e.g. for separators)
QColor customColor(const int index) const;
void setCustomColor(const int index, const QColor& c);

// since MO v2.6.0, custom colors are no longer stored globally in Qt; this ensures
// custom colors set in older versions are retained when updating
void copyGlobalCustomColors();

// whether the scrollbar of the mod list should have colors for custom
// separator colors
//
Expand Down
Loading