diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-06-30 12:55:55 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-07-13 17:07:22 -0700 |
commit | 0aaa1bf3862901933ed68c15a38fed9dc4c621a4 (patch) | |
tree | 191f7833c73d1f428f0437336c023f320180c281 /profile-widget | |
parent | b2422f88569a2bba50db74835fcd09dd5b070ec9 (diff) | |
download | subsurface-0aaa1bf3862901933ed68c15a38fed9dc4c621a4.tar.gz |
Dive pictures: update thumbnail positions on deletion
If pictures were deleted, the remaining thumbails where staying at
their positions. Only when switching between dives, the new positions
were recalculated. Do the recalculation immediately. More precisely:
the x-coordinate, which is determined by the timestamp, stays identical.
Only the y-coordinate is recalculated such that overlapping of thumbnails
is avoided.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'profile-widget')
-rw-r--r-- | profile-widget/profilewidget2.cpp | 42 | ||||
-rw-r--r-- | profile-widget/profilewidget2.h | 1 |
2 files changed, 29 insertions, 14 deletions
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 9af364f20..4e0e0527e 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -2094,6 +2094,26 @@ bool ProfileWidget2::PictureEntry::operator< (const PictureEntry &e) const return std::tie(offset.seconds, filename) < std::tie(e.offset.seconds, e.filename); } +void ProfileWidget2::calculatePictureYPositions() +{ + double lastX = -1.0, lastY; + for (PictureEntry &e: pictures) { + if (!e.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 y; + if (lastX >= 0.0 && fabs(x - lastX) < 3 && lastY <= (10 + 14 * 3)) + y = lastY + 3; + else + y = 10; + lastX = x; + lastY = y; + e.thumbnail->setY(y); + } +} + // This function resets the picture thumbnails of the current dive. void ProfileWidget2::plotPictures() { @@ -2115,8 +2135,7 @@ void ProfileWidget2::plotPictures() std::sort(pictures.begin(), pictures.end()); // Add the DivePictureItems to the scene, set their pixmaps and filenames - // and finaly calculate their positions. - double x, y, lastX = -1.0, lastY = -1.0; + // and finally calculate their positions. int size = Thumbnailer::defaultThumbnailSize(); for (PictureEntry &e: pictures) { scene()->addItem(e.thumbnail.get()); @@ -2124,19 +2143,13 @@ void ProfileWidget2::plotPictures() QImage thumbnail = Thumbnailer::instance()->fetchThumbnail(e.filename).scaled(size, size, Qt::KeepAspectRatio); e.thumbnail->setPixmap(QPixmap::fromImage(thumbnail)); e.thumbnail->setFileUrl(e.filename); - // 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. - x = timeAxis->posAtValue(e.offset.seconds); - if (lastX < 0.0) - y = 10; - else if (fabs(x - lastX) < 3 && lastY <= (10 + 14 * 3)) - y = lastY + 3; - else - y = 10; - lastX = x; - lastY = y; - e.thumbnail->setPos(x, y); + + // Here, we only set the x-coordinate of the picture. The y-coordinate + // will be set later in calculatePictureYPositions(). + double x = timeAxis->posAtValue(e.offset.seconds); + e.thumbnail->setX(x); } + calculatePictureYPositions(); } // Remove the pictures with the given filenames from the profile plot. @@ -2155,6 +2168,7 @@ void ProfileWidget2::removePictures(const QVector<QString> &fileUrls) // Check whether filename of entry is in list of provided filenames { return std::find(fileUrls.begin(), fileUrls.end(), e.filename) != fileUrls.end(); }); pictures.erase(it, pictures.end()); + calculatePictureYPositions(); } #endif diff --git a/profile-widget/profilewidget2.h b/profile-widget/profilewidget2.h index c7db09a92..4fdc1dc26 100644 --- a/profile-widget/profilewidget2.h +++ b/profile-widget/profilewidget2.h @@ -240,6 +240,7 @@ private: bool operator< (const PictureEntry &e) const; }; std::vector<PictureEntry> pictures; + void calculatePictureYPositions(); QList<DiveHandler *> handles; void repositionDiveHandlers(); |