Merge pull request #2596 from TayouVR/more-system-themes

Display all system themes in widget theme selector
This commit is contained in:
Alexandru Ionut Tripon 2024-07-09 12:55:22 +03:00 committed by GitHub
commit 5f345cedea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 236 additions and 37 deletions

View File

@ -1,3 +1,37 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2024 Tayou <git@tayou.org>
*
* 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 <https://www.gnu.org/licenses/>.
*
* 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.
*/
#include "BrightTheme.h" #include "BrightTheme.h"
#include <QObject> #include <QObject>
@ -55,3 +89,7 @@ QString BrightTheme::appStyleSheet()
{ {
return QString(); return QString();
} }
QString BrightTheme::tooltip()
{
return QString();
}

View File

@ -1,3 +1,37 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2024 Tayou <git@tayou.org>
*
* 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 <https://www.gnu.org/licenses/>.
*
* 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 #pragma once
#include "FusionTheme.h" #include "FusionTheme.h"
@ -8,6 +42,7 @@ class BrightTheme : public FusionTheme {
QString id() override; QString id() override;
QString name() override; QString name() override;
QString tooltip() override;
bool hasStyleSheet() override; bool hasStyleSheet() override;
QString appStyleSheet() override; QString appStyleSheet() override;
bool hasColorScheme() override; bool hasColorScheme() override;

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
/* /*
* Prism Launcher - Minecraft Launcher * Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Tayou <git@tayou.org> * Copyright (C) 2024 Tayou <git@tayou.org>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -285,3 +285,7 @@ QString CustomTheme::qtTheme()
{ {
return m_widgets; return m_widgets;
} }
QString CustomTheme::tooltip()
{
return m_tooltip;
}

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
/* /*
* Prism Launcher - Minecraft Launcher * Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Tayou <git@tayou.org> * Copyright (C) 2024 Tayou <git@tayou.org>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -44,6 +44,7 @@ class CustomTheme : public ITheme {
QString id() override; QString id() override;
QString name() override; QString name() override;
QString tooltip() override;
bool hasStyleSheet() override; bool hasStyleSheet() override;
QString appStyleSheet() override; QString appStyleSheet() override;
bool hasColorScheme() override; bool hasColorScheme() override;
@ -62,4 +63,10 @@ class CustomTheme : public ITheme {
QString m_id; QString m_id;
QString m_widgets; QString m_widgets;
QString m_qssFilePath; QString m_qssFilePath;
/**
* The tooltip could be defined in the theme json,
* or composed of other fields that could be in there.
* like author, license, etc.
*/
QString m_tooltip = "";
}; };

View File

@ -1,3 +1,37 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2024 Tayou <git@tayou.org>
*
* 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 <https://www.gnu.org/licenses/>.
*
* 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.
*/
#include "DarkTheme.h" #include "DarkTheme.h"
#include <QObject> #include <QObject>
@ -56,3 +90,7 @@ QString DarkTheme::appStyleSheet()
{ {
return "QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"; return "QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }";
} }
QString DarkTheme::tooltip()
{
return "";
}

View File

