better way to solve yesterday font problem, small visual avatar rendering fix

This commit is contained in:
Blue 2023-01-12 20:56:01 +03:00
parent 15fb4bbd62
commit d4bf7e599a
Signed by: blue
GPG key ID: 9B203B252A63EE38
9 changed files with 62 additions and 56 deletions

View file

@ -17,6 +17,7 @@
*/
#include "global.h"
#include <QFontDatabase>
#include "enums.h"
#include "ui/models/roster.h"
@ -26,6 +27,25 @@ constexpr bool OMEMO_SUPPORT = true;
constexpr bool OMEMO_SUPPORT = false
#endif
QFont getFont (QFontDatabase::SystemFont type, bool bold = false, bool italic = false, qreal factor = 1.0) {
QFont font = QFontDatabase::systemFont(type);
if (bold)
font.setBold(true);
if (italic)
font.setItalic(true);
if (factor != 1.0) {
float ps = font.pointSizeF();
if (ps != -1) {
font.setPointSizeF(ps * factor);
} else {
font.setPointSize(font.pointSize() * factor);
}
}
return font;
}
Shared::Global* Shared::Global::instance = 0;
const std::set<QString> Shared::Global::supportedImagesExts = {"png", "jpg", "webp", "jpeg", "gif", "svg"};
@ -102,6 +122,14 @@ Shared::Global::Global():
defaultSystemStyle(QApplication::style()->objectName()),
defaultSystemPalette(QApplication::palette()),
omemoSupport(OMEMO_SUPPORT),
defaultFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont)),
smallFont(getFont(QFontDatabase::SmallestReadableFont, false, true)),
headerFont(getFont(QFontDatabase::TitleFont, true, false, 1.1)),
titleFont(getFont(QFontDatabase::TitleFont, true, false, 1.3)),
defaultFontMetrics(defaultFont),
smallFontMetrics(smallFont),
headerFontMetrics(headerFont),
titleFontMetrics(titleFont),
pluginSupport({
{"KWallet", false},
{"openFileManagerWindowJob", false},

View file

@ -42,6 +42,8 @@
#include <QProcess>
#include <QDesktopServices>
#include <QRegularExpression>
#include <QFont>
#include <QFontMetrics>
namespace Shared {
@ -100,6 +102,14 @@ namespace Shared {
static void setTheme(const QString& path);
static void setStyle(const QString& style);
const bool omemoSupport;
QFont defaultFont;
QFont smallFont;
QFont headerFont;
QFont titleFont;
QFontMetrics defaultFontMetrics;
QFontMetrics smallFontMetrics;
QFontMetrics headerFontMetrics;
QFontMetrics titleFontMetrics;
template<typename T>
static T fromInt(int src);