icon font: logic minor improvement
No need to bundle the Segoe icon font file, the OS will always have them installed. Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
b8fee2e732
commit
b9d187d5f1
|
@ -1,7 +1,5 @@
|
||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/org.wangwenx190.FramelessHelper">
|
<qresource prefix="/org.wangwenx190.FramelessHelper">
|
||||||
<file>resources/fonts/Segoe Fluent Icons.ttf</file>
|
|
||||||
<file>resources/fonts/Segoe MDL2 Assets.ttf</file>
|
|
||||||
<file>resources/fonts/Micon.ttf</file>
|
<file>resources/fonts/Micon.ttf</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -59,37 +59,26 @@ Q_GLOBAL_STATIC(FramelessManagerHelper, g_helper)
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(FramelessManager, g_manager)
|
Q_GLOBAL_STATIC(FramelessManager, g_manager)
|
||||||
|
|
||||||
FRAMELESSHELPER_STRING_CONSTANT2(IconFontResourcePrefix, ":/org.wangwenx190.FramelessHelper/resources/fonts/")
|
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFilePath, ":/org.wangwenx190.FramelessHelper/resources/fonts/Micon.ttf")
|
||||||
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFileName_win11, "Segoe Fluent Icons.ttf")
|
|
||||||
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFileName_win, "Segoe MDL2 Assets.ttf")
|
|
||||||
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFileName_unix, "Micon.ttf")
|
|
||||||
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win11, "Segoe Fluent Icons")
|
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win11, "Segoe Fluent Icons")
|
||||||
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win, "Segoe MDL2 Assets")
|
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win10, "Segoe MDL2 Assets")
|
||||||
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_unix, "micon_nb")
|
FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_common, "micon_nb")
|
||||||
static constexpr const int kIconFontPointSize = 8;
|
static constexpr const int kIconFontPointSize = 8;
|
||||||
|
|
||||||
[[nodiscard]] static inline QString iconFontFilePath()
|
|
||||||
{
|
|
||||||
static const QString result = []() -> QString {
|
|
||||||
#ifdef Q_OS_WINDOWS
|
|
||||||
static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
|
|
||||||
return (kIconFontResourcePrefix + (isWin11OrGreater ? kIconFontFileName_win11 : kIconFontFileName_win));
|
|
||||||
#else
|
|
||||||
return (kIconFontResourcePrefix + kIconFontFileName_unix);
|
|
||||||
#endif
|
|
||||||
}();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] static inline QString iconFontFamilyName()
|
[[nodiscard]] static inline QString iconFontFamilyName()
|
||||||
{
|
{
|
||||||
static const QString result = []() -> QString {
|
static const QString result = []() -> QString {
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
|
static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
|
||||||
return (isWin11OrGreater ? kIconFontFamilyName_win11 : kIconFontFamilyName_win);
|
if (isWin11OrGreater) {
|
||||||
#else
|
return kIconFontFamilyName_win11;
|
||||||
return kIconFontFamilyName_unix;
|
}
|
||||||
|
static const bool isWin10OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1507);
|
||||||
|
if (isWin10OrGreater) {
|
||||||
|
return kIconFontFamilyName_win10;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
return kIconFontFamilyName_common;
|
||||||
}();
|
}();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -132,9 +121,9 @@ void FramelessManagerPrivate::initializeIconFont()
|
||||||
}
|
}
|
||||||
inited = true;
|
inited = true;
|
||||||
initResource();
|
initResource();
|
||||||
const int id = QFontDatabase::addApplicationFont(iconFontFilePath());
|
const int id = QFontDatabase::addApplicationFont(kIconFontFilePath);
|
||||||
if (id < 0) {
|
if (id < 0) {
|
||||||
qWarning() << "Failed to load icon font:" << iconFontFilePath();
|
qWarning() << "Failed to load icon font:" << kIconFontFilePath;
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Successfully registered icon font:" << QFontDatabase::applicationFontFamilies(id);
|
qDebug() << "Successfully registered icon font:" << QFontDatabase::applicationFontFamilies(id);
|
||||||
}
|
}
|
||||||
|
@ -261,7 +250,8 @@ void FramelessManagerPrivate::initialize()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
FramelessManager::FramelessManager(QObject *parent) : QObject(parent), d_ptr(new FramelessManagerPrivate(this))
|
FramelessManager::FramelessManager(QObject *parent) :
|
||||||
|
QObject(parent), d_ptr(new FramelessManagerPrivate(this))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -38,8 +38,8 @@ using namespace Global;
|
||||||
|
|
||||||
struct FONT_ICON
|
struct FONT_ICON
|
||||||
{
|
{
|
||||||
quint32 win = 0;
|
quint32 segoe = 0;
|
||||||
quint32 unix = 0;
|
quint32 micon = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const QHash<int, FONT_ICON> g_fontIconsTable = {
|
static const QHash<int, FONT_ICON> g_fontIconsTable = {
|
||||||
|
@ -123,16 +123,22 @@ Qt::Edges Utils::calculateWindowEdges(const QWindow *window, const QPoint &pos)
|
||||||
|
|
||||||
QString Utils::getSystemButtonIconCode(const SystemButtonType button)
|
QString Utils::getSystemButtonIconCode(const SystemButtonType button)
|
||||||
{
|
{
|
||||||
if (!g_fontIconsTable.contains(static_cast<int>(button))) {
|
const auto index = static_cast<int>(button);
|
||||||
|
if (!g_fontIconsTable.contains(index)) {
|
||||||
qWarning() << "FIXME: Add FONT_ICON value for button" << button;
|
qWarning() << "FIXME: Add FONT_ICON value for button" << button;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const FONT_ICON icon = g_fontIconsTable.value(static_cast<int>(button));
|
const FONT_ICON icon = g_fontIconsTable.value(index);
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
return QChar(icon.win);
|
// Windows 11: Segoe Fluent Icons (https://docs.microsoft.com/en-us/windows/apps/design/style/segoe-fluent-icons-font)
|
||||||
#else
|
// Windows 10: Segoe MDL2 Assets (https://docs.microsoft.com/en-us/windows/apps/design/style/segoe-ui-symbol-font)
|
||||||
return QChar(icon.unix);
|
// Windows 7~8.1: Micon (http://xtoolkit.github.io/Micon/)
|
||||||
|
static const bool isWin10OrGreater = isWindowsVersionOrGreater(WindowsVersion::_10_1507);
|
||||||
|
if (isWin10OrGreater) {
|
||||||
|
return QChar(icon.segoe);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
return QChar(icon.micon);
|
||||||
}
|
}
|
||||||
|
|
||||||
QWindow *Utils::findWindow(const WId windowId)
|
QWindow *Utils::findWindow(const WId windowId)
|
||||||
|
|
Loading…
Reference in New Issue