1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include "projectlistview.h"
22 #include "projectitem.h"
23 #include "kdenlivesettings.h"
29 #include <QApplication>
30 #include <QHeaderView>
33 ProjectListView::ProjectListView(QWidget *parent) :
37 setSelectionMode(QAbstractItemView::ExtendedSelection);
38 setDragDropMode(QAbstractItemView::DragDrop);
39 setDropIndicatorShown(true);
40 setAlternatingRowColors(true);
46 headers << i18n("Thumbnail") << i18n("Filename") << i18n("Description") << i18n("Rating");
47 setHeaderLabels(headers);
48 sortByColumn(1, Qt::AscendingOrder);
50 QHeaderView* headerView = header();
51 headerView->setContextMenuPolicy(Qt::CustomContextMenu);
52 connect(headerView, SIGNAL(customContextMenuRequested(const QPoint&)),
53 this, SLOT(configureColumns(const QPoint&)));
55 //connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(slotFocusOut(QTreeWidgetItem *, QTreeWidgetItem *)));
57 if (!KdenliveSettings::showdescriptioncolumn()) hideColumn(2);
58 if (!KdenliveSettings::showratingcolumn()) hideColumn(3);
60 setSortingEnabled(true);
63 ProjectListView::~ProjectListView()
68 void ProjectListView::configureColumns(const QPoint& pos)
71 popup.addTitle(i18nc("@title:menu", "Columns"));
73 QHeaderView* headerView = header();
74 for (int i = 2; i < headerView->count(); ++i) {
75 const QString text = model()->headerData(i, Qt::Horizontal).toString();
76 QAction* action = popup.addAction(text);
77 action->setCheckable(true);
78 action->setChecked(!headerView->isSectionHidden(i));
82 QAction* activatedAction = popup.exec(header()->mapToGlobal(pos));
83 if (activatedAction != 0) {
84 const bool show = activatedAction->isChecked();
86 // remember the changed column visibility in the settings
87 const int columnIndex = activatedAction->data().toInt();
88 switch (columnIndex) {
90 KdenliveSettings::setShowdescriptioncolumn(show);
93 KdenliveSettings::setShowratingcolumn(show);
99 // apply the changed column visibility
101 showColumn(columnIndex);
103 hideColumn(columnIndex);
109 void ProjectListView::contextMenuEvent(QContextMenuEvent * event)
111 emit requestMenu(event->globalPos(), itemAt(event->pos()));
115 void ProjectListView::mouseDoubleClickEvent(QMouseEvent * event)
117 ProjectItem *item = static_cast <ProjectItem *>(itemAt(event->pos()));
122 if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
123 if (item->isGroup()) {
124 if ((columnAt(event->pos().x()) == 1)) QTreeWidget::mouseDoubleClickEvent(event);
126 if ((columnAt(event->pos().x()) == 1) && (item->clipType() == SLIDESHOW || item->clipType() == TEXT || item->clipType() == COLOR)) QTreeWidget::mouseDoubleClickEvent(event);
127 else if ((columnAt(event->pos().x()) == 2)) QTreeWidget::mouseDoubleClickEvent(event);
128 else emit showProperties(item->referencedClip());
133 void ProjectListView::dragEnterEvent(QDragEnterEvent *event)
135 if (event->mimeData()->hasUrls() || event->mimeData()->hasText()) {
136 kDebug() << "//////////////// DRAG ENTR OK";
138 event->acceptProposedAction();
142 void ProjectListView::dropEvent(QDropEvent *event)
144 kDebug() << "//////////////// DROPPED EVENT";
145 if (event->mimeData()->hasUrls()) {
146 ProjectItem *item = static_cast <ProjectItem *>(itemAt(event->pos()));
150 if (item->parent()) item = static_cast <ProjectItem *>(item->parent());
151 if (item->isGroup()) {
152 groupName = item->groupName();
153 groupId = item->clipId();
156 emit addClip(event->mimeData()->urls(), groupName, groupId);
157 } else if (event->mimeData()->hasFormat("kdenlive/producerslist")) {
158 ProjectItem *item = static_cast <ProjectItem *>(itemAt(event->pos()));
160 if (item->parent()) item = static_cast <ProjectItem *>(item->parent());
161 if (item->isGroup()) {
162 //emit addClip(event->mimeData->text());
163 kDebug() << "//////////////// DROPPED RIGHT 1 ";
164 const QList <QTreeWidgetItem *> list = selectedItems();
166 QString parentId = item->clipId();
167 foreach(QTreeWidgetItem *it, list) {
168 // TODO allow dragging of folders ?
169 if (!((ProjectItem *) it)->isGroup()/* && ((ProjectItem *) it)->clipId() < 10000*/) {
170 if (it->parent()) clone = (ProjectItem*) it->parent()->takeChild(it->parent()->indexOfChild(it));
171 else clone = (ProjectItem*) takeTopLevelItem(indexOfTopLevelItem(it));
173 item->addChild(clone);
174 QMap <QString, QString> props;
175 props.insert("groupname", item->groupName());
176 props.insert("groupid", parentId);
177 clone->setProperties(props);
184 kDebug() << "//////////////// DROPPED ONÂ EMPTY ZONE";
185 // item dropped in empty zone, move it to top level
186 const QList <QTreeWidgetItem *> list = selectedItems();
188 foreach(QTreeWidgetItem *it, list) {
189 QTreeWidgetItem *parent = it->parent();
190 if (parent/* && ((ProjectItem *) it)->clipId() < 10000*/) {
191 kDebug() << "++ item parent: " << parent->text(1);
192 clone = static_cast <ProjectItem*>(parent->takeChild(parent->indexOfChild(it)));
194 addTopLevelItem(clone);
195 clone->clearProperty("groupname");
196 clone->clearProperty("groupid");
202 event->acceptProposedAction();
206 void ProjectListView::mousePressEvent(QMouseEvent *event)
208 if (event->button() == Qt::LeftButton) {
209 m_DragStartPosition = event->pos();
210 m_dragStarted = true;
211 /*QTreeWidgetItem *underMouse = itemAt(event->pos());
212 if (underMouse && underMouse->isSelected()) emit focusMonitor();*/
214 QTreeWidget::mousePressEvent(event);
218 void ProjectListView::mouseReleaseEvent(QMouseEvent *event)
220 QTreeWidget::mouseReleaseEvent(event);
225 void ProjectListView::mouseMoveEvent(QMouseEvent *event)
227 //kDebug() << "// DRAG STARTED, MOUSE MOVED: ";
228 if (!m_dragStarted) return;
230 if ((event->pos() - m_DragStartPosition).manhattanLength()
231 < QApplication::startDragDistance())
235 ProjectItem *clickItem = static_cast <ProjectItem *>(itemAt(m_DragStartPosition));
236 if (clickItem && (clickItem->flags() & Qt::ItemIsDragEnabled)) {
237 QDrag *drag = new QDrag(this);
238 QMimeData *mimeData = new QMimeData;
239 const QList <QTreeWidgetItem *> list = selectedItems();
241 foreach(const QTreeWidgetItem *item, list) {
242 const ProjectItem *clip = static_cast <const ProjectItem *>(item);
243 if (!clip->isGroup()) ids.append(clip->clipId());
245 const int children = item->childCount();
246 for (int i = 0; i < children; i++) {
247 ids.append(static_cast <ProjectItem *>(item->child(i))->clipId());
251 if (ids.isEmpty()) return;
253 data.append(ids.join(";").toUtf8()); //doc.toString().toUtf8());
254 mimeData->setData("kdenlive/producerslist", data);
255 //mimeData->setText(ids.join(";")); //doc.toString());
256 //mimeData->setImageData(image);
257 drag->setMimeData(mimeData);
258 drag->setPixmap(clickItem->icon(0).pixmap(iconSize()));
259 drag->setHotSpot(QPoint(0, 50));
260 drag->exec(Qt::MoveAction);
267 void ProjectListView::dragMoveEvent(QDragMoveEvent * event)
269 event->setDropAction(Qt::IgnoreAction);
270 event->setDropAction(Qt::MoveAction);
271 if (event->mimeData()->hasText()) {
272 event->acceptProposedAction();
274 // stop playing because we get a crash otherwise when fetching the thumbnails
278 QStringList ProjectListView::mimeTypes() const
280 QStringList qstrList;
281 qstrList << QTreeWidget::mimeTypes();
282 // list of accepted mime types for drop
283 qstrList.append("text/uri-list");
284 qstrList.append("text/plain");
285 qstrList.append("kdenlive/producerslist");
290 Qt::DropActions ProjectListView::supportedDropActions() const
292 // returns what actions are supported when dropping
293 return Qt::MoveAction;
296 #include "projectlistview.moc"