diff --git a/makespec/BUILDVERSION b/makespec/BUILDVERSION index 864d5650..c48f9e04 100644 --- a/makespec/BUILDVERSION +++ b/makespec/BUILDVERSION @@ -1 +1 @@ -268 +269 diff --git a/src/base/settings.cpp b/src/base/settings.cpp index ec6d00cf..fba3e3ce 100644 --- a/src/base/settings.cpp +++ b/src/base/settings.cpp @@ -54,6 +54,15 @@ QColor ColorTheme::getColorNf() const { return colorNf; } QColor ColorTheme::getColorCe() const { return colorCe; } +void ColorTheme::invertLightness() { + mxColor.l = 100 - mxColor.l; + miColor.l = 100 - miColor.l; + nfColor.l = 100 - nfColor.l; + ceColor.l = 100 - ceColor.l; + colorNf = nfColor.toHsl(); + colorCe = ceColor.toHsl(); +} + void ColorTheme::copyFrom(ColorTheme *others) { setName(others->getName()); setColor(others->getMxColor(), others->getMiColor(), others->getNfColor(), others->getCeColor(), @@ -131,7 +140,7 @@ auto Settings::getCompilerList() const -> const QList & { return com const QList &Settings::getColorThemeList() const { return colorThemeList; } -const ColorTheme *Settings::getCurrentColorTheme() const { return colorThemeList[currentColorTheme]; } +ColorTheme Settings::getCurrentColorTheme() const { return *colorThemeList[currentColorTheme]; } auto Settings::getUiLanguage() const -> const QString & { return uiLanguage; } diff --git a/src/base/settings.h b/src/base/settings.h index bb56f4a3..84702318 100644 --- a/src/base/settings.h +++ b/src/base/settings.h @@ -59,8 +59,14 @@ class ColorTheme { QColor getColorPer(double, double) const; QColor getColorGrand(double, double) const; + void invertLightness(); + private: QString name; + // mxColor maxColor + // miColor minColor + // nfColor nofileColor + // ceColor compileErrorColor hslTuple mxColor, miColor, nfColor, ceColor; QColor colorNf, colorCe; dddTuple grandComp, grandRate; @@ -116,7 +122,7 @@ class Settings { void addColorTheme(ColorTheme *); void deleteColorTheme(int); ColorTheme *getColorTheme(int); - const ColorTheme *getCurrentColorTheme() const; + ColorTheme getCurrentColorTheme() const; int getCurrentColorThemeIndex() const; void setColorTheme(ColorTheme *, int); diff --git a/src/component/exportutil/exportutil.cpp b/src/component/exportutil/exportutil.cpp index 47aba669..aebc7dc0 100644 --- a/src/component/exportutil/exportutil.cpp +++ b/src/component/exportutil/exportutil.cpp @@ -217,9 +217,8 @@ auto ExportUtil::getContestantHtmlCode(Contest *contest, Contestant *contestant, */ void ExportUtil::exportHtml(QWidget *widget, Contest *contest, const QString &fileName) { Settings settings; - const ColorTheme *colors; contest->copySettings(settings); - colors = settings.getCurrentColorTheme(); + ColorTheme colors = settings.getCurrentColorTheme(); QFile file(fileName); @@ -343,7 +342,7 @@ void ExportUtil::exportHtml(QWidget *widget, Contest *contest, const QString &fi double s = NAN; double l = NAN; #endif - colors->getColorGrand(allScore, sfullScore).getHslF(&h, &s, &l); + colors.getColorGrand(allScore, sfullScore).getHslF(&h, &s, &l); h *= 360, s *= 100, l *= 100; out << QString("%1") @@ -369,15 +368,15 @@ void ExportUtil::exportHtml(QWidget *widget, Contest *contest, const QString &fi double s = NAN; double l = NAN; #endif - QColor col = colors->getColorPer(score, fullScore[j]); + QColor col = colors.getColorPer(score, fullScore[j]); col.getHslF(&h, &s, &l); if (taskList[j]->getTaskType() != Task::AnswersOnly && contestant->getCompileState(j) != CompileSuccessfully) { if (contestant->getCompileState(j) == NoValidSourceFile) { - colors->getColorNf().getHslF(&h, &s, &l); + colors.getColorNf().getHslF(&h, &s, &l); } else { - colors->getColorCe().getHslF(&h, &s, &l); + colors.getColorCe().getHslF(&h, &s, &l); } } diff --git a/src/resultviewer.cpp b/src/resultviewer.cpp index 27f2f5d4..c6c160ad 100644 --- a/src/resultviewer.cpp +++ b/src/resultviewer.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #define LEMON_MODULE_NAME "ResultViewer" @@ -107,8 +108,14 @@ void ResultViewer::refreshViewer() { QList taskList = curContest->getTaskList(); Settings setting; curContest->copySettings(setting); - const ColorTheme *colors = setting.getCurrentColorTheme(); + ColorTheme colors = setting.getCurrentColorTheme(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark) { + colors.invertLightness(); + LOG("Auto dark mode has been set"); + } +#endif for (auto &i : taskList) { headerList << i->getProblemTitle(); } @@ -144,11 +151,11 @@ void ResultViewer::refreshViewer() { if (taskList[j]->getTaskType() != Task::AnswersOnly && contestantList[i]->getCompileState(j) != CompileSuccessfully) { if (contestantList[i]->getCompileState(j) == NoValidSourceFile) - bg = colors->getColorNf(); + bg = colors.getColorNf(); else - bg = colors->getColorCe(); + bg = colors.getColorCe(); } else - bg = colors->getColorPer(score, fullScore[j]); + bg = colors.getColorPer(score, fullScore[j]); item(i, j + 3)->setBackground(bg); @@ -166,7 +173,7 @@ void ResultViewer::refreshViewer() { if (totalScore != -1) { item(i, 2)->setData(Qt::DisplayRole, totalScore); - item(i, 2)->setBackground(colors->getColorGrand(totalScore, sfullScore)); + item(i, 2)->setBackground(colors.getColorGrand(totalScore, sfullScore)); QFont font; font.setBold(true); item(i, 2)->setFont(font);