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)
31 setSelectionMode(QAbstractItemView::ExtendedSelection);
32 setDragDropMode(QAbstractItemView::DragDrop);
33 setDropIndicatorShown(true);
38 ProjectListView::~ProjectListView()
43 void ProjectListView::contextMenuEvent ( QContextMenuEvent * event )
45 emit requestMenu(event->globalPos(), itemAt(event->pos()));
49 void ProjectListView::mouseDoubleClickEvent ( QMouseEvent * event )
51 if (!itemAt(event->pos())) emit addClip();
55 void ProjectListView::dragEnterEvent(QDragEnterEvent *event)
57 if (event->mimeData()->hasUrls() || event->mimeData()->hasText()) {
58 kDebug()<<"//////////////// DRAG ENTR OK";
60 event->acceptProposedAction();
64 void ProjectListView::dropEvent(QDropEvent *event)
66 kDebug()<<"//////////////// DROPPED EVENT";
67 if (event->mimeData()->hasUrls()) {
68 QTreeWidgetItem *item = itemAt(event->pos());
71 if (((ProjectItem *) item)->isGroup()) groupName = item->text(1);
72 else if (item->parent() && ((ProjectItem *) item->parent())->isGroup())
73 groupName = item->parent()->text(1);
76 list = event->mimeData()->urls();
77 foreach (QUrl url, list) {
78 emit addClip(url, groupName);
82 else if (event->mimeData()->hasText())
84 QTreeWidgetItem *item = itemAt(event->pos());
86 if (item->parent()) item = item->parent();
87 if (((ProjectItem *) item)->isGroup()) {
88 //emit addClip(event->mimeData->text());
89 kDebug()<<"//////////////// DROPPED RIGHT 1 ";
90 QList <QTreeWidgetItem *> list;
91 list = selectedItems ();
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));
98 if (clone) item->addChild(clone);
105 kDebug()<<"//////////////// DROPPED ONÂ EMPTY ZONE";
106 // item dropped in empty zone, move it to top level
107 QList <QTreeWidgetItem *> list;
108 list = selectedItems();
110 foreach (QTreeWidgetItem *it, list) {
111 QTreeWidgetItem *parent = it->parent();
112 if (parent && ((ProjectItem *) it)->clipId() < 10000) {
113 kDebug()<<"++ item parent: "<<parent->text(1);
114 clone = (ProjectItem* ) parent->takeChild(parent->indexOfChild(it));
115 if (clone) addTopLevelItem(clone);
120 event->acceptProposedAction();
124 void ProjectListView::mousePressEvent(QMouseEvent *event)
126 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)
138 kDebug()<<"// DRAG STARTED, MOUSE MOVED: ";
139 if (!m_dragStarted) return;
141 if ((event->pos() - m_DragStartPosition).manhattanLength()
142 < QApplication::startDragDistance())
146 ProjectItem *clickItem = (ProjectItem *) itemAt(event->pos());
148 QDrag *drag = new QDrag(this);
149 QMimeData *mimeData = new QMimeData;
151 QList <QTreeWidgetItem *> list;
152 list = selectedItems ();
153 foreach (QTreeWidgetItem *item, list) {
154 // TODO allow dragging of folders
155 if (!((ProjectItem *) item)->isGroup())
156 doc.appendChild(doc.importNode(((ProjectItem *) item)->toXml(), true));
159 //data.append(doc.toString().toUtf8());
160 //mimeData->setData("kdenlive/westley",data );
161 mimeData->setText(doc.toString());
162 //mimeData->setImageData(image);
163 drag->setMimeData(mimeData);
164 drag->setPixmap(clickItem->icon(0).pixmap(50 *16/9.0, 50));
165 drag->setHotSpot(QPoint(0, 50));
166 drag->start(Qt::MoveAction);
168 //Qt::DropAction dropAction;
169 //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
171 //Qt::DropAction dropAction = drag->exec();
178 void ProjectListView::dragMoveEvent(QDragMoveEvent * event) {
179 QTreeWidgetItem * item = itemAt(event->pos());
180 event->setDropAction(Qt::IgnoreAction);
182 event->setDropAction(Qt::MoveAction);
183 if (event->mimeData()->hasText()) {
184 event->acceptProposedAction();
189 QStringList ProjectListView::mimeTypes () const
191 QStringList qstrList;
192 // list of accepted mime types for drop
193 qstrList.append("text/uri-list");
194 qstrList.append("text/plain");
199 Qt::DropActions ProjectListView::supportedDropActions () const
201 // returns what actions are supported when dropping
202 return Qt::MoveAction;
205 #include "projectlistview.moc"