QML UI: yet another attempt to fix the profile scaling

This one appears to work in my testing so far. And reading the code it
seems to make sense. We look at the size that the widget thinks it is. And
we scale the scene to fill that size (including a margin). And then let Qt
and QML deal with the rest of it. Assuming this works it shows that we
have been trying too hard all this time.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2016-01-18 12:32:47 -08:00
parent 38c60e02c7
commit 464b88f01f

View file

@ -22,20 +22,14 @@ QMLProfile::~QMLProfile()
void QMLProfile::paint(QPainter *painter)
{
m_profileWidget->setGeometry(QRect(0, 0, width(), height()));
// scale the profile widget's image to devicePixelRatio and a magic number
qreal dpr = 104; // that should give us 2% margin all around
qreal sx = width() / dpr;
qreal sy = height() / dpr;
qDebug() << "paint called; rect" << x() << y() << width() << height() << "dpr" << dpr << "sx/sy" << sx << sy;
// let's look at the intended size of the content and scale our scene accordingly
QRect rect = m_profileWidget->contentsRect();
qreal sceneSize = 104; // that should give us 2% margin all around (100x100 scene)
qreal sx = rect.width() / sceneSize;
qreal sy = rect.height() / sceneSize;
QTransform profileTransform;
profileTransform.scale(sx, sy);
m_profileWidget->setTransform(profileTransform);
qDebug() << "viewportTransform" << m_profileWidget->viewportTransform();
qDebug() << "after scaling we have margin/rect" << m_profileWidget->contentsMargins() << m_profileWidget->contentsRect();
qDebug() << "size of the QMLProfile:" << this->contentsSize() << this->contentsScale();
m_profileWidget->render(painter);
}