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

« back to all changes in this revision

Viewing changes to digikam/albumselectiontreeview.cpp

  • 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        : 2005-05-06
 
7
 * Description : Albums folder view.
 
8
 *
 
9
 * Copyright (C) 2005-2006 by Joern Ahrens <joern dot ahrens at kdemail dot net>
 
10
 * Copyright (C) 2006-2009 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
11
 * Copyright (C) 2009 by Andi Clemens <andi dot clemens at gmx dot net>
 
12
 * Copyright (C) 2009 by Johannes Wienke <languitar at semipol dot de>
 
13
 *
 
14
 * This program is free software; you can redistribute it
 
15
 * and/or modify it under the terms of the GNU General
 
16
 * Public License as published by the Free Software Foundation;
 
17
 * either version 2, or (at your option)
 
18
 * any later version.
 
19
 *
 
20
 * This program is distributed in the hope that it will be useful,
 
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
23
 * GNU General Public License for more details.
 
24
 *
 
25
 * ============================================================ */
 
26
 
 
27
#include "albumselectiontreeview.moc"
 
28
 
 
29
// QT includes
 
30
#include <qaction.h>
 
31
#include <qevent.h>
 
32
#include <qsortfilterproxymodel.h>
 
33
#include <qtooltip.h>
 
34
 
 
35
// KDE includes
 
36
#include <kdebug.h>
 
37
#include <kiconloader.h>
 
38
#include <kmenu.h>
 
39
 
 
40
// Local includes
 
41
#include "albummanager.h"
 
42
#include "contextmenuhelper.h"
 
43
#include "itemviewtooltip.h"
 
44
#include "tooltipfiller.h"
 
45
 
 
46
namespace Digikam
 