@ -1,3 +1,37 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2024 Tayou <git@tayou.org>
*
* 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 <https://www.gnu.org/licenses/>.
*
* 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 #pragma once
#include "FusionTheme.h" #include "FusionTheme.h"
@ -8,6 +42,7 @@ class DarkTheme : public FusionTheme {
QString id() override; QString id() override;
QString name() override; QString name() override;
QString tooltip() override;
bool hasStyleSheet() override; bool hasStyleSheet() override;
QString appStyleSheet() override; QString appStyleSheet() override;
bool hasColorScheme() override; bool hasColorScheme() override;

View File

@ -44,6 +44,7 @@ class ITheme {
virtual void apply(bool initial); virtual void apply(bool initial);
virtual QString id() = 0; virtual QString id() = 0;
virtual QString name() = 0; virtual QString name() = 0;
virtual QString tooltip() = 0;
virtual bool hasStyleSheet() = 0; virtual bool hasStyleSheet() = 0;
virtual QString appStyleSheet() = 0; virtual QString appStyleSheet() = 0;
virtual QString qtTheme() = 0; virtual QString qtTheme() = 0;

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
/* /*
* Prism Launcher - Minecraft Launcher * Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Tayou <git@tayou.org> * Copyright (C) 2024 Tayou <git@tayou.org>
* Copyright (C) 2024 TheKodeToad <TheKodeToad@proton.me> * Copyright (C) 2024 TheKodeToad <TheKodeToad@proton.me>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -35,31 +35,16 @@
*/ */
#include "SystemTheme.h" #include "SystemTheme.h"
#include <QApplication> #include <QApplication>
#include <QDebug>
#include <QStyle> #include <QStyle>
#include <QStyleFactory> #include <QStyleFactory>
#include "HintOverrideProxyStyle.h" #include "HintOverrideProxyStyle.h"
#include "ThemeManager.h" #include "ThemeManager.h"
SystemTheme::SystemTheme() SystemTheme::SystemTheme(QString& styleName, bool isSystemTheme)
{ {
themeDebugLog() << "Determining System Theme..."; themeName = isSystemTheme ? "system" : styleName;
const auto& style = QApplication::style(); widgetTheme = styleName;
systemPalette = QApplication::palette(); colorPalette = QApplication::palette();
QString lowerThemeName = style->objectName();
themeDebugLog() << "System theme seems to be:" << lowerThemeName;
QStringList styles = QStyleFactory::keys();
for (auto& st : styles) {
themeDebugLog() << "Considering theme from theme factory:" << st.toLower();
if (st.toLower() == lowerThemeName) {
systemTheme = st;
themeDebugLog() << "System theme has been determined to be:" << systemTheme;
return;
}
}
// fall back to fusion if we can't find the current theme.
systemTheme = "Fusion";
themeDebugLog() << "System theme not found, defaulted to Fusion";
} }
void SystemTheme::apply(bool initial) void SystemTheme::apply(bool initial)
@ -76,22 +61,49 @@ void SystemTheme::apply(bool initial)
QString SystemTheme::id() QString SystemTheme::id()
{ {
return "system"; return themeName;
} }
QString SystemTheme::name() QString SystemTheme::name()
{ {
if (themeName.toLower() == "windowsvista") {
return QObject::tr("Windows Vista");
} else if (themeName.toLower() == "windows") {
return QObject::tr("Windows 9x");
} else if (themeName.toLower() == "windows11") {
return QObject::tr("Windows 11");
} else if (themeName.toLower() == "system") {
return QObject::tr("System"); return QObject::tr("System");
} else {
return themeName;
}
}
QString SystemTheme::tooltip()
{
if (themeName.toLower() == "windowsvista") {
return QObject::tr("Widget style trying to look like your win32 theme");
} else if (themeName.toLower() == "windows") {
return QObject::tr("Windows 9x inspired widget style");
} else if (themeName.toLower() == "windows11") {
return QObject::tr("WinUI 3 inspired Qt widget style");
} else if (themeName.toLower() == "fusion") {
return QObject::tr("The default Qt widget style");
} else if (themeName.toLower() == "system") {
return QObject::tr("Your current system theme");
} else {
return "";
}
} }
QString SystemTheme::qtTheme() QString SystemTheme::qtTheme()
{ {
return systemTheme; return widgetTheme;
} }
QPalette SystemTheme::colorScheme() QPalette SystemTheme::colorScheme()
{ {
return systemPalette; return colorPalette;
} }
QString SystemTheme::appStyleSheet() QString SystemTheme::appStyleSheet()

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
/* /*
* Prism Launcher - Minecraft Launcher * Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Tayou <git@tayou.org> * Copyright (C) 2024 Tayou <git@tayou.org>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -38,12 +38,13 @@
class SystemTheme : public ITheme { class SystemTheme : public ITheme {
public: public:
SystemTheme(); SystemTheme(QString& themeName, bool isSystemTheme = false);
virtual ~SystemTheme() {} virtual ~SystemTheme() {}
void apply(bool initial) override; void apply(bool initial) override;
QString id() override; QString id() override;
QString name() override; QString name() override;
QString tooltip() override;
QString qtTheme() override; QString qtTheme() override;
bool hasStyleSheet() override; bool hasStyleSheet() override;
QString appStyleSheet() override; QString appStyleSheet() override;
@ -53,6 +54,7 @@ class SystemTheme : public ITheme {
QColor fadeColor() override; QColor fadeColor() override;
private: private:
QPalette systemPalette; QPalette colorPalette;
QString systemTheme; QString widgetTheme;
QString themeName;
}; };

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
/* /*
* Prism Launcher - Minecraft Launcher * Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Tayou <git@tayou.org> * Copyright (C) 2024 Tayou <git@tayou.org>
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me> * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -23,6 +23,8 @@
#include <QDirIterator> #include <QDirIterator>
#include <QIcon> #include <QIcon>
#include <QImageReader> #include <QImageReader>
#include <QStyle>
#include <QStyleFactory>
#include "Exception.h" #include "Exception.h"
#include "ui/themes/BrightTheme.h" #include "ui/themes/BrightTheme.h"
#include "ui/themes/CatPack.h" #include "ui/themes/CatPack.h"
@ -119,14 +121,30 @@ void ThemeManager::initializeIcons()
void ThemeManager::initializeWidgets() void ThemeManager::initializeWidgets()
{ {
themeDebugLog() << "Determining System Widget Theme...";
const auto& style = QApplication::style();
currentlySelectedSystemTheme = style->objectName();
themeDebugLog() << "System theme seems to be:" << currentlySelectedSystemTheme;
themeDebugLog() << "<> Initializing Widget Themes"; themeDebugLog() << "<> Initializing Widget Themes";
themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<SystemTheme>()); themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<SystemTheme>(currentlySelectedSystemTheme, true));
auto darkThemeId = addTheme(std::make_unique<DarkTheme>()); auto darkThemeId = addTheme(std::make_unique<DarkTheme>());
themeDebugLog() << "Loading Built-in Theme:" << darkThemeId; themeDebugLog() << "Loading Built-in Theme:" << darkThemeId;
themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<BrightTheme>()); themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<BrightTheme>());
// TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in themeDebugLog() << "<> Initializing System Widget Themes";
// dropdown?) QStringList styles = QStyleFactory::keys();
for (auto& st : styles) {
#ifdef Q_OS_WINDOWS
if (QSysInfo::productVersion() != "11" && st == "windows11") {
continue;
}
#endif
themeDebugLog() << "Loading System Theme:" << addTheme(std::make_unique<SystemTheme>(st));
}
// TODO: need some way to differentiate same name themes in different subdirectories
// (maybe smaller grey text next to theme name in dropdown?)
if (!m_applicationThemeFolder.mkpath(".")) if (!m_applicationThemeFolder.mkpath("."))
themeWarningLog() << "Couldn't create theme folder"; themeWarningLog() << "Couldn't create theme folder";
@ -238,7 +256,11 @@ void ThemeManager::applyCurrentlySelectedTheme(bool initial)
auto settings = APPLICATION->settings(); auto settings = APPLICATION->settings();
setIconTheme(settings->get("IconTheme").toString()); setIconTheme(settings->get("IconTheme").toString());
themeDebugLog() << "<> Icon theme set."; themeDebugLog() << "<> Icon theme set.";
setApplicationTheme(settings->get("ApplicationTheme").toString(), initial); auto applicationTheme = settings->get("ApplicationTheme").toString();
if (applicationTheme == "") {
applicationTheme = currentlySelectedSystemTheme;
}
setApplicationTheme(applicationTheme, initial);
themeDebugLog() << "<> Application theme set."; themeDebugLog() << "<> Application theme set.";
} }

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
/* /*
* Prism Launcher - Minecraft Launcher * Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Tayou <git@tayou.org> * Copyright (C) 2024 Tayou <git@tayou.org>
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me> * Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -64,6 +64,7 @@ class ThemeManager {
QDir m_applicationThemeFolder{ "themes" }; QDir m_applicationThemeFolder{ "themes" };
QDir m_catPacksFolder{ "catpacks" }; QDir m_catPacksFolder{ "catpacks" };
std::map<QString, std::unique_ptr<CatPack>> m_cat_packs; std::map<QString, std::unique_ptr<CatPack>> m_cat_packs;
QString currentlySelectedSystemTheme;
void initializeThemes(); void initializeThemes();
void initializeCatPacks(); void initializeCatPacks();

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
/* /*
* Prism Launcher - Minecraft Launcher * Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Tayou <git@tayou.org> * Copyright (C) 2024 Tayou <git@tayou.org>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -151,6 +151,10 @@ void ThemeCustomizationWidget::loadSettings()
int idx = 0; int idx = 0;
for (auto& theme : themes) { for (auto& theme : themes) {
ui->widgetStyleComboBox->addItem(theme->name(), theme->id()); ui->widgetStyleComboBox->addItem(theme->name(), theme->id());
if (theme->tooltip() != "") {
int index = ui->widgetStyleComboBox->count() - 1;
ui->widgetStyleComboBox->setItemData(index, theme->tooltip(), Qt::ToolTipRole);
}
if (currentTheme == theme->id()) { if (currentTheme == theme->id()) {
ui->widgetStyleComboBox->setCurrentIndex(idx); ui->widgetStyleComboBox->setCurrentIndex(idx);
} }