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()
42 void ProjectListView::editItem ( QTreeWidgetItem * item, int column )
44 kDebug()<<"//////////////// EDIT ITEM, COL: "<<column;
48 void ProjectListView::contextMenuEvent ( QContextMenuEvent * event )
50 emit requestMenu(event->globalPos(), itemAt(event->pos()));
54 void ProjectListView::mouseDoubleClickEvent ( QMouseEvent * event )
56 if (!itemAt(event->pos())) emit addClip();
57 else if (columnAt(event->pos().x()) == 2) QTreeWidget::mouseDoubleClickEvent( event );
61 void ProjectListView::dragEnterEvent(QDragEnterEvent *event)
63 if (event->mimeData()->hasUrls() || event->mimeData()->hasText()) {
64 kDebug()<<"//////////////// DRAG ENTR OK";
66 event->acceptProposedAction();
70 void ProjectListView::dropEvent(QDropEvent *event)
72 kDebug()<<"//////////////// DROPPED EVENT";
73 if (event->mimeData()->hasUrls()) {
74 QTreeWidgetItem *item = itemAt(event->pos());
77 if (((ProjectItem *) item)->isGroup()) groupName = item->text(1);
78 else if (item->parent() && ((ProjectItem *) item->parent())->isGroup())
79 groupName = item->parent()->text(1);
82 list = event->mimeData()->urls();
83 foreach (QUrl url, list) {
84 emit addClip(url, groupName);
88 else if (event->mimeData()->hasText())
90 QTreeWidgetItem *item = itemAt(event->pos());
92 if (item->parent()) item = item->parent();
93 if (((ProjectItem *) item)->isGroup()) {
94 //emit addClip(event->mimeData->text());
95 kDebug()<<"//////////////// DROPPED RIGHT 1 ";
96 QList <QTreeWidgetItem *> list;
97 list = selectedItems ();
99 foreach (QTreeWidgetItem *it, list) {
100 // TODO allow dragging of folders ?
101 if (!((ProjectItem *) it)->isGroup() && ((ProjectItem *) it)->clipId() < 10000) {
102 if (it->parent()) clone = (ProjectItem* ) it->parent()->takeChild(it->parent()->indexOfChild(it));
103 else clone = (ProjectItem* ) takeTopLevelItem(indexOfTopLevelItem(it));
104 if (clone) item->addChild(clone);
111 kDebug()<<"//////////////// DROPPED ONÂ EMPTY ZONE";
112 // item dropped in empty zone, move it to top level
113 QList <QTreeWidgetItem *> list;
114 list = selectedItems();
116 foreach (QTreeWidgetItem *it, list) {
117 QTreeWidgetItem *parent = it->parent();
118 if (parent && ((ProjectItem *) it)->clipId() < 10000) {
119 kDebug()<<"++ item parent: "<<parent->text(1);
120 clone = (ProjectItem* ) parent->takeChild(parent->indexOfChild(it));
121 if (clone) addTopLevelItem(clone);
126 event->acceptProposedAction();
130 void ProjectListView::mousePressEvent(QMouseEvent *event)
132 if( event->button() == Qt::LeftButton )
134 this->m_DragStartPosition = event->pos();
135 m_dragStarted = true;
137 QTreeWidget::mousePressEvent(event);
142 void ProjectListView::mouseMoveEvent(QMouseEvent *event)
144 kDebug()<<"// DRAG STARTED, MOUSE MOVED: ";
145 if (!m_dragStarted) return;
147 if ((event->pos() - m_DragStartPosition).manhattanLength()
148 < QApplication::startDragDistance())
152 ProjectItem *clickItem = (ProjectItem *) itemAt(event->pos());
154 QDrag *drag = new QDrag(this);
155 QMimeData *mimeData = new QMimeData;
157 QList <QTreeWidgetItem *> list;
158 list = selectedItems ();
159 foreach (QTreeWidgetItem *item, list) {
160 // TODO allow dragging of folders
161 if (!((ProjectItem *) item)->isGroup())
162 doc.appendChild(doc.importNode(((ProjectItem *) item)->toXml(), true));
165 //data.append(doc.toString().toUtf8());
166 //mimeData->setData("kdenlive/westley",data );
167 mimeData->setText(doc.toString());
168 //mimeData->setImageData(image);
169 drag->setMimeData(mimeData);
170 drag->setPixmap(clickItem->icon(0).pixmap(50 *16/9.0, 50));
171 drag->setHotSpot(QPoint(0, 50));
172 drag->start(Qt::MoveAction);
174 //Qt::DropAction dropAction;
175 //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
177 //Qt::DropAction dropAction = drag->exec();
184 void ProjectListView::dragMoveEvent(QDragMoveEvent * event) {
185 QTreeWidgetItem * item = itemAt(event->pos());
186 event->setDropAction(Qt::IgnoreAction);
188 event->setDropAction(Qt::MoveAction);
189 if (event->mimeData()->hasText()) {
190 event->acceptProposedAction();
195 QStringList ProjectListView::mimeTypes () const
197 QStringList qstrList;
198 // list of accepted mime types for drop
199 qstrList.append("text/uri-list");
200 qstrList.append("text/plain");
205 Qt::DropActions ProjectListView::supportedDropActions () const
207 // returns what actions are supported when dropping
208 return Qt::MoveAction;
211 #include "projectlistview.moc"