X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fprojectlistview.cpp;h=c6d6c40a757cea1070ed511f2b1f07e3e9893c70;hb=4ea740d89bef3af2870a2578f252f889be897516;hp=08e774c11652b403e44b1f33e90d3965fba3aba6;hpb=d32938da41916fbc37d6f47c1618b679c0aaf718;p=kdenlive diff --git a/src/projectlistview.cpp b/src/projectlistview.cpp index 08e774c1..c6d6c40a 100644 --- a/src/projectlistview.cpp +++ b/src/projectlistview.cpp @@ -20,6 +20,8 @@ #include "projectlistview.h" #include "projectitem.h" +#include "subprojectitem.h" +#include "folderprojectitem.h" #include "kdenlivesettings.h" #include @@ -30,44 +32,56 @@ #include #include -ProjectListView::ProjectListView(QWidget *parent) - : QTreeWidget(parent), m_dragStarted(false) { +ProjectListView::ProjectListView(QWidget *parent) : + QTreeWidget(parent), + m_dragStarted(false) +{ setSelectionMode(QAbstractItemView::ExtendedSelection); setDragDropMode(QAbstractItemView::DragDrop); setDropIndicatorShown(true); setAlternatingRowColors(true); setDragEnabled(true); setAcceptDrops(true); + setFrameShape(QFrame::NoFrame); + setRootIsDecorated(false); - setColumnCount(4); + setColumnCount(3); QStringList headers; - headers << i18n("Thumbnail") << i18n("Filename") << i18n("Description") << i18n("Rating"); + headers << i18n("Clip") << i18n("Description") << i18n("Rating"); setHeaderLabels(headers); - sortByColumn(1, Qt::AscendingOrder); QHeaderView* headerView = header(); headerView->setContextMenuPolicy(Qt::CustomContextMenu); connect(headerView, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(configureColumns(const QPoint&))); - - //connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(slotFocusOut(QTreeWidgetItem *, QTreeWidgetItem *))); - - if (!KdenliveSettings::showdescriptioncolumn()) hideColumn(2); - if (!KdenliveSettings::showratingcolumn()) hideColumn(3); - + connect(this, SIGNAL(itemCollapsed(QTreeWidgetItem *)), this, SLOT(slotCollapsed(QTreeWidgetItem *))); + connect(this, SIGNAL(itemExpanded(QTreeWidgetItem *)), this, SLOT(slotExpanded(QTreeWidgetItem *))); + headerView->setClickable(true); + headerView->setSortIndicatorShown(true); + headerView->setMovable(false); + sortByColumn(0, Qt::AscendingOrder); setSortingEnabled(true); + installEventFilter(this); + if (!KdenliveSettings::showdescriptioncolumn()) hideColumn(1); + if (!KdenliveSettings::showratingcolumn()) hideColumn(2); } -ProjectListView::~ProjectListView() { +ProjectListView::~ProjectListView() +{ } +void ProjectListView::processLayout() +{ + executeDelayedItemsLayout(); +} -void ProjectListView::configureColumns(const QPoint& pos) { +void ProjectListView::configureColumns(const QPoint& pos) +{ KMenu popup(this); popup.addTitle(i18nc("@title:menu", "Columns")); QHeaderView* headerView = header(); - for (int i = 2; i < headerView->count(); ++i) { + for (int i = 1; i < headerView->count(); ++i) { const QString text = model()->headerData(i, Qt::Horizontal).toString(); QAction* action = popup.addAction(text); action->setCheckable(true); @@ -82,10 +96,10 @@ void ProjectListView::configureColumns(const QPoint& pos) { // remember the changed column visibility in the settings const int columnIndex = activatedAction->data().toInt(); switch (columnIndex) { - case 2: + case 1: KdenliveSettings::setShowdescriptioncolumn(show); break; - case 3: + case 2: KdenliveSettings::setShowratingcolumn(show); break; default: @@ -102,72 +116,147 @@ void ProjectListView::configureColumns(const QPoint& pos) { } // virtual -void ProjectListView::contextMenuEvent(QContextMenuEvent * event) { +void ProjectListView::contextMenuEvent(QContextMenuEvent * event) +{ emit requestMenu(event->globalPos(), itemAt(event->pos())); } -// virtual -void ProjectListView::mouseDoubleClickEvent(QMouseEvent * event) { - ProjectItem *item = static_cast (itemAt(event->pos())); - if (!item) emit addClip(); - else if (item->isGroup()) { - if ((columnAt(event->pos().x()) == 1)) QTreeWidget::mouseDoubleClickEvent(event); +void ProjectListView::slotCollapsed(QTreeWidgetItem *item) +{ + if (item->type() == PROJECTFOLDERTYPE) { + blockSignals(true); + static_cast (item)->switchIcon(); + blockSignals(false); + } +} + +void ProjectListView::slotExpanded(QTreeWidgetItem *item) +{ + if (item->type() == PROJECTFOLDERTYPE) { + blockSignals(true); + static_cast (item)->switchIcon(); + blockSignals(false); + } +} + +bool ProjectListView::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::KeyPress || event->type() == QEvent::ShortcutOverride) { + QKeyEvent* ke = (QKeyEvent*) event; + if (ke->key() == Qt::Key_Plus) { + if (currentItem()) currentItem()->setExpanded(true); + event->accept(); + return true; + } else if (ke->key() == Qt::Key_Minus) { + if (currentItem()) currentItem()->setExpanded(false); + event->accept(); + return true; + } else { + return false; + } } else { - if ((columnAt(event->pos().x()) == 1) && (item->clipType() == SLIDESHOW || item->clipType() == TEXT || item->clipType() == COLOR)) QTreeWidget::mouseDoubleClickEvent(event); - else if ((columnAt(event->pos().x()) == 2)) QTreeWidget::mouseDoubleClickEvent(event); - else emit showProperties(item->referencedClip()); + // pass the event on to the parent class + return QTreeWidget::eventFilter(obj, event); } } // virtual -void ProjectListView::dragEnterEvent(QDragEnterEvent *event) { - if (event->mimeData()->hasUrls() || event->mimeData()->hasText()) { - kDebug() << "//////////////// DRAG ENTR OK"; +void ProjectListView::mouseDoubleClickEvent(QMouseEvent * event) +{ + QTreeWidgetItem *it = itemAt(event->pos()); + if (!it) { + emit addClip(); + return; } - event->acceptProposedAction(); + ProjectItem *item; + if (it->type() == PROJECTFOLDERTYPE) { + if ((columnAt(event->pos().x()) == 0)) { + QPixmap pix = qVariantValue(it->data(0, Qt::DecorationRole)); + int offset = pix.width() + indentation(); + if (event->pos().x() < offset) { + it->setExpanded(!it->isExpanded()); + event->accept(); + } else QTreeWidget::mouseDoubleClickEvent(event); + } + return; + } + if (it->type() == PROJECTSUBCLIPTYPE) { + // subitem + if ((columnAt(event->pos().x()) == 1)) { + QTreeWidget::mouseDoubleClickEvent(event); + return; + } + item = static_cast (it->parent()); + } else item = static_cast (it); + + if (!(item->flags() & Qt::ItemIsDragEnabled)) return; + + int column = columnAt(event->pos().x()); + if (column == 0 && (item->clipType() == SLIDESHOW || item->clipType() == TEXT || item->clipType() == COLOR || it->childCount() > 0)) { + QPixmap pix = qVariantValue(it->data(0, Qt::DecorationRole)); + int offset = pix.width() + indentation(); + if (item->parent()) offset += indentation(); + if (it->childCount() > 0) { + if (offset > event->pos().x()) { + it->setExpanded(!it->isExpanded()); + event->accept(); + return; + } + } else if (pix.isNull() || offset < event->pos().x()) { + QTreeWidget::mouseDoubleClickEvent(event); + return; + } + } + if ((column == 1) && it->type() != PROJECTSUBCLIPTYPE) { + QTreeWidget::mouseDoubleClickEvent(event); + return; + } + emit showProperties(item->referencedClip()); } + // virtual -void ProjectListView::dropEvent(QDropEvent *event) { - kDebug() << "//////////////// DROPPED EVENT"; +void ProjectListView::dropEvent(QDropEvent *event) +{ + FolderProjectItem *item = NULL; + QTreeWidgetItem *it = itemAt(event->pos()); + while (it && it->type() != PROJECTFOLDERTYPE) { + it = it->parent(); + } + if (it) item = static_cast (it); if (event->mimeData()->hasUrls()) { - QTreeWidgetItem *item = itemAt(event->pos()); QString groupName; + QString groupId; if (item) { - if (((ProjectItem *) item)->isGroup()) groupName = item->text(1); - else if (item->parent() && ((ProjectItem *) item->parent())->isGroup()) - groupName = item->parent()->text(1); + groupName = item->groupName(); + groupId = item->clipId(); } - emit addClip(event->mimeData()->urls(), groupName); - + emit addClip(event->mimeData()->urls(), groupName, groupId); + event->setDropAction(Qt::CopyAction); + event->accept(); + QTreeWidget::dropEvent(event); + return; } else if (event->mimeData()->hasFormat("kdenlive/producerslist")) { - ProjectItem *item = static_cast (itemAt(event->pos())); if (item) { - if (item->parent()) item = static_cast (item->parent()); - if (item->isGroup()) { - //emit addClip(event->mimeData->text()); - kDebug() << "//////////////// DROPPED RIGHT 1 "; - const QList list = selectedItems(); - ProjectItem *clone; - QString parentId = item->clipId(); - 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); - QMap props; - props.insert("groupname", item->groupName()); - props.insert("groupid", parentId); - clone->setProperties(props); - } + //emit addClip(event->mimeData->text()); + const QList list = selectedItems(); + ProjectItem *clone; + QString parentId = item->clipId(); + foreach(QTreeWidgetItem *it, list) { + // TODO allow dragging of folders ? + if (it->type() == PROJECTCLIPTYPE) { + if (it->parent()) clone = (ProjectItem*) it->parent()->takeChild(it->parent()->indexOfChild(it)); + else clone = (ProjectItem*) takeTopLevelItem(indexOfTopLevelItem(it)); + if (clone) { + item->addChild(clone); + QMap props; + props.insert("groupname", item->groupName()); + props.insert("groupid", parentId); + clone->setProperties(props); } - } - } else item = NULL; - } - if (!item) { - kDebug() << "//////////////// DROPPED ON EMPTY ZONE"; + } else item = NULL; + } + } else { // item dropped in empty zone, move it to top level const QList list = selectedItems(); ProjectItem *clone; @@ -184,24 +273,38 @@ void ProjectListView::dropEvent(QDropEvent *event) { } } } + emit projectModified(); + } else if (event->mimeData()->hasFormat("kdenlive/clip")) { + QStringList list = QString(event->mimeData()->data("kdenlive/clip")).split(';'); + emit addClipCut(list.at(0), list.at(1).toInt(), list.at(2).toInt()); } event->acceptProposedAction(); + QTreeWidget::dropEvent(event); } // virtual -void ProjectListView::mousePressEvent(QMouseEvent *event) { +void ProjectListView::mousePressEvent(QMouseEvent *event) +{ if (event->button() == Qt::LeftButton) { m_DragStartPosition = event->pos(); m_dragStarted = true; - QTreeWidgetItem *underMouse = itemAt(event->pos()); - if (underMouse && underMouse->isSelected()) emit focusMonitor(); + /*QTreeWidgetItem *underMouse = itemAt(event->pos()); + if (underMouse && underMouse->isSelected()) emit focusMonitor();*/ } QTreeWidget::mousePressEvent(event); } +// virtual +void ProjectListView::mouseReleaseEvent(QMouseEvent *event) +{ + QTreeWidget::mouseReleaseEvent(event); + QTreeWidgetItem *underMouse = itemAt(event->pos()); + if (underMouse) emit focusMonitor(); +} // virtual -void ProjectListView::mouseMoveEvent(QMouseEvent *event) { +void ProjectListView::mouseMoveEvent(QMouseEvent *event) +{ //kDebug() << "// DRAG STARTED, MOUSE MOVED: "; if (!m_dragStarted) return; @@ -209,22 +312,44 @@ void ProjectListView::mouseMoveEvent(QMouseEvent *event) { < QApplication::startDragDistance()) return; - { - ProjectItem *clickItem = (ProjectItem *) itemAt(m_DragStartPosition); //event->pos()); - if (clickItem) { + QTreeWidgetItem *it = itemAt(m_DragStartPosition); + if (!it) return; + if (it->type() == PROJECTSUBCLIPTYPE) { + // subitem + SubProjectItem *clickItem = static_cast (it); + if (clickItem && (clickItem->flags() & Qt::ItemIsDragEnabled)) { + ProjectItem *clip = static_cast (it->parent()); + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + + QStringList list; + list.append(clip->clipId()); + QPoint p = clickItem->zone(); + list.append(QString::number(p.x())); + list.append(QString::number(p.y())); + QByteArray data; + data.append(list.join(";").toUtf8()); + mimeData->setData("kdenlive/clip", data); + drag->setMimeData(mimeData); + drag->setPixmap(clickItem->data(0, Qt::DecorationRole).value()); + drag->setHotSpot(QPoint(0, 50)); + drag->exec(); + } + } else { + if (it && (it->flags() & Qt::ItemIsDragEnabled)) { QDrag *drag = new QDrag(this); QMimeData *mimeData = new QMimeData; - QDomDocument doc; const QList list = selectedItems(); QStringList ids; foreach(const QTreeWidgetItem *item, list) { - const ProjectItem *clip = static_cast (item); - if (!clip->isGroup()) ids.append(clip->clipId()); - else { + if (item->type() == PROJECTFOLDERTYPE) { const int children = item->childCount(); for (int i = 0; i < children; i++) { ids.append(static_cast (item->child(i))->clipId()); } + } else { + const ProjectItem *clip = static_cast (item); + ids.append(clip->clipId()); } } if (ids.isEmpty()) return; @@ -234,39 +359,39 @@ void ProjectListView::mouseMoveEvent(QMouseEvent *event) { //mimeData->setText(ids.join(";")); //doc.toString()); //mimeData->setImageData(image); drag->setMimeData(mimeData); - drag->setPixmap(clickItem->icon(0).pixmap(iconSize())); + drag->setPixmap(it->data(0, Qt::DecorationRole).value()); drag->setHotSpot(QPoint(0, 50)); - drag->exec(Qt::MoveAction); + drag->exec(); } //event->accept(); } } // virtual -void ProjectListView::dragMoveEvent(QDragMoveEvent * event) { - event->setDropAction(Qt::IgnoreAction); - event->setDropAction(Qt::MoveAction); - if (event->mimeData()->hasText()) { - event->acceptProposedAction(); - } +void ProjectListView::dragLeaveEvent(QDragLeaveEvent *event) +{ // stop playing because we get a crash otherwise when fetching the thumbnails emit pauseMonitor(); + QTreeWidget::dragLeaveEvent(event); } -QStringList ProjectListView::mimeTypes() const { +QStringList ProjectListView::mimeTypes() const +{ QStringList qstrList; qstrList << QTreeWidget::mimeTypes(); // list of accepted mime types for drop qstrList.append("text/uri-list"); qstrList.append("text/plain"); qstrList.append("kdenlive/producerslist"); + qstrList.append("kdenlive/clip"); return qstrList; } -Qt::DropActions ProjectListView::supportedDropActions() const { +Qt::DropActions ProjectListView::supportedDropActions() const +{ // returns what actions are supported when dropping - return Qt::MoveAction; + return Qt::MoveAction | Qt::CopyAction; } #include "projectlistview.moc"