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 if (!itemAt(event->pos())) emit addClip();
53 else if (columnAt(event->pos().x()) == 2) QTreeWidget::mouseDoubleClickEvent(event);
57 void ProjectListView::dragEnterEvent(QDragEnterEvent *event) {
58 if (event->mimeData()->hasUrls() || event->mimeData()->hasText()) {
59 kDebug() << "//////////////// DRAG ENTR OK";
61 event->acceptProposedAction();
65 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);
81 } else if (event->mimeData()->hasText()) {
82 QTreeWidgetItem *item = itemAt(event->pos());
84 if (item->parent()) item = item->parent();
85 if (((ProjectItem *) item)->isGroup()) {
86 //emit addClip(event->mimeData->text());
87 kDebug() << "//////////////// DROPPED RIGHT 1 ";
88 QList <QTreeWidgetItem *> list;
89 list = selectedItems();
91 foreach(QTreeWidgetItem *it, list) {
92 // TODO allow dragging of folders ?
93 if (!((ProjectItem *) it)->isGroup() && ((ProjectItem *) it)->clipId() < 10000) {
94 if (it->parent()) clone = (ProjectItem*) it->parent()->takeChild(it->parent()->indexOfChild(it));
95 else clone = (ProjectItem*) takeTopLevelItem(indexOfTopLevelItem(it));
96 if (clone) item->addChild(clone);
102 kDebug() << "//////////////// DROPPED ONÂ EMPTY ZONE";
103 // item dropped in empty zone, move it to top level
104 QList <QTreeWidgetItem *> list;
105 list = selectedItems();
107 foreach(QTreeWidgetItem *it, list) {
108 QTreeWidgetItem *parent = it->parent();
109 if (parent && ((ProjectItem *) it)->clipId() < 10000) {
110 kDebug() << "++ item parent: " << parent->text(1);
111 clone = (ProjectItem*) parent->takeChild(parent->indexOfChild(it));
112 if (clone) addTopLevelItem(clone);
117 event->acceptProposedAction();
121 void ProjectListView::mousePressEvent(QMouseEvent *event) {
122 if (event->button() == Qt::LeftButton) {
123 this->m_DragStartPosition = event->pos();
124 m_dragStarted = true;
126 QTreeWidget::mousePressEvent(event);
131 void ProjectListView::mouseMoveEvent(QMouseEvent *event) {
132 kDebug() << "// DRAG STARTED, MOUSE MOVED: ";
133 if (!m_dragStarted) return;
135 if ((event->pos() - m_DragStartPosition).manhattanLength()
136 < QApplication::startDragDistance())
140 ProjectItem *clickItem = (ProjectItem *) itemAt(event->pos());
142 QDrag *drag = new QDrag(this);
143 QMimeData *mimeData = new QMimeData;
145 QList <QTreeWidgetItem *> list;
146 list = selectedItems();
148 foreach(QTreeWidgetItem *item, list) {
149 // TODO allow dragging of folders
150 if (!((ProjectItem *) item)->isGroup())
151 ids.append(QString::number(((ProjectItem *) item)->clipId()));
154 data.append(ids.join(";").toUtf8()); //doc.toString().toUtf8());
155 mimeData->setData("kdenlive/producerslist", data);
156 //mimeData->setText(ids.join(";")); //doc.toString());
157 //mimeData->setImageData(image);
158 drag->setMimeData(mimeData);
159 drag->setPixmap(clickItem->icon(0).pixmap(50 *16 / 9.0, 50));
160 drag->setHotSpot(QPoint(0, 50));
161 drag->start(Qt::MoveAction);
163 //Qt::DropAction dropAction;
164 //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
166 //Qt::DropAction dropAction = drag->exec();
173 void ProjectListView::dragMoveEvent(QDragMoveEvent * event) {
174 QTreeWidgetItem * item = itemAt(event->pos());
175 event->setDropAction(Qt::IgnoreAction);
177 event->setDropAction(Qt::MoveAction);
178 if (event->mimeData()->hasText()) {
179 event->acceptProposedAction();
184 QStringList ProjectListView::mimeTypes() const {
185 QStringList qstrList;
186 // list of accepted mime types for drop
187 qstrList.append("text/uri-list");
188 qstrList.append("text/plain");
193 Qt::DropActions ProjectListView::supportedDropActions() const {
194 // returns what actions are supported when dropping
195 return Qt::MoveAction;
198 #include "projectlistview.moc"