refactor: Fonts (#5228)

This commit is contained in:
pajlada
2024-03-10 14:27:08 +01:00
committed by GitHub
parent e56f7136a9
commit e7508332ff
16 changed files with 128 additions and 143 deletions
+10 -7
View File
@@ -1,4 +1,6 @@
#include "Label.hpp"
#include "widgets/Label.hpp"
#include "Application.hpp"
#include <QPainter>
@@ -14,9 +16,10 @@ Label::Label(BaseWidget *parent, QString text, FontStyle style)
, text_(std::move(text))
, fontStyle_(style)
{
this->connections_.managedConnect(getFonts()->fontChanged, [this] {
this->updateSize();
});
this->connections_.managedConnect(getIApp()->getFonts()->fontChanged,
[this] {
this->updateSize();
});
}
const QString &Label::getText() const
@@ -92,12 +95,12 @@ void Label::paintEvent(QPaintEvent *)
1.0;
#endif
QFontMetrics metrics = getFonts()->getFontMetrics(
QFontMetrics metrics = getIApp()->getFonts()->getFontMetrics(
this->getFontStyle(),
this->scale() * 96.f /
std::max<float>(
0.01F, static_cast<float>(this->logicalDpiX() * deviceDpi)));
painter.setFont(getFonts()->getFont(
painter.setFont(getIApp()->getFonts()->getFont(
this->getFontStyle(),
this->scale() * 96.f /
std::max<float>(
@@ -128,7 +131,7 @@ void Label::paintEvent(QPaintEvent *)
void Label::updateSize()
{
QFontMetrics metrics =
getFonts()->getFontMetrics(this->fontStyle_, this->scale());
getIApp()->getFonts()->getFontMetrics(this->fontStyle_, this->scale());
int width =
metrics.horizontalAdvance(this->text_) + (2 * this->getOffset());