summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-07-25 17:26:56 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-07-28 15:31:25 -0700
commita76433279e1be42cf4f11a748c5654fbb8cd8c7c (patch)
tree74d592f6a0dc953c13215fc1e878907f40f4fce8 /qt-models
parentfce42d4858d33e10b7a1c48d75838f1901b6b123 (diff)
downloadsubsurface-a76433279e1be42cf4f11a748c5654fbb8cd8c7c.tar.gz
Dive media: put duration on video thumbnails
On the profile, the run-length of the videos is visualized by a bar. Add the same information to video-thumbnails in the dive-photo-tab. Though in this case, render it as text on top of the thumbnails. Fixes #359 Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/divepicturemodel.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/qt-models/divepicturemodel.cpp b/qt-models/divepicturemodel.cpp
index f0b5eff47..4db81d546 100644
--- a/qt-models/divepicturemodel.cpp
+++ b/qt-models/divepicturemodel.cpp
@@ -7,6 +7,7 @@
#include "core/qthelper.h"
#include <QFileInfo>
+#include <QPainter>
DivePictureModel *DivePictureModel::instance()
{
@@ -165,10 +166,39 @@ int DivePictureModel::findPictureId(const QString &filename)
return -1;
}
-void DivePictureModel::updateThumbnail(QString filename, QImage thumbnail, duration_t)
+static void addDurationToThumbnail(QImage &img, duration_t duration)
+{
+ int seconds = duration.seconds;
+ if (seconds < 0)
+ return;
+ QString s = seconds >= 3600 ?
+ QStringLiteral("%1:%2:%3").arg(seconds / 3600, 2, 10, QChar('0'))
+ .arg((seconds % 3600) / 60, 2, 10, QChar('0'))
+ .arg(seconds % 60, 2, 10, QChar('0')) :
+ QStringLiteral("%1:%2").arg(seconds / 60, 2, 10, QChar('0'))
+ .arg(seconds % 60, 2, 10, QChar('0'));
+
+ QFont font(system_divelist_default_font, 30);
+ QFontMetrics metrics(font);
+ QSize size = metrics.size(Qt::TextSingleLine, s);
+ QSize imgSize = img.size();
+ int x = imgSize.width() - size.width();
+ int y = imgSize.height() - size.height() + metrics.descent();
+ QPainter painter(&img);
+ painter.setBrush(Qt::white);
+ painter.setPen(Qt::NoPen);
+ painter.drawRect(x, y, size.width(), size.height() - metrics.descent());
+ painter.setFont(font);
+ painter.setPen(Qt::black);
+ painter.drawText(x, imgSize.height(), s);
+}
+
+void DivePictureModel::updateThumbnail(QString filename, QImage thumbnail, duration_t duration)
{
int i = findPictureId(filename);
if (i >= 0) {
+ if (duration.seconds > 0)
+ addDurationToThumbnail(thumbnail, duration); // If we know the duration paint it on top of the thumbnail
pictures[i].image = thumbnail;
emit dataChanged(createIndex(i, 0), createIndex(i, 1));
}