File indexing completed on 2025-01-19 03:59:22
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2012-05-07 0007 * Description : Item delegate for import interface items. 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_ITEM_VIEW_IMPORT_DELEGATE_H 0017 #define DIGIKAM_ITEM_VIEW_IMPORT_DELEGATE_H 0018 0019 // Local includes 0020 0021 #include "thumbnailsize.h" 0022 #include "ditemdelegate.h" 0023 #include "itemdelegateoverlay.h" 0024 0025 namespace Digikam 0026 { 0027 0028 class ImportCategoryDrawer; 0029 class ImportCategorizedView; 0030 class ImportFilterModel; 0031 class ImportItemModel; 0032 class ItemViewImportDelegatePrivate; 0033 0034 /// NOTE: Some reuse of the existing model-view classes. 0035 0036 class ItemViewImportDelegate : public DItemDelegate, public ItemDelegateOverlayContainer 0037 { 0038 Q_OBJECT 0039 0040 public: 0041 0042 explicit ItemViewImportDelegate(QWidget* const parent); 0043 ~ItemViewImportDelegate() override; 0044 0045 ThumbnailSize thumbnailSize() const; 0046 double displayRatio() const; 0047 int spacing() const; 0048 QRect rect() const; 0049 0050 QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override; 0051 QSize gridSize() const override; 0052 0053 /// reimplemented from DItemDelegate 0054 0055 void setThumbnailSize(const ThumbnailSize& thumbSize) override; 0056 void setSpacing(int spacing) override; 0057 void setDefaultViewOptions(const QStyleOptionViewItem& option) override; 0058 bool acceptsToolTip(const QPoint& pos, const QRect& visualRect, 0059 const QModelIndex& index, QRect* tooltipRect = nullptr) const override; 0060 bool acceptsActivation(const QPoint& pos, const QRect& visualRect, 0061 const QModelIndex& index, QRect* activationRect = nullptr) const override; 0062 0063 /** 0064 * Returns the area where the pixmap is drawn, 0065 * or null if not supported 0066 */ 0067 virtual QRect pixmapRect() const; 0068 0069 /** 0070 * Returns the area where the image information is drawn, 0071 * or null if empty / not supported. 0072 * The image information is textual or graphical information, 0073 * but not the pixmap. The ratingRect() will e.g. typically 0074 * be contained in this area. 0075 */ 0076 virtual QRect imageInformationRect() const; 0077 0078 /** 0079 * Can be used to temporarily disable drawing of the rating. 0080 * Call with QModelIndex() afterwards. 0081 */ 0082 void setRatingEdited(const QModelIndex& index); 0083 0084 /** 0085 * Returns the rectangle where the rating is drawn, 0086 * or a null rectangle if not supported. 0087 */ 0088 virtual QRect ratingRect() const; 0089 0090 void mouseMoved(QMouseEvent* e, const QRect& visualRect, const QModelIndex& index) override; 0091 0092 protected Q_SLOTS: 0093 0094 void slotThemeChanged(); 0095 void slotSetupChanged(); 0096 0097 void overlayDestroyed(QObject* o) override; 0098 0099 Q_SIGNALS: 0100 0101 void requestNotification(const QModelIndex& index, const QString& message); 0102 void hideNotification(); 0103 0104 protected: 0105 0106 /// Use the tool methods for painting in subclasses 0107 QRect drawThumbnail(QPainter* p, const QRect& thumbRect, const QPixmap& background, const QPixmap& thumbnail) const; 0108 void drawRating(QPainter* p, const QModelIndex& index, const QRect& ratingRect, int rating, bool isSelected) const; 0109 void drawName(QPainter* p,const QRect& nameRect, const QString& name) const; 0110 void drawCreationDate(QPainter* p, const QRect& dateRect, const QDateTime& date) const; 0111 void drawImageSize(QPainter* p, const QRect& dimsRect, const QSize& dims) const; 0112 void drawImageFormat(QPainter* p, const QRect& dimsRect, const QString& mime) const; 0113 void drawFileSize(QPainter* p, const QRect& r, qlonglong bytes) const; 0114 void drawTags(QPainter* p, const QRect& r, const QString& tagsString, bool isSelected) const; 0115 void drawGroupIndicator(QPainter* p, const QRect& r, int numberOfGroupedImages, bool open) const; 0116 void drawPickLabelIcon(QPainter* p, const QRect& r, int pickLabel) const; 0117 void drawColorLabelRect(QPainter* p, const QStyleOptionViewItem& option,bool isSelected, int colorId) const; 0118 void drawGeolocationIndicator(QPainter* p, const QRect& r) const; 0119 void drawDownloadIndicator(QPainter* p, const QRect& r, int itemType) const; 0120 void drawLockIndicator(QPainter* p, const QRect& r, int lockStatus) const; 0121 void drawFocusRect(QPainter* p, const QStyleOptionViewItem& option, bool isSelected) const; 0122 void drawMouseOverRect(QPainter* p, const QStyleOptionViewItem& option) const; 0123 void prepareFonts(); 0124 void prepareMetrics(int maxWidth); 0125 void prepareBackground(); 0126 void prepareRatingPixmaps(bool composeOverBackground = true); 0127 0128 /// Returns the relevant pixmap from the cached rating pixmaps 0129 QPixmap ratingPixmap(int rating, bool selected) const; 0130 0131 QAbstractItemDelegate* asDelegate() override; 0132 0133 /// reimplement these in subclasses 0134 virtual void invalidatePaintingCache(); 0135 virtual void updateSizeRectsAndPixmaps() = 0; 0136 0137 protected: 0138 0139 ItemViewImportDelegatePrivate* const d_ptr; 0140 ItemViewImportDelegate(ItemViewImportDelegatePrivate& dd, QWidget* const parent); 0141 0142 private: 0143 0144 // Disable 0145 ItemViewImportDelegate(const ItemViewImportDelegate&) = delete; 0146 ItemViewImportDelegate& operator=(const ItemViewImportDelegate&) = delete; 0147 0148 private: 0149 0150 Q_DECLARE_PRIVATE(ItemViewImportDelegate) 0151 }; 0152 0153 } // namespace Digikam 0154 0155 #endif // DIGIKAM_ITEM_VIEW_IMPORT_DELEGATE_H