1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : A widget to display a list of camera folders.
9
* Copyright (C) 2003-2005 by Renchi Raju <renchi@pooh.tam.uiuc.edu>
10
* Copyright (C) 2006-2011 by Gilles Caulier <caulier dot gilles at gmail dot com>
12
* This program is free software; you can redistribute it
13
* and/or modify it under the terms of the GNU General
14
* Public License as published by the Free Software Foundation;
15
* either version 2, or (at your option)
18
* This program is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
23
* ============================================================ */
25
#include "camerafolderview.moc"
29
#include <kiconloader.h>
35
#include "camerafolderitem.h"
40
class CameraFolderView::CameraFolderViewPriv
44
CameraFolderViewPriv() :
53
CameraFolderItem* virtualFolder;
54
CameraFolderItem* rootFolder;
57
CameraFolderView::CameraFolderView(QWidget* parent)
58
: QTreeWidget(parent), d(new CameraFolderViewPriv)
61
setRootIsDecorated(false);
62
setSelectionMode(QAbstractItemView::SingleSelection);
63
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
64
setAllColumnsShowFocus(true);
65
setDragEnabled(false);
66
setDropIndicatorShown(false);
67
setAcceptDrops(false);
68
setHeaderLabels(QStringList() << i18n("Camera Folders"));
70
connect(this, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
71
this, SLOT(slotCurrentChanged(QTreeWidgetItem*,int)));
73
connect(this, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
74
this, SLOT(slotCurrentChanged(QTreeWidgetItem*,int)));
77
CameraFolderView::~CameraFolderView()
82
void CameraFolderView::addVirtualFolder(const QString& name, const QPixmap& pixmap)
85
d->virtualFolder = new CameraFolderItem(this, d->cameraName, pixmap);
86
d->virtualFolder->setExpanded(true);
87
d->virtualFolder->setSelected(false);
88
// item is not selectable.
89
d->virtualFolder->setFlags(d->virtualFolder->flags() & (int)!Qt::ItemIsSelectable);
90
d->virtualFolder->setDisabled(false);
93
void CameraFolderView::addRootFolder(const QString& folder, int nbItems, const QPixmap& pixmap)
95
d->rootFolder = new CameraFolderItem(d->virtualFolder, folder, folder, pixmap);
96
d->rootFolder->setExpanded(true);
100
d->rootFolder->setCount(nbItems);
104
CameraFolderItem* CameraFolderView::addFolder(const QString& folder, const QString& subFolder,
105
int nbItems, const QPixmap& pixmap)
107
CameraFolderItem* parentItem = findFolder(folder);
109
kDebug() << "Adding Subfolder " << subFolder
110
<< " of folder " << folder;
114
QString path(folder);
116
if (!folder.endsWith('/'))
122
CameraFolderItem* item = new CameraFolderItem(parentItem, subFolder, path, pixmap);
124
kDebug() << "Added ViewItem with path "
125
<< item->folderPath();
127
item->setCount(nbItems);
128
item->setExpanded(true);
133
kWarning() << "Could not find parent for subFolder "
134
<< subFolder << " of folder " << folder;
139
CameraFolderItem* CameraFolderView::findFolder(const QString& folderPath)
141
QTreeWidgetItemIterator it(this);
145
CameraFolderItem* lvItem = dynamic_cast<CameraFolderItem*>(*it);
147
if (lvItem && lvItem->folderPath() == folderPath)
158
void CameraFolderView::slotCurrentChanged(QTreeWidgetItem* item, int)
162
emit signalFolderChanged(0);
166
emit signalFolderChanged(dynamic_cast<CameraFolderItem*>(item));
170
CameraFolderItem* CameraFolderView::virtualFolder() const
172
return d->virtualFolder;
175
CameraFolderItem* CameraFolderView::rootFolder() const
177
return d->rootFolder;
180
void CameraFolderView::clear()
182
QTreeWidget::clear();
183
d->virtualFolder = 0;
185
emit signalCleared();
188
} // namespace Digikam