X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fprojectlistview.cpp;h=f35f5abb04b8793b27f05a14a35fb87ab62207bb;hb=2a223cff6e45c560c28857b72c0cb7e584f9a4ef;hp=ab2b7b924cde300aa9b89c5f9584fcb739d6454b;hpb=e7a03c1e0263a39a6c3b2fa7f8f85dbfc293996f;p=kdenlive diff --git a/src/projectlistview.cpp b/src/projectlistview.cpp index ab2b7b92..f35f5abb 100644 --- a/src/projectlistview.cpp +++ b/src/projectlistview.cpp @@ -26,112 +26,100 @@ ProjectListView::ProjectListView(QWidget *parent) - : QTreeWidget(parent), m_dragStarted(false) -{ - setSelectionMode(QAbstractItemView::ExtendedSelection); - setDragDropMode(QAbstractItemView::DragDrop); - setDropIndicatorShown(true); - setAlternatingRowColors(true); - setDragEnabled(true); - setAcceptDrops(true); + : QTreeWidget(parent), m_dragStarted(false) { + setSelectionMode(QAbstractItemView::ExtendedSelection); + setDragDropMode(QAbstractItemView::DragDrop); + setDropIndicatorShown(true); + setAlternatingRowColors(true); + setDragEnabled(true); + setAcceptDrops(true); } -ProjectListView::~ProjectListView() -{ +ProjectListView::~ProjectListView() { } -void ProjectListView::editItem ( QTreeWidgetItem * item, int column ) -{ - kDebug()<<"//////////////// EDIT ITEM, COL: "<globalPos(), itemAt(event->pos())); +void ProjectListView::contextMenuEvent(QContextMenuEvent * event) { + emit requestMenu(event->globalPos(), itemAt(event->pos())); } // virtual -void ProjectListView::mouseDoubleClickEvent ( QMouseEvent * event ) -{ - if (!itemAt(event->pos())) emit addClip(); - else if (columnAt(event->pos().x()) == 2) QTreeWidget::mouseDoubleClickEvent( event ); +void ProjectListView::mouseDoubleClickEvent(QMouseEvent * event) { + if (!itemAt(event->pos())) emit addClip(); + else if (columnAt(event->pos().x()) == 2) QTreeWidget::mouseDoubleClickEvent(event); } // virtual -void ProjectListView::dragEnterEvent(QDragEnterEvent *event) -{ - if (event->mimeData()->hasUrls() || event->mimeData()->hasText()) { - kDebug()<<"//////////////// DRAG ENTR OK"; - } - event->acceptProposedAction(); +void ProjectListView::dragEnterEvent(QDragEnterEvent *event) { + if (event->mimeData()->hasUrls() || event->mimeData()->hasText()) { + kDebug() << "//////////////// DRAG ENTR OK"; + } + event->acceptProposedAction(); } // virtual -void ProjectListView::dropEvent(QDropEvent *event) -{ - kDebug()<<"//////////////// DROPPED EVENT"; - if (event->mimeData()->hasUrls()) { - QTreeWidgetItem *item = itemAt(event->pos()); - QString groupName; - if (item) { - if (((ProjectItem *) item)->isGroup()) groupName = item->text(1); - else if (item->parent() && ((ProjectItem *) item->parent())->isGroup()) - groupName = item->parent()->text(1); - } - QList list; - list = event->mimeData()->urls(); - foreach (QUrl url, list) { - emit addClip(url, groupName); - } - - } - else if (event->mimeData()->hasText()) - { - QTreeWidgetItem *item = itemAt(event->pos()); - if (item) { - if (item->parent()) item = item->parent(); - if (((ProjectItem *) item)->isGroup()) { - //emit addClip(event->mimeData->text()); - kDebug()<<"//////////////// DROPPED RIGHT 1 "; - QList list; - list = selectedItems (); - ProjectItem *clone; - foreach (QTreeWidgetItem *it, list) { - // TODO allow dragging of folders ? - if (!((ProjectItem *) it)->isGroup() && ((ProjectItem *) it)->clipId() < 10000) { - if (it->parent()) clone = (ProjectItem* ) it->parent()->takeChild(it->parent()->indexOfChild(it)); - else clone = (ProjectItem* ) takeTopLevelItem(indexOfTopLevelItem(it)); - if (clone) item->addChild(clone); - } - } - } - else item = NULL; +void ProjectListView::dropEvent(QDropEvent *event) { + kDebug() << "//////////////// DROPPED EVENT"; + if (event->mimeData()->hasUrls()) { + QTreeWidgetItem *item = itemAt(event->pos()); + QString groupName; + if (item) { + if (((ProjectItem *) item)->isGroup()) groupName = item->text(1); + else if (item->parent() && ((ProjectItem *) item->parent())->isGroup()) + groupName = item->parent()->text(1); + } + QList list; + list = event->mimeData()->urls(); + foreach(QUrl url, list) { + emit addClip(url, groupName); + } + + } else if (event->mimeData()->hasText()) { + QTreeWidgetItem *item = itemAt(event->pos()); + if (item) { + if (item->parent()) item = item->parent(); + if (((ProjectItem *) item)->isGroup()) { + //emit addClip(event->mimeData->text()); + kDebug() << "//////////////// DROPPED RIGHT 1 "; + QList list; + list = selectedItems(); + ProjectItem *clone; + foreach(QTreeWidgetItem *it, list) { + // TODO allow dragging of folders ? + if (!((ProjectItem *) it)->isGroup() && ((ProjectItem *) it)->clipId() < 10000) { + if (it->parent()) clone = (ProjectItem*) it->parent()->takeChild(it->parent()->indexOfChild(it)); + else clone = (ProjectItem*) takeTopLevelItem(indexOfTopLevelItem(it)); + if (clone) item->addChild(clone); + } + } + } else item = NULL; + } + if (!item) { + kDebug() << "//////////////// DROPPED ON EMPTY ZONE"; + // item dropped in empty zone, move it to top level + QList list; + list = selectedItems(); + ProjectItem *clone; + foreach(QTreeWidgetItem *it, list) { + QTreeWidgetItem *parent = it->parent(); + if (parent && ((ProjectItem *) it)->clipId() < 10000) { + kDebug() << "++ item parent: " << parent->text(1); + clone = (ProjectItem*) parent->takeChild(parent->indexOfChild(it)); + if (clone) addTopLevelItem(clone); + } + } + } } - if (!item) { - kDebug()<<"//////////////// DROPPED ON EMPTY ZONE"; - // item dropped in empty zone, move it to top level - QList list; - list = selectedItems(); - ProjectItem *clone; - foreach (QTreeWidgetItem *it, list) { - QTreeWidgetItem *parent = it->parent(); - if (parent && ((ProjectItem *) it)->clipId() < 10000) { - kDebug()<<"++ item parent: "<text(1); - clone = (ProjectItem* ) parent->takeChild(parent->indexOfChild(it)); - if (clone) addTopLevelItem(clone); - } - } - } - } - event->acceptProposedAction(); + event->acceptProposedAction(); } // virtual -void ProjectListView::mousePressEvent(QMouseEvent *event) -{ - if( event->button() == Qt::LeftButton ) - { +void ProjectListView::mousePressEvent(QMouseEvent *event) { + if (event->button() == Qt::LeftButton) { this->m_DragStartPosition = event->pos(); m_dragStarted = true; } @@ -140,72 +128,69 @@ void ProjectListView::mousePressEvent(QMouseEvent *event) // virtual -void ProjectListView::mouseMoveEvent(QMouseEvent *event) -{ - kDebug()<<"// DRAG STARTED, MOUSE MOVED: "; - if (!m_dragStarted) return; +void ProjectListView::mouseMoveEvent(QMouseEvent *event) { + kDebug() << "// DRAG STARTED, MOUSE MOVED: "; + if (!m_dragStarted) return; - if ((event->pos() - m_DragStartPosition).manhattanLength() + if ((event->pos() - m_DragStartPosition).manhattanLength() < QApplication::startDragDistance()) return; - - { - ProjectItem *clickItem = (ProjectItem *) itemAt(event->pos()); - if (clickItem) { - QDrag *drag = new QDrag(this); - QMimeData *mimeData = new QMimeData; - QDomDocument doc; - QList list; - list = selectedItems (); - QStringList ids; - foreach (QTreeWidgetItem *item, list) { - // TODO allow dragging of folders - if (!((ProjectItem *) item)->isGroup()) - ids.append(QString::number(((ProjectItem *) item)->clipId())); - } - QByteArray data; - data.append(ids.join(";").toUtf8()); //doc.toString().toUtf8()); - mimeData->setData("kdenlive/producerslist",data ); - //mimeData->setText(ids.join(";")); //doc.toString()); - //mimeData->setImageData(image); - drag->setMimeData(mimeData); - drag->setPixmap(clickItem->icon(0).pixmap(50 *16/9.0, 50)); - drag->setHotSpot(QPoint(0, 50)); - drag->start(Qt::MoveAction); - - //Qt::DropAction dropAction; - //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction); - - //Qt::DropAction dropAction = drag->exec(); - + + { + ProjectItem *clickItem = (ProjectItem *) itemAt(event->pos()); + if (clickItem) { + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + QDomDocument doc; + QList list; + list = selectedItems(); + QStringList ids; + foreach(QTreeWidgetItem *item, list) { + // TODO allow dragging of folders + if (!((ProjectItem *) item)->isGroup()) + ids.append(QString::number(((ProjectItem *) item)->clipId())); + } + QByteArray data; + data.append(ids.join(";").toUtf8()); //doc.toString().toUtf8()); + mimeData->setData("kdenlive/producerslist", data); + //mimeData->setText(ids.join(";")); //doc.toString()); + //mimeData->setImageData(image); + drag->setMimeData(mimeData); + drag->setPixmap(clickItem->icon(0).pixmap(50 *16 / 9.0, 50)); + drag->setHotSpot(QPoint(0, 50)); + drag->start(Qt::MoveAction); + + //Qt::DropAction dropAction; + //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction); + + //Qt::DropAction dropAction = drag->exec(); + + } + //event->accept(); } - //event->accept(); - } } void ProjectListView::dragMoveEvent(QDragMoveEvent * event) { - QTreeWidgetItem * item = itemAt(event->pos()); - event->setDropAction(Qt::IgnoreAction); - //if (item) { - event->setDropAction(Qt::MoveAction); - if (event->mimeData()->hasText()) { - event->acceptProposedAction(); - } - //} + QTreeWidgetItem * item = itemAt(event->pos()); + event->setDropAction(Qt::IgnoreAction); + //if (item) { + event->setDropAction(Qt::MoveAction); + if (event->mimeData()->hasText()) { + event->acceptProposedAction(); + } + //} } -QStringList ProjectListView::mimeTypes () const -{ +QStringList ProjectListView::mimeTypes() const { QStringList qstrList; // list of accepted mime types for drop qstrList.append("text/uri-list"); qstrList.append("text/plain"); return qstrList; } - - -Qt::DropActions ProjectListView::supportedDropActions () const -{ + + +Qt::DropActions ProjectListView::supportedDropActions() const { // returns what actions are supported when dropping return Qt::MoveAction; }