digiKam
itemdelegate.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2009-04-19
7  * Description : Qt model-view for items - the delegate
8  *
9  * Copyright (C) 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2009-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_ITEM_DELEGATE_H
26 #define DIGIKAM_ITEM_DELEGATE_H
27 
28 // Local includes
29 
30 #include "itemviewdelegate.h"
31 #include "thumbnailsize.h"
32 
33 namespace Digikam
34 {
35 
36 class ItemCategoryDrawer;
37 class ItemCategorizedView;
38 class ItemDelegateOverlay;
39 class ItemFilterModel;
40 class ItemModel;
41 class ItemThumbnailModel;
42 
44 {
45  Q_OBJECT
46 
47 public:
48 
49  explicit ItemDelegate(QObject* const parent = nullptr);
50  ~ItemDelegate() override;
51 
52  void setView(ItemCategorizedView* view);
53 
55 
56  QRect commentsRect() const;
57  QRect tagsRect() const;
58  QRect actualPixmapRect(const QModelIndex& index) const;
59  QRect groupIndicatorRect() const;
60  QRect coordinatesIndicatorRect() const;
61 
62  int calculatethumbSizeToFit(int ws);
63 
64  void setSpacing(int spacing) override;
65  void setDefaultViewOptions(const QStyleOptionViewItem& option) override;
66  bool acceptsToolTip(const QPoint& pos, const QRect& visualRect,
67  const QModelIndex& index, QRect* tooltipRect = nullptr) const override;
68  bool acceptsActivation(const QPoint& pos, const QRect& visualRect,
69  const QModelIndex& index, QRect* activationRect = nullptr) const override;
70 
71  QRect pixmapRect() const override;
72  QRect imageInformationRect() const override;
73 
74  void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
75  QPixmap pixmapForDrag(const QStyleOptionViewItem& option, const QList<QModelIndex>& indexes) const override;
76 
81  static QPixmap retrieveThumbnailPixmap(const QModelIndex& index, int thumbnailSize);
82 
83 public:
84 
85  // Declared as public because of use in DigikamItemDelegate class.
86  class ItemDelegatePrivate;
87 
88 protected:
89 
93  virtual void updateContentWidth();
94 
98  virtual void updateRects() = 0;
99 
100  void clearCaches() override;
101 
105  virtual void clearModelDataCaches();
106 
107  virtual QPixmap thumbnailPixmap(const QModelIndex& index) const;
108 
109  bool onActualPixmapRect(const QPoint& pos, const QRect& visualRect,
110  const QModelIndex& index, QRect* actualRect) const;
111  void updateActualPixmapRect(const QModelIndex& index, const QRect& rect);
112 
113  void invalidatePaintingCache() override;
114  void updateSizeRectsAndPixmaps() override;
115 
116  void setModel(QAbstractItemModel* model);
117 
118  ItemDelegate(ItemDelegate::ItemDelegatePrivate& dd, QObject* const parent);
119 
120 protected Q_SLOTS:
121 
122  void modelChanged();
123  void modelContentsChanged();
124 
125 private:
126 
127  Q_DECLARE_PRIVATE(ItemDelegate)
128 };
129 
130 } // namespace Digikam
131 
132 #endif // DIGIKAM_ITEM_DELEGATE_H
Definition: itemcategorizedview.h:49
Definition: itemcategorydrawer.h:44
Definition: itemdelegate_p.h:45
Definition: itemdelegate.h:44
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: itemdelegate.cpp:232
virtual QPixmap thumbnailPixmap(const QModelIndex &index) const
Definition: itemdelegate.cpp:226
QRect actualPixmapRect(const QModelIndex &index) const
Definition: itemdelegate.cpp:523
QRect tagsRect() const
Definition: itemdelegate.cpp:182
ItemDelegate(QObject *const parent=nullptr)
Definition: itemdelegate.cpp:80
QRect pixmapRect() const override
Definition: itemdelegate.cpp:188
void updateSizeRectsAndPixmaps() override
Definition: itemdelegate.cpp:464
virtual void updateRects()=0
QRect commentsRect() const
Definition: itemdelegate.cpp:176
virtual void clearModelDataCaches()
Definition: itemdelegate.cpp:505
QRect groupIndicatorRect() const
Definition: itemdelegate.cpp:200
void invalidatePaintingCache() override
Definition: itemdelegate.cpp:446
ItemCategoryDrawer * categoryDrawer() const
Definition: itemdelegate.cpp:170
static QPixmap retrieveThumbnailPixmap(const QModelIndex &index, int thumbnailSize)
Definition: itemdelegate.cpp:212
void updateActualPixmapRect(const QModelIndex &index, const QRect &rect)
Definition: itemdelegate.cpp:539
virtual void updateContentWidth()
Definition: itemdelegate.cpp:458
bool acceptsActivation(const QPoint &pos, const QRect &visualRect, const QModelIndex &index, QRect *activationRect=nullptr) const override
Definition: itemdelegate.cpp:408
QRect coordinatesIndicatorRect() const
Definition: itemdelegate.cpp:206
void setDefaultViewOptions(const QStyleOptionViewItem &option) override
Definition: itemdelegate.cpp:434
void modelChanged()
Definition: itemdelegate.cpp:511
void clearCaches() override
Definition: itemdelegate.cpp:498
void setView(ItemCategorizedView *view)
Definition: itemdelegate.cpp:98
int calculatethumbSizeToFit(int ws)
Definition: itemdelegate.cpp:550
~ItemDelegate() override
Definition: itemdelegate.cpp:90
bool onActualPixmapRect(const QPoint &pos, const QRect &visualRect, const QModelIndex &index, QRect *actualRect) const
Definition: itemdelegate.cpp:414
QPixmap pixmapForDrag(const QStyleOptionViewItem &option, const QList< QModelIndex > &indexes) const override
Definition: itemdelegate.cpp:390
QRect imageInformationRect() const override
Definition: itemdelegate.cpp:194
void setSpacing(int spacing) override
Definition: itemdelegate.cpp:158
void setModel(QAbstractItemModel *model)
Definition: itemdelegate.cpp:120
void modelContentsChanged()
Definition: itemdelegate.cpp:518
bool acceptsToolTip(const QPoint &pos, const QRect &visualRect, const QModelIndex &index, QRect *tooltipRect=nullptr) const override
Definition: itemdelegate.cpp:402
Definition: itemviewdelegate.h:42
ThumbnailSize thumbnailSize() const
Definition: itemviewdelegate.cpp:112
int spacing() const
Definition: itemviewdelegate.cpp:143
QRect rect() const
Definition: itemviewdelegate.cpp:150
Definition: datefolderview.cpp:43