File indexing completed on 2025-01-19 03:59:21
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2012-07-08 0007 * Description : Qt item view to import items - the delegate 0008 * 0009 * SPDX-FileCopyrightText: 2012 by Islam Wazery <wazery at ubuntu dot com> 0010 * SPDX-FileCopyrightText: 2012-2024 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_IMPORT_DELEGATE_H 0017 #define DIGIKAM_IMPORT_DELEGATE_H 0018 0019 #include <QtGlobal> 0020 #include <QListView> 0021 0022 // Local includes 0023 0024 #include "itemviewimportdelegate.h" 0025 #include "importthumbnailmodel.h" 0026 #include "importcategorydrawer.h" 0027 0028 namespace Digikam 0029 { 0030 0031 class ImportCategorizedView; 0032 class ImportThumbnailDelegatePrivate; 0033 class ImportNormalDelegatePrivate; 0034 0035 class ImportDelegate : public ItemViewImportDelegate 0036 { 0037 Q_OBJECT 0038 0039 public: 0040 0041 explicit ImportDelegate(QWidget* const parent); 0042 ~ImportDelegate() override; 0043 0044 void setView(ImportCategorizedView* view); 0045 0046 ImportCategoryDrawer* categoryDrawer() const; 0047 0048 /* 0049 QRect commentsRect() const; 0050 */ 0051 QRect tagsRect() const; 0052 QRect actualPixmapRect(const QModelIndex& index) const; 0053 QRect groupIndicatorRect() const; 0054 QRect downloadIndicatorRect() const; 0055 QRect lockIndicatorRect() const; 0056 QRect coordinatesIndicatorRect() const; 0057 0058 int calculatethumbSizeToFit(int ws); 0059 0060 void setSpacing(int spacing) override; 0061 void setDefaultViewOptions(const QStyleOptionViewItem& option) override; 0062 bool acceptsToolTip(const QPoint& pos, const QRect& visualRect, 0063 const QModelIndex& index, QRect* tooltipRect = nullptr) const override; 0064 bool acceptsActivation(const QPoint& pos, const QRect& visualRect, 0065 const QModelIndex& index, QRect* activationRect = nullptr) const override; 0066 0067 QRect pixmapRect() const override; 0068 QRect imageInformationRect() const override; 0069 0070 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override; 0071 QPixmap pixmapForDrag(const QStyleOptionViewItem& option, const QList<QModelIndex>& indexes) const override; 0072 0073 /** 0074 * Retrieve the thumbnail pixmap in given size for the ImportItemModel::ThumbnailRole for 0075 * the given index from the given index, which must adhere to ImportThumbnailModel semantics. 0076 */ 0077 static QPixmap retrieveThumbnailPixmap(const QModelIndex& index, int thumbnailSize); 0078 0079 public: 0080 0081 // Declared as public because of use in ImportNormalDelegate class. 0082 class ImportDelegatePrivate; 0083 0084 protected: 0085 0086 bool onActualPixmapRect(const QPoint& pos, const QRect& visualRect, 0087 const QModelIndex& index, QRect* actualRect) const; 0088 void updateActualPixmapRect(const QModelIndex& index, const QRect& rect); 0089 0090 void setModel(QAbstractItemModel* model); 0091 0092 ImportDelegate(ImportDelegate::ImportDelegatePrivate& dd, QWidget* const parent); 0093 0094 /** 0095 * Reimplement this to set contentWidth. This is the maximum width of all 0096 * content rectangles, typically excluding margins on both sides. 0097 */ 0098 virtual void updateContentWidth(); 0099 0100 /** 0101 * In a subclass, you need to implement this method to set up the rects 0102 * for drawing. The paint() method operates depending on these rects. 0103 */ 0104 virtual void updateRects() = 0; 0105 0106 void clearCaches() override; 0107 0108 /** 0109 * Reimplement to clear caches based on model indexes (hash on row number etc.) 0110 * Change signals are listened to this is called whenever such properties become invalid. 0111 */ 0112 virtual void clearModelDataCaches(); 0113 0114 virtual QPixmap thumbnailPixmap(const QModelIndex& index) const; 0115 0116 void invalidatePaintingCache() override; 0117 void updateSizeRectsAndPixmaps() override; 0118 0119 protected Q_SLOTS: 0120 0121 void modelChanged(); 0122 void modelContentsChanged(); 0123 0124 private: 0125 0126 Q_DECLARE_PRIVATE(ImportDelegate) 0127 }; 0128 0129 // ------ ImportThumbnailDelegate ---------------------------------------- 0130 0131 class ImportThumbnailDelegate : public ImportDelegate 0132 { 0133 Q_OBJECT 0134 0135 public: 0136 0137 explicit ImportThumbnailDelegate(ImportCategorizedView* const parent); 0138 ~ImportThumbnailDelegate() override; 0139 0140 void setFlow(QListView::Flow flow); 0141 0142 /** 0143 * Returns the minimum or maximum viewport size in the limiting dimension, 0144 * width or height, depending on current flow. 0145 */ 0146 int maximumSize() const; 0147 int minimumSize() const; 0148 0149 void setDefaultViewOptions(const QStyleOptionViewItem& option) override; 0150 bool acceptsActivation(const QPoint& pos, const QRect& visualRect, const QModelIndex& index, 0151 QRect* activationRect) const override; 0152 0153 protected: 0154 0155 void updateContentWidth() override; 0156 void updateRects() override; 0157 int thumbnailPixmapSize(bool withHighlight, int size); 0158 0159 private: 0160 0161 Q_DECLARE_PRIVATE(ImportThumbnailDelegate) 0162 }; 0163 0164 // ------ ImportNormalDelegate ---------------------------------------- 0165 0166 class ImportNormalDelegate : public ImportDelegate 0167 { 0168 Q_OBJECT 0169 0170 public: 0171 0172 explicit ImportNormalDelegate(ImportCategorizedView* const parent); 0173 ~ImportNormalDelegate() override; 0174 0175 protected: 0176 0177 ImportNormalDelegate(ImportNormalDelegatePrivate& dd, ImportCategorizedView* const parent); 0178 0179 void updateRects() override; 0180 0181 private: 0182 0183 Q_DECLARE_PRIVATE(ImportNormalDelegate) 0184 }; 0185 0186 } // namespace Digikam 0187 0188 #endif // DIGIKAM_IMPORT_DELEGATE_H