digiKam
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  * Copyright (C) 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_ITEM_DELEGATE_OVERLAY_H
25 #define DIGIKAM_ITEM_DELEGATE_OVERLAY_H
26 
27 // Qt includes
28 
29 #include <QAbstractItemView>
30 
31 // Local includes
32 
33 #include "digikam_export.h"
34 
35 namespace Digikam
36 {
37 
38 class ItemViewHoverButton;
39 
40 class DIGIKAM_EXPORT ItemDelegateOverlay : public QObject
41 {
42  Q_OBJECT
43 
44 public:
45 
46  explicit ItemDelegateOverlay(QObject* const parent = nullptr);
47  ~ItemDelegateOverlay() override;
48 
55  virtual void setActive(bool active);
56 
63  virtual void mouseMoved(QMouseEvent* e, const QRect& visualRect, const QModelIndex& index);
64  virtual void paint(QPainter* p, const QStyleOptionViewItem& option, const QModelIndex& index);
65 
66  void setView(QAbstractItemView* view);
67  QAbstractItemView* view() const;
68 
69  void setDelegate(QAbstractItemDelegate* delegate);
70  QAbstractItemDelegate* delegate() const;
71 
72  virtual bool acceptsDelegate(QAbstractItemDelegate*) const { return true; }
73 
74 Q_SIGNALS:
75 
76  void update(const QModelIndex& index);
77 
78  void requestNotification(const QModelIndex& index, const QString& message);
80 
81 protected Q_SLOTS:
82 
87  virtual void visualChange();
88 
89 protected:
90 
97  bool affectsMultiple(const QModelIndex& index) const;
98  QList<QModelIndex> affectedIndexes(const QModelIndex& index) const;
99  int numberOfAffectedIndexes(const QModelIndex& index) const;
100 
104  bool viewHasMultiSelection() const;
105 
106 protected:
107 
108  QAbstractItemView* m_view;
109  QAbstractItemDelegate* m_delegate;
110 };
111 
112 #define REQUIRE_DELEGATE(Delegate) \
113  \
114 public: \
115  \
116  void setDelegate(Delegate* delegate) { ItemDelegateOverlay::setDelegate(delegate); } \
117  Delegate* delegate() const { return static_cast<Delegate*>(ItemDelegateOverlay::delegate()); } \
118  virtual bool acceptsDelegate(QAbstractItemDelegate*d) const override { return dynamic_cast<Delegate*>(d); } \
119  \
120 private:
121 
122 // -------------------------------------------------------------------------------------------
123 
125 {
126  Q_OBJECT
127 
128 public:
129 
136  explicit AbstractWidgetDelegateOverlay(QObject* const parent);
137 
144  void setActive(bool active) override;
145 
146 protected:
147 
152  virtual QWidget* createWidget() = 0;
153 
158  virtual void hide();
159 
163  QWidget* parentWidget() const;
164 
169  virtual bool checkIndex(const QModelIndex& index) const;
170 
175  virtual void viewportLeaveEvent(QObject* obj, QEvent* event);
176 
181  virtual void widgetEnterEvent();
182  virtual void widgetLeaveEvent();
183 
187  void widgetEnterNotifyMultiple(const QModelIndex& index);
188  void widgetLeaveNotifyMultiple();
189  virtual QString notifyMultipleMessage(const QModelIndex&, int number);
190 
194  bool checkIndexOnEnter(const QModelIndex& index) const;
195 
196 protected Q_SLOTS:
197 
201  virtual void slotEntered(const QModelIndex& index);
202 
206  virtual void slotReset();
207  virtual void slotViewportEntered();
208  virtual void slotRowsRemoved(const QModelIndex& parent, int start, int end);
209  virtual void slotLayoutChanged();
210 
211 protected:
212 
213  bool eventFilter(QObject* obj, QEvent* event) override;
214 
215 protected:
216 
217  QWidget* m_widget;
218 
220 };
221 
222 // -------------------------------------------------------------------------------------------
223 
225 {
226  Q_OBJECT
227 
228 public:
229 
230  explicit HoverButtonDelegateOverlay(QObject* const parent);
231 
235  void setActive(bool active) override;
236 
237  ItemViewHoverButton* button() const;
238 
239 protected:
240 
245 
250  virtual void updateButton(const QModelIndex& index) = 0;
251 
252  QWidget* createWidget() override;
253  void visualChange() override;
254 
255 protected Q_SLOTS:
256 
257  void slotEntered(const QModelIndex& index) override;
258  void slotReset() override;
259 };
260 
261 // -------------------------------------------------------------------------------------------
262 
264 {
265  Q_OBJECT
266 
274 public:
275 
276  explicit PersistentWidgetDelegateOverlay(QObject* const parent);
278 
279  void setActive(bool active) override;
280 
281  bool isPersistent() const;
282 
283 public Q_SLOTS:
284 
289  void setPersistent(bool persistent);
290  void enterPersistentMode();
291  void leavePersistentMode();
292 
293  void storeFocus();
294 
295 protected:
296 
297  QModelIndex index() const;
298 
305  void slotEntered(const QModelIndex& index) override;
306  void slotReset() override;
307  void slotViewportEntered() override;
308  void slotRowsRemoved(const QModelIndex& parent, int start, int end) override;
309  void slotLayoutChanged() override;
310  void viewportLeaveEvent(QObject* obj, QEvent* event) override;
311  void hide() override;
312 
317  virtual void setFocusOnWidget();
318 
320  virtual void showOnIndex(const QModelIndex& index);
321 
322  void restoreFocus();
323 
324 private:
325 
326  class Private;
327  Private* const d;
328 };
329 
330 // -------------------------------------------------------------------------------------------
331 
332 class DIGIKAM_EXPORT ItemDelegateOverlayContainer
333 {
334 public:
335 
343  virtual ~ItemDelegateOverlayContainer() = default;
344 
345  QList<ItemDelegateOverlay*> overlays() const;
346 
347  void installOverlay(ItemDelegateOverlay* overlay);
348  void removeOverlay(ItemDelegateOverlay* overlay);
349  void setAllOverlaysActive(bool active);
350  void setViewOnAllOverlays(QAbstractItemView* view);
351  void removeAllOverlays();
352  void mouseMoved(QMouseEvent* e, const QRect& visualRect, const QModelIndex& index);
353 
354 /*
356  void visualChange();
357  void requestNotification(const QModelIndex& index, const QString& message);
358  void hideNotification();
359 */
360 
361 protected:
362 
363  virtual void drawOverlays(QPainter* p, const QStyleOptionViewItem& option, const QModelIndex& index) const;
364 
366  virtual void overlayDestroyed(QObject* o);
367 
369  virtual QAbstractItemDelegate* asDelegate() = 0;
370 
371 protected:
372 
374 
375 private:
376 
377  Q_DISABLE_COPY(ItemDelegateOverlayContainer)
378 };
379 
380 } // namespace Digikam
381 
382 #endif // DIGIKAM_ITEM_DELEGATE_OVERLAY_H
Definition: itemdelegateoverlay.h:125
QWidget * m_widget
Definition: itemdelegateoverlay.h:217
bool m_mouseButtonPressedOnWidget
Definition: itemdelegateoverlay.h:219
Definition: itemdelegateoverlay.h:225
virtual ItemViewHoverButton * createButton()=0
virtual void updateButton(const QModelIndex &index)=0
Definition: itemdelegateoverlay.h:333
virtual QAbstractItemDelegate * asDelegate()=0
Returns the delegate, typically, the derived class.
QList< ItemDelegateOverlay * > m_overlays
Definition: itemdelegateoverlay.h:373
virtual ~ItemDelegateOverlayContainer()=default
Definition: itemdelegateoverlay.h:41
QAbstractItemView * m_view
Definition: itemdelegateoverlay.h:108
virtual bool acceptsDelegate(QAbstractItemDelegate *) const
Definition: itemdelegateoverlay.h:72
void update(const QModelIndex &index)
void requestNotification(const QModelIndex &index, const QString &message)
QAbstractItemDelegate * m_delegate
Definition: itemdelegateoverlay.h:109
Definition: itemviewhoverbutton.h:42
Definition: itemdelegateoverlay.h:264
Definition: datefolderview.cpp:43