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);
34 setAlternatingRowColors(true);
39 ProjectListView::~ProjectListView()
43 void ProjectListView::editItem ( QTreeWidgetItem * item, int column )
45 kDebug()<<"//////////////// EDIT ITEM, COL: "<<column;
49 void ProjectListView::contextMenuEvent ( QContextMenuEvent * event )
51 emit requestMenu(event->globalPos(), itemAt(event->pos()));
55 void ProjectListView::mouseDoubleClickEvent ( QMouseEvent * event )
57 if (!itemAt(event->pos())) emit addClip();
58 else if (columnAt(event->pos().x()) == 2) QTreeWidget::mouseDoubleClickEvent( event );
62 void ProjectListView::dragEnterEvent(QDragEnterEvent *event)
64 if (event->mimeData()->hasUrls() || event->mimeData()->hasText()) {
65 kDebug()<<"//////////////// DRAG ENTR OK";
67 event->acceptProposedAction();
71 void ProjectListView::dropEvent(QDropEvent *event)
73 kDebug()<<"//////////////// DROPPED EVENT";
74 if (event->mimeData()->hasUrls()) {
75 QTreeWidgetItem *item = itemAt(event->pos());
78 if (((ProjectItem *) item)->isGroup()) groupName = item->text(1);
79 else if (item->parent() && ((ProjectItem *) item->parent())->isGroup())
80 groupName = item->parent()->text(1);
83 list = event->mimeData()->urls();
84 foreach (QUrl url, list) {
85 emit addClip(url, groupName);
89 else if (event->mimeData()->hasText())
91 QTreeWidgetItem *item = itemAt(event->pos());
93 if (item->parent()) item = item->parent();
94 if (((ProjectItem *) item)->isGroup()) {
95 //emit addClip(event->mimeData->text());
96 kDebug()<<"//////////////// DROPPED RIGHT 1 ";
97 QList <QTreeWidgetItem *> list;
98 list = selectedItems ();
100 foreach (QTreeWidgetItem *it, list) {
101 // TODO allow dragging of folders ?
102 if (!((ProjectItem *) it)->isGroup() && ((ProjectItem *) it)->clipId() < 10000) {
103 if (it->parent()) clone = (ProjectItem* ) it->parent()->takeChild(it->parent()->indexOfChild(it));
104 else clone = (ProjectItem* ) takeTopLevelItem(indexOfTopLevelItem(it));
105 if (clone) item->addChild(clone);
112 kDebug()<<"//////////////// DROPPED ONÂ EMPTY ZONE";
113 // item dropped in empty zone, move it to top level
114 QList <QTreeWidgetItem *> list;
115 list = selectedItems();
117 foreach (QTreeWidgetItem *it, list) {
118 QTreeWidgetItem *parent = it->parent();
119 if (parent && ((ProjectItem *) it)->clipId() < 10000) {
120 kDebug()<<"++ item parent: "<<parent->text(1);
121 clone = (ProjectItem* ) parent->takeChild(parent->indexOfChild(it));
122 if (clone) addTopLevelItem(clone);
127 event->acceptProposedAction();
131 void ProjectListView::mousePressEvent(QMouseEvent *event)
133 if( event->button() == Qt::LeftButton )
135 this->m_DragStartPosition = event->pos();
136 m_dragStarted = true;
138 QTreeWidget::mousePressEvent(event);
143 void ProjectListView::mouseMoveEvent(QMouseEvent *event)
145 kDebug()<<"// DRAG STARTED, MOUSE MOVED: ";
146 if (!m_dragStarted) return;
148 if ((event->pos() - m_DragStartPosition).manhattanLength()
149 < QApplication::startDragDistance())
153 ProjectItem *clickItem = (ProjectItem *) itemAt(event->pos());
155 QDrag *drag = new QDrag(this);
156 QMimeData *mimeData = new QMimeData;
158 QList <QTreeWidgetItem *> list;
159 list = selectedItems ();
161 foreach (QTreeWidgetItem *item, list) {
162 // TODO allow dragging of folders
163 if (!((ProjectItem *) item)->isGroup())
164 ids.append(QString::number(((ProjectItem *) item)->clipId()));
167 data.append(ids.join(";").toUtf8()); //doc.toString().toUtf8());
168 mimeData->setData("kdenlive/producerslist",data );
169 //mimeData->setText(ids.join(";")); //doc.toString());
170 //mimeData->setImageData(image);
171 drag->setMimeData(mimeData);
172 drag->setPixmap(clickItem->icon(0).pixmap(50 *16/9.0, 50));
173 drag->setHotSpot(QPoint(0, 50));
174 drag->start(Qt::MoveAction);
176 //Qt::DropAction dropAction;
177 //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
179 //Qt::DropAction dropAction = drag->exec();
186 void ProjectListView::dragMoveEvent(QDragMoveEvent * event) {
187 QTreeWidgetItem * item = itemAt(event->pos());
188 event->setDropAction(Qt::IgnoreAction);
190 event->setDropAction(Qt::MoveAction);
191 if (event->mimeData()->hasText()) {
192 event->acceptProposedAction();
197 QStringList ProjectListView::mimeTypes () const
199 QStringList qstrList;
200 // list of accepted mime types for drop
201 qstrList.append("text/uri-list");
202 qstrList.append("text/plain");
207 Qt::DropActions ProjectListView::supportedDropActions () const
209 // returns what actions are supported when dropping
210 return Qt::MoveAction;
213 #include "projectlistview.moc"