~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to digikam/imagedelegateoverlay.h

  • Committer: Bazaar Package Importer
  • Author(s): Christian Mangold
  • Date: 2010-04-09 21:30:01 UTC
  • mfrom: (1.2.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100409213001-4bfyibrd359rn7o3
Tags: 2:1.2.0-0ubuntu1
* New upstream release (LP: #560576)
* Remove all patches, fixed upstream
  - Remove quilt build-depend

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ============================================================
2
 
 *
3
 
 * This file is a part of digiKam project
4
 
 * http://www.digikam.org
5
 
 *
6
 
 * Date        : 2009-04-29
7
 
 * Description : Qt item view for images - delegate additions
8
 
 *
9
 
 * Copyright (C) 2009 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 IMAGEDELEGATEOVERLAY_H
25
 
#define IMAGEDELEGATEOVERLAY_H
26
 
 
27
 
// Qt includes
28
 
 
29
 
#include <QAbstractItemView>
30
 
 
31
 
namespace Digikam
32
 
{
33
 
 
34
 
class ImageCategorizedView;
35
 
class ImageDelegate;
36
 
class ItemViewHoverButton;
37
 
 
38
 
class ImageDelegateOverlay : public QObject
39
 
{
40
 
    Q_OBJECT
41
 
 
42
 
public:
43
 
 
44
 
    ImageDelegateOverlay(QObject *parent = 0);
45
 
    ~ImageDelegateOverlay();
46
 
 
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);
52
 
 
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);
59
 
 
60
 
    void setView(ImageCategorizedView *view);
61
 
    ImageCategorizedView *view() const;
62
 
    void setDelegate(ImageDelegate *delegate);
63
 
    ImageDelegate *delegate() const;
64
 
 
65
 
Q_SIGNALS:
66
 
 
67
 
    void update(const QModelIndex& index);
68
 
 
69
 
protected Q_SLOTS:
70
 
 
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();
74
 
 
75
 
protected:
76
 
 
77
 
    ImageCategorizedView *m_view;
78
 
    ImageDelegate        *m_delegate;
79
 
};
80
 
 
81
 
// -------------------------------------------------------------------------------------------
82
 
 
83
 
class AbstractWidgetDelegateOverlay : public ImageDelegateOverlay
84
 
{
85
 
    Q_OBJECT
86
 
 
87
 
public:
88
 
 
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);
94
 
 
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);
100
 
 
101
 
protected:
102
 
 
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. */
108
 
    virtual void hide();
109
 
 
110
 
    /// Returns the widget to be used as parent for your widget created in createWidget()
111
 
    QWidget *parentWidget() const;
112
 
 
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;
116
 
 
117
 
protected Q_SLOTS:
118
 
 
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();
126
 
 
127
 
protected:
128
 
 
129
 
    bool eventFilter(QObject* obj, QEvent* event);
130
 
 
131
 
    QWidget *m_widget;
132
 
 
133
 
    bool m_mouseButtonPressedOnWidget;
134
 
};
135
 
 
136
 
class HoverButtonDelegateOverlay : public AbstractWidgetDelegateOverlay
137
 
{
138
 
    Q_OBJECT
139
 
 
140
 
public:
141
 
 
142
 
    HoverButtonDelegateOverlay(QObject *parent);
143
 
 
144
 
    /** Will call createButton(). */
145
 
    virtual void setActive(bool active);
146
 
 
147
 
    ItemViewHoverButton *button() const;
148
 
 
149
 
protected:
150
 
 
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;
156
 
 
157
 
    virtual QWidget *createWidget();
158
 
    virtual void visualChange();
159
 
 
160
 
 
161
 
protected Q_SLOTS:
162
 
 
163
 
    virtual void slotEntered(const QModelIndex& index);
164
 
    virtual void slotReset();
165
 
 
166
 
};
167
 
 
168
 
} // namespace Digikam
169
 
 
170
 
#endif /* IMAGEDELEGATEOVERLAY_H */