File indexing completed on 2025-03-09 03:49:57
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-04-19 0007 * Description : Qt model-view for items - the delegate 0008 * 0009 * SPDX-FileCopyrightText: 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0010 * SPDX-FileCopyrightText: 2009-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_ITEM_DELEGATE_H 0017 #define DIGIKAM_ITEM_DELEGATE_H 0018 0019 // Local includes 0020 0021 #include "itemviewdelegate.h" 0022 #include "thumbnailsize.h" 0023 0024 namespace Digikam 0025 { 0026 0027 class ItemCategoryDrawer; 0028 class ItemCategorizedView; 0029 class ItemDelegateOverlay; 0030 class ItemFilterModel; 0031 class ItemModel; 0032 class ItemThumbnailModel; 0033 0034 class ItemDelegate : public ItemViewDelegate 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 0040 explicit ItemDelegate(QWidget* const parent); 0041 ~ItemDelegate() override; 0042 0043 void setView(ItemCategorizedView* view); 0044 0045 ItemCategoryDrawer* categoryDrawer() const; 0046 0047 QRect commentsRect() const; 0048 QRect tagsRect() const; 0049 QRect actualPixmapRect(const QModelIndex& index) const; 0050 QRect groupIndicatorRect() const; 0051 QRect coordinatesIndicatorRect() const; 0052 0053 int calculatethumbSizeToFit(int ws); 0054 0055 void setSpacing(int spacing) override; 0056 void setDefaultViewOptions(const QStyleOptionViewItem& option) override; 0057 bool acceptsToolTip(const QPoint& pos, const QRect& visualRect, 0058 const QModelIndex& index, QRect* tooltipRect = nullptr) const override; 0059 bool acceptsActivation(const QPoint& pos, const QRect& visualRect, 0060 const QModelIndex& index, QRect* activationRect = nullptr) const override; 0061 0062 QRect pixmapRect() const override; 0063 QRect imageInformationRect() const override; 0064 0065 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override; 0066 QPixmap pixmapForDrag(const QStyleOptionViewItem& option, const QList<QModelIndex>& indexes) const override; 0067 0068 /** 0069 * Retrieve the thumbnail pixmap in given size for the ItemModel::ThumbnailRole for 0070 * the given index from the given index, which must adhere to ItemThumbnailModel semantics. 0071 */ 0072 static QPixmap retrieveThumbnailPixmap(const QModelIndex& index, int thumbnailSize); 0073 0074 public: 0075 0076 // Declared as public because of use in DigikamItemDelegate class. 0077 class ItemDelegatePrivate; 0078 0079 protected: 0080 0081 /** Reimplement this to set contentWidth. This is the maximum width of all 0082 * content rectangles, typically excluding margins on both sides. 0083 */ 0084 virtual void updateContentWidth(); 0085 0086 /** In a subclass, you need to implement this method to set up the rects 0087 * for drawing. The paint() method operates depending on these rects. 0088 */ 0089 virtual void updateRects() = 0; 0090 0091 void clearCaches() override; 0092 0093 /** Reimplement to clear caches based on model indexes (hash on row number etc.) 0094 * Change signals are listened to this is called whenever such properties become invalid. 0095 */ 0096 virtual void clearModelDataCaches(); 0097 0098 virtual QPixmap thumbnailPixmap(const QModelIndex& index) const; 0099 0100 bool onActualPixmapRect(const QPoint& pos, const QRect& visualRect, 0101 const QModelIndex& index, QRect* actualRect) const; 0102 void updateActualPixmapRect(const QModelIndex& index, const QRect& rect); 0103 0104 void invalidatePaintingCache() override; 0105 void updateSizeRectsAndPixmaps() override; 0106 0107 void setModel(QAbstractItemModel* model); 0108 0109 ItemDelegate(ItemDelegate::ItemDelegatePrivate& dd, QWidget* const parent); 0110 0111 protected Q_SLOTS: 0112 0113 void modelChanged(); 0114 void modelContentsChanged(); 0115 0116 private: 0117 0118 Q_DECLARE_PRIVATE(ItemDelegate) 0119 }; 0120 0121 } // namespace Digikam 0122 0123 #endif // DIGIKAM_ITEM_DELEGATE_H