From 464b88f01fed745342080af3be12c21d64f1e449 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 18 Jan 2016 12:32:47 -0800 Subject: 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 --- qt-mobile/qmlprofile.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'qt-mobile/qmlprofile.cpp') diff --git a/qt-mobile/qmlprofile.cpp b/qt-mobile/qmlprofile.cpp index c617b73a3..82f7dfe4c 100644 --- a/qt-mobile/qmlprofile.cpp +++ b/qt-mobile/qmlprofile.cpp @@ -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); } -- cgit v1.2.3-70-g09d2