File indexing completed on 2025-01-05 03:54:13
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-03-05 0007 * Description : Qt item model for database entries with support for thumbnail loading 0008 * 0009 * SPDX-FileCopyrightText: 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0010 * SPDX-FileCopyrightText: 2011 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #ifndef DIGIKAM_ITEM_THUMBNAIL_MODEL_H 0017 #define DIGIKAM_ITEM_THUMBNAIL_MODEL_H 0018 0019 // Local includes 0020 0021 #include "itemmodel.h" 0022 #include "thumbnailsize.h" 0023 #include "digikam_export.h" 0024 0025 namespace Digikam 0026 { 0027 0028 class LoadingDescription; 0029 class ThumbnailLoadThread; 0030 0031 class DIGIKAM_DATABASE_EXPORT ItemThumbnailModel : public ItemModel 0032 { 0033 Q_OBJECT 0034 0035 public: 0036 0037 /** 0038 * An ItemModel that supports thumbnail loading. 0039 * You need to set a ThumbnailLoadThread to enable thumbnail loading. 0040 * Adjust the thumbnail size to your needs. 0041 * Note that setKeepsFilePathCache is enabled per default. 0042 */ 0043 explicit ItemThumbnailModel(QWidget* const parent); 0044 ~ItemThumbnailModel() override; 0045 0046 /** 0047 * Enable thumbnail loading and set the thread that shall be used. 0048 * The thumbnail size of this thread will be adjusted. 0049 */ 0050 void setThumbnailLoadThread(ThumbnailLoadThread* const thread); 0051 ThumbnailLoadThread* thumbnailLoadThread() const; 0052 0053 /// Set the thumbnail size to use 0054 void setThumbnailSize(const ThumbnailSize& thumbSize); 0055 0056 /// If you want to fix a size for preloading, do it here. 0057 void setPreloadThumbnailSize(const ThumbnailSize& thumbSize); 0058 0059 void setExifRotate(bool rotate); 0060 0061 /** 0062 * Enable emitting dataChanged() when a thumbnail becomes available. 0063 * The thumbnailAvailable() signal will be emitted in any case. 0064 * Default is true. 0065 */ 0066 void setEmitDataChanged(bool emitSignal); 0067 0068 /** 0069 * Enable preloading of thumbnails: 0070 * If preloading is enabled, for every entry in the model a thumbnail generation is started. 0071 * Default: false. 0072 */ 0073 void setPreloadThumbnails(bool preload); 0074 0075 ThumbnailSize thumbnailSize() const; 0076 0077 /** 0078 * Handles the ThumbnailRole. 0079 * If the pixmap is available, returns it in the QVariant. 0080 * If it still needs to be loaded, returns a null QVariant and emits 0081 * thumbnailAvailable() as soon as it is available. 0082 */ 0083 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; 0084 0085 /** 0086 * You can override the current thumbnail size by giving an integer value for ThumbnailRole. 0087 * Set a null QVariant to use the thumbnail size set by setThumbnailSize() again. 0088 * The index given here is ignored for this purpose. 0089 */ 0090 bool setData(const QModelIndex& index, 0091 const QVariant& value, 0092 int role = Qt::DisplayRole) override; 0093 0094 public Q_SLOTS: 0095 0096 /** 0097 * Preload thumbnail for the given infos resp. indexes. 0098 * Note: Use setPreloadThumbnails to automatically preload all entries in the model. 0099 * Note: This only ensures thumbnail generation. It is not guaranteed that pixmaps 0100 * are stored in the cache. For thumbnails that are expect to be drawn immediately, 0101 * include them in prepareThumbnails(). 0102 * Note: Stops preloading of previously added thumbnails. 0103 */ 0104 void preloadThumbnails(const QList<ItemInfo>&); 0105 void preloadThumbnails(const QList<QModelIndex>&); 0106 void preloadAllThumbnails(); 0107 0108 Q_SIGNALS: 0109 0110 void thumbnailAvailable(const QModelIndex& index, int requestedSize); 0111 void thumbnailFailed(const QModelIndex& index, int requestedSize); 0112 0113 protected: 0114 0115 void imageInfosCleared() override; 0116 0117 protected Q_SLOTS: 0118 0119 void slotThumbnailLoadedFromStorage(const LoadingDescription& loadingDescription, 0120 const QPixmap& thumb); 0121 void slotThumbnailLoaded(const LoadingDescription& loadingDescription, 0122 const QPixmap& thumb); 0123 0124 private: 0125 0126 // Disable 0127 ItemThumbnailModel(const ItemThumbnailModel&) = delete; 0128 ItemThumbnailModel& operator=(const ItemThumbnailModel&) = delete; 0129 0130 class Private; 0131 Private* const d; 0132 }; 0133 0134 } // namespace Digikam 0135 0136 #endif // DIGIKAM_ITEM_THUMBNAIL_MODEL_H