digiKam
Loading...
Searching...
No Matches
itemdelegateoverlay.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-29
7 * Description : Qt item view for images - delegate additions
8 *
9 * SPDX-FileCopyrightText: 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
13 * ============================================================ */
14
15#pragma once
16
17// Qt includes
18
19#include <QAbstractItemView>
20
21// Local includes
22
23#include "digikam_export.h"
24
25namespace Digikam
26{
27
28class ItemViewHoverButton;
29
30class DIGIKAM_EXPORT ItemDelegateOverlay : public QObject
31{
32 Q_OBJECT
33
34public:
35
36 explicit ItemDelegateOverlay(QObject* const parent = nullptr);
37 ~ItemDelegateOverlay() override = default;
38
45 virtual void setActive(bool active);
46
53 virtual void mouseMoved(QMouseEvent* e, const QRect& visualRect, const QModelIndex& index);
54 virtual void paint(QPainter* p, const QStyleOptionViewItem& option, const QModelIndex& index);
55
56 void setView(QAbstractItemView* view);
57 QAbstractItemView* view() const;
58
59 void setDelegate(QAbstractItemDelegate* delegate);
60 QAbstractItemDelegate* delegate() const;
61
62 virtual bool acceptsDelegate(QAbstractItemDelegate*) const { return true; }
63
64Q_SIGNALS:
65
66 void update(const QModelIndex& index);
67
68 void requestNotification(const QModelIndex& index, const QString& message);
70
71protected Q_SLOTS:
72
77 virtual void visualChange();
78
79protected:
80
87 bool affectsMultiple(const QModelIndex& index) const;
88 QList<QModelIndex> affectedIndexes(const QModelIndex& index) const;
89 int numberOfAffectedIndexes(const QModelIndex& index) const;
90
94 bool viewHasMultiSelection() const;
95
96protected:
97
98 QAbstractItemView* m_view = nullptr;
99 QAbstractItemDelegate* m_delegate = nullptr;
100};
101
102#define REQUIRE_DELEGATE(Delegate) \
103 \
104public: \
105 \
106 void setDelegate(Delegate* delegate) { ItemDelegateOverlay::setDelegate(delegate); } \
107 Delegate* delegate() const { return static_cast<Delegate*>(ItemDelegateOverlay::delegate()); } \
108 virtual bool acceptsDelegate(QAbstractItemDelegate*d) const override { return dynamic_cast<Delegate*>(d); } \
109 \
110private:
111
112// -------------------------------------------------------------------------------------------
113
115{
116 Q_OBJECT
117
118public:
119
126 explicit AbstractWidgetDelegateOverlay(QObject* const parent);
127
134 void setActive(bool active) override;
135
136protected:
137
142 virtual QWidget* createWidget() = 0;
143
148 virtual void hide();
149
153 QWidget* parentWidget() const;
154
159 virtual bool checkIndex(const QModelIndex& index) const;
160
165 virtual void viewportLeaveEvent(QObject* obj, QEvent* event);
166
171 virtual void widgetEnterEvent();
172 virtual void widgetLeaveEvent();
173
177 void widgetEnterNotifyMultiple(const QModelIndex& index);
178 void widgetLeaveNotifyMultiple();
179 virtual QString notifyMultipleMessage(const QModelIndex&, int number);
180
184 bool checkIndexOnEnter(const QModelIndex& index) const;
185
186protected Q_SLOTS:
187
191 virtual void slotEntered(const QModelIndex& index);
192
196 virtual void slotReset();
197 virtual void slotViewportEntered();
198 virtual void slotRowsRemoved(const QModelIndex& parent, int start, int end);
199 virtual void slotLayoutChanged();
200
201protected:
202
203 bool eventFilter(QObject* obj, QEvent* event) override;
204
205protected:
206
207 QWidget* m_widget = nullptr;
208
209 bool m_mouseButtonPressedOnWidget = false;
210};
211
212// -------------------------------------------------------------------------------------------
213
215{
216 Q_OBJECT
217
218public:
219
220 explicit HoverButtonDelegateOverlay(QObject* const parent);
221
225 void setActive(bool active) override;
226
227 ItemViewHoverButton* button() const;
228
229protected:
230
235
240 virtual void updateButton(const QModelIndex& index) = 0;
241
242 QWidget* createWidget() override;
243 void visualChange() override;
244
245protected Q_SLOTS:
246
247 void slotEntered(const QModelIndex& index) override;
248 void slotReset() override;
249};
250
251// -------------------------------------------------------------------------------------------
252
254{
255 Q_OBJECT
256
264public:
265
266 explicit PersistentWidgetDelegateOverlay(QObject* const parent);
268
269 void setActive(bool active) override;
270
271 bool isPersistent() const;
272
273public Q_SLOTS:
274
279 void setPersistent(bool persistent);
280 void enterPersistentMode();
281 void leavePersistentMode();
282
283 void storeFocus();
284
285protected:
286
287 QModelIndex index() const;
288
295 void slotEntered(const QModelIndex& index) override;
296 void slotReset() override;
297 void slotViewportEntered() override;
298 void slotRowsRemoved(const QModelIndex& parent, int start, int end) override;
299 void slotLayoutChanged() override;
300 void viewportLeaveEvent(QObject* obj, QEvent* event) override;
301 void hide() override;
302
307 virtual void setFocusOnWidget();
308
310 virtual void showOnIndex(const QModelIndex& index);
311
312 void restoreFocus();
313
314private:
315
316 class Private;
317 Private* const d = nullptr;
318};
319
320// -------------------------------------------------------------------------------------------
321
323{
324public:
325
333 virtual ~ItemDelegateOverlayContainer() = default;
334
335 QList<ItemDelegateOverlay*> overlays() const;
336
337 void installOverlay(ItemDelegateOverlay* overlay);
338 void removeOverlay(ItemDelegateOverlay* overlay);
339 void setAllOverlaysActive(bool active);
340 void setViewOnAllOverlays(QAbstractItemView* view);
341 void removeAllOverlays();
342 void mouseMoved(QMouseEvent* e, const QRect& visualRect, const QModelIndex& index);
343
344/*
346 void visualChange();
347 void requestNotification(const QModelIndex& index, const QString& message);
348 void hideNotification();
349*/
350
351protected:
352
353 virtual void drawOverlays(QPainter* p, const QStyleOptionViewItem& option, const QModelIndex& index) const;
354
356 virtual void overlayDestroyed(QObject* o);
357
359 virtual QAbstractItemDelegate* asDelegate() = 0;
360
361protected:
362
363 QList<ItemDelegateOverlay*> m_overlays;
364
365private:
366
367 Q_DISABLE_COPY(ItemDelegateOverlayContainer)
368};
369
370} // namespace Digikam
Definition itemdelegateoverlay.h:115
Definition itemdelegateoverlay.h:215
virtual ItemViewHoverButton * createButton()=0
virtual void updateButton(const QModelIndex &index)=0
Definition itemdelegateoverlay.h:323
virtual QAbstractItemDelegate * asDelegate()=0
Returns the delegate, typically, the derived class.
QList< ItemDelegateOverlay * > m_overlays
Definition itemdelegateoverlay.h:363
virtual ~ItemDelegateOverlayContainer()=default
Definition itemdelegateoverlay.h:31
virtual bool acceptsDelegate(QAbstractItemDelegate *) const
Definition itemdelegateoverlay.h:62
~ItemDelegateOverlay() override=default
void update(const QModelIndex &index)
void requestNotification(const QModelIndex &index, const QString &message)
Definition itemviewhoverbutton.h:32
Definition itemdelegateoverlay.h:254
Definition datefolderview.cpp:34