Files
create/src/Mod/Start/Gui/ThemeSelectorWidget.cpp

91 lines
3.7 KiB
C++

// SPDX-License-Identifier: LGPL-2.1-or-later
/****************************************************************************
* *
* Copyright (c) 2024 The FreeCAD Project Association AISBL *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
***************************************************************************/
#include <QHBoxLayout>
#include <QLabel>
#include <QString>
#include <QToolButton>
#include "ThemeSelectorWidget.h"
#include <gsl/pointers>
#include <Gui/PreferencePackManager.h>
using namespace StartGui;
ThemeSelectorWidget::ThemeSelectorWidget(QWidget* parent)
: QWidget(parent)
, _titleLabel {nullptr}
, _descriptionLabel {nullptr}
, _themeButton {nullptr}
{
setObjectName(QLatin1String("ThemeSelectorWidget"));
applyKindredCreateTheme();
setupUi();
qApp->installEventFilter(this);
}
void ThemeSelectorWidget::applyKindredCreateTheme()
{
auto prefPackManager = Gui::Application::Instance->prefPackManager();
prefPackManager->apply("KindredCreate");
}
void ThemeSelectorWidget::setupUi()
{
auto* outerLayout = gsl::owner<QVBoxLayout*>(new QVBoxLayout(this));
auto* buttonLayout = gsl::owner<QHBoxLayout*>(new QHBoxLayout);
_titleLabel = gsl::owner<QLabel*>(new QLabel);
_descriptionLabel = gsl::owner<QLabel*>(new QLabel);
outerLayout->addWidget(_titleLabel);
outerLayout->addLayout(buttonLayout);
outerLayout->addWidget(_descriptionLabel);
_themeButton = gsl::owner<QToolButton*>(new QToolButton());
_themeButton->setCheckable(true);
_themeButton->setChecked(true);
_themeButton->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextUnderIcon);
_themeButton->setIcon(QIcon(QLatin1String(":/thumbnails/Theme_thumbnail_dark.png")));
_themeButton->setIconSize(_themeButton->icon().actualSize(QSize(256, 256)));
buttonLayout->addWidget(_themeButton);
retranslateUi();
}
bool ThemeSelectorWidget::eventFilter(QObject* object, QEvent* event)
{
if (object == this && event->type() == QEvent::LanguageChange) {
this->retranslateUi();
}
return QWidget::eventFilter(object, event);
}
void ThemeSelectorWidget::retranslateUi()
{
_titleLabel->setText(QLatin1String("<h2>") + tr("Theme") + QLatin1String("</h2>"));
_descriptionLabel->setText(
tr("Kindred Create uses the Catppuccin Mocha theme.")
);
_themeButton->setText(tr("Kindred Create", "Visual theme name"));
}