profile: fix y-coordinate of picture thumbnails

When changing from relative to absolute scaling of the char
elements, positioning of the picture thumbnails was broken.

To emulate the old behavior, add a function to DiveCartesianAxis,
that allows positioning with respect to the axis on the screen.

To simplify tuning of the poctuire positions, name a few
constants explicitly.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-10-26 09:40:38 +02:00 committed by Dirk Hohndel
parent 51be326879
commit 6cc6fe4d91
3 changed files with 25 additions and 5 deletions

View file

@ -375,6 +375,18 @@ qreal DiveCartesianAxis::posAtValue(qreal value) const
return adjusted; return adjusted;
} }
double DiveCartesianAxis::screenPosition(double pos) const
{
QLineF m = line();
double from = position == Position::Bottom ? m.x1() : m.y1();
double to = position == Position::Bottom ? m.x2() : m.y2();
if ((position == Position::Bottom) == inverted)
pos = 1.0 - pos;
return (to - from) * pos + from;
}
double DiveCartesianAxis::maximum() const double DiveCartesianAxis::maximum() const
{ {
return max; return max;

View file

@ -39,6 +39,7 @@ public:
qreal valueAt(const QPointF &p) const; qreal valueAt(const QPointF &p) const;
qreal posAtValue(qreal value) const; qreal posAtValue(qreal value) const;
void setPosition(const QRectF &rect); void setPosition(const QRectF &rect);
double screenPosition(double pos) const; // 0.0 = begin, 1.0 = end of axis, independent of represented values
void setTextVisible(bool arg1); void setTextVisible(bool arg1);
void setLinesVisible(bool arg1); void setLinesVisible(bool arg1);
void updateTicks(int animSpeed); void updateTicks(int animSpeed);

View file

@ -1150,18 +1150,25 @@ void ProfileWidget2::updateThumbnailPaintOrder()
void ProfileWidget2::calculatePictureYPositions() void ProfileWidget2::calculatePictureYPositions()
{ {
double lastX = -1.0, lastY = 0.0; double lastX = -1.0, lastY = 0.0;
const double yStart = 0.05; // At which depth the thumbnails start (in fraction of total depth).
const double yStep = 0.01; // Increase of depth for overlapping thumbnails (in fraction of total depth).
const double xSpace = 18.0 * profileScene->dpr; // Horizontal range in which thumbnails are supposed to be overlapping (in pixels).
const int maxDepth = 14; // Maximal depth of thumbnail stack (in thumbnails).
for (PictureEntry &e: pictures) { for (PictureEntry &e: pictures) {
// let's put the picture at the correct time, but at a fixed "depth" on the profile // Let's put the picture at the correct time, but at a fixed "depth" on the profile
// not sure this is ideal, but it seems to look right. // not sure this is ideal, but it seems to look right.
double x = e.thumbnail->x(); double x = e.thumbnail->x();
if (x < 0.0)
continue;
double y; double y;
if (lastX >= 0.0 && fabs(x - lastX) < 3 && lastY <= (10 + 14 * 3)) if (lastX >= 0.0 && fabs(x - lastX) < xSpace * profileScene->dpr && lastY <= (yStart + maxDepth * yStep) - 1e-10)
y = lastY + 3; y = lastY + yStep;
else else
y = 10; y = yStart;
lastX = x; lastX = x;
lastY = y; lastY = y;
e.thumbnail->setY(y); double yScreen = profileScene->timeAxis->screenPosition(y);
e.thumbnail->setY(yScreen);
updateDurationLine(e); // If we changed the y-position, we also have to change the duration-line. updateDurationLine(e); // If we changed the y-position, we also have to change the duration-line.
} }
updateThumbnailPaintOrder(); updateThumbnailPaintOrder();