summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-24 15:47:00 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-25 09:28:05 -0700
commit577f713f1aece8328a5ff7cca9a0d14ab543c4d4 (patch)
tree5fba8bde73cf21ef9bc5f4f5bcb6fe374d9cf80e
parentf084852f5c71624033862242b23579feeac03cb8 (diff)
downloadsubsurface-577f713f1aece8328a5ff7cca9a0d14ab543c4d4.tar.gz
mobile/profile: don't pan outside the actual profile
When zooming and panning the profile, make sure we always show a subset of the profile and don't end up showing the empty space outside of the profile. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--profile-widget/qmlprofile.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/profile-widget/qmlprofile.cpp b/profile-widget/qmlprofile.cpp
index 733ee4633..08f5836af 100644
--- a/profile-widget/qmlprofile.cpp
+++ b/profile-widget/qmlprofile.cpp
@@ -62,6 +62,25 @@ void QMLProfile::paint(QPainter *painter)
// shift the painter (taking its existing transformation into account)
QTransform profileTransform = QTransform();
profileTransform.scale(sx, sy);
+
+ // this is a bit complex because of the interaction with the Qt widget scaling
+ // logic. We use the default setup where the scale happens with the center of the
+ // widget as transformation center.
+ // The QML code *should* already ensure that we don't shrink the profile, but for
+ // the math below to work, let's make sure
+ qreal profileScale = scale();
+ if (profileScale < 1.0) {
+ profileScale = 1.0;
+ setScale(profileScale);
+ }
+ // When zooming and panning we want to ensure that we always show a subset of the
+ // profile and not the "empty space" around the profile.
+ // a bit of math on a piece of paper shows that our offsets need to stay within +/- dx and dy
+ qreal dx = width() * (profileScale - 1) / (2 * dpr * profileScale);
+ qreal dy = height() * (profileScale - 1) / (2 * dpr * profileScale);
+ m_xOffset = std::max(-dx, std::min(m_xOffset, dx));
+ m_yOffset = std::max(-dy, std::min(m_yOffset, dy));
+
QTransform painterTransform = painter->transform();
painterTransform.translate(dpr * m_xOffset - painterRect.width() * magicShiftFactor, dpr * m_yOffset - painterRect.height() * magicShiftFactor);