2022-10-18 09:35:04 +00:00
|
|
|
#include "theme.h"
|
2021-11-18 14:58:01 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QFont>
|
|
|
|
#include <QFontMetrics>
|
2022-10-18 09:35:04 +00:00
|
|
|
#include <QPalette>
|
|
|
|
#include <QStyleFactory>
|
2021-11-18 14:58:01 +00:00
|
|
|
|
|
|
|
QColor Theme::white = QColor(0xf7, 0xd9, 0xc8);
|
|
|
|
QColor Theme::red = QColor(0xfc, 0x66, 0x21);
|
|
|
|
QColor Theme::green = QColor(0xaa, 0xeb, 0xc4);
|
|
|
|
QColor Theme::blue = QColor(0x0d, 0xa9, 0xf1);
|
2022-10-02 22:04:46 +00:00
|
|
|
QColor Theme::black = QColor(25, 25, 25);
|
|
|
|
QColor Theme::gray = QColor(0x32, 0x32, 0x32);
|
2021-11-18 14:58:01 +00:00
|
|
|
float Theme::normalAlpha = 96.0 / 255;
|
|
|
|
float Theme::checkedAlpha = 1.0;
|
|
|
|
float Theme::edgeAlpha = 1.0;
|
|
|
|
float Theme::fillAlpha = 50.0 / 255;
|
|
|
|
int Theme::toolIconFontSize = 0;
|
|
|
|
int Theme::toolIconSize = 0;
|
|
|
|
int Theme::miniIconFontSize = 0;
|
|
|
|
int Theme::miniIconSize = 0;
|
|
|
|
int Theme::partPreviewImageSize = 0;
|
|
|
|
int Theme::sidebarPreferredWidth = 0;
|
2022-10-05 12:26:39 +00:00
|
|
|
int Theme::previewIconBorderSize = 0;
|
|
|
|
int Theme::previewIconMargin = 0;
|
|
|
|
int Theme::previewIconBorderRadius = 0;
|
2021-11-18 14:58:01 +00:00
|
|
|
|
|
|
|
void Theme::initialize()
|
|
|
|
{
|
|
|
|
QApplication::setStyle(QStyleFactory::create("Fusion"));
|
|
|
|
|
|
|
|
QPalette darkPalette;
|
|
|
|
darkPalette.setColor(QPalette::Window, QColor(0x25, 0x25, 0x25));
|
|
|
|
darkPalette.setColor(QPalette::WindowText, QColor(0xf7, 0xd9, 0xc8));
|
|
|
|
darkPalette.setColor(QPalette::Base, QColor(25, 25, 25));
|
|
|
|
darkPalette.setColor(QPalette::AlternateBase, QColor(53, 53, 53));
|
|
|
|
darkPalette.setColor(QPalette::Text, QColor(0xf7, 0xd9, 0xc8));
|
|
|
|
darkPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(0x25, 0x25, 0x25));
|
|
|
|
darkPalette.setColor(QPalette::Button, QColor(53, 53, 53));
|
|
|
|
darkPalette.setColor(QPalette::ButtonText, QColor(0xf7, 0xd9, 0xc8));
|
|
|
|
darkPalette.setColor(QPalette::BrightText, QColor(0xfc, 0x66, 0x21));
|
|
|
|
darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
|
|
|
|
darkPalette.setColor(QPalette::Highlight, QColor(0xfc, 0x66, 0x21));
|
2022-10-18 09:35:04 +00:00
|
|
|
darkPalette.setColor(QPalette::HighlightedText, QColor(0x25, 0x25, 0x25));
|
2021-11-18 14:58:01 +00:00
|
|
|
QApplication::setPalette(darkPalette);
|
2022-10-18 09:35:04 +00:00
|
|
|
|
2021-11-18 14:58:01 +00:00
|
|
|
QFont font;
|
|
|
|
font.setWeight(QFont::Light);
|
|
|
|
font.setBold(false);
|
|
|
|
QApplication::setFont(font);
|
2022-10-18 09:35:04 +00:00
|
|
|
|
2021-11-18 14:58:01 +00:00
|
|
|
QFontMetrics fontMetrics(QApplication::font());
|
|
|
|
Theme::toolIconFontSize = fontMetrics.height();
|
|
|
|
Theme::toolIconSize = (int)(Theme::toolIconFontSize * 1.5);
|
|
|
|
Theme::miniIconFontSize = (int)(Theme::toolIconFontSize * 0.85);
|
|
|
|
Theme::miniIconSize = (int)(Theme::miniIconFontSize * 1.67);
|
2022-10-07 21:39:38 +00:00
|
|
|
Theme::partPreviewImageSize = (Theme::miniIconSize * 2.3);
|
2022-10-02 22:04:46 +00:00
|
|
|
Theme::sidebarPreferredWidth = Theme::partPreviewImageSize * 4.5;
|
2022-10-05 12:26:39 +00:00
|
|
|
Theme::previewIconBorderSize = std::max(1, Theme::partPreviewImageSize / 20);
|
|
|
|
Theme::previewIconMargin = std::max(1, Theme::previewIconBorderSize / 2);
|
|
|
|
Theme::previewIconBorderRadius = std::max(3, Theme::partPreviewImageSize / 10);
|
2021-11-18 14:58:01 +00:00
|
|
|
}
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
QtAwesome* Theme::awesome()
|
2021-11-18 14:58:01 +00:00
|
|
|
{
|
2022-10-18 09:35:04 +00:00
|
|
|
static QtAwesome* s_awesome = nullptr;
|
2021-11-18 14:58:01 +00:00
|
|
|
if (nullptr == s_awesome) {
|
|
|
|
s_awesome = new QtAwesome();
|
|
|
|
s_awesome->initFontAwesome();
|
|
|
|
s_awesome->setDefaultOption("color", Theme::white);
|
|
|
|
s_awesome->setDefaultOption("color-disabled", QColor(0xcc, 0xcc, 0xcc));
|
|
|
|
s_awesome->setDefaultOption("color-active", Theme::white);
|
|
|
|
s_awesome->setDefaultOption("color-selected", Theme::white);
|
|
|
|
}
|
|
|
|
return s_awesome;
|
|
|
|
}
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
void Theme::initAwesomeButton(QPushButton* button)
|
2021-11-18 14:58:01 +00:00
|
|
|
{
|
|
|
|
button->setFont(Theme::awesome()->font(Theme::toolIconFontSize));
|
|
|
|
button->setFixedSize(Theme::toolIconSize, Theme::toolIconSize);
|
|
|
|
button->setStyleSheet("QPushButton {color: " + Theme::white.name() + "}");
|
|
|
|
button->setFocusPolicy(Qt::NoFocus);
|
|
|
|
}
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
void Theme::initAwesomeLabel(QLabel* label)
|
2021-11-18 14:58:01 +00:00
|
|
|
{
|
|
|
|
label->setFont(Theme::awesome()->font(Theme::toolIconFontSize));
|
|
|
|
label->setStyleSheet("QLabel {color: " + Theme::white.name() + "}");
|
|
|
|
}
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
void Theme::initAwesomeMiniButton(QPushButton* button)
|
2021-11-18 14:58:01 +00:00
|
|
|
{
|
|
|
|
button->setFont(Theme::awesome()->font(Theme::miniIconFontSize));
|
|
|
|
button->setFixedSize(Theme::miniIconSize, Theme::miniIconSize);
|
|
|
|
button->setFocusPolicy(Qt::NoFocus);
|
|
|
|
}
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
void Theme::updateAwesomeMiniButton(QPushButton* button, QChar icon, bool highlighted, bool enabled, bool unnormal)
|
2021-11-18 14:58:01 +00:00
|
|
|
{
|
|
|
|
button->setText(icon);
|
|
|
|
QColor color;
|
|
|
|
bool needDesaturation = true;
|
2022-10-18 09:35:04 +00:00
|
|
|
|
2021-11-18 14:58:01 +00:00
|
|
|
if (highlighted) {
|
|
|
|
if (unnormal) {
|
|
|
|
color = Theme::blue;
|
|
|
|
needDesaturation = false;
|
|
|
|
} else {
|
|
|
|
color = Theme::white;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
color = QColor("#525252");
|
|
|
|
}
|
2022-10-18 09:35:04 +00:00
|
|
|
|
2021-11-18 14:58:01 +00:00
|
|
|
if (needDesaturation) {
|
|
|
|
color = color.toHsv();
|
|
|
|
color.setHsv(color.hue(), color.saturation() / 5, color.value() * 2 / 3);
|
|
|
|
color = color.toRgb();
|
|
|
|
}
|
2022-10-18 09:35:04 +00:00
|
|
|
|
2021-11-18 14:58:01 +00:00
|
|
|
if (!enabled) {
|
|
|
|
color = QColor(42, 42, 42);
|
|
|
|
}
|
|
|
|
|
|
|
|
button->setStyleSheet("QPushButton {border: none; background: none; color: " + color.name() + ";}");
|
|
|
|
}
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
void Theme::initAwesomeToolButtonWithoutFont(QPushButton* button)
|
2021-11-18 14:58:01 +00:00
|
|
|
{
|
|
|
|
button->setFixedSize(Theme::toolIconSize * 0.75, Theme::toolIconSize * 0.75);
|
|
|
|
button->setStyleSheet("QPushButton {color: " + Theme::white.name() + "}");
|
|
|
|
button->setFocusPolicy(Qt::NoFocus);
|
|
|
|
}
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
void Theme::initAwesomeToolButton(QPushButton* button)
|
2021-11-18 14:58:01 +00:00
|
|
|
{
|
|
|
|
button->setFont(Theme::awesome()->font(Theme::toolIconFontSize * 0.75));
|
|
|
|
Theme::initAwesomeToolButtonWithoutFont(button);
|
|
|
|
}
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
void Theme::initToolButton(QPushButton* button)
|
2021-11-18 14:58:01 +00:00
|
|
|
{
|
|
|
|
QFont font = button->font();
|
|
|
|
font.setWeight(QFont::Light);
|
|
|
|
font.setBold(false);
|
|
|
|
button->setFont(font);
|
|
|
|
button->setFixedHeight(Theme::toolIconSize * 0.75);
|
|
|
|
button->setStyleSheet("QPushButton {color: " + Theme::white.name() + "}");
|
|
|
|
button->setFocusPolicy(Qt::NoFocus);
|
|
|
|
}
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
void Theme::initCheckbox(QCheckBox* checkbox)
|
2021-11-18 14:58:01 +00:00
|
|
|
{
|
|
|
|
QPalette palette = checkbox->palette();
|
|
|
|
palette.setColor(QPalette::Background, Theme::white);
|
|
|
|
checkbox->setPalette(palette);
|
|
|
|
}
|
2022-10-14 11:11:41 +00:00
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
void Theme::initIconButton(QPushButton* button)
|
2022-10-14 11:11:41 +00:00
|
|
|
{
|
|
|
|
button->setFixedSize(Theme::toolIconSize, Theme::toolIconSize);
|
|
|
|
}
|