mobile/profile: adjust offsets when scaling

If the user is scaling out again we need to make sure that our offsets
are adjusted so that we always show a subset of the profile and not
'empty space' outside of it. Instead of reimplementing the offset logic,
let's just trigger another paint() call.
This requires a trampoline function because of different signal and slot
signatures.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-03-24 15:02:17 -07:00
parent 577f713f1a
commit 6629d046b7
2 changed files with 13 additions and 0 deletions

View file

@ -24,9 +24,20 @@ QMLProfile::QMLProfile(QQuickItem *parent) :
m_profileWidget->setPrintMode(true); m_profileWidget->setPrintMode(true);
m_profileWidget->setFontPrintScale(fontScale); m_profileWidget->setFontPrintScale(fontScale);
connect(QMLManager::instance(), &QMLManager::sendScreenChanged, this, &QMLProfile::screenChanged); connect(QMLManager::instance(), &QMLManager::sendScreenChanged, this, &QMLProfile::screenChanged);
connect(this, &QMLProfile::scaleChanged, this, &QMLProfile::triggerUpdate);
setDevicePixelRatio(QMLManager::instance()->lastDevicePixelRatio()); setDevicePixelRatio(QMLManager::instance()->lastDevicePixelRatio());
} }
// we need this so we can connect update() to the scaleChanged() signal - which the connect above cannot do
// directly as it chokes on the default parameter for update().
// If the scale changes we may need to change our offsets to ensure that we still only show a subset of
// the profile and not empty space around it, which the paint() method below will take care of, which will
// eventually get called after we call update()
void QMLProfile::triggerUpdate()
{
update();
}
void QMLProfile::paint(QPainter *painter) void QMLProfile::paint(QPainter *painter)
{ {
QElapsedTimer timer; QElapsedTimer timer;

View file

@ -28,6 +28,8 @@ public:
public slots: public slots:
void setMargin(int margin); void setMargin(int margin);
void screenChanged(QScreen *screen); void screenChanged(QScreen *screen);
void triggerUpdate();
private: private:
int m_diveId; int m_diveId;
qreal m_devicePixelRatio; qreal m_devicePixelRatio;