* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
-#include "QApplication"
-#include "KDebug"
-
-#include "projectitem.h"
#include "projectlistview.h"
+#include "projectitem.h"
+#include "subprojectitem.h"
+#include "folderprojectitem.h"
+#include "kdenlivesettings.h"
+#include <KDebug>
+#include <KMenu>
+#include <KLocale>
-ProjectListView::ProjectListView(QWidget *parent)
- : QTreeWidget(parent), m_dragStarted(false) {
+#include <QApplication>
+#include <QHeaderView>
+#include <QAction>
+
+ProjectListView::ProjectListView(QWidget *parent) :
+ QTreeWidget(parent),
+ m_dragStarted(false)
+{
setSelectionMode(QAbstractItemView::ExtendedSelection);
setDragDropMode(QAbstractItemView::DragDrop);
setDropIndicatorShown(true);
setAlternatingRowColors(true);
setDragEnabled(true);
setAcceptDrops(true);
+
+
+ setColumnCount(3);
+ QStringList headers;
+ headers << i18n("Clip") << i18n("Description") << i18n("Rating");
+ setHeaderLabels(headers);
+
+ QHeaderView* headerView = header();
+ headerView->setContextMenuPolicy(Qt::CustomContextMenu);
+ connect(headerView, SIGNAL(customContextMenuRequested(const QPoint&)),
+ this, SLOT(configureColumns(const QPoint&)));
+ headerView->setClickable(true);
+ headerView->setSortIndicatorShown(true);
+ headerView->setMovable(false);
+ sortByColumn(0, Qt::AscendingOrder);
+ setSortingEnabled(true);
+
+ if (!KdenliveSettings::showdescriptioncolumn()) hideColumn(1);
+ if (!KdenliveSettings::showratingcolumn()) hideColumn(2);
}
-ProjectListView::~ProjectListView() {
+ProjectListView::~ProjectListView()
+{
}
-void ProjectListView::editItem(QTreeWidgetItem * item, int column) {
- kDebug() << "//////////////// EDIT ITEM, COL: " << column;
+void ProjectListView::configureColumns(const QPoint& pos)
+{
+ KMenu popup(this);
+ popup.addTitle(i18nc("@title:menu", "Columns"));
+
+ QHeaderView* headerView = header();
+ 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);
+ action->setChecked(!headerView->isSectionHidden(i));
+ action->setData(i);
+ }
+
+ QAction* activatedAction = popup.exec(header()->mapToGlobal(pos));
+ if (activatedAction != 0) {
+ const bool show = activatedAction->isChecked();
+
+ // remember the changed column visibility in the settings
+ const int columnIndex = activatedAction->data().toInt();
+ switch (columnIndex) {
+ case 1:
+ KdenliveSettings::setShowdescriptioncolumn(show);
+ break;
+ case 2:
+ KdenliveSettings::setShowratingcolumn(show);
+ break;
+ default:
+ break;
+ }
+
+ // apply the changed column visibility
+ if (show) {
+ showColumn(columnIndex);
+ } else {
+ hideColumn(columnIndex);
+ }
+ }
}
// virtual
-void ProjectListView::contextMenuEvent(QContextMenuEvent * event) {
+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)
+{
+ QTreeWidgetItem *it = itemAt(event->pos());
+ if (!it) {
+ emit addClip();
+ return;
+ }
+ ProjectItem *item;
+ if (it->type() == PROJECTFOLDERTYPE) {
+ if ((columnAt(event->pos().x()) == 0)) QTreeWidget::mouseDoubleClickEvent(event);
+ return;
+ }
+ if (it->type() == PROJECTSUBCLIPTYPE) {
+ // subitem
+ if ((columnAt(event->pos().x()) == 1)) {
+ QTreeWidget::mouseDoubleClickEvent(event);
+ return;
+ }
+ item = static_cast <ProjectItem *>(it->parent());
+ } else item = static_cast <ProjectItem *>(it);
+
+ if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
+ if ((columnAt(event->pos().x()) == 0) && (item->clipType() == SLIDESHOW || item->clipType() == TEXT || item->clipType() == COLOR)) QTreeWidget::mouseDoubleClickEvent(event);
+ else if ((columnAt(event->pos().x()) == 1) && it->type() != PROJECTSUBCLIPTYPE) 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";
}
}
// 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 <FolderProjectItem *>(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);
- }
- QList <QUrl> list;
- list = event->mimeData()->urls();
- foreach(QUrl url, list) {
- emit addClip(url, groupName);
+ groupName = item->groupName();
+ groupId = item->clipId();
}
-
- } else if (event->mimeData()->hasText()) {
- QTreeWidgetItem *item = itemAt(event->pos());
+ emit addClip(event->mimeData()->urls(), groupName, groupId);
+ event->setDropAction(Qt::CopyAction);
+ event->accept();
+ return;
+ } else if (event->mimeData()->hasFormat("kdenlive/producerslist")) {
if (item) {
- if (item->parent()) item = item->parent();
- if (((ProjectItem *) item)->isGroup()) {
- //emit addClip(event->mimeData->text());
- kDebug() << "//////////////// DROPPED RIGHT 1 ";
- QList <QTreeWidgetItem *> 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);
+ //emit addClip(event->mimeData->text());
+ const QList <QTreeWidgetItem *> 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 <QString, QString> 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
- QList <QTreeWidgetItem *> list;
- list = selectedItems();
+ const QList <QTreeWidgetItem *> 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 <ProjectItem*>(parent->takeChild(parent->indexOfChild(it)));
+ if (clone) {
+ addTopLevelItem(clone);
+ clone->clearProperty("groupname");
+ clone->clearProperty("groupid");
+ }
}
}
}
+ } 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();
}
// 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::mouseReleaseEvent(QMouseEvent *event)
+{
+ QTreeWidget::mouseReleaseEvent(event);
+ QTreeWidgetItem *underMouse = itemAt(event->pos());
+ if (underMouse) emit focusMonitor();
+}
// 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()
< QApplication::startDragDistance())
return;
- {
- ProjectItem *clickItem = (ProjectItem *) itemAt(event->pos());
- if (clickItem) {
+ QTreeWidgetItem *it = itemAt(m_DragStartPosition);
+ if (!it) return;
+ if (it->type() == PROJECTSUBCLIPTYPE) {
+ // subitem
+ SubProjectItem *clickItem = static_cast <SubProjectItem *>(it);
+ if (clickItem && (clickItem->flags() & Qt::ItemIsDragEnabled)) {
+ ProjectItem *clip = static_cast <ProjectItem *>(it->parent());
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
- QDomDocument doc;
- QList <QTreeWidgetItem *> list;
- list = selectedItems();
+
+ 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<QPixmap>());
+ drag->setHotSpot(QPoint(0, 50));
+ drag->exec();
+ }
+ } else {
+ if (it && (it->flags() & Qt::ItemIsDragEnabled)) {
+ QDrag *drag = new QDrag(this);
+ QMimeData *mimeData = new QMimeData;
+ const QList <QTreeWidgetItem *> list = selectedItems();
QStringList ids;
- foreach(QTreeWidgetItem *item, list) {
- // TODO allow dragging of folders
- if (!((ProjectItem *) item)->isGroup())
- ids.append(QString::number(((ProjectItem *) item)->clipId()));
+ foreach(const QTreeWidgetItem *item, list) {
+ if (item->type() == PROJECTFOLDERTYPE) {
+ const int children = item->childCount();
+ for (int i = 0; i < children; i++) {
+ ids.append(static_cast <ProjectItem *>(item->child(i))->clipId());
+ }
+ } else {
+ const ProjectItem *clip = static_cast <const ProjectItem *>(item);
+ ids.append(clip->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(50 *16 / 9.0, 50));
+ drag->setPixmap(it->data(0, Qt::DecorationRole).value<QPixmap>());
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();
}
//event->accept();
}
}
-void ProjectListView::dragMoveEvent(QDragMoveEvent * event) {
- QTreeWidgetItem * item = itemAt(event->pos());
- event->setDropAction(Qt::IgnoreAction);
- //if (item) {
- event->setDropAction(Qt::MoveAction);
+// virtual
+void ProjectListView::dragMoveEvent(QDragMoveEvent * event)
+{
+ //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
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;
}