mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
mobile/profile: add x/y offsets to widget
This will allow us to pan the profile around in the QML UI. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
31afa976f3
commit
51100cb20e
2 changed files with 30 additions and 4 deletions
|
@ -12,9 +12,12 @@ QMLProfile::QMLProfile(QQuickItem *parent) :
|
||||||
QQuickPaintedItem(parent),
|
QQuickPaintedItem(parent),
|
||||||
m_devicePixelRatio(1.0),
|
m_devicePixelRatio(1.0),
|
||||||
m_margin(0),
|
m_margin(0),
|
||||||
m_profileWidget(new ProfileWidget2)
|
m_profileWidget(new ProfileWidget2),
|
||||||
|
m_xOffset(0.0),
|
||||||
|
m_yOffset(0.0)
|
||||||
{
|
{
|
||||||
setAntialiasing(true);
|
setAntialiasing(true);
|
||||||
|
setFlags(QQuickItem::ItemClipsChildrenToShape | QQuickItem::ItemHasContents );
|
||||||
m_profileWidget->setProfileState();
|
m_profileWidget->setProfileState();
|
||||||
m_profileWidget->setPrintMode(true);
|
m_profileWidget->setPrintMode(true);
|
||||||
m_profileWidget->setFontPrintScale(0.8);
|
m_profileWidget->setFontPrintScale(0.8);
|
||||||
|
@ -58,7 +61,7 @@ void QMLProfile::paint(QPainter *painter)
|
||||||
QTransform profileTransform = QTransform();
|
QTransform profileTransform = QTransform();
|
||||||
profileTransform.scale(sx, sy);
|
profileTransform.scale(sx, sy);
|
||||||
QTransform painterTransform = painter->transform();
|
QTransform painterTransform = painter->transform();
|
||||||
painterTransform.translate(-painterRect.width() * magicShiftFactor ,-painterRect.height() * magicShiftFactor);
|
painterTransform.translate(dpr * m_xOffset - painterRect.width() * magicShiftFactor, dpr * m_yOffset - painterRect.height() * magicShiftFactor);
|
||||||
|
|
||||||
#if defined(PROFILE_SCALING_DEBUG)
|
#if defined(PROFILE_SCALING_DEBUG)
|
||||||
// some debugging messages to help adjust this in case the magic above is insufficient
|
// some debugging messages to help adjust this in case the magic above is insufficient
|
||||||
|
@ -79,7 +82,7 @@ void QMLProfile::paint(QPainter *painter)
|
||||||
// finally, render the profile
|
// finally, render the profile
|
||||||
m_profileWidget->render(painter);
|
m_profileWidget->render(painter);
|
||||||
if (verbose)
|
if (verbose)
|
||||||
qDebug() << "finished rendering profile in" << timer.elapsed() << "ms";
|
qDebug() << "finished rendering profile with offset" << QString::number(m_xOffset, 'f', 1) << "/" << QString::number(m_yOffset, 'f', 1) << "in" << timer.elapsed() << "ms";
|
||||||
}
|
}
|
||||||
|
|
||||||
void QMLProfile::setMargin(int margin)
|
void QMLProfile::setMargin(int margin)
|
||||||
|
@ -98,7 +101,7 @@ void QMLProfile::updateProfile()
|
||||||
if (!d)
|
if (!d)
|
||||||
return;
|
return;
|
||||||
if (verbose)
|
if (verbose)
|
||||||
qDebug() << "update profile for dive #" << d->number;
|
qDebug() << "update profile for dive #" << d->number << "offeset" << QString::number(m_xOffset, 'f', 1) << "/" << QString::number(m_yOffset, 'f', 1);
|
||||||
m_profileWidget->plotDive(d, true);
|
m_profileWidget->plotDive(d, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +128,24 @@ void QMLProfile::setDevicePixelRatio(qreal dpr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// don't update the profile here, have the user update x and y and then manually trigger an update
|
||||||
|
void QMLProfile::setXOffset(qreal value)
|
||||||
|
{
|
||||||
|
if (IS_FP_SAME(value, m_xOffset))
|
||||||
|
return;
|
||||||
|
m_xOffset = value;
|
||||||
|
emit xOffsetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
// don't update the profile here, have the user update x and y and then manually trigger an update
|
||||||
|
void QMLProfile::setYOffset(qreal value)
|
||||||
|
{
|
||||||
|
if (IS_FP_SAME(value, m_yOffset))
|
||||||
|
return;
|
||||||
|
m_yOffset = value;
|
||||||
|
emit yOffsetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void QMLProfile::screenChanged(QScreen *screen)
|
void QMLProfile::screenChanged(QScreen *screen)
|
||||||
{
|
{
|
||||||
setDevicePixelRatio(screen->devicePixelRatio());
|
setDevicePixelRatio(screen->devicePixelRatio());
|
||||||
|
|
|
@ -10,6 +10,8 @@ class QMLProfile : public QQuickPaintedItem
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(int diveId MEMBER m_diveId WRITE setDiveId)
|
Q_PROPERTY(int diveId MEMBER m_diveId WRITE setDiveId)
|
||||||
Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio WRITE setDevicePixelRatio NOTIFY devicePixelRatioChanged)
|
Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio WRITE setDevicePixelRatio NOTIFY devicePixelRatioChanged)
|
||||||
|
Q_PROPERTY(qreal xOffset MEMBER m_xOffset WRITE setXOffset NOTIFY xOffsetChanged)
|
||||||
|
Q_PROPERTY(qreal yOffset MEMBER m_yOffset WRITE setYOffset NOTIFY yOffsetChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QMLProfile(QQuickItem *parent = 0);
|
explicit QMLProfile(QQuickItem *parent = 0);
|
||||||
|
@ -30,12 +32,15 @@ private:
|
||||||
int m_diveId;
|
int m_diveId;
|
||||||
qreal m_devicePixelRatio;
|
qreal m_devicePixelRatio;
|
||||||
int m_margin;
|
int m_margin;
|
||||||
|
qreal m_xOffset, m_yOffset;
|
||||||
QScopedPointer<ProfileWidget2> m_profileWidget;
|
QScopedPointer<ProfileWidget2> m_profileWidget;
|
||||||
void updateProfile();
|
void updateProfile();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void rightAlignedChanged();
|
void rightAlignedChanged();
|
||||||
void devicePixelRatioChanged();
|
void devicePixelRatioChanged();
|
||||||
|
void xOffsetChanged();
|
||||||
|
void yOffsetChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QMLPROFILE_H
|
#endif // QMLPROFILE_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue