1
0
Fork 0

Qt: Fix MicroProfile dpi scaling

This commit is contained in:
Yuri Kunde Schlesner 2016-06-18 23:37:09 -07:00
parent 8f86cc4df9
commit c52754e79a
1 changed files with 6 additions and 7 deletions

View File

@ -151,8 +151,8 @@ private:
/// This timer is used to redraw the widget's contents continuously. To save resources, it only /// This timer is used to redraw the widget's contents continuously. To save resources, it only
/// runs while the widget is visible. /// runs while the widget is visible.
QTimer update_timer; QTimer update_timer;
/// Scale the coordinate system appropriately when physical DPI != logical DPI. /// Scale the coordinate system appropriately when dpi != 96.
qreal x_scale, y_scale; qreal x_scale = 1.0, y_scale = 1.0;
}; };
#endif #endif
@ -222,15 +222,14 @@ MicroProfileWidget::MicroProfileWidget(QWidget* parent) : QWidget(parent) {
MicroProfileInitUI(); MicroProfileInitUI();
connect(&update_timer, SIGNAL(timeout()), SLOT(update())); connect(&update_timer, SIGNAL(timeout()), SLOT(update()));
QPainter painter(this);
x_scale = qreal(painter.device()->physicalDpiX()) / qreal(painter.device()->logicalDpiX());
y_scale = qreal(painter.device()->physicalDpiY()) / qreal(painter.device()->logicalDpiY());
} }
void MicroProfileWidget::paintEvent(QPaintEvent* ev) { void MicroProfileWidget::paintEvent(QPaintEvent* ev) {
QPainter painter(this); QPainter painter(this);
// The units used by Microprofile for drawing are based in pixels on a 96 dpi display.
x_scale = qreal(painter.device()->logicalDpiX()) / 96.0;
y_scale = qreal(painter.device()->logicalDpiY()) / 96.0;
painter.scale(x_scale, y_scale); painter.scale(x_scale, y_scale);
painter.setBackground(Qt::black); painter.setBackground(Qt::black);
@ -241,7 +240,7 @@ void MicroProfileWidget::paintEvent(QPaintEvent* ev) {
painter.setFont(font); painter.setFont(font);
mp_painter = &painter; mp_painter = &painter;
MicroProfileDraw(rect().width(), rect().height()); MicroProfileDraw(rect().width() / x_scale, rect().height() / y_scale);
mp_painter = nullptr; mp_painter = nullptr;
} }