digiKam
importdelegate.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 : 2012-07-08
7  * Description : Qt item view to import items - the delegate
8  *
9  * Copyright (C) 2012 by Islam Wazery <wazery at ubuntu dot com>
10  * Copyright (C) 2012-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_IMPORT_DELEGATE_H
26 #define DIGIKAM_IMPORT_DELEGATE_H
27 
28 #include <QtGlobal>
29 #include <QListView>
30 
31 // Local includes
32 
33 #include "itemviewimportdelegate.h"
34 #include "importthumbnailmodel.h"
35 #include "importcategorydrawer.h"
36 
37 namespace Digikam
38 {
39 
40 class ImportCategorizedView;
41 class ImportThumbnailDelegatePrivate;
42 class ImportNormalDelegatePrivate;
43 
45 {
46  Q_OBJECT
47 
48 public:
49 
50  explicit ImportDelegate(QObject* const parent = nullptr);
51  ~ImportDelegate() override;
52 
53  void setView(ImportCategorizedView* view);
54 
56 
57 /*
58  QRect commentsRect() const;
59 */
60  QRect tagsRect() const;
61  QRect actualPixmapRect(const QModelIndex& index) const;
62  QRect groupIndicatorRect() const;
63  QRect downloadIndicatorRect() const;
64  QRect lockIndicatorRect() const;
65  QRect coordinatesIndicatorRect() const;
66 
67  int calculatethumbSizeToFit(int ws);
68 
69  void setSpacing(int spacing) override;
70  void setDefaultViewOptions(const QStyleOptionViewItem& option) override;
71  bool acceptsToolTip(const QPoint& pos, const QRect& visualRect,
72  const QModelIndex& index, QRect* tooltipRect = nullptr) const override;
73  bool acceptsActivation(const QPoint& pos, const QRect& visualRect,
74  const QModelIndex& index, QRect* activationRect = nullptr) const override;
75 
76  QRect pixmapRect() const override;
77  QRect imageInformationRect() const override;
78 
79  void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
80  QPixmap pixmapForDrag(const QStyleOptionViewItem& option, const QList<QModelIndex>& indexes) const override;
81 
86  static QPixmap retrieveThumbnailPixmap(const QModelIndex& index, int thumbnailSize);
87 
88 public:
89 
90  // Declared as public because of use in ImportNormalDelegate class.
92 
93 protected:
94 
95  bool onActualPixmapRect(const QPoint& pos, const QRect& visualRect,
96  const QModelIndex& index, QRect* actualRect) const;
97  void updateActualPixmapRect(const QModelIndex& index, const QRect& rect);
98 
99  void setModel(QAbstractItemModel* model);
100 
101  ImportDelegate(ImportDelegate::ImportDelegatePrivate& dd, QObject* const parent);
102 
107  virtual void updateContentWidth();
108 
113  virtual void updateRects() = 0;
114 
115  void clearCaches() override;
116 
121  virtual void clearModelDataCaches();
122 
123  virtual QPixmap thumbnailPixmap(const QModelIndex& index) const;
124 
125  void invalidatePaintingCache() override;
126  void updateSizeRectsAndPixmaps() override;
127 
128 protected Q_SLOTS:
129 
130  void modelChanged();
131  void modelContentsChanged();
132 
133 private:
134 
135  Q_DECLARE_PRIVATE(ImportDelegate)
136 };
137 
138 // ------ ImportThumbnailDelegate ----------------------------------------
139 
141 {
142  Q_OBJECT
143 
144 public:
145 
146  explicit ImportThumbnailDelegate(ImportCategorizedView* const parent);
147  ~ImportThumbnailDelegate() override;
148 
149  void setFlow(QListView::Flow flow);
150 
155  int maximumSize() const;
156  int minimumSize() const;
157 
158  void setDefaultViewOptions(const QStyleOptionViewItem& option) override;
159  bool acceptsActivation(const QPoint& pos, const QRect& visualRect, const QModelIndex& index,
160  QRect* activationRect) const override;
161 
162 protected:
163 
164  void updateContentWidth() override;
165  void updateRects() override;
166  int thumbnailPixmapSize(bool withHighlight, int size);
167 
168 private:
169 
170  Q_DECLARE_PRIVATE(ImportThumbnailDelegate)
171 };
172 
173 // ------ ImportNormalDelegate ----------------------------------------
174 
176 {
177  Q_OBJECT
178 
179 public:
180 
181  explicit ImportNormalDelegate(ImportCategorizedView* const parent);
182  ~ImportNormalDelegate() override;
183 
184 protected:
185 
187 
188  void updateRects() override;
189 
190 private:
191 
192  Q_DECLARE_PRIVATE(ImportNormalDelegate)
193 };
194 
195 } // namespace Digikam
196 
197 #endif // DIGIKAM_IMPORT_DELEGATE_H
Definition: importcategorizedview.h:44
Definition: importcategorydrawer.h:41
Definition: importdelegate_p.h:46
Definition: importdelegate.h:45
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: importdelegate.cpp:238
void clearCaches() override
Definition: importdelegate.cpp:485
bool onActualPixmapRect(const QPoint &pos, const QRect &visualRect, const QModelIndex &index, QRect *actualRect) const
Definition: importdelegate.cpp:400
void setDefaultViewOptions(const QStyleOptionViewItem &option) override
Definition: importdelegate.cpp:420
virtual void updateRects()=0
virtual QPixmap thumbnailPixmap(const QModelIndex &index) const
Definition: importdelegate.cpp:232
virtual void clearModelDataCaches()
Definition: importdelegate.cpp:492
void modelChanged()
Definition: importdelegate.cpp:498
void updateSizeRectsAndPixmaps() override
Definition: importdelegate.cpp:450
QRect downloadIndicatorRect() const
Definition: importdelegate.cpp:197
void modelContentsChanged()
Definition: importdelegate.cpp:505
void setSpacing(int spacing) override
Definition: importdelegate.cpp:147
QRect imageInformationRect() const override
Definition: importdelegate.cpp:185
QRect pixmapRect() const override
Definition: importdelegate.cpp:179
QPixmap pixmapForDrag(const QStyleOptionViewItem &option, const QList< QModelIndex > &indexes) const override
Definition: importdelegate.cpp:376
QRect lockIndicatorRect() const
Definition: importdelegate.cpp:203
void invalidatePaintingCache() override
reimplement these in subclasses
Definition: importdelegate.cpp:432
QRect coordinatesIndicatorRect() const
Definition: importdelegate.cpp:209
void setView(ImportCategorizedView *view)
Definition: importdelegate.cpp:87
~ImportDelegate() override
Definition: importdelegate.cpp:81
bool acceptsToolTip(const QPoint &pos, const QRect &visualRect, const QModelIndex &index, QRect *tooltipRect=nullptr) const override
Definition: importdelegate.cpp:388
void updateActualPixmapRect(const QModelIndex &index, const QRect &rect)
Definition: importdelegate.cpp:528
void setModel(QAbstractItemModel *model)
Definition: importdelegate.cpp:109
QRect groupIndicatorRect() const
Definition: importdelegate.cpp:191
QRect tagsRect() const
Definition: importdelegate.cpp:173
ImportDelegate(QObject *const parent=nullptr)
Definition: importdelegate.cpp:71
QRect actualPixmapRect(const QModelIndex &index) const
Definition: importdelegate.cpp:510
ImportCategoryDrawer * categoryDrawer() const
Definition: importdelegate.cpp:159
virtual void updateContentWidth()
Definition: importdelegate.cpp:444
int calculatethumbSizeToFit(int ws)
Definition: importdelegate.cpp:539
static QPixmap retrieveThumbnailPixmap(const QModelIndex &index, int thumbnailSize)
Definition: importdelegate.cpp:215
bool acceptsActivation(const QPoint &pos, const QRect &visualRect, const QModelIndex &index, QRect *activationRect=nullptr) const override
Definition: importdelegate.cpp:394
Definition: importdelegate_p.h:124
Definition: importdelegate.h:176
ImportNormalDelegate(ImportCategorizedView *const parent)
Definition: importdelegate.cpp:737
void updateRects() override
Definition: importdelegate.cpp:756
~ImportNormalDelegate() override
Definition: importdelegate.cpp:752
Definition: importdelegate.h:141
int maximumSize() const
Definition: importdelegate.cpp:636
void setFlow(QListView::Flow flow)
Definition: importdelegate.cpp:620
int thumbnailPixmapSize(bool withHighlight, int size)
Definition: importdelegate.cpp:677
void setDefaultViewOptions(const QStyleOptionViewItem &option) override
Definition: importdelegate.cpp:626
ImportThumbnailDelegate(ImportCategorizedView *const parent)
Definition: importdelegate.cpp:609
void updateRects() override
Definition: importdelegate.cpp:687
void updateContentWidth() override
Definition: importdelegate.cpp:658
int minimumSize() const
Definition: importdelegate.cpp:643
~ImportThumbnailDelegate() override
Definition: importdelegate.cpp:616
bool acceptsActivation(const QPoint &pos, const QRect &visualRect, const QModelIndex &index, QRect *activationRect) const override
Definition: importdelegate.cpp:650
NOTE: Some reuse of the existing model-view classes.
Definition: itemviewimportdelegate.h:46
int spacing() const
Definition: itemviewimportdelegate.cpp:140
QRect rect() const
Definition: itemviewimportdelegate.cpp:147
ThumbnailSize thumbnailSize() const
Definition: itemviewimportdelegate.cpp:109
Definition: datefolderview.cpp:43