Make log colours themeable

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad
2024-08-21 22:11:43 +01:00
parent 1edfbeec8d
commit 2ad34c724e
18 changed files with 230 additions and 356 deletions

View File

@ -4,6 +4,7 @@
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (c) 2022 dada513 <dada513@protonmail.com>
* Copyright (C) 2022 Tayou <git@tayou.org>
* Copyright (C) 2024 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -50,6 +51,7 @@
#include "DesktopServices.h"
#include "settings/SettingsObject.h"
#include "ui/themes/ITheme.h"
#include "ui/themes/ThemeManager.h"
#include "updater/ExternalUpdater.h"
#include <QApplication>
@ -66,9 +68,6 @@ enum InstSortMode {
LauncherPage::LauncherPage(QWidget* parent) : QWidget(parent), ui(new Ui::LauncherPage)
{
ui->setupUi(this);
auto origForeground = ui->fontPreview->palette().color(ui->fontPreview->foregroundRole());
auto origBackground = ui->fontPreview->palette().color(ui->fontPreview->backgroundRole());
m_colors.reset(new LogColorCache(origForeground, origBackground));
ui->sortingModeGroup->setId(ui->sortByNameBtn, Sort_Name);
ui->sortingModeGroup->setId(ui->sortLastLaunchedBtn, Sort_LastLaunch);
@ -80,8 +79,9 @@ LauncherPage::LauncherPage(QWidget* parent) : QWidget(parent), ui(new Ui::Launch
ui->updateSettingsBox->setHidden(!APPLICATION->updater());
connect(ui->fontSizeBox, SIGNAL(valueChanged(int)), SLOT(refreshFontPreview()));
connect(ui->consoleFont, SIGNAL(currentFontChanged(QFont)), SLOT(refreshFontPreview()));
connect(ui->fontSizeBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &LauncherPage::refreshFontPreview);
connect(ui->consoleFont, &QFontComboBox::currentFontChanged, this, &LauncherPage::refreshFontPreview);
connect(ui->themeCustomizationWidget, &ThemeCustomizationWidget::currentWidgetThemeChanged, this, &LauncherPage::refreshFontPreview);
connect(ui->themeCustomizationWidget, &ThemeCustomizationWidget::currentCatChanged, APPLICATION, &Application::currentCatChanged);
}
@ -311,37 +311,47 @@ void LauncherPage::loadSettings()
void LauncherPage::refreshFontPreview()
{
const LogColors& colors = APPLICATION->themeManager()->getLogColors();
int fontSize = ui->fontSizeBox->value();
QString fontFamily = ui->consoleFont->currentFont().family();
ui->fontPreview->clear();
defaultFormat->setFont(QFont(fontFamily, fontSize));
{
auto print = [this, colors](const QString& message, MessageLevel::Enum level) {
QTextCharFormat format(*defaultFormat);
format.setForeground(m_colors->getFront(MessageLevel::Error));
QColor bg = colors.background.value(level);
QColor fg = colors.foreground.value(level);
if (bg.isValid())
format.setBackground(bg);
if (fg.isValid())
format.setForeground(fg);
// append a paragraph/line
auto workCursor = ui->fontPreview->textCursor();
workCursor.movePosition(QTextCursor::End);
workCursor.insertText(tr("[Something/ERROR] A spooky error!"), format);
workCursor.insertText(message, format);
workCursor.insertBlock();
}
{
QTextCharFormat format(*defaultFormat);
format.setForeground(m_colors->getFront(MessageLevel::Message));
// append a paragraph/line
auto workCursor = ui->fontPreview->textCursor();
workCursor.movePosition(QTextCursor::End);
workCursor.insertText(tr("[Test/INFO] A harmless message..."), format);
workCursor.insertBlock();
}
{
QTextCharFormat format(*defaultFormat);
format.setForeground(m_colors->getFront(MessageLevel::Warning));
// append a paragraph/line
auto workCursor = ui->fontPreview->textCursor();
workCursor.movePosition(QTextCursor::End);
workCursor.insertText(tr("[Something/WARN] A not so spooky warning."), format);
workCursor.insertBlock();
}
};
print(QString("%1 version: %2 (%3)\n")
.arg(BuildConfig.LAUNCHER_DISPLAYNAME, BuildConfig.printableVersionString(), BuildConfig.BUILD_PLATFORM),
MessageLevel::Launcher);
QDate today = QDate::currentDate();
if (today.month() == 10 && today.day() == 31)
print(tr("[Test/ERROR] OOoooOOOoooo! A spooky error!"), MessageLevel::Error);
else
print(tr("[Test/ERROR] A spooky error!"), MessageLevel::Error);
print(tr("[Test/INFO] A harmless message..."), MessageLevel::Info);
print(tr("[Test/WARN] A not so spooky warning."), MessageLevel::Warning);
print(tr("[Test/DEBUG] A secret debugging message..."), MessageLevel::Debug);
print(tr("[Test/FATAL] A terrifying fatal error!"), MessageLevel::Fatal);
}
void LauncherPage::retranslate()