mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
38c60e02c7
commit
464b88f01f
1 changed files with 5 additions and 11 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue