1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2013-08-01
* Description : Qt model view for Showfoto item - the delegate
*
* SPDX-FileCopyrightText: 2013 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
* SPDX-FileCopyrightText: 2013-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#pragma once
// Qt includes
#include <QListView>
// Local includes
#include "showfotoitemviewdelegate.h"
#include "showfotothumbnailmodel.h"
namespace ShowFoto
{
class ShowfotoThumbnailBar;
class ShowfotoThumbnailDelegatePrivate;
class ShowfotoNormalDelegatePrivate;
class ShowfotoFilterModel;
class ShowfotoDelegate : public ShowfotoItemViewDelegate
{
Q_OBJECT
public:
explicit ShowfotoDelegate(QWidget* const parent);
~ShowfotoDelegate() override;
void setView(ShowfotoThumbnailBar* view);
QRect actualPixmapRect(const QModelIndex& index) const;
QRect groupIndicatorRect() const;
QRect coordinatesIndicatorRect() const;
int calculatethumbSizeToFit(int ws);
void setDefaultViewOptions(const QStyleOptionViewItem& option) override;<--- Function in derived class
bool acceptsToolTip(const QPoint& pos, const QRect& visualRect,
const QModelIndex& index, QRect* tooltipRect = nullptr) const override;
bool acceptsActivation(const QPoint& pos, const QRect& visualRect,
const QModelIndex& index, QRect* activationRect = nullptr) const override;
QRect pixmapRect() const override;
QRect imageInformationRect() const override;
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
QPixmap pixmapForDrag(const QStyleOptionViewItem& option, const QList<QModelIndex>& indexes) const override;
/**
* Retrieve the thumbnail pixmap in given size for the ShowfotoItemModel::ThumbnailRole for
* the given index from the given index, which must adhere to ShowfotoThumbnailModel semantics.
*/
static QPixmap retrieveThumbnailPixmap(const QModelIndex& index, int thumbnailSize);
public:
/// Declared as public because of use in ShowfotoNormalDelegate class.
class ShowfotoDelegatePrivate;
protected:
bool onActualPixmapRect(const QPoint& pos, const QRect& visualRect,
const QModelIndex& index, QRect* actualRect) const;
void updateActualPixmapRect(const QModelIndex& index, const QRect& rect);
void setModel(QAbstractItemModel* model);
ShowfotoDelegate(ShowfotoDelegate::ShowfotoDelegatePrivate& dd, QWidget* const parent);
/**
* Reimplement this to set contentWidth. This is the maximum width of all
* content rectangles, typically excluding margins on both sides.
*/
virtual void updateContentWidth();
/**
* In a subclass, you need to implement this method to set up the rects
* for drawing. The paint() method operates depending on these rects.
*/
virtual void updateRects() = 0;
void clearCaches() override;
/**
* Reimplement to clear caches based on model indexes (hash on row number etc.)
* Change signals are listened to this is called whenever such properties become invalid.
*/
virtual void clearModelDataCaches();
virtual QPixmap thumbnailPixmap(const QModelIndex& index) const;
void updateSizeRectsAndPixmaps() override;
protected Q_SLOTS:
void modelChanged();
void modelContentsChanged();
private:
Q_DECLARE_PRIVATE(ShowfotoDelegate)
};
// -------------- ShowfotoThumbnailDelegate ---------------------
class ShowfotoThumbnailDelegate : public ShowfotoDelegate
{
Q_OBJECT
public:
explicit ShowfotoThumbnailDelegate(ShowfotoThumbnailBar* const parent);
~ShowfotoThumbnailDelegate() override;
void setFlow(QListView::Flow flow);
/**
* Returns the minimum or maximum viewport size in the limiting dimension,
* width or height, depending on current flow.
*/
int maximumSize() const;
int minimumSize() const;
void setDefaultViewOptions(const QStyleOptionViewItem& option) override;
bool acceptsActivation(const QPoint& pos,
const QRect& visualRect,
const QModelIndex& index,
QRect* activationRect) const override;
protected:
void updateContentWidth() override;
void updateRects() override;
int thumbnailPixmapSize(bool withHighlight, int size);
private:
// Disable
explicit ShowfotoThumbnailDelegate(QObject*) = delete;
private:
Q_DECLARE_PRIVATE(ShowfotoThumbnailDelegate)
};
// ------------------- ShowfotoNormalDelegate ------------------
class ShowfotoNormalDelegate : public ShowfotoDelegate
{
Q_OBJECT
public:
explicit ShowfotoNormalDelegate(ShowfotoThumbnailBar* const bar,
QObject* const parent = nullptr);
~ShowfotoNormalDelegate() override;
protected:
ShowfotoNormalDelegate(ShowfotoNormalDelegatePrivate& dd,
ShowfotoThumbnailBar* const bar,
QObject* const parent = nullptr);
void updateRects() override;
private:
Q_DECLARE_PRIVATE(ShowfotoNormalDelegate)
};
} // namespace ShowFoto
|