添加项目文件。
This commit is contained in:
131
APP/APP_Theme.cpp
Normal file
131
APP/APP_Theme.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
#include "APP/APP_Theme.h"
|
||||
|
||||
#include <QtGui/QFontDatabase>
|
||||
#include <QtWidgets/QApplication>
|
||||
|
||||
namespace APP {
|
||||
|
||||
QPalette APP_Theme::App_Func_GetPalette()
|
||||
{
|
||||
/*
|
||||
* 不用样式表时,Qt 最稳妥的统一美化方式就是调色板:
|
||||
* 1. 先选 Fusion 风格
|
||||
* 2. 再给标准控件一组统一颜色
|
||||
*/
|
||||
QPalette Palette;
|
||||
|
||||
const QColor WindowColor(20, 25, 33);
|
||||
const QColor BaseColor(28, 34, 42);
|
||||
const QColor AltBaseColor(34, 40, 49);
|
||||
const QColor ButtonColor(38, 44, 54);
|
||||
const QColor BorderHintColor(86, 96, 108);
|
||||
const QColor HighlightColor(72, 184, 162);
|
||||
const QColor TextColor(238, 242, 247);
|
||||
const QColor DimTextColor(162, 170, 182);
|
||||
|
||||
Palette.setColor(QPalette::Window, WindowColor);
|
||||
Palette.setColor(QPalette::WindowText, TextColor);
|
||||
Palette.setColor(QPalette::Base, BaseColor);
|
||||
Palette.setColor(QPalette::AlternateBase, AltBaseColor);
|
||||
Palette.setColor(QPalette::Text, TextColor);
|
||||
Palette.setColor(QPalette::Button, ButtonColor);
|
||||
Palette.setColor(QPalette::ButtonText, TextColor);
|
||||
Palette.setColor(QPalette::BrightText, QColor(255, 255, 255));
|
||||
Palette.setColor(QPalette::Light, BorderHintColor.lighter(120));
|
||||
Palette.setColor(QPalette::Midlight, BorderHintColor);
|
||||
Palette.setColor(QPalette::Mid, BorderHintColor.darker(120));
|
||||
Palette.setColor(QPalette::Dark, WindowColor.darker(140));
|
||||
Palette.setColor(QPalette::Shadow, QColor(0, 0, 0, 140));
|
||||
Palette.setColor(QPalette::Highlight, HighlightColor);
|
||||
Palette.setColor(QPalette::HighlightedText, TextColor);
|
||||
Palette.setColor(QPalette::ToolTipBase, BaseColor);
|
||||
Palette.setColor(QPalette::ToolTipText, TextColor);
|
||||
Palette.setColor(QPalette::Link, QColor(103, 146, 224));
|
||||
Palette.setColor(QPalette::PlaceholderText, QColor(170, 178, 188, 170));
|
||||
Palette.setColor(QPalette::Disabled, QPalette::WindowText, DimTextColor);
|
||||
Palette.setColor(QPalette::Disabled, QPalette::Text, DimTextColor);
|
||||
Palette.setColor(QPalette::Disabled, QPalette::ButtonText, DimTextColor);
|
||||
|
||||
return Palette;
|
||||
}
|
||||
|
||||
QFont APP_Theme::App_Func_GetBodyFont()
|
||||
{
|
||||
// 正文用相对稳妥、系统常见的字体候选。
|
||||
QFont Font(App_Func_PickFontFamily(QStringList()
|
||||
<< QStringLiteral("Segoe UI Variable Text")
|
||||
<< QStringLiteral("Microsoft YaHei UI")
|
||||
<< QStringLiteral("Segoe UI")
|
||||
<< QStringLiteral("Bahnschrift")));
|
||||
Font.setPointSize(10);
|
||||
Font.setWeight(QFont::Medium);
|
||||
return Font;
|
||||
}
|
||||
|
||||
QFont APP_Theme::App_Func_GetTitleFont()
|
||||
{
|
||||
// 页面标题字号更大、字重更高。
|
||||
QFont Font(App_Func_PickFontFamily(QStringList()
|
||||
<< QStringLiteral("Segoe UI Variable Display Semibold")
|
||||
<< QStringLiteral("Microsoft YaHei UI")
|
||||
<< QStringLiteral("Bahnschrift SemiBold")));
|
||||
Font.setPointSize(21);
|
||||
Font.setWeight(QFont::DemiBold);
|
||||
return Font;
|
||||
}
|
||||
|
||||
QFont APP_Theme::App_Func_GetMetricFont()
|
||||
{
|
||||
// 指标类标题用比正文更有力度的字重。
|
||||
QFont Font(App_Func_PickFontFamily(QStringList()
|
||||
<< QStringLiteral("Bahnschrift SemiBold")
|
||||
<< QStringLiteral("Segoe UI Semibold")
|
||||
<< QStringLiteral("Microsoft YaHei UI")));
|
||||
Font.setPointSize(12);
|
||||
Font.setWeight(QFont::DemiBold);
|
||||
return Font;
|
||||
}
|
||||
|
||||
QFont APP_Theme::App_Func_GetKeyLabelFont()
|
||||
{
|
||||
// 按键主文字字号较大,保证小键盘一眼能看清。
|
||||
QFont Font(App_Func_PickFontFamily(QStringList()
|
||||
<< QStringLiteral("Bahnschrift SemiBold")
|
||||
<< QStringLiteral("Segoe UI Semibold")
|
||||
<< QStringLiteral("Microsoft YaHei UI")));
|
||||
Font.setPointSize(22);
|
||||
return Font;
|
||||
}
|
||||
|
||||
QFont APP_Theme::App_Func_GetKeyHintFont()
|
||||
{
|
||||
// 按键 hint 放左上角,所以字号更小。
|
||||
QFont Font(App_Func_PickFontFamily(QStringList()
|
||||
<< QStringLiteral("Segoe UI Semibold")
|
||||
<< QStringLiteral("Bahnschrift SemiBold")
|
||||
<< QStringLiteral("Microsoft YaHei UI")));
|
||||
Font.setPointSize(8);
|
||||
Font.setLetterSpacing(QFont::AbsoluteSpacing, 1.0);
|
||||
return Font;
|
||||
}
|
||||
|
||||
QString APP_Theme::App_Func_PickFontFamily(const QStringList& FamilyList)
|
||||
{
|
||||
// 从候选字体里依次挑选系统真实存在的字体。
|
||||
const QFontDatabase Database;
|
||||
const QStringList AvailableFamilyList = Database.families();
|
||||
|
||||
for (int Index = 0; Index < FamilyList.size(); ++Index)
|
||||
{
|
||||
const QString& Family = FamilyList.at(Index);
|
||||
if (AvailableFamilyList.contains(Family))
|
||||
{
|
||||
return Family;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果都不存在,就退回 Qt 当前默认字体。
|
||||
return QApplication::font().family();
|
||||
}
|
||||
|
||||
} // namespace APP
|
||||
Reference in New Issue
Block a user