File indexing completed on 2025-04-27 03:58:29
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 item view for items - the delegate 0008 * 0009 * SPDX-FileCopyrightText: 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0010 * SPDX-FileCopyrightText: 2011-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_VIEW_DELEGATE_H 0017 #define DIGIKAM_ITEM_VIEW_DELEGATE_H 0018 0019 // Local includes 0020 0021 #include "ditemdelegate.h" 0022 #include "itemdelegateoverlay.h" 0023 #include "thumbnailsize.h" 0024 #include "digikam_export.h" 0025 0026 namespace Digikam 0027 { 0028 0029 class ItemViewDelegatePrivate; 0030 0031 class DIGIKAM_EXPORT ItemViewDelegate : public DItemDelegate, 0032 public ItemDelegateOverlayContainer 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 0038 explicit ItemViewDelegate(QWidget* const parent); 0039 ~ItemViewDelegate() override; 0040 0041 ThumbnailSize thumbnailSize() const; 0042 double displayRatio() const; 0043 int spacing() const; 0044 QRect rect() const; 0045 0046 /** 0047 * Can be used to temporarily disable drawing of the rating. 0048 * Call with QModelIndex() afterwards. 0049 */ 0050 void setRatingEdited(const QModelIndex& index); 0051 0052 QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override; 0053 QSize gridSize() const override; 0054 0055 // reimplemented from DItemDelegate 0056 void setThumbnailSize(const ThumbnailSize& thumbSize) override; 0057 void setSpacing(int spacing) override; 0058 void setDefaultViewOptions(const QStyleOptionViewItem& option) override; 0059 bool acceptsToolTip(const QPoint& pos, const QRect& visualRect, 0060 const QModelIndex& index, QRect* tooltipRect = nullptr) const override; 0061 bool acceptsActivation(const QPoint& pos, const QRect& visualRect, 0062 const QModelIndex& index, QRect* activationRect = nullptr) const override; 0063 0064 /** 0065 * Returns the area where the pixmap is drawn, 0066 * or null if not supported. 0067 */ 0068 virtual QRect pixmapRect() const; 0069 0070 /** 0071 * Returns the area where the image information is drawn, 0072 * or null if empty / not supported. 0073 * The image information is textual or graphical information, 0074 * but not the pixmap. The ratingRect() will e.g. typically 0075 * be contained in this area. 0076 */ 0077 virtual QRect imageInformationRect() const; 0078 0079 /** 0080 * Returns the rectangle where the rating is drawn, 0081 * or a null rectangle if not supported. 0082 */ 0083 virtual QRect ratingRect() const; 0084 0085 void mouseMoved(QMouseEvent* e, const QRect& visualRect, const QModelIndex& index) override; 0086 0087 protected Q_SLOTS: 0088 0089 void slotThemeChanged(); 0090 void slotSetupChanged(); 0091 0092 void overlayDestroyed(QObject* o) override; 0093 0094 Q_SIGNALS: 0095 0096 void requestNotification(const QModelIndex& index, const QString& message); 0097 void hideNotification(); 0098 0099 protected: 0100 0101 /** 0102 * Use the tool methods for painting in subclasses 0103 */ 0104 QRect drawThumbnail(QPainter* p, const QRect& thumbRect, const QPixmap& background, const QPixmap& thumbnail, bool isGrouped) const; 0105 void drawRating(QPainter* p, const QModelIndex& index, const QRect& ratingRect, int rating, bool isSelected) const; 0106 void drawSpecialInfo(QPainter* p,const QRect& r, const QString& text) const; 0107 void drawName(QPainter* p,const QRect& nameRect, const QString& name) const; 0108 void drawTitle(QPainter *p, const QRect& titleRect, const QString& title) const; 0109 void drawComments(QPainter* p, const QRect& commentsRect, const QString& comments) const; 0110 void drawCreationDate(QPainter* p, const QRect& dateRect, const QDateTime& date) const; 0111 void drawModificationDate(QPainter* p, const QRect& dateRect, const QDateTime& date) const; 0112 void drawImageSize(QPainter* p, const QRect& dimsRect, const QSize& dims) const; 0113 void drawAspectRatio(QPainter* p, const QRect& dimsRect, const QSize& dims) const; 0114 void drawFileSize(QPainter* p, const QRect& r, qlonglong bytes) const; 0115 void drawTags(QPainter* p, const QRect& r, const QString& tagsString, bool isSelected) const; 0116 void drawImageFormat(QPainter* p, const QRect& r, const QString& f, bool drawTop) const; 0117 void drawColorLabelRect(QPainter* p, const QStyleOptionViewItem& option, bool isSelected, int colorId) const; 0118 void drawPickLabelIcon(QPainter* p, const QRect& r, int pickLabel) const; 0119 void drawGroupIndicator(QPainter* p, const QRect& r, int numberOfGroupedImages, bool open) const; 0120 void drawGeolocationIndicator(QPainter* p, const QRect& r) const; 0121 void drawPanelSideIcon(QPainter* p, bool left, bool right) const; 0122 void drawFocusRect(QPainter* p, const QStyleOptionViewItem& option, bool isSelected) const; 0123 void drawMouseOverRect(QPainter* p, const QStyleOptionViewItem& option) const; 0124 void prepareFonts(); 0125 void prepareMetrics(int maxWidth); 0126 void prepareBackground(); 0127 void prepareRatingPixmaps(bool composeOverBackground = true); 0128 0129 /** 0130 * Returns the relevant pixmap from the cached rating pixmaps. 0131 */ 0132 QPixmap ratingPixmap(int rating, bool selected) const; 0133 0134 QAbstractItemDelegate* asDelegate() override; 0135 0136 // reimplement these in subclasses 0137 virtual void invalidatePaintingCache(); 0138 virtual void updateSizeRectsAndPixmaps() = 0; 0139 0140 protected: 0141 0142 ItemViewDelegatePrivate* const d_ptr; 0143 ItemViewDelegate(ItemViewDelegatePrivate& dd, QWidget* const parent); 0144 0145 private: 0146 0147 // Disable 0148 ItemViewDelegate(const ItemViewDelegate&); 0149 ItemViewDelegate& operator=(const ItemViewDelegate&); 0150 0151 Q_DECLARE_PRIVATE(ItemViewDelegate) 0152 }; 0153 0154 } // namespace Digikam 0155 0156 #endif // DIGIKAM_ITEM_VIEW_DELEGATE_H