X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fprojectlistview.cpp;h=cc71757265d3acbb712e1dcade6c88c0f6c53f15;hb=5ee798aed90c5a3a50024e6b5bd26753e03ec7cc;hp=f51c0b2330e5f9e4f0434aebec754b5d9cec639d;hpb=0493c5f7f78bb61c4b52d22fc5eb2a25bdfe47f0;p=kdenlive diff --git a/src/projectlistview.cpp b/src/projectlistview.cpp index f51c0b23..cc717572 100644 --- a/src/projectlistview.cpp +++ b/src/projectlistview.cpp @@ -17,21 +17,23 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ -#include -#include -#include + +#include "projectlistview.h" +#include "projectitem.h" +#include "kdenlivesettings.h" #include #include #include -#include "projectitem.h" -#include "projectlistview.h" -#include "kdenlivesettings.h" - +#include +#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); @@ -50,30 +52,30 @@ ProjectListView::ProjectListView(QWidget *parent) connect(headerView, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(configureColumns(const QPoint&))); - connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(slotFocusOut(QTreeWidgetItem *, QTreeWidgetItem *))); + //connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(slotFocusOut(QTreeWidgetItem *, QTreeWidgetItem *))); if (!KdenliveSettings::showdescriptioncolumn()) hideColumn(2); if (!KdenliveSettings::showratingcolumn()) hideColumn(3); - setIconSize(QSize(60, 40)); setSortingEnabled(true); } -ProjectListView::~ProjectListView() { +ProjectListView::~ProjectListView() +{ } -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) { - const int logicalIndex = headerView->logicalIndex(i); const QString text = model()->headerData(i, Qt::Horizontal).toString(); QAction* action = popup.addAction(text); action->setCheckable(true); - action->setChecked(!headerView->isSectionHidden(logicalIndex)); + action->setChecked(!headerView->isSectionHidden(i)); action->setData(i); } @@ -104,20 +106,28 @@ 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) { +void ProjectListView::mouseDoubleClickEvent(QMouseEvent * event) +{ ProjectItem *item = static_cast (itemAt(event->pos())); if (!item) emit addClip(); - else if ((item->clipType() == FOLDER && columnAt(event->pos().x()) == 1) || columnAt(event->pos().x()) == 2) QTreeWidget::mouseDoubleClickEvent(event); - else emit showProperties(item->referencedClip()); + else if (item->isGroup()) { + if ((columnAt(event->pos().x()) == 1)) QTreeWidget::mouseDoubleClickEvent(event); + } 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()); + } } // virtual -void ProjectListView::dragEnterEvent(QDragEnterEvent *event) { +void ProjectListView::dragEnterEvent(QDragEnterEvent *event) +{ if (event->mimeData()->hasUrls() || event->mimeData()->hasText()) { kDebug() << "//////////////// DRAG ENTR OK"; } @@ -125,7 +135,8 @@ void ProjectListView::dragEnterEvent(QDragEnterEvent *event) { } // virtual -void ProjectListView::dropEvent(QDropEvent *event) { +void ProjectListView::dropEvent(QDropEvent *event) +{ kDebug() << "//////////////// DROPPED EVENT"; if (event->mimeData()->hasUrls()) { QTreeWidgetItem *item = itemAt(event->pos()); @@ -135,11 +146,7 @@ void ProjectListView::dropEvent(QDropEvent *event) { 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); - } + emit addClip(event->mimeData()->urls(), groupName); } else if (event->mimeData()->hasFormat("kdenlive/producerslist")) { ProjectItem *item = static_cast (itemAt(event->pos())); @@ -148,18 +155,20 @@ void ProjectListView::dropEvent(QDropEvent *event) { if (item->isGroup()) { //emit addClip(event->mimeData->text()); kDebug() << "//////////////// DROPPED RIGHT 1 "; - QList list; - list = selectedItems(); + const QList list = selectedItems(); ProjectItem *clone; - int parentId = item->clipId(); + QString parentId = item->clipId(); foreach(QTreeWidgetItem *it, list) { // TODO allow dragging of folders ? - if (!((ProjectItem *) it)->isGroup() && ((ProjectItem *) it)->clipId() < 10000) { + 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); - clone->setGroup(item->groupName(), QString::number(parentId)); + QMap props; + props.insert("groupname", item->groupName()); + props.insert("groupid", parentId); + clone->setProperties(props); } } } @@ -168,15 +177,18 @@ void ProjectListView::dropEvent(QDropEvent *event) { if (!item) { kDebug() << "//////////////// DROPPED ON EMPTY ZONE"; // item dropped in empty zone, move it to top level - QList list; - list = selectedItems(); + const QList list = selectedItems(); ProjectItem *clone; foreach(QTreeWidgetItem *it, list) { QTreeWidgetItem *parent = it->parent(); - if (parent && ((ProjectItem *) it)->clipId() < 10000) { + if (parent/* && ((ProjectItem *) it)->clipId() < 10000*/) { kDebug() << "++ item parent: " << parent->text(1); - clone = (ProjectItem*) parent->takeChild(parent->indexOfChild(it)); - if (clone) addTopLevelItem(clone); + clone = static_cast (parent->takeChild(parent->indexOfChild(it))); + if (clone) { + addTopLevelItem(clone); + clone->clearProperty("groupname"); + clone->clearProperty("groupid"); + } } } } @@ -185,18 +197,22 @@ void ProjectListView::dropEvent(QDropEvent *event) { } // virtual -void ProjectListView::mousePressEvent(QMouseEvent *event) { +void ProjectListView::mousePressEvent(QMouseEvent *event) +{ if (event->button() == Qt::LeftButton) { - this->m_DragStartPosition = event->pos(); + m_DragStartPosition = event->pos(); m_dragStarted = true; + QTreeWidgetItem *underMouse = itemAt(event->pos()); + if (underMouse && underMouse->isSelected()) emit focusMonitor(); } QTreeWidget::mousePressEvent(event); } // virtual -void ProjectListView::mouseMoveEvent(QMouseEvent *event) { - kDebug() << "// DRAG STARTED, MOUSE MOVED: "; +void ProjectListView::mouseMoveEvent(QMouseEvent *event) +{ + //kDebug() << "// DRAG STARTED, MOUSE MOVED: "; if (!m_dragStarted) return; if ((event->pos() - m_DragStartPosition).manhattanLength() @@ -204,50 +220,51 @@ void ProjectListView::mouseMoveEvent(QMouseEvent *event) { return; { - ProjectItem *clickItem = (ProjectItem *) itemAt(event->pos()); + ProjectItem *clickItem = (ProjectItem *) itemAt(m_DragStartPosition); //event->pos()); if (clickItem) { QDrag *drag = new QDrag(this); QMimeData *mimeData = new QMimeData; - QDomDocument doc; - QList list; - list = selectedItems(); + const QList list = selectedItems(); QStringList ids; - foreach(QTreeWidgetItem *item, list) { - // TODO allow dragging of folders - ids.append(QString::number(((ProjectItem *) item)->clipId())); + foreach(const QTreeWidgetItem *item, list) { + const ProjectItem *clip = static_cast (item); + if (!clip->isGroup()) ids.append(clip->clipId()); + else { + const int children = item->childCount(); + for (int i = 0; i < children; i++) { + ids.append(static_cast (item->child(i))->clipId()); + } + } } + if (ids.isEmpty()) return; 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((int)(50 *16 / 9.0), 50)); + drag->setPixmap(clickItem->icon(0).pixmap(iconSize())); drag->setHotSpot(QPoint(0, 50)); - drag->start(Qt::MoveAction); - - //Qt::DropAction dropAction; - //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction); - - //Qt::DropAction dropAction = drag->exec(); - + drag->exec(Qt::MoveAction); } //event->accept(); } } -void ProjectListView::dragMoveEvent(QDragMoveEvent * event) { - QTreeWidgetItem * item = itemAt(event->pos()); +// virtual +void ProjectListView::dragMoveEvent(QDragMoveEvent * event) +{ event->setDropAction(Qt::IgnoreAction); - //if (item) { event->setDropAction(Qt::MoveAction); if (event->mimeData()->hasText()) { event->acceptProposedAction(); } - //} + // stop playing because we get a crash otherwise when fetching the thumbnails + emit pauseMonitor(); } -QStringList ProjectListView::mimeTypes() const { +QStringList ProjectListView::mimeTypes() const +{ QStringList qstrList; qstrList << QTreeWidget::mimeTypes(); // list of accepted mime types for drop @@ -258,7 +275,8 @@ QStringList ProjectListView::mimeTypes() const { } -Qt::DropActions ProjectListView::supportedDropActions() const { +Qt::DropActions ProjectListView::supportedDropActions() const +{ // returns what actions are supported when dropping return Qt::MoveAction; }