summaryrefslogtreecommitdiffstats
path: root/profile-widget
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-07-15 17:30:34 +0200
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2018-07-16 23:29:21 +0300
commit4931b5a8e61ab40d393a13742bec4e26fd4da155 (patch)
tree2cea45bd47a689713b28532a7360d4eed41a85f1 /profile-widget
parentb53672507dea35f5eed97f357dc6d5e13be95482 (diff)
downloadsubsurface-4931b5a8e61ab40d393a13742bec4e26fd4da155.tar.gz
Dive media: fix stacking of thumbnails in profile plot
9efb56e2d43161d952efb444d1f13d87bfdd45b5 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>
Diffstat (limited to 'profile-widget')
-rw-r--r--profile-widget/profilewidget2.cpp30
1 files changed, 21 insertions, 9 deletions
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp
index 6c4f0f2cc..5cc5a3a18 100644
--- a/profile-widget/profilewidget2.cpp
+++ b/profile-widget/profilewidget2.cpp
@@ -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)