From b450c155fd78e304f07549c35667dc4e6349ec32 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 11 Mar 2018 10:19:08 +0100 Subject: Dive pictures: Move thumbnail-size to Thumbnailer class The size of the to-be-created thumbnails was passed from DivePictureModel to Thumbnailer. This became more and more bothersome, because the size had to be stored with the request. Calling from Thumbnailer into DivePictureModel was not an option, since this is not linked to all tests. Therefore, move these functions to the Thumbnailer class. Since the maximum thumbnail size is now known to the thumbnailer, the dummy and failure images can be precalculated, which makes switching between dives faster. Signed-off-by: Berthold Stoeger --- qt-models/divepicturemodel.cpp | 16 +++------------- qt-models/divepicturemodel.h | 2 +- 2 files changed, 4 insertions(+), 14 deletions(-) (limited to 'qt-models') diff --git a/qt-models/divepicturemodel.cpp b/qt-models/divepicturemodel.cpp index c5453c3a9..89917761c 100644 --- a/qt-models/divepicturemodel.cpp +++ b/qt-models/divepicturemodel.cpp @@ -8,8 +8,6 @@ #include -static const int maxZoom = 3; // Maximum zoom: thrice of standard size - DivePictureModel *DivePictureModel::instance() { static DivePictureModel *self = new DivePictureModel(); @@ -19,7 +17,7 @@ DivePictureModel *DivePictureModel::instance() DivePictureModel::DivePictureModel() : rowDDStart(0), rowDDEnd(0), zoomLevel(0.0), - defaultSize(defaultIconMetrics().sz_pic) + defaultSize(Thumbnailer::defaultThumbnailSize()) { connect(Thumbnailer::instance(), &Thumbnailer::thumbnailChanged, this, &DivePictureModel::updateThumbnail, Qt::QueuedConnection); @@ -47,22 +45,14 @@ void DivePictureModel::setZoomLevel(int level) void DivePictureModel::updateZoom() { - // Calculate size of thumbnails. The standard size is defaultIconMetrics().sz_pic. - // We use exponential scaling so that the central point is the standard - // size and the minimum and maximum extreme points are a third respectively - // three times the standard size. - // Naturally, these three zoom levels are then represented by - // -1.0 (minimum), 0 (standard) and 1.0 (maximum). The actual size is - // calculated as standard_size*3.0^zoomLevel. - size = static_cast(round(defaultSize * pow(maxZoom, zoomLevel))); + size = Thumbnailer::thumbnailSize(zoomLevel); } void DivePictureModel::updateThumbnails() { - int maxSize = defaultSize * maxZoom; updateZoom(); for (PictureEntry &entry: pictures) - entry.image = Thumbnailer::instance()->fetchThumbnail(entry, maxSize); + entry.image = Thumbnailer::instance()->fetchThumbnail(entry); } void DivePictureModel::updateDivePictures() diff --git a/qt-models/divepicturemodel.h b/qt-models/divepicturemodel.h index 0839630bd..e68c00570 100644 --- a/qt-models/divepicturemodel.h +++ b/qt-models/divepicturemodel.h @@ -31,8 +31,8 @@ private: DivePictureModel(); QList pictures; double zoomLevel; // -1.0: minimum, 0.0: standard, 1.0: maximum - int defaultSize; int size; + int defaultSize; void updateThumbnails(); void updateZoom(); }; -- cgit v1.2.3-70-g09d2