47
{
 
48
 
 
49
class AlbumViewToolTip: public ItemViewToolTip
 
50
{
 
51
public:
 
52
    AlbumViewToolTip(AlbumSelectionTreeView *view) :
 
53
        ItemViewToolTip(view)
 
54
    {
 
55
    }
 
56
 
 
57
    AlbumSelectionTreeView *view() const
 
58
    {
 
59
        return static_cast<AlbumSelectionTreeView*>(ItemViewToolTip::view());
 
60
    }
 
61
 
 
62
protected:
 
63
 
 
64
    virtual QString tipContents()
 
65
    {
 
66
        PAlbum *album = view()->albumForIndex(currentIndex());
 
67
        return ToolTipFiller::albumTipContents(album,
 
68
                        view()->albumModel()->albumCount(album));
 
69
    }
 
70
 
 
71
};
 
72
 
 
73
class AlbumSelectionTreeViewPriv
 
74
{
 
75
 
 
76
public:
 
77
    AlbumSelectionTreeViewPriv() :
 
78
        albumModificationHelper(0),
 
79
        enableToolTips(false),
 
80
        toolTip(0),
 
81
        renameAction(0),
 
82
        resetIconAction(0),
 
83
        findDuplAction(0)
 
84
    {
 
85
    }
 
86
 
 
87
    AlbumModificationHelper *albumModificationHelper;
 
88
    bool enableToolTips;
 
89
    AlbumViewToolTip *toolTip;
 
90
 
 
91
    QAction *renameAction;
 
92
    QAction *resetIconAction;
 
93
    QAction *findDuplAction;
 
94
 
 
95
};
 
96
 
 
97
AlbumSelectionTreeView::AlbumSelectionTreeView(QWidget *parent, AlbumModel *model,
 
98
                AlbumModificationHelper *albumModificationHelper) :
 
99
    AlbumTreeView(model, parent), d(new AlbumSelectionTreeViewPriv)
 
100
{
 
101
 
 
102
    d->albumModificationHelper = albumModificationHelper;
 
103
 
 
104
    d->toolTip = new AlbumViewToolTip(this);
 
105
 
 
106
    d->renameAction    = new QAction(SmallIcon("edit-rename"), i18n("Rename..."), this);
 
107
    d->resetIconAction = new QAction(SmallIcon("view-refresh"), i18n("Reset Album Icon"), this);
 
108
    d->findDuplAction  = new QAction(SmallIcon("tools-wizard"), i18n("Find Duplicates..."), this);
 
109
 
 
110
    setSortingEnabled(true);
 
111
    setSelectAlbumOnClick(true);
 
112
    setEnableContextMenu(true);
 
113
 
 
114
}
 
115
 
 
116
AlbumSelectionTreeView::~AlbumSelectionTreeView()
 
117
{
 
118
    delete d;
 
119
}
 
120
 
 
121
void AlbumSelectionTreeView::setEnableToolTips(bool enable)
 
122
{
 
123
    d->enableToolTips = enable;
 
124
}
 
125
 
 
126
QString AlbumSelectionTreeView::contextMenuTitle() const
 
127
{
 
128
    return i18n("My Albums");
 
129
}
 
130
 
 
131
void AlbumSelectionTreeView::addCustomContextMenuActions(ContextMenuHelper &cmh, Album *a)
 
132
{
 
133
 
 
134
    PAlbum *album = dynamic_cast<PAlbum*> (a);
 
135
    if (!a)
 
136
    {
 
137
        return;
 
138
    }
 
139
 
 
140
    d->renameAction->setEnabled(!album->isAlbumRoot());
 
141
 
 
142
    // --------------------------------------------------------
 
143
 
 
144
    cmh.addAction("album_new");
 
145
    cmh.addAction(d->renameAction);
 
146
    cmh.addAction(d->resetIconAction);
 
147
    cmh.addAction("album_openinkonqui");
 
148
    cmh.addSeparator();
 
149
    // --------------------------------------------------------
 
150
    cmh.addAction(d->findDuplAction);
 
151
    cmh.addImportMenu();
 
152
    cmh.addExportMenu();
 
153
    cmh.addBatchMenu();
 
154
    cmh.addAlbumActions();
 
155
    cmh.addSeparator();
 
156
    // --------------------------------------------------------
 
157
    cmh.addAction("album_delete");
 
158
    cmh.addSeparator();
 
159
    // --------------------------------------------------------
 
160
    cmh.addAction("album_propsEdit");
 
161
 
 
162
}
 
163
 
 
164
void AlbumSelectionTreeView::handleCustomContextMenuAction(QAction *action, AlbumPointer<Album> a)
 
165
{
 
166
 
 
167
    Album *alb = a;
 
168
    PAlbum *album = dynamic_cast<PAlbum*> (alb);
 
169
 
 
170
    if (!action || !album)
 
171
    {
 
172
        return;
 
173
    }
 
174
 
 
175
    if (action == d->resetIconAction)
 
176
    {
 
177
        QString err;
 
178
        AlbumManager::instance()->updatePAlbumIcon(album, 0, err);
 
179
    }
 
180
    else if (action == d->renameAction)
 
181
    {
 
182
        d->albumModificationHelper->slotAlbumRename(album);
 
183
    }
 
184
    else if (action == d->findDuplAction)
 
185
    {
 
186
        kDebug() << "emitting signal for finding duplicates";
 
187
        emit signalFindDuplicatesInAlbum(album);
 
188
    }
 
189
 
 
190
}
 
191
 
 
192
bool AlbumSelectionTreeView::viewportEvent(QEvent *event)
 
193
{
 
194
 
 
195
    // let the base class handle the event if it is not a tool tip request
 
196
    if (event->type() != QEvent::ToolTip)
 
197
    {
 
198
        return AlbumTreeView::viewportEvent(event);
 
199
    }
 
200
 
 
201
    // only show tool tips if requested
 
202
    if (!d->enableToolTips)
 
203
    {
 
204
        return false;
 
205
    }
 
206
 
 
207
    // check that we got a correct event
 
208
    QHelpEvent *helpEvent = dynamic_cast<QHelpEvent*> (event);
 
209
    if (!helpEvent)
 
210
    {
 
211
        kError() << "Unable to determine the correct type of the event. "
 
212
                 << "This should not happen.";
 
213
        return false;
 
214
    }
 
215
 
 
216
    // find the item this tool tip belongs to
 
217
    QModelIndex index = indexAt(helpEvent->pos());
 
218
    if (!index.isValid())
 
219
    {
 
220
        return true;
 
221
    }
 
222
 
 
223
    PAlbum *album = albumForIndex(index);
 
224
    if (!album || album->isRoot() || album->isAlbumRoot())
 
225
    {
 
226
        // there was no album so we really don't want to show a tooltip.
 
227
        return true;
 
228
    }
 
229
 
 
230
    QRect itemRect = visualRect(index);
 
231
    if (!itemRect.contains(helpEvent->pos()))
 
232
        return true;
 
233
    QStyleOptionViewItem option = viewOptions();
 
234
    option.rect = itemRect;
 
235
    // visualRect can be larger than viewport, intersect with viewport rect
 
236
    option.rect &= viewport()->rect();
 
237
    option.state |= (index == currentIndex() ? QStyle::State_HasFocus : QStyle::State_None);
 
238
    d->toolTip->show(helpEvent, option, index);
 
239
 
 
240
    return true;
 
241
 
 
242
}
 
243
 
 
244
}