2022-10-29 18:27:20 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
2022-11-03 03:54:57 +00:00
|
|
|
* Prism Launcher - Minecraft Launcher
|
2023-06-28 22:02:34 +01:00
|
|
|
* Copyright (C) 2022 Tayou <git@tayou.org>
|
2022-10-29 18:27:20 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-10-21 08:07:26 +01:00
|
|
|
#include "SystemTheme.h"
|
|
|
|
#include <QApplication>
|
2023-01-09 15:54:10 +00:00
|
|
|
#include <QDebug>
|
2016-10-21 08:07:26 +01:00
|
|
|
#include <QStyle>
|
2016-10-22 00:43:36 +01:00
|
|
|
#include <QStyleFactory>
|
2022-10-29 18:27:20 +01:00
|
|
|
#include "ThemeManager.h"
|
2016-10-21 08:07:26 +01:00
|
|
|
|
|
|
|
SystemTheme::SystemTheme()
|
|
|
|
{
|
2022-11-01 14:41:08 +00:00
|
|
|
themeDebugLog() << "Determining System Theme...";
|
2023-01-09 15:54:10 +00:00
|
|
|
const auto& style = QApplication::style();
|
2023-05-24 14:18:08 +01:00
|
|
|
systemPalette = QApplication::palette();
|
2016-10-22 00:43:36 +01:00
|
|
|
QString lowerThemeName = style->objectName();
|
2022-11-01 14:41:08 +00:00
|
|
|
themeDebugLog() << "System theme seems to be:" << lowerThemeName;
|
2016-10-22 00:43:36 +01:00
|
|
|
QStringList styles = QStyleFactory::keys();
|
2023-01-09 15:54:10 +00:00
|
|
|
for (auto& st : styles) {
|
2022-11-01 14:41:08 +00:00
|
|
|
themeDebugLog() << "Considering theme from theme factory:" << st.toLower();
|
2023-01-09 15:54:10 +00:00
|
|
|
if (st.toLower() == lowerThemeName) {
|
2016-10-22 00:43:36 +01:00
|
|
|
systemTheme = st;
|
2022-11-01 14:41:08 +00:00
|
|
|
themeDebugLog() << "System theme has been determined to be:" << systemTheme;
|
2016-10-22 00:43:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fall back to fusion if we can't find the current theme.
|
|
|
|
systemTheme = "Fusion";
|
2022-11-01 14:41:08 +00:00
|
|
|
themeDebugLog() << "System theme not found, defaulted to Fusion";
|
2016-10-21 08:07:26 +01:00
|
|
|
}
|
|
|
|
|
2023-04-08 17:48:02 +01:00
|
|
|
void SystemTheme::apply(bool initial)
|
2017-01-18 01:45:04 +00:00
|
|
|
{
|
2023-04-08 17:48:02 +01:00
|
|
|
// See https://github.com/MultiMC/Launcher/issues/1790
|
|
|
|
// or https://github.com/PrismLauncher/PrismLauncher/issues/490
|
|
|
|
if (initial)
|
2023-08-14 17:16:53 +01:00
|
|
|
return;
|
2023-04-08 17:48:02 +01:00
|
|
|
ITheme::apply(initial);
|
2017-01-18 01:45:04 +00:00
|
|
|
}
|
|
|
|
|
2016-10-21 08:07:26 +01:00
|
|
|
QString SystemTheme::id()
|
|
|
|
{
|
|
|
|
return "system";
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SystemTheme::name()
|
|
|
|
{
|
|
|
|
return QObject::tr("System");
|
|
|
|
}
|
|
|
|
|
2016-10-22 00:43:36 +01:00
|
|
|
QString SystemTheme::qtTheme()
|
|
|
|
{
|
|
|
|
return systemTheme;
|
|
|
|
}
|
|
|
|
|
2016-10-21 08:07:26 +01:00
|
|
|
QPalette SystemTheme::colorScheme()
|
|
|
|
{
|
|
|
|
return systemPalette;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SystemTheme::appStyleSheet()
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
2016-11-06 03:29:12 +00:00
|
|
|
|
|
|
|
double SystemTheme::fadeAmount()
|
2017-01-18 01:45:04 +00:00
|
|
|
{
|
|
|
|
return 0.5;
|
|
|
|
}
|
2016-11-06 03:29:12 +00:00
|
|
|
|
|
|
|
QColor SystemTheme::fadeColor()
|
2017-01-18 01:45:04 +00:00
|
|
|
{
|
2023-01-09 15:54:10 +00:00
|
|
|
return QColor(128, 128, 128);
|
2017-01-18 01:45:04 +00:00
|
|
|
}
|
2017-01-15 21:56:03 +00:00
|
|
|
|
|
|
|
bool SystemTheme::hasStyleSheet()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemTheme::hasColorScheme()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|