#include <KDebug>
#include <KMenu>
-#include <KLocale>
+#include <KLocalizedString>
#include <QApplication>
#include <QHeaderView>
setAlternatingRowColors(true);
setDragEnabled(true);
setAcceptDrops(true);
+ setFrameShape(QFrame::NoFrame);
+ setRootIsDecorated(true);
+ updateStyleSheet();
- setColumnCount(3);
+ setColumnCount(4);
QStringList headers;
- headers << i18n("Clip") << i18n("Description") << i18n("Rating");
+ headers << i18n("Clip") << i18n("Description") << i18n("Rating") << i18n("Date");
setHeaderLabels(headers);
-
+ setIndentation(12);
+
QHeaderView* headerView = header();
headerView->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(headerView, SIGNAL(customContextMenuRequested(const QPoint&)),
- this, SLOT(configureColumns(const QPoint&)));
+ connect(headerView, SIGNAL(customContextMenuRequested(QPoint)),
+ this, SLOT(configureColumns(QPoint)));
+ 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);
+ if (!KdenliveSettings::showdatecolumn()) hideColumn(3);
}
ProjectListView::~ProjectListView()
{
}
+void ProjectListView::updateStyleSheet()
+{
+ QString style = "QTreeView::branch:has-siblings:!adjoins-item{border-image: none;border:0px} \
+ QTreeView::branch:has-siblings:adjoins-item {border-image: none;border:0px} \
+ QTreeView::branch:!has-children:!has-siblings:adjoins-item {border-image: none;border:0px} \
+ QTreeView::branch:has-children:!has-siblings:closed,QTreeView::branch:closed:has-children:has-siblings { \
+ border-image: none;image: url(:/images/stylesheet-branch-closed.png);} \
+ QTreeView::branch:open:has-children:!has-siblings,QTreeView::branch:open:has-children:has-siblings { \
+ border-image: none;image: url(:/images/stylesheet-branch-open.png);}";
+ setStyleSheet(style);
+}
+
+void ProjectListView::processLayout()
+{
+ executeDelayedItemsLayout();
+}
+
void ProjectListView::configureColumns(const QPoint& pos)
{
KMenu popup(this);
case 2:
KdenliveSettings::setShowratingcolumn(show);
break;
+ case 3:
+ KdenliveSettings::setShowdatecolumn(show);
+ break;
default:
break;
}
emit requestMenu(event->globalPos(), itemAt(event->pos()));
}
+void ProjectListView::slotCollapsed(QTreeWidgetItem *item)
+{
+ if (item->type() == PROJECTFOLDERTYPE) {
+ blockSignals(true);
+ static_cast <FolderProjectItem *>(item)->switchIcon();
+ blockSignals(false);
+ }
+}
+
+void ProjectListView::slotExpanded(QTreeWidgetItem *item)
+{
+ if (item->type() == PROJECTFOLDERTYPE) {
+ blockSignals(true);
+ static_cast <FolderProjectItem *>(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 {
+ // pass the event on to the parent class
+ return QTreeWidget::eventFilter(obj, event);
+ }
+}
+
// virtual
void ProjectListView::mouseDoubleClickEvent(QMouseEvent * event)
{
QTreeWidgetItem *it = itemAt(event->pos());
if (!it) {
+ emit pauseMonitor();
emit addClip();
return;
}
ProjectItem *item;
if (it->type() == PROJECTFOLDERTYPE) {
- if ((columnAt(event->pos().x()) == 0)) QTreeWidget::mouseDoubleClickEvent(event);
+ if ((columnAt(event->pos().x()) == 0)) {
+ QPixmap pix = qVariantValue<QPixmap>(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;
- }
+ 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)
-{
- if (event->mimeData()->hasUrls() || event->mimeData()->hasText()) {
- kDebug() << "//////////////// DRAG ENTR OK";
+ int column = columnAt(event->pos().x());
+ if (column == 0 && (item->clipType() == SLIDESHOW || item->clipType() == TEXT || item->clipType() == COLOR || it->childCount() > 0)) {
+ QPixmap pix = qVariantValue<QPixmap>(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;
}
- event->acceptProposedAction();
+ emit showProperties(item->referencedClip());
}
+
// virtual
void ProjectListView::dropEvent(QDropEvent *event)
{
emit addClip(event->mimeData()->urls(), groupName, groupId);
event->setDropAction(Qt::CopyAction);
event->accept();
+ QTreeWidget::dropEvent(event);
return;
} else if (event->mimeData()->hasFormat("kdenlive/producerslist")) {
if (item) {
if (it->type() == PROJECTCLIPTYPE) {
if (it->parent()) clone = (ProjectItem*) it->parent()->takeChild(it->parent()->indexOfChild(it));
else clone = (ProjectItem*) takeTopLevelItem(indexOfTopLevelItem(it));
- if (clone) {
+ if (clone && item) {
item->addChild(clone);
QMap <QString, QString> props;
props.insert("groupname", item->groupName());
const QList <QTreeWidgetItem *> list = selectedItems();
ProjectItem *clone;
foreach(QTreeWidgetItem *it, list) {
+ if (it->type() != PROJECTCLIPTYPE) continue;
QTreeWidgetItem *parent = it->parent();
if (parent/* && ((ProjectItem *) it)->clipId() < 10000*/) {
kDebug() << "++ item parent: " << parent->text(1);
}
}
}
+ 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();
+ if (event->source() == this) {
+ event->setDropAction(Qt::MoveAction);
+ event->accept();
+ } else {
+ event->acceptProposedAction();
+ }
+ QTreeWidget::dropEvent(event);
}
// virtual
m_DragStartPosition = event->pos();
m_dragStarted = true;
/*QTreeWidgetItem *underMouse = itemAt(event->pos());
- if (underMouse && underMouse->isSelected()) emit focusMonitor();*/
+ ProjectItem *item = static_cast<ProjectItem *>(underMouse);
+ if (item) {
+ QRect itemRect = visualItemRect(item);
+ if (item->underJobMenu(itemRect, event->pos())) {
+ emit display
+ }
+
+ && underMouse->isSelected()) emit focusMonitor()
+ }*/
}
QTreeWidget::mousePressEvent(event);
}
{
QTreeWidget::mouseReleaseEvent(event);
QTreeWidgetItem *underMouse = itemAt(event->pos());
- if (underMouse) emit focusMonitor();
+ if (underMouse) emit focusMonitor(true);
}
// virtual
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;
-
- 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(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 (it && (it->flags() & Qt::ItemIsDragEnabled)) {
+ QDrag *drag = new QDrag(this);
+ QMimeData *mimeData = new QMimeData;
+ const QList <QTreeWidgetItem *> list = selectedItems();
+ QStringList ids;
+ 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 if (item->type() == PROJECTSUBCLIPTYPE) {
+ const ProjectItem *parentclip = static_cast <const ProjectItem *>(item->parent());
+ const SubProjectItem *clickItem = static_cast <const SubProjectItem *>(item);
+ QPoint p = clickItem->zone();
+ QString data = parentclip->clipId();
+ data.append("/" + QString::number(p.x()));
+ data.append("/" + QString::number(p.y()));
+ ids.append(data);
+ } 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(it->data(0, Qt::DecorationRole).value<QPixmap>());
- drag->setHotSpot(QPoint(0, 50));
- drag->exec();
}
- //event->accept();
+ 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(it->data(0, Qt::DecorationRole).value<QPixmap>());
+ drag->setHotSpot(QPoint(0, 40));
+ drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
}
}
// virtual
-void ProjectListView::dragMoveEvent(QDragMoveEvent * event)
+void ProjectListView::dragLeaveEvent(QDragLeaveEvent *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();
+ QTreeWidget::dragLeaveEvent(event);
}
QStringList ProjectListView::mimeTypes() const
Qt::DropActions ProjectListView::supportedDropActions() const
{
// returns what actions are supported when dropping
- return Qt::MoveAction;
+ return Qt::MoveAction | Qt::CopyAction;
}
#include "projectlistview.moc"