File indexing completed on 2024-05-12 15:55:49
0001 // SPDX-FileCopyrightText: 2009-2014 Jesper K. Pedersen <jesper.pedersen@kdab.com> 0002 // SPDX-FileCopyrightText: 2010 Jan Kundrát <jkt@flaska.net> 0003 // SPDX-FileCopyrightText: 2010 Tuomas Suutari <tuomas@nepnep.net> 0004 // SPDX-FileCopyrightText: 2013 Dominik Broj <broj.dominik@gmail.com> 0005 // SPDX-FileCopyrightText: 2013-2023 Johannes Zarl-Zierl <johannes@zarl-zierl.at> 0006 // SPDX-FileCopyrightText: 2019-2022 Tobias Leupold <tl@stonemx.de> 0007 // SPDX-FileCopyrightText: 2020 Robert Krawitz <rlk@alum.mit.edu> 0008 // 0009 // SPDX-License-Identifier: GPL-2.0-or-later 0010 0011 #ifndef THUMBNAILMODEL_H 0012 #define THUMBNAILMODEL_H 0013 0014 #include "ThumbnailComponent.h" 0015 #include "enums.h" 0016 0017 #include <DB/ImageInfo.h> 0018 #include <DB/search/ImageSearchInfo.h> 0019 #include <ImageManager/ImageClientInterface.h> 0020 #include <ImageManager/enums.h> 0021 #include <kpabase/FileNameList.h> 0022 0023 #include <QAbstractListModel> 0024 #include <QPixmap> 0025 0026 namespace ImageManager 0027 { 0028 class ThumbnailCache; 0029 } 0030 0031 namespace ThumbnailView 0032 { 0033 class ThumbnailFactory; 0034 class FilterWidget; 0035 0036 class ThumbnailModel : public QAbstractListModel, public ImageManager::ImageClientInterface, private ThumbnailComponent 0037 { 0038 Q_OBJECT 0039 0040 public: 0041 explicit ThumbnailModel(ThumbnailFactory *factory, const ImageManager::ThumbnailCache *thumbnailCache); 0042 0043 // -------------------------------------------------- QAbstractListModel 0044 using QAbstractListModel::beginResetModel; 0045 using QAbstractListModel::endResetModel; 0046 int rowCount(const QModelIndex &) const override; 0047 QVariant data(const QModelIndex &, int) const override; 0048 QString thumbnailText(const QModelIndex &index) const; 0049 void updateCell(int row); 0050 void updateCell(const QModelIndex &index); 0051 void updateCell(const DB::FileName &id); 0052 0053 // -------------------------------------------------- ImageClient API 0054 void pixmapLoaded(ImageManager::ImageRequest *request, const QImage &image) override; 0055 bool thumbnailStillNeeded(int row) const; 0056 0057 //-------------------------------------------------- Drag and Drop of items 0058 DB::FileName rightDropItem() const; 0059 void setRightDropItem(const DB::FileName &item); 0060 DB::FileName leftDropItem() const; 0061 void setLeftDropItem(const DB::FileName &item); 0062 0063 //-------------------------------------------------- Stack 0064 void toggleStackExpansion(const DB::FileName &id); 0065 void collapseAllStacks(); 0066 void expandAllStacks(); 0067 bool isItemInExpandedStack(const DB::StackID &id) const; 0068 0069 //-------------------------------------------------- Position Information 0070 DB::FileName imageAt(int index) const; 0071 int indexOf(const DB::FileName &fileName) const; 0072 int indexOf(const DB::FileName &fileName); 0073 QModelIndex fileNameToIndex(const DB::FileName &fileName) const; 0074 0075 //-------------------------------------------------- Images 0076 void setImageList(const DB::FileNameList &list); 0077 DB::FileNameList imageList(Order) const; 0078 int imageCount() const; 0079 void setOverrideImage(const DB::FileName &fileName, const QPixmap &pixmap); 0080 0081 //-------------------------------------------------- Misc. 0082 void updateDisplayModel(); 0083 void updateIndexCache(); 0084 void setSortDirection(SortDirection); 0085 QPixmap pixmap(const DB::FileName &fileName) const; 0086 0087 /** 0088 * @brief isFiltered 0089 * @return \c true, if the filter is currently active, \c false otherwise. 0090 */ 0091 bool isFiltered() const; 0092 0093 FilterWidget *createFilterWidget(QWidget *parent); 0094 0095 public Q_SLOTS: 0096 void updateVisibleRowInfo(); 0097 0098 void toggleFilter(bool enable); 0099 /** 0100 * @brief clearFilter clears the filter so that all images in the current view are displayed. 0101 */ 0102 void clearFilter(); 0103 /** 0104 * @brief filterByRating sets the filter to only show images with the given rating. 0105 * @param rating a number between 0 and 10 (or -1 to disable) 0106 */ 0107 void filterByRating(short rating); 0108 /** 0109 * @brief toggleRatingFilter sets the filter to only show images with the given rating, 0110 * if no rating filter is active. If the rating filter is already set to the given rating, 0111 * clear the rating filter. 0112 * @param rating a number between 0 and 10 0113 */ 0114 void toggleRatingFilter(short rating); 0115 /** 0116 * @brief filterByCategory sets the filter to only show images with the given tag. 0117 * Calling this method again for the same category will overwrite the previous filter 0118 * for that category. 0119 * @param category 0120 * @param tag 0121 * 0122 * @see DB::ImageSearchinfo::setCategoryMatchText() 0123 */ 0124 void filterByCategory(const QString &category, const QString &tag); 0125 /** 0126 * @brief toggleCategoryFilter is similar to filterByCategory(), except resets the 0127 * category filter if called again with the same value. 0128 * @param category 0129 * @param tag 0130 */ 0131 void toggleCategoryFilter(const QString &category, const QString &tag); 0132 /** 0133 * @brief filterByFreeformText filters by a plain text search. 0134 * To clear this filter specifically, pass an empty QString. 0135 * @param text 0136 */ 0137 void filterByFreeformText(const QString &text); 0138 0139 Q_SIGNALS: 0140 void collapseAllStacksEnabled(bool enabled); 0141 void expandAllStacksEnabled(bool enabled); 0142 void selectionChanged(int numberOfItemsSelected); 0143 void filterChanged(const DB::ImageSearchInfo &filter); 0144 0145 private: // Methods 0146 void requestThumbnail(const DB::FileName &mediaId, const ImageManager::Priority priority); 0147 void preloadThumbnails(); 0148 0149 private Q_SLOTS: 0150 void imagesDeletedFromDB(const DB::FileNameList &); 0151 0152 private: // Instance variables. 0153 /** 0154 * The list of images shown. The difference between m_imageList and 0155 * m_displayList is that m_imageList contains all the images given to us, 0156 * while m_displayList only includes those that currently should be 0157 * shown, ie. it exclude images from stacks that are collapsed and thus 0158 * not visible. 0159 */ 0160 DB::FileNameList m_displayList; 0161 0162 /** The input list for images. See documentation for m_displayList */ 0163 DB::FileNameList m_imageList; 0164 0165 /** 0166 * File which should have drop indication point drawn on its left side 0167 */ 0168 DB::FileName m_leftDrop; 0169 0170 /** 0171 * File which should have drop indication point drawn on its right side 0172 */ 0173 DB::FileName m_rightDrop; 0174 0175 int stringWidth(const QString &text) const; 0176 0177 SortDirection m_sortDirection; 0178 0179 /** 0180 * All the stacks that should be shown expanded 0181 */ 0182 QSet<DB::StackID> m_expandedStacks; 0183 0184 /** @short Store stack IDs for all images in current list 0185 * 0186 * Used by expandAllStacks. */ 0187 QSet<DB::StackID> m_allStacks; 0188 0189 /** 0190 * A hash mapping from Id to its index in m_displayList. 0191 * The structure is not iterated over, so order doesn't matter. 0192 */ 0193 QHash<DB::FileName, int> m_fileNameToIndex; 0194 0195 int m_firstVisibleRow; 0196 int m_lastVisibleRow; 0197 0198 DB::FileName m_overrideFileName; 0199 QPixmap m_overrideImage; 0200 // placeholder pixmaps to be displayed before thumbnails are loaded: 0201 QPixmap m_ImagePlaceholder; 0202 QPixmap m_VideoPlaceholder; 0203 0204 DB::ImageSearchInfo m_filter; 0205 DB::ImageSearchInfo m_previousFilter; 0206 0207 const ImageManager::ThumbnailCache *m_thumbnailCache; 0208 }; 0209 0210 } 0211 0212 #endif /* THUMBNAILMODEL_H */ 0213 0214 // vi:expandtab:tabstop=4 shiftwidth=4: