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 ***************************************************************************/
20 #include "QApplication"
24 #include "projectitem.h"
25 #include "projectlistview.h"
28 ProjectListView::ProjectListView(QWidget *parent)
29 : QTreeWidget(parent), m_dragStarted(false) {
30 setSelectionMode(QAbstractItemView::ExtendedSelection);
31 setDragDropMode(QAbstractItemView::DragDrop);
32 setDropIndicatorShown(true);
33 setAlternatingRowColors(true);
38 ProjectListView::~ProjectListView() {
41 void ProjectListView::editItem(QTreeWidgetItem * item, int column) {
42 kDebug() << "//////////////// EDIT ITEM, COL: " << column;
46 void ProjectListView::contextMenuEvent(QContextMenuEvent * event) {
47 emit requestMenu(event->globalPos(), itemAt(event->pos()));
51 void ProjectListView::mouseDoubleClickEvent(QMouseEvent * event) {
52 ProjectItem *item = static_cast <ProjectItem *>(itemAt(event->pos()));
53 if (!item) emit addClip();
54 else if ((item->clipType() == FOLDER && columnAt(event->pos().x()) == 1) || columnAt(event->pos().x()) == 2) QTreeWidget::mouseDoubleClickEvent(event);
58 void ProjectListView::dragEnterEvent(QDragEnterEvent *event) {
59 if (event->mimeData()->hasUrls() || event->mimeData()->hasText()) {
60 kDebug() << "//////////////// DRAG ENTR OK";
62 event->acceptProposedAction();
66 void ProjectListView::dropEvent(QDropEvent *event) {
67 kDebug() << "//////////////// DROPPED EVENT";
68 if (event->mimeData()->hasUrls()) {
69 QTreeWidgetItem *item = itemAt(event->pos());
72 if (((ProjectItem *) item)->isGroup()) groupName = item->text(1);
73 else if (item->parent() && ((ProjectItem *) item->parent())->isGroup())
74 groupName = item->parent()->text(1);
77 list = event->mimeData()->urls();
78 foreach(QUrl url, list) {
79 emit addClip(url, groupName);
82 } else if (event->mimeData()->hasFormat("kdenlive/producerslist")) {
83 ProjectItem *item = static_cast <ProjectItem *>(itemAt(event->pos()));
85 if (item->parent()) item = static_cast <ProjectItem *>(item->parent());
86 if (item->isGroup()) {
87 //emit addClip(event->mimeData->text());
88 kDebug() << "//////////////// DROPPED RIGHT 1 ";
89 QList <QTreeWidgetItem *> list;
90 list = selectedItems();
92 int parentId = item->clipId();
93 foreach(QTreeWidgetItem *it, list) {
94 // TODO allow dragging of folders ?
95 if (!((ProjectItem *) it)->isGroup() && ((ProjectItem *) it)->clipId() < 10000) {
96 if (it->parent()) clone = (ProjectItem*) it->parent()->takeChild(it->parent()->indexOfChild(it));
97 else clone = (ProjectItem*) takeTopLevelItem(indexOfTopLevelItem(it));
99 item->addChild(clone);
100 clone->setGroup(item->groupName(), QString::number(parentId));
107 kDebug() << "//////////////// DROPPED ONÂ EMPTY ZONE";
108 // item dropped in empty zone, move it to top level
109 QList <QTreeWidgetItem *> list;
110 list = selectedItems();
112 foreach(QTreeWidgetItem *it, list) {
113 QTreeWidgetItem *parent = it->parent();
114 if (parent && ((ProjectItem *) it)->clipId() < 10000) {
115 kDebug() << "++ item parent: " << parent->text(1);
116 clone = (ProjectItem*) parent->takeChild(parent->indexOfChild(it));
117 if (clone) addTopLevelItem(clone);
122 event->acceptProposedAction();
126 void ProjectListView::mousePressEvent(QMouseEvent *event) {
127 if (event->button() == Qt::LeftButton) {
128 this->m_DragStartPosition = event->pos();
129 m_dragStarted = true;
131 QTreeWidget::mousePressEvent(event);
136 void ProjectListView::mouseMoveEvent(QMouseEvent *event) {
137 kDebug() << "// DRAG STARTED, MOUSE MOVED: ";
138 if (!m_dragStarted) return;
140 if ((event->pos() - m_DragStartPosition).manhattanLength()
141 < QApplication::startDragDistance())
145 ProjectItem *clickItem = (ProjectItem *) itemAt(event->pos());
147 QDrag *drag = new QDrag(this);
148 QMimeData *mimeData = new QMimeData;
150 QList <QTreeWidgetItem *> list;
151 list = selectedItems();
153 foreach(QTreeWidgetItem *item, list) {
154 // TODO allow dragging of folders
155 ids.append(QString::number(((ProjectItem *) item)->clipId()));
158 data.append(ids.join(";").toUtf8()); //doc.toString().toUtf8());
159 mimeData->setData("kdenlive/producerslist", data);
160 //mimeData->setText(ids.join(";")); //doc.toString());
161 //mimeData->setImageData(image);
162 drag->setMimeData(mimeData);
163 drag->setPixmap(clickItem->icon(0).pixmap((int)(50 *16 / 9.0), 50));
164 drag->setHotSpot(QPoint(0, 50));
165 drag->start(Qt::MoveAction);
167 //Qt::DropAction dropAction;
168 //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
170 //Qt::DropAction dropAction = drag->exec();
177 void ProjectListView::dragMoveEvent(QDragMoveEvent * event) {
178 QTreeWidgetItem * item = itemAt(event->pos());
179 event->setDropAction(Qt::IgnoreAction);
181 event->setDropAction(Qt::MoveAction);
182 if (event->mimeData()->hasText()) {
183 event->acceptProposedAction();
188 QStringList ProjectListView::mimeTypes() const {
189 QStringList qstrList;
190 qstrList << QTreeWidget::mimeTypes();
191 // list of accepted mime types for drop
192 qstrList.append("text/uri-list");
193 qstrList.append("text/plain");
194 qstrList.append("kdenlive/producerslist");
199 Qt::DropActions ProjectListView::supportedDropActions() const {
200 // returns what actions are supported when dropping
201 return Qt::MoveAction;
204 #include "projectlistview.moc"