1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : Albums folder view.
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>
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)
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.
25
* ============================================================ */
27
#include "albumselectiontreeview.moc"
32
#include <qsortfilterproxymodel.h>
37
#include <kiconloader.h>
41
#include "albummanager.h"
42
#include "contextmenuhelper.h"
43
#include "itemviewtooltip.h"
44
#include "tooltipfiller.h"
49
class AlbumViewToolTip: public ItemViewToolTip
52
AlbumViewToolTip(AlbumSelectionTreeView *view) :
57
AlbumSelectionTreeView *view() const
59
return static_cast<AlbumSelectionTreeView*>(ItemViewToolTip::view());
64
virtual QString tipContents()
66
PAlbum *album = view()->albumForIndex(currentIndex());
67
return ToolTipFiller::albumTipContents(album,
68
view()->albumModel()->albumCount(album));
73
class AlbumSelectionTreeViewPriv
77
AlbumSelectionTreeViewPriv() :
78
albumModificationHelper(0),
79
enableToolTips(false),
87
AlbumModificationHelper *albumModificationHelper;
89
AlbumViewToolTip *toolTip;
91
QAction *renameAction;
92
QAction *resetIconAction;
93
QAction *findDuplAction;
97
AlbumSelectionTreeView::AlbumSelectionTreeView(QWidget *parent, AlbumModel *model,
98
AlbumModificationHelper *albumModificationHelper) :
99
AlbumTreeView(model, parent), d(new AlbumSelectionTreeViewPriv)
102
d->albumModificationHelper = albumModificationHelper;
104
d->toolTip = new AlbumViewToolTip(this);
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);
110
setSortingEnabled(true);
111
setSelectAlbumOnClick(true);
112
setEnableContextMenu(true);
116
AlbumSelectionTreeView::~AlbumSelectionTreeView()
121
void AlbumSelectionTreeView::setEnableToolTips(bool enable)
123
d->enableToolTips = enable;
126
QString AlbumSelectionTreeView::contextMenuTitle() const
128
return i18n("My Albums");
131
void AlbumSelectionTreeView::addCustomContextMenuActions(ContextMenuHelper &cmh, Album *a)
134
PAlbum *album = dynamic_cast<PAlbum*> (a);
140
d->renameAction->setEnabled(!album->isAlbumRoot());
142
// --------------------------------------------------------
144
cmh.addAction("album_new");
145
cmh.addAction(d->renameAction);
146
cmh.addAction(d->resetIconAction);
147
cmh.addAction("album_openinkonqui");
149
// --------------------------------------------------------
150
cmh.addAction(d->findDuplAction);
154
cmh.addAlbumActions();
156
// --------------------------------------------------------
157
cmh.addAction("album_delete");
159
// --------------------------------------------------------
160
cmh.addAction("album_propsEdit");
164
void AlbumSelectionTreeView::handleCustomContextMenuAction(QAction *action, AlbumPointer<Album> a)
168
PAlbum *album = dynamic_cast<PAlbum*> (alb);
170
if (!action || !album)
175
if (action == d->resetIconAction)
178
AlbumManager::instance()->updatePAlbumIcon(album, 0, err);
180
else if (action == d->renameAction)
182
d->albumModificationHelper->slotAlbumRename(album);
184
else if (action == d->findDuplAction)
186
kDebug() << "emitting signal for finding duplicates";
187
emit signalFindDuplicatesInAlbum(album);
192
bool AlbumSelectionTreeView::viewportEvent(QEvent *event)
195
// let the base class handle the event if it is not a tool tip request
196
if (event->type() != QEvent::ToolTip)
198
return AlbumTreeView::viewportEvent(event);
201
// only show tool tips if requested
202
if (!d->enableToolTips)
207
// check that we got a correct event
208
QHelpEvent *helpEvent = dynamic_cast<QHelpEvent*> (event);
211
kError() << "Unable to determine the correct type of the event. "
212
<< "This should not happen.";
216
// find the item this tool tip belongs to
217
QModelIndex index = indexAt(helpEvent->pos());
218
if (!index.isValid())
223
PAlbum *album = albumForIndex(index);
224
if (!album || album->isRoot() || album->isAlbumRoot())
226
// there was no album so we really don't want to show a tooltip.
230
QRect itemRect = visualRect(index);
231
if (!itemRect.contains(helpEvent->pos()))
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);