]> git.sesse.net Git - kdenlive/blobdiff - src/projectlistview.cpp
Improve proxy handling (missing or broken proxies)
[kdenlive] / src / projectlistview.cpp
index 30e0f4355795e2db9058f61b808fc5dfc70fdb75..450670368024aabb093cec7b639ef13620d981ee 100644 (file)
@@ -42,23 +42,37 @@ ProjectListView::ProjectListView(QWidget *parent) :
     setAlternatingRowColors(true);
     setDragEnabled(true);
     setAcceptDrops(true);
+    setFrameShape(QFrame::NoFrame);
+    setRootIsDecorated(true);
 
+    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);
 
     setColumnCount(3);
     QStringList headers;
     headers << i18n("Clip") << i18n("Description") << i18n("Rating");
     setHeaderLabels(headers);
-
+    setIndentation(12);
+    
     QHeaderView* headerView = header();
     headerView->setContextMenuPolicy(Qt::CustomContextMenu);
     connect(headerView, SIGNAL(customContextMenuRequested(const QPoint&)),
             this, SLOT(configureColumns(const 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);
 }
@@ -67,6 +81,11 @@ ProjectListView::~ProjectListView()
 {
 }
 
+void ProjectListView::processLayout()
+{
+    executeDelayedItemsLayout();
+}
+
 void ProjectListView::configureColumns(const QPoint& pos)
 {
     KMenu popup(this);
@@ -113,6 +132,45 @@ void ProjectListView::contextMenuEvent(QContextMenuEvent * event)
     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)
 {
@@ -123,29 +181,51 @@ void ProjectListView::mouseDoubleClickEvent(QMouseEvent * event)
     }
     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;
+        }
         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;
+        }
     }
-    event->acceptProposedAction();
+    if ((column == 1) && it->type() != PROJECTSUBCLIPTYPE) {
+        QTreeWidget::mouseDoubleClickEvent(event);
+        return;
+    }
+    emit showProperties(item->referencedClip());
 }
 
+
 // virtual
 void ProjectListView::dropEvent(QDropEvent *event)
 {
@@ -165,6 +245,7 @@ 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) {
@@ -203,11 +284,13 @@ 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
@@ -259,7 +342,7 @@ void ProjectListView::mouseMoveEvent(QMouseEvent *event)
             data.append(list.join(";").toUtf8());
             mimeData->setData("kdenlive/clip", data);
             drag->setMimeData(mimeData);
-            drag->setPixmap(clickItem->icon(0).pixmap(iconSize()));
+            drag->setPixmap(clickItem->data(0, Qt::DecorationRole).value<QPixmap>());
             drag->setHotSpot(QPoint(0, 50));
             drag->exec();
         }
@@ -287,7 +370,7 @@ void ProjectListView::mouseMoveEvent(QMouseEvent *event)
             //mimeData->setText(ids.join(";")); //doc.toString());
             //mimeData->setImageData(image);
             drag->setMimeData(mimeData);
-            drag->setPixmap(it->icon(0).pixmap(iconSize()));
+            drag->setPixmap(it->data(0, Qt::DecorationRole).value<QPixmap>());
             drag->setHotSpot(QPoint(0, 50));
             drag->exec();
         }
@@ -296,14 +379,11 @@ void ProjectListView::mouseMoveEvent(QMouseEvent *event)
 }
 
 // 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
@@ -322,7 +402,7 @@ 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"