digiKam
itemviewdelegate.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 item view for items - the delegate
8  *
9  * Copyright (C) 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2011-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_VIEW_DELEGATE_H
26 #define DIGIKAM_ITEM_VIEW_DELEGATE_H
27 
28 // Local includes
29 
30 #include "ditemdelegate.h"
31 #include "itemdelegateoverlay.h"
32 #include "thumbnailsize.h"
33 #include "digikam_export.h"
34 
35 namespace Digikam
36 {
37 
38 class ItemViewDelegatePrivate;
39 
40 class DIGIKAM_EXPORT ItemViewDelegate : public DItemDelegate,
42 {
43  Q_OBJECT
44 
45 public:
46 
47  explicit ItemViewDelegate(QObject* const parent = nullptr);
48  ~ItemViewDelegate() override;
49 
50  ThumbnailSize thumbnailSize() const;
51  int spacing() const;
52  QRect rect() const;
53 
58  void setRatingEdited(const QModelIndex& index);
59 
60  QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
61  QSize gridSize() const override;
62 
63  // reimplemented from DItemDelegate
64  void setThumbnailSize(const ThumbnailSize& thumbSize) override;
65  void setSpacing(int spacing) override;
66  void setDefaultViewOptions(const QStyleOptionViewItem& option) override;
67  bool acceptsToolTip(const QPoint& pos, const QRect& visualRect,
68  const QModelIndex& index, QRect* tooltipRect = nullptr) const override;
69  bool acceptsActivation(const QPoint& pos, const QRect& visualRect,
70  const QModelIndex& index, QRect* activationRect = nullptr) const override;
71 
76  virtual QRect pixmapRect() const;
77 
85  virtual QRect imageInformationRect() const;
86 
91  virtual QRect ratingRect() const;
92 
93  void mouseMoved(QMouseEvent* e, const QRect& visualRect, const QModelIndex& index) override;
94 
95 protected Q_SLOTS:
96 
97  void slotThemeChanged();
98  void slotSetupChanged();
99 
100  void overlayDestroyed(QObject* o) override;
101 
102 Q_SIGNALS:
103 
104  void requestNotification(const QModelIndex& index, const QString& message);
106 
107 protected:
108 
112  QRect drawThumbnail(QPainter* p, const QRect& thumbRect, const QPixmap& background, const QPixmap& thumbnail, bool isGrouped) const;
113  void drawRating(QPainter* p, const QModelIndex& index, const QRect& ratingRect, int rating, bool isSelected) const;
114  void drawSpecialInfo(QPainter* p,const QRect& r, const QString& text) const;
115  void drawName(QPainter* p,const QRect& nameRect, const QString& name) const;
116  void drawTitle(QPainter *p, const QRect& titleRect, const QString& title) const;
117  void drawComments(QPainter* p, const QRect& commentsRect, const QString& comments) const;
118  void drawCreationDate(QPainter* p, const QRect& dateRect, const QDateTime& date) const;
119  void drawModificationDate(QPainter* p, const QRect& dateRect, const QDateTime& date) const;
120  void drawImageSize(QPainter* p, const QRect& dimsRect, const QSize& dims) const;
121  void drawAspectRatio(QPainter* p, const QRect& dimsRect, const QSize& dims) const;
122  void drawFileSize(QPainter* p, const QRect& r, qlonglong bytes) const;
123  void drawTags(QPainter* p, const QRect& r, const QString& tagsString, bool isSelected) const;
124  void drawImageFormat(QPainter* p, const QRect& r, const QString& f, bool drawTop) const;
125  void drawColorLabelRect(QPainter* p, const QStyleOptionViewItem& option, bool isSelected, int colorId) const;
126  void drawPickLabelIcon(QPainter* p, const QRect& r, int pickLabel) const;
127  void drawGroupIndicator(QPainter* p, const QRect& r, int numberOfGroupedImages, bool open) const;
128  void drawGeolocationIndicator(QPainter* p, const QRect& r) const;
129  void drawPanelSideIcon(QPainter* p, bool left, bool right) const;
130  void drawFocusRect(QPainter* p, const QStyleOptionViewItem& option, bool isSelected) const;
131  void drawMouseOverRect(QPainter* p, const QStyleOptionViewItem& option) const;
132  void prepareFonts();
133  void prepareMetrics(int maxWidth);
134  void prepareBackground();
135  void prepareRatingPixmaps(bool composeOverBackground = true);
136 
140  QPixmap ratingPixmap(int rating, bool selected) const;
141 
142  QAbstractItemDelegate* asDelegate() override;
143 
144  // reimplement these in subclasses
145  virtual void invalidatePaintingCache();
146  virtual void updateSizeRectsAndPixmaps() = 0;
147 
148 protected:
149 
151  ItemViewDelegate(ItemViewDelegatePrivate& dd, QObject* const parent);
152 
153 private:
154 
155  // Disable
157  ItemViewDelegate& operator=(const ItemViewDelegate&);
158 
159  Q_DECLARE_PRIVATE(ItemViewDelegate)
160 };
161 
162 } // namespace Digikam
163 
164 #endif // DIGIKAM_ITEM_VIEW_DELEGATE_H
Definition: ditemdelegate.h:42
Definition: itemdelegateoverlay.h:333
Definition: itemviewdelegate_p.h:50
Definition: itemviewdelegate.h:42
virtual void updateSizeRectsAndPixmaps()=0
void requestNotification(const QModelIndex &index, const QString &message)
ItemViewDelegatePrivate *const d_ptr
Definition: itemviewdelegate.h:150
Definition: thumbnailsize.h:42
Definition: datefolderview.cpp:43