mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Dive media: fix stacking of thumbnails in profile plot
9efb56e2d4
added code to rearrange
pictures on drag'n'drop. To keep the correct repainting order (i.e.
later thumbnails are painted on top of previous thumbnails), the
z-value was set accordingly. In principle a sound idea, but it did
not work out, because on hoverEnter and hoverExit events, the z-values
were modified, thus restoring the wrong drawing order.
Instead, use the QGraphicsItem::packBefore() function. Experimentation
showed that this only works if stacking is done from the back
of the list.
Silence an erroneous compiler warning by initializing a variable to 0.0.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
b53672507d
commit
4931b5a8e6
1 changed files with 21 additions and 9 deletions
|
@ -2103,17 +2103,21 @@ bool ProfileWidget2::PictureEntry::operator< (const PictureEntry &e) const
|
|||
|
||||
// Calculate the y-coordinates of the thumbnails, which are supposed to be sorted by x-coordinate.
|
||||
// This will also change the order in which the thumbnails are painted, to avoid weird effects,
|
||||
// when items are added later to the scene. This is simply done by increasing the Z-value.
|
||||
// when items are added later to the scene. This is done using the QGraphicsItem::packBefore() function.
|
||||
// We can't use the z-value, because that will be modified on hoverEnter and hoverExit events.
|
||||
void ProfileWidget2::calculatePictureYPositions()
|
||||
{
|
||||
double lastX = -1.0, lastY;
|
||||
double z = 0.0;
|
||||
for (PictureEntry &e: pictures) {
|
||||
if (!e.thumbnail)
|
||||
// Quit early if there are no items. The last loop in this function assumes that the vector is not empty.
|
||||
if (pictures.empty())
|
||||
return;
|
||||
|
||||
double lastX = -1.0, lastY = 0.0;
|
||||
for (auto it = pictures.begin(); it != pictures.end(); ++it) {
|
||||
if (!it->thumbnail)
|
||||
continue;
|
||||
// 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.
|
||||
double x = e.thumbnail->x();
|
||||
double x = it->thumbnail->x();
|
||||
double y;
|
||||
if (lastX >= 0.0 && fabs(x - lastX) < 3 && lastY <= (10 + 14 * 3))
|
||||
y = lastY + 3;
|
||||
|
@ -2121,10 +2125,18 @@ void ProfileWidget2::calculatePictureYPositions()
|
|||
y = 10;
|
||||
lastX = x;
|
||||
lastY = y;
|
||||
e.thumbnail->setY(y);
|
||||
e.thumbnail->setZValue(z);
|
||||
z += 1.0;
|
||||
it->thumbnail->setY(y);
|
||||
|
||||
// hoverEnter and hoverExit events modify the z-value. Objects with different z-values
|
||||
// are not considered in stackBefore() calls. Therefore, just to be sure, reset the
|
||||
// z-values of all picture entries.
|
||||
it->thumbnail->setZValue(0.0);
|
||||
}
|
||||
|
||||
// Plot the items in the correct order. Experience showed that this works only
|
||||
// if we rearrange the items starting from the back. Therefore, use rbegin() and rend().
|
||||
for (auto it = pictures.rbegin(); std::next(it) != pictures.rend(); ++it)
|
||||
std::next(it)->thumbnail->stackBefore(it->thumbnail.get());
|
||||
}
|
||||
|
||||
void ProfileWidget2::updateThumbnailXPos(PictureEntry &e)
|
||||
|
|
Loading…
Reference in a new issue