1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : Qt item view for images - delegate additions
9
* Copyright (C) 2009 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
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)
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.
22
* ============================================================ */
24
#ifndef IMAGEDELEGATEOVERLAY_H
25
#define IMAGEDELEGATEOVERLAY_H
29
#include <QAbstractItemView>
34
class ImageCategorizedView;
36
class ItemViewHoverButton;
38
class ImageDelegateOverlay : public QObject
44
ImageDelegateOverlay(QObject *parent = 0);
45
~ImageDelegateOverlay();
47
/** Called when the overlay was installed and shall begin working,
48
* and before it is removed and shall stop.
49
* Setup your connections to view and delegate here.
50
* You will be disconnected automatically on removal. */
51
virtual void setActive(bool active);
53
/** Only these two methods are implemented as virtual methods.
54
* For all other events, connect to the view's signals.
55
* There are a few signals specifically for overlays and all
56
* QAbstractItemView standard signals. */
57
virtual void mouseMoved(QMouseEvent *e, const QRect& visualRect, const QModelIndex& index);
58
virtual void paint(QPainter *p, const QStyleOptionViewItem& option, const QModelIndex& index);
60
void setView(ImageCategorizedView *view);
61
ImageCategorizedView *view() const;
62
void setDelegate(ImageDelegate *delegate);
63
ImageDelegate *delegate() const;
67
void update(const QModelIndex& index);
71
/** Called when any change from the delegate occurs - when the overlay is installed,
72
* when size hints, styles or fonts change */
73
virtual void visualChange();
77
ImageCategorizedView *m_view;
78
ImageDelegate *m_delegate;
81
// -------------------------------------------------------------------------------------------
83
class AbstractWidgetDelegateOverlay : public ImageDelegateOverlay
89
/** This class provides functionality for using a widget in an overlay.
90
* You must reimplement at least createWidget to return your widget.
91
* Per default it will be shown when the cursor enters an index and hidden when left.
92
* Reimplement slotEntered() and mouseMove() for more fine grained control. */
93
AbstractWidgetDelegateOverlay(QObject *parent);
95
/** If active is true, this will call createWidget(), initialize the widget for use,
96
* and setup connections for the virtual slots.
97
* If active is false, this will delete the widget and
98
* disconnect all signal from model and view to this object (!) */
99
virtual void setActive(bool active);
103
/** Create your widget here. When creating the object, pass parentWidget() as parent widget.
104
* Ownership of the object is passed. It will be deleted in setActive(false). */
105
virtual QWidget *createWidget() = 0;
106
/** Called when the widget shall be hidden (mouse cursor left index, viewport, uninstalled etc.).
107
* Default implementation hide()s m_widget. */
110
/// Returns the widget to be used as parent for your widget created in createWidget()
111
QWidget *parentWidget() const;
113
/** Return true here if you want to show the overlay for the given index.
114
* The default implementation returns true. */
115
virtual bool checkIndex(const QModelIndex& index) const;
119
/** Default implementation shows the widget iff the index is valid and checkIndex returns true. */
120
virtual void slotEntered(const QModelIndex& index);
121
/** Default implementations of these three slots call hide() */
122
virtual void slotReset();
123
virtual void slotViewportEntered();
124
virtual void slotRowsRemoved(const QModelIndex& parent, int start, int end);
125
virtual void slotLayoutChanged();
129
bool eventFilter(QObject* obj, QEvent* event);
133
bool m_mouseButtonPressedOnWidget;
136
class HoverButtonDelegateOverlay : public AbstractWidgetDelegateOverlay
142
HoverButtonDelegateOverlay(QObject *parent);
144
/** Will call createButton(). */
145
virtual void setActive(bool active);
147
ItemViewHoverButton *button() const;
151
/** Create your widget here. Pass view() as parent. */
152
virtual ItemViewHoverButton *createButton() = 0;
153
/** Called when a new index is entered. Reposition your button here,
154
* adjust and store state. */
155
virtual void updateButton(const QModelIndex& index) = 0;
157
virtual QWidget *createWidget();
158
virtual void visualChange();
163
virtual void slotEntered(const QModelIndex& index);
164
virtual void slotReset();
168
} // namespace Digikam
170
#endif /* IMAGEDELEGATEOVERLAY_H */