1 /* ============================================================ 2 * 3 * This file is a part of digiKam project 4 * https://www.digikam.org 5 * 6 * Date : 2010-01-16 7 * Description : Qt item view for images - common delegate code 8 * 9 * Copyright (C) 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 10 * 11 * This program is free software; you can redistribute it 12 * and/or modify it under the terms of the GNU General 13 * Public License as published by the Free Software Foundation; 14 * either version 2, or (at your option) 15 * any later version. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details. 21 * 22 * ============================================================ */ 23 24 #ifndef DIGIKAM_DITEM_DELEGATE_H 25 #define DIGIKAM_DITEM_DELEGATE_H 26 27 // Qt includes 28 29 #include <QAbstractItemDelegate> 30 31 // Local includes 32 33 #include "digikam_export.h" 34 #include "thumbnailsize.h" 35 36 namespace Digikam 37 { 38 39 class ItemViewCategorized; 40 41 class DIGIKAM_EXPORT DItemDelegate : public QAbstractItemDelegate 42 { 43 Q_OBJECT 44 45 public: 46 47 explicit DItemDelegate(QObject* const parent = nullptr); 48 ~DItemDelegate() override; 49 50 /** 51 * Returns the gridsize to be set by the view. It's sizeHint plus spacing. 52 */ 53 virtual QSize gridSize() const = 0; 54 virtual QPixmap pixmapForDrag(const QStyleOptionViewItem& option, const QList<QModelIndex>& indexes) const = 0; 55 56 /** 57 * You must set these options from the view 58 */ 59 virtual void setThumbnailSize(const ThumbnailSize& thumbSize) = 0; 60 virtual void setSpacing(int spacing) = 0; 61 62 /** 63 * Style option with standard values to use for cached rendering. 64 * option.rect shall be the viewport rectangle. 65 * Call on resize, font change. 66 */ 67 virtual void setDefaultViewOptions(const QStyleOptionViewItem& option) = 0; 68 69 /** 70 * These methods take four parameters: The position on viewport, the rect on viewport, 71 * the index, and optionally a parameter into which, if the return value is true, 72 * a rectangle can be written for which the return value will be true as well. 73 */ 74 virtual bool acceptsToolTip(const QPoint& pos, const QRect& visualRect, 75 const QModelIndex& index, QRect* tooltipRect = nullptr) const = 0; 76 virtual bool acceptsActivation(const QPoint& pos, const QRect& visualRect, 77 const QModelIndex& index, QRect* activationRect = nullptr) const = 0; 78 79 /** 80 * NOTE: to be called by ItemViewCategorized only 81 */ 82 virtual void mouseMoved(QMouseEvent* e, const QRect& visualRect, const QModelIndex& index) = 0; 83 84 static QString squeezedText(const QFontMetrics& fm, int width, const QString& text); 85 static QString dateToString(const QDateTime& datetime); 86 static QPixmap makeDragPixmap(const QStyleOptionViewItem& option, const QList<QModelIndex>& indexes, 87 const QPixmap& suggestedPixmap = QPixmap()); 88 89 Q_SIGNALS: 90 91 void gridSizeChanged(const QSize& newSize); 92 void visualChange(); 93 94 protected: 95 96 virtual void clearCaches(); 97 98 QString squeezedTextCached(QPainter* const p, int width, const QString& text) const; 99 QPixmap thumbnailBorderPixmap(const QSize& pixSize, bool isGrouped = false) const; 100 101 private: 102 103 class Private; 104 Private* const d; 105 }; 106 107 } // namespace Digikam 108 109 #endif // DIGIKAM_DITEM_DELEGATE_H 110