File indexing completed on 2025-04-27 03:58:28

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2010-01-16
0007  * Description : Qt item view for images - common delegate code
0008  *
0009  * SPDX-FileCopyrightText: 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_DITEM_DELEGATE_H
0016 #define DIGIKAM_DITEM_DELEGATE_H
0017 
0018 // Qt includes
0019 
0020 #include <QWidget>
0021 #include <QAbstractItemDelegate>
0022 
0023 // Local includes
0024 
0025 #include "digikam_export.h"
0026 #include "thumbnailsize.h"
0027 
0028 namespace Digikam
0029 {
0030 
0031 class ItemViewCategorized;
0032 
0033 class DIGIKAM_EXPORT DItemDelegate : public QAbstractItemDelegate
0034 {
0035     Q_OBJECT
0036 
0037 public:
0038 
0039     explicit DItemDelegate(QObject* const parent = nullptr);
0040     ~DItemDelegate() override;
0041 
0042     /**
0043      * Returns the gridsize to be set by the view. It's sizeHint plus spacing.
0044      */
0045     virtual QSize gridSize() const = 0;
0046     virtual QPixmap pixmapForDrag(const QStyleOptionViewItem& option, const QList<QModelIndex>& indexes) const = 0;
0047 
0048     /**
0049      * You must set these options from the view
0050      */
0051     virtual void setThumbnailSize(const ThumbnailSize& thumbSize) = 0;
0052     virtual void setSpacing(int spacing) = 0;
0053 
0054     /**
0055      * Style option with standard values to use for cached rendering.
0056      * option.rect shall be the viewport rectangle.
0057      * Call on resize, font change.
0058      */
0059     virtual void setDefaultViewOptions(const QStyleOptionViewItem& option) = 0;
0060 
0061     /**
0062      * These methods take four parameters: The position on viewport, the rect on viewport,
0063      * the index, and optionally a parameter into which, if the return value is true,
0064      * a rectangle can be written for which the return value will be true as well.
0065      */
0066     virtual bool acceptsToolTip(const QPoint& pos, const QRect& visualRect,
0067                                 const QModelIndex& index, QRect* tooltipRect = nullptr) const = 0;
0068     virtual bool acceptsActivation(const QPoint& pos, const QRect& visualRect,
0069                                    const QModelIndex& index, QRect* activationRect = nullptr) const = 0;
0070 
0071     /**
0072      * NOTE: to be called by ItemViewCategorized only
0073      */
0074     virtual void mouseMoved(QMouseEvent* e, const QRect& visualRect, const QModelIndex& index) = 0;
0075 
0076     static QString squeezedText(const QFontMetrics& fm, int width, const QString& text);
0077     static QString dateToString(const QDateTime& datetime);
0078     static QPixmap makeDragPixmap(const QStyleOptionViewItem& option, const QList<QModelIndex>& indexes,
0079                                   double displayRatio, const QPixmap& suggestedPixmap = QPixmap());
0080 
0081 Q_SIGNALS:
0082 
0083     void gridSizeChanged(const QSize& newSize);
0084     void visualChange();
0085 
0086 protected:
0087 
0088     virtual void clearCaches();
0089 
0090     QString squeezedTextCached(QPainter* const p, int width, const QString& text) const;
0091     QPixmap thumbnailBorderPixmap(const QSize& pixSize, bool isGrouped = false) const;
0092 
0093 private:
0094 
0095     class Private;
0096     Private* const d;
0097 };
0098 
0099 } // namespace Digikam
0100 
0101 #endif // DIGIKAM_DITEM_DELEGATE_H