Use Qt's High-DPI scaling on Windows (#4868)

This commit is contained in:
nerix
2024-05-12 13:59:14 +02:00
committed by GitHub
parent 8202cd0d99
commit febcf464fe
21 changed files with 459 additions and 320 deletions
+4 -15
View File
@@ -27,15 +27,6 @@
namespace chatterino {
namespace {
qreal deviceDpi(QWidget *widget)
{
#ifdef Q_OS_WIN
return widget->devicePixelRatioF();
#else
return 1.0;
#endif
}
// Translates the given rectangle by an amount in the direction to appear like the tab is selected.
// For example, if location is Top, the rectangle will be translated in the negative Y direction,
// or "up" on the screen, by amount.
@@ -196,8 +187,8 @@ int NotebookTab::normalTabWidth()
float scale = this->scale();
int width;
auto metrics = getIApp()->getFonts()->getFontMetrics(
FontStyle::UiTabs, float(qreal(this->scale()) * deviceDpi(this)));
QFontMetrics metrics =
getIApp()->getFonts()->getFontMetrics(FontStyle::UiTabs, scale);
if (this->hasXButton())
{
@@ -439,11 +430,9 @@ void NotebookTab::paintEvent(QPaintEvent *)
QPainter painter(this);
float scale = this->scale();
auto div = std::max<float>(0.01f, this->logicalDpiX() * deviceDpi(this));
painter.setFont(
getIApp()->getFonts()->getFont(FontStyle::UiTabs, scale * 96.f / div));
painter.setFont(app->getFonts()->getFont(FontStyle::UiTabs, scale));
QFontMetrics metrics =
app->getFonts()->getFontMetrics(FontStyle::UiTabs, scale * 96.f / div);
app->getFonts()->getFontMetrics(FontStyle::UiTabs, scale);
int height = int(scale * NOTEBOOK_TAB_HEIGHT);