diff --git a/launcher/Application.cpp b/launcher/Application.cpp index c3477d331..b1cad5ad4 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -137,6 +137,7 @@ #if defined(Q_OS_LINUX) #include +#include #endif #if defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) @@ -798,6 +799,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) { m_globalSettingsProvider = std::make_shared(tr("Settings")); m_globalSettingsProvider->addPage(); + m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 0e4204cfb..0c07ca618 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -924,7 +924,7 @@ SET(LAUNCHER_SOURCES ui/pages/instance/McResolver.h ui/pages/instance/ServerPingTask.cpp ui/pages/instance/ServerPingTask.h - + # GUI - global settings pages ui/pages/global/AccountListPage.cpp ui/pages/global/AccountListPage.h @@ -937,6 +937,8 @@ SET(LAUNCHER_SOURCES ui/pages/global/MinecraftPage.h ui/pages/global/LauncherPage.cpp ui/pages/global/LauncherPage.h + ui/pages/global/AppearancePage.cpp + ui/pages/global/AppearancePage.h ui/pages/global/ProxyPage.cpp ui/pages/global/ProxyPage.h ui/pages/global/APIPage.cpp @@ -1177,6 +1179,7 @@ qt_wrap_ui(LAUNCHER_UI ui/pages/global/AccountListPage.ui ui/pages/global/JavaPage.ui ui/pages/global/LauncherPage.ui + ui/pages/global/AppearancePage.ui ui/pages/global/APIPage.ui ui/pages/global/ProxyPage.ui ui/pages/global/ExternalToolsPage.ui diff --git a/launcher/ui/pages/global/AppearancePage.cpp b/launcher/ui/pages/global/AppearancePage.cpp new file mode 100644 index 000000000..7b6c893c7 --- /dev/null +++ b/launcher/ui/pages/global/AppearancePage.cpp @@ -0,0 +1,104 @@ +#include "AppearancePage.h" +#include "ui_AppearancePage.h" + +#include +#include +#include + +AppearancePage::AppearancePage(QWidget* parent) : QWidget(parent), m_ui(new Ui::AppearancePage) +{ + m_ui->setupUi(this); + + defaultFormat = new QTextCharFormat(m_ui->fontPreview->currentCharFormat()); + + loadSettings(); + connect(m_ui->fontSizeBox, QOverload::of(&QSpinBox::valueChanged), this, &AppearancePage::updateFontPreview); + connect(m_ui->consoleFont, &QFontComboBox::currentFontChanged, this, &AppearancePage::updateFontPreview); + connect(m_ui->themeCustomizationWidget, &ThemeCustomizationWidget::currentWidgetThemeChanged, this, &AppearancePage::updateFontPreview); + connect(m_ui->themeCustomizationWidget, &ThemeCustomizationWidget::currentCatChanged, APPLICATION, &Application::currentCatChanged); +} + +AppearancePage::~AppearancePage() +{ + delete m_ui; +} + +bool AppearancePage::apply() +{ + applySettings(); + return true; +} + +void AppearancePage::retranslate() +{ + m_ui->retranslateUi(this); +} + +void AppearancePage::applySettings() +{ + SettingsObjectPtr settings = APPLICATION->settings(); + QString consoleFontFamily = m_ui->consoleFont->currentFont().family(); + settings->set("ConsoleFont", consoleFontFamily); + settings->set("ConsoleFontSize", m_ui->fontSizeBox->value()); +} + +void AppearancePage::loadSettings() +{ + QString fontFamily = APPLICATION->settings()->get("ConsoleFont").toString(); + QFont consoleFont(fontFamily); + m_ui->consoleFont->setCurrentFont(consoleFont); + + bool conversionOk = true; + int fontSize = APPLICATION->settings()->get("ConsoleFontSize").toInt(&conversionOk); + if (!conversionOk) { + fontSize = 11; + } + m_ui->fontSizeBox->setValue(fontSize); + + updateFontPreview(); +} + +void AppearancePage::updateFontPreview() +{ + const LogColors& colors = APPLICATION->themeManager()->getLogColors(); + + int fontSize = m_ui->fontSizeBox->value(); + QString fontFamily = m_ui->consoleFont->currentFont().family(); + m_ui->fontPreview->clear(); + defaultFormat->setFont(QFont(fontFamily, fontSize)); + + auto print = [this, colors](const QString& message, MessageLevel::Enum level) { + QTextCharFormat format(*defaultFormat); + + 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 = m_ui->fontPreview->textCursor(); + workCursor.movePosition(QTextCursor::End); + workCursor.insertText(message, 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); +} diff --git a/launcher/ui/pages/global/AppearancePage.h b/launcher/ui/pages/global/AppearancePage.h new file mode 100644 index 000000000..fe7cb3da7 --- /dev/null +++ b/launcher/ui/pages/global/AppearancePage.h @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (c) 2022 Jamie Mansfield + * + * 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 + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +#include +#include +#include "java/JavaChecker.h" +#include "ui/pages/BasePage.h" + +class QTextCharFormat; +class SettingsObject; + +namespace Ui { +class AppearancePage; +} + +class AppearancePage : public QWidget, public BasePage { + Q_OBJECT + + public: + explicit AppearancePage(QWidget* parent = 0); + ~AppearancePage(); + + QString displayName() const override { return tr("Appearance"); } + QIcon icon() const override { return APPLICATION->getThemedIcon("resourcepacks"); } + QString id() const override { return "appearance-settings"; } + QString helpPage() const override { return "Launcher-settings"; } + bool apply() override; + void retranslate() override; + + private: + void applySettings(); + void loadSettings(); + void updateFontPreview(); + + private: + Ui::AppearancePage* m_ui; + QTextCharFormat* defaultFormat; +}; diff --git a/launcher/ui/pages/global/AppearancePage.ui b/launcher/ui/pages/global/AppearancePage.ui new file mode 100644 index 000000000..d3ddfdb20 --- /dev/null +++ b/launcher/ui/pages/global/AppearancePage.ui @@ -0,0 +1,286 @@ + + + AppearancePage + + + + 0 + 0 + 600 + 700 + + + + Form + + + + + + Theme + + + + + + + + + + + + + 0 + 0 + + + + &Fonts + + + + + + + 0 + 0 + + + + + + + + 5 + + + 16 + + + 11 + + + + + + + Monospace Font + + + + + + + + + + Preview + + + + + + Icons + + + + + + + + + + + + + .. + + + true + + + + + + + + + + + .. + + + true + + + + + + + + + + + .. + + + true + + + + + + + + + + + .. + + + true + + + + + + + + + + + .. + + + true + + + + + + + + + + + .. + + + true + + + + + + + + + + + .. + + + true + + + + + + + + + + + .. + + + true + + + + + + + + + + + .. + + + true + + + + + + + + + + + .. + + + true + + + + + + + Qt::Horizontal + + + + + + + + + Qt::Horizontal + + + + + + + Console + + + + + + + + 0 + 0 + + + + Qt::ScrollBarAsNeeded + + + false + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + + + ThemeCustomizationWidget + QWidget +
ui/widgets/ThemeCustomizationWidget.h
+ 1 +
+
+ + +
diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.ui b/launcher/ui/widgets/ThemeCustomizationWidget.ui index 1faa45c4f..ed05c4292 100644 --- a/launcher/ui/widgets/ThemeCustomizationWidget.ui +++ b/launcher/ui/widgets/ThemeCustomizationWidget.ui @@ -13,180 +13,125 @@ Form - - - QLayout::SetMinimumSize - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - &Icons - - - iconsComboBox - - - - - - - - - - 0 - 0 - - - - Qt::StrongFocus - - - - - - - View icon themes folder. - - - - - - - - - true - - - - - - - - - &Widgets - - - widgetStyleComboBox - - - - - - - - - - 0 - 0 - - - - Qt::StrongFocus - - - - - - - View widget themes folder. - - - - - - - - - true - - - - - - - - - The cat appears in the background and is not shown by default. It is only made visible when pressing the Cat button in the Toolbar. - - - C&at - - - backgroundCatComboBox - - - - - - - - - - 0 - 0 - - - - Qt::StrongFocus - - - The cat appears in the background and is not shown by default. It is only made visible when pressing the Cat button in the Toolbar. - - - - - - - View cat packs folder. - - - - - - - - - true - - - - - - + + + + + View icon themes folder. + + + Open Folder + + - - + + + + The cat appears in the background and is not shown by default. It is only made visible when pressing the Cat button in the Toolbar. + + + C&at + + + backgroundCatComboBox + + + + + + + View cat packs folder. + + + Open Folder + + + + + + + &Icons + + + iconsComboBox + + + + + + + + 0 + 0 + + + + Qt::StrongFocus + + + + + + + &Widgets + + + widgetStyleComboBox + + + + + + + View widget themes folder. + + + Open Folder + + + + + + + + 0 + 0 + + + + Qt::StrongFocus + + + The cat appears in the background and is not shown by default. It is only made visible when pressing the Cat button in the Toolbar. + + + + + + + + 0 + 0 + + + + Qt::StrongFocus + + + + + Qt::Horizontal - - - 40 - 20 - - - Refresh all + Refresh All @@ -195,12 +140,6 @@ Qt::Horizontal - - - 40 - 20 - -