digiKam
thumbnailloadthread.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2007-06-05
7  * Description : Thumbnail loading
8  *
9  * Copyright (C) 2006-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2008-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_THUMB_NAIL_LOAD_THREAD_H
26 #define DIGIKAM_THUMB_NAIL_LOAD_THREAD_H
27 
28 // Qt includes
29 
30 #include <QPixmap>
31 #include <QImage>
32 
33 // Local includes
34 
35 #include "managedloadsavethread.h"
36 #include "thumbnailinfo.h"
37 
38 namespace Digikam
39 {
40 
41 class DbEngineParameters;
42 class ThumbnailCreator;
43 class ThumbnailInfoProvider;
44 
45 class DIGIKAM_EXPORT ThumbnailLoadThread : public ManagedLoadSaveThread
46 {
47  Q_OBJECT
48 
49 public:
50 
51  explicit ThumbnailLoadThread(QObject* const parent = nullptr);
52  ~ThumbnailLoadThread() override;
53 
59  static ThumbnailLoadThread* defaultThread();
60  static ThumbnailLoadThread* defaultIconViewThread();
61 
62  static void cleanUp();
63 
70  static void initializeThumbnailDatabase(const DbEngineParameters& params, ThumbnailInfoProvider* const provider = nullptr);
71 
76  static void setDisplayingWidget(QWidget* const widget);
77 
85  bool find(const ThumbnailIdentifier& identifier, QPixmap& pixmap);
86 
90  bool find(const ThumbnailIdentifier& identifier, QPixmap& pixmap, int size);
91 
98  void find(const ThumbnailIdentifier& identifier);
99 
103  void find(const ThumbnailIdentifier& identifier, int size);
104 
109  void findGroup(QList<ThumbnailIdentifier>& identifiers);
110  void findGroup(QList<ThumbnailIdentifier>& identifiers, int size);
111 
115  bool find(const ThumbnailIdentifier& identifier, const QRect& rect, QPixmap& pixmap);
116  bool find(const ThumbnailIdentifier& identifier, const QRect& rect, QPixmap& pixmap, int size);
117  void find(const ThumbnailIdentifier& identifier, const QRect& rect);
118  void find(const ThumbnailIdentifier& identifier, const QRect& rect, int size);
119  void findGroup(const QList<QPair<ThumbnailIdentifier, QRect> >& filePathAndRects);
120  void findGroup(const QList<QPair<ThumbnailIdentifier, QRect> >& filePathsAndRects, int size);
121 
126  void preload(const ThumbnailIdentifier& identifier);
127  void preload(const ThumbnailIdentifier& identifier, int size);
128  void preloadGroup(QList<ThumbnailIdentifier>& identifiers);
129  void preloadGroup(QList<ThumbnailIdentifier>& identifiers, int size);
130 
135  void pregenerateGroup(const QList<ThumbnailIdentifier>& identifiers);
136  void pregenerateGroup(const QList<ThumbnailIdentifier>& identifiers, int size);
137 
144  void load(const LoadingDescription& description);
145 
154  QList<LoadingDescription> lastDescriptions() const;
155 
165  void setThumbnailSize(int size, bool forFace = false);
166 
172  static int maximumThumbnailSize();
173  static int maximumThumbnailPixmapSize(bool withHighlighting);
174 
184  void setPixmapRequested(bool wantPixmap);
185 
191  void setHighlightPixmap(bool highlight);
192 
197  int thumbnailToPixmapSize(int size) const;
198  static int thumbnailToPixmapSize(bool withHighlight, int size);
199 
203  int pixmapToThumbnailSize(int size) const;
204 
213  void setSendSurrogatePixmap(bool send);
214 
221  void storeDetailThumbnail(const QString& filePath,
222  const QRect& detailRect,
223  const QImage& image,
224  bool isFace = false);
225  int storedSize() const;
226 
234  static void deleteThumbnail(const QString& filePath);
235 
236 Q_SIGNALS:
237 
239  void signalThumbnailLoaded(const LoadingDescription& loadingDescription, const QPixmap& pix);
240 
241 public:
242 
244  ThumbnailCreator* thumbnailCreator() const;
245 
246 protected:
247 
248  void thumbnailLoaded(const LoadingDescription& loadingDescription, const QImage& img) override;
249 
250 private:
251 
252  bool find(const ThumbnailIdentifier& identifier, int size, QPixmap* retPixmap, bool emitSignal, const QRect& detailRect);
253  void load(const LoadingDescription& description, bool pregenerate);
254  bool checkSize(int size);
255  QPixmap surrogatePixmap(const LoadingDescription& loadingDescription);
256 
257 Q_SIGNALS:
258 
261  void ThumbnailLoaded(const LoadingDescription&, const QImage&);
262 
263 private Q_SLOTS:
264 
265  void slotThumbnailsAvailable();
266  void slotThumbnailLoaded(const LoadingDescription&, const QImage&);
267 
268 private:
269 
270  // Disable
271  ThumbnailLoadThread(const ThumbnailLoadThread&) = delete;
272  ThumbnailLoadThread& operator=(const ThumbnailLoadThread&) = delete;
273 
274 private:
275 
276  class Private;
277  Private* const d;
278 };
279 
280 // --------------------------------------------------------------------------------------------------
281 
282 class DIGIKAM_EXPORT ThumbnailImageCatcher : public QObject
283 {
284  Q_OBJECT
285 
286 public:
287 
298  explicit ThumbnailImageCatcher(QObject* const parent = nullptr);
299  explicit ThumbnailImageCatcher(ThumbnailLoadThread* const thread,
300  QObject* const parent = nullptr);
301  ~ThumbnailImageCatcher() override;
302 
303  ThumbnailLoadThread* thread() const;
304  void setThumbnailLoadThread(ThumbnailLoadThread* const thread);
305 
315  int enqueue();
316  QList<QImage> waitForThumbnails();
317 
318 public Q_SLOTS:
319 
326  void setActive(bool active);
327 
332  void cancel();
333 
334 protected Q_SLOTS:
335 
336  void slotThumbnailLoaded(const LoadingDescription&, const QImage&);
337 
338 private:
339 
340  // Disable
342  ThumbnailImageCatcher& operator=(const ThumbnailImageCatcher&) = delete;
343 
344 private:
345 
346  class Private;
347  Private* const d;
348 };
349 
350 } // namespace Digikam
351 
352 #endif // DIGIKAM_THUMB_NAIL_LOAD_THREAD_H
Definition: dbengineparameters.h:49
Definition: loadingdescription.h:45
Definition: managedloadsavethread.h:39
Definition: thumbnailcreator.h:51
Definition: thumbnailinfo.h:40
Definition: thumbnailloadthread_p.h:149
Definition: thumbnailloadthread.h:283
Definition: thumbnailinfo.h:112
Definition: thumbnailloadthread_p.h:105
Definition: thumbnailloadthread.h:46
void thumbnailsAvailable()
NOTE: For internal use only.
void ThumbnailLoaded(const LoadingDescription &, const QImage &)
void signalThumbnailLoaded(const LoadingDescription &loadingDescription, const QPixmap &pix)
NOTE: See LoadSaveThread for a QImage-based thumbnailLoaded() signal.
Definition: piwigotalker.h:48
Definition: datefolderview.cpp:43