]> git.sesse.net Git - kdenlive/blobdiff - src/projectlist.cpp
* Fix crash when using razor tool while playing
[kdenlive] / src / projectlist.cpp
index 217e0b1ba9364d1e4ca4c31830cd9e47c1536afc..aa012b2fca5ebbad7aa0d55fa3bf2c229610ce19 100644 (file)
@@ -41,6 +41,7 @@
 #include "kdenlivesettings.h"
 #include "slideshowclip.h"
 #include "ui_colorclip_ui.h"
+#include "titlewidget.h"
 
 
 #include "definitions.h"
@@ -129,8 +130,10 @@ ProjectList::~ProjectList() {
 
 void ProjectList::slotEditClip() {
     ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
-    if (item && !item->isGroup()) emit clipSelected(item->referencedClip());
-    emit showClipProperties(item->referencedClip());
+    if (item && !item->isGroup()) {
+        emit clipSelected(item->referencedClip());
+        emit showClipProperties(item->referencedClip());
+    }
 }
 
 
@@ -140,10 +143,17 @@ void ProjectList::setRenderer(Render *projectRender) {
 }
 
 void ProjectList::slotClipSelected() {
-    ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
-    if (item && !item->isGroup()) {
-        m_selectedItem = item;
-        emit clipSelected(item->referencedClip());
+    if (listView->currentItem()) {
+        ProjectItem *clip = static_cast <ProjectItem*>(listView->currentItem());
+        if (!clip->isGroup()) {
+            m_selectedItem = clip;
+            emit clipSelected(clip->referencedClip());
+        }
+        m_editAction->setEnabled(true);
+        m_deleteAction->setEnabled(true);
+    } else {
+        m_editAction->setEnabled(false);
+        m_deleteAction->setEnabled(false);
     }
 }
 
@@ -158,7 +168,7 @@ void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QSt
 
 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties) {
     if (!clip) return;
-    clip->setProperties(properties);
+    if (!clip->isGroup()) clip->setProperties(properties);
     if (properties.contains("description")) {
         CLIPTYPE type = clip->clipType();
         clip->setText(2, properties.value("description"));
@@ -182,8 +192,14 @@ void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column) {
         QMap <QString, QString> props;
         props["description"] = item->text(2);
         slotUpdateClipProperties(clip, props);
-    } else if (column == 1 && clip->clipType() == FOLDER) {
+    } else if (column == 1 && clip->isGroup()) {
         m_doc->slotEditFolder(item->text(1), clip->groupName(), clip->clipId());
+        clip->setGroupName(item->text(1));
+        const int children = item->childCount();
+        for (int i = 0; i < children; i++) {
+            ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
+            child->setProperty("groupname", item->text(1));
+        }
     }
 }
 
@@ -194,29 +210,36 @@ void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item) {
     }
     m_editAction->setEnabled(enable);
     m_deleteAction->setEnabled(enable);
-
     m_menu->popup(pos);
 }
 
 void ProjectList::slotRemoveClip() {
     if (!listView->currentItem()) return;
-    ProjectItem *item = static_cast <ProjectItem *>(listView->currentItem());
     QList <QString> ids;
     QMap <QString, QString> folderids;
-    if (item->clipType() == FOLDER) folderids[item->groupName()] = item->clipId();
-    else ids << item->clipId();
-    if (item->numReferences() > 0) {
-        if (KMessageBox::questionYesNo(this, i18np("Delete clip <b>%2</b> ?<br>This will also remove the clip in timeline", "Delete clip <b>%2</b> ?<br>This will also remove its %1 clips in timeline", item->numReferences(), item->names().at(1)), i18n("Delete Clip")) != KMessageBox::Yes) return;
-    } else if (item->clipType() == FOLDER && item->childCount() > 0) {
-        int children = item->childCount();
-        if (KMessageBox::questionYesNo(this, i18n("Delete folder <b>%2</b> ?<br>This will also remove the %1 clips in that folder", children, item->names().at(1)), i18n("Delete Folder")) != KMessageBox::Yes) return;
-        for (int i = 0; i < children; ++i) {
-            ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
-            ids << child->clipId();
+    QList<QTreeWidgetItem *> selected = listView->selectedItems();
+    ProjectItem *item;
+    for (int i = 0; i < selected.count(); i++) {
+        item = static_cast <ProjectItem *>(selected.at(i));
+        if (item->isGroup()) folderids[item->groupName()] = item->clipId();
+        else ids << item->clipId();
+        if (item->numReferences() > 0) {
+            if (KMessageBox::questionYesNo(this, i18np("Delete clip <b>%2</b> ?<br>This will also remove the clip in timeline", "Delete clip <b>%2</b> ?<br>This will also remove its %1 clips in timeline", item->numReferences(), item->names().at(1)), i18n("Delete Clip")) != KMessageBox::Yes) return;
+        } else if (item->isGroup() && item->childCount() > 0) {
+            int children = item->childCount();
+            if (KMessageBox::questionYesNo(this, i18n("Delete folder <b>%2</b> ?<br>This will also remove the %1 clips in that folder", children, item->names().at(1)), i18n("Delete Folder")) != KMessageBox::Yes) return;
+            for (int i = 0; i < children; ++i) {
+                ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
+                ids << child->clipId();
+            }
         }
     }
     if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
     if (!folderids.isEmpty()) m_doc->deleteProjectFolder(folderids);
+    if (listView->topLevelItemCount() == 0) {
+        m_editAction->setEnabled(false);
+        m_deleteAction->setEnabled(false);
+    }
 }
 
 void ProjectList::selectItemById(const QString &clipId) {
@@ -249,7 +272,7 @@ void ProjectList::slotAddFolder(const QString foldername, const QString &clipId,
         QTreeWidgetItemIterator it(listView);
         while (*it) {
             item = static_cast <ProjectItem *>(*it);
-            if (item->clipType() == FOLDER && item->clipId() == clipId) {
+            if (item->isGroup() && item->clipId() == clipId) {
                 delete item;
                 break;
             }
@@ -257,18 +280,23 @@ void ProjectList::slotAddFolder(const QString foldername, const QString &clipId,
         }
     } else {
         if (edit) {
-            disconnect(listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotUpdateItemDescription(QTreeWidgetItem *, int)));
+            listView->blockSignals(true);
             ProjectItem *item;
             QTreeWidgetItemIterator it(listView);
             while (*it) {
                 item = static_cast <ProjectItem *>(*it);
-                if (item->clipType() == FOLDER && item->clipId() == clipId) {
-                    item->setText(1, foldername);
+                if (item->isGroup() && item->clipId() == clipId) {
+                    item->setGroupName(foldername);
+                    const int children = item->childCount();
+                    for (int i = 0; i < children; i++) {
+                        ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
+                        child->setProperty("groupname", foldername);
+                    }
                     break;
                 }
                 ++it;
             }
-            connect(listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotUpdateItemDescription(QTreeWidgetItem *, int)));
+            listView->blockSignals(false);
         } else {
             QStringList text;
             text << QString() << foldername;
@@ -278,10 +306,19 @@ void ProjectList::slotAddFolder(const QString foldername, const QString &clipId,
 }
 
 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) {
-    const QString parent = clip->toXML().attribute("groupid");
+    const QString parent = clip->getProperty("groupid");
     ProjectItem *item = NULL;
-    if (parent != 0) {
+    if (!parent.isEmpty()) {
         ProjectItem *parentitem = getItemById(parent);
+        if (!parentitem) {
+            QStringList text;
+            QString groupName = clip->getProperty("groupname");
+            if (groupName.isEmpty()) groupName = i18n("Folder");
+            text << QString() << groupName;
+            listView->blockSignals(true);
+            parentitem = new ProjectItem(listView, text, parent);
+            listView->blockSignals(false);
+        }
         if (parentitem) item = new ProjectItem(parentitem, clip);
     }
     if (item == NULL) item = new ProjectItem(listView, clip);
@@ -315,8 +352,20 @@ void ProjectList::updateAllClips() {
     while (*it) {
         ProjectItem *item = static_cast <ProjectItem *>(*it);
         if (!item->isGroup()) {
-            if (item->referencedClip()->producer() == NULL) emit getFileProperties(item->referencedClip()->toXML(), item->referencedClip()->getId());
-            else {
+            if (item->referencedClip()->producer() == NULL) {
+                DocClipBase *clip = item->referencedClip();
+                if (clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
+                    // regenerate text clip image if required
+                    TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
+                    QDomDocument doc;
+                    doc.setContent(clip->getProperty("xmldata"));
+                    dia_ui->setXml(doc);
+                    QPixmap pix = dia_ui->renderedPixmap();
+                    pix.save(clip->fileURL().path());
+                    delete dia_ui;
+                }
+                emit getFileProperties(clip->toXML(), clip->getId());
+            } else {
                 slotRefreshClipThumbnail(item, false);
                 item->changeDuration(item->referencedClip()->producer()->get_playtime());
             }
@@ -331,20 +380,20 @@ void ProjectList::slotAddClip(QUrl givenUrl, QString group) {
     if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!!  NO CMD STK";
     KUrl::List list;
     if (givenUrl.isEmpty()) {
-        list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), "application/vnd.kde.kdenlive application/vnd.westley.scenelist application/flv application/vnd.rn-realmedia video/x-dv video/dv video/x-msvideo video/mpeg video/x-ms-wmv audio/mpeg audio/x-mp3 audio/x-wav application/ogg video/mp4 video/quicktime image/gif image/jpeg image/png image/x-bmp image/svg+xml image/tiff image/x-xcf-gimp image/x-vnd.adobe.photoshop image/x-pcx image/x-exr video/mlt-playlist", this);
+        list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), "application/x-kdenlive application/x-flash-video application/vnd.rn-realmedia video/x-dv video/dv video/x-msvideo video/mpeg video/x-ms-wmv audio/mpeg audio/x-mp3 audio/x-wav application/ogg video/mp4 video/quicktime image/gif image/jpeg image/png image/x-bmp image/svg+xml image/tiff image/x-xcf-gimp image/x-vnd.adobe.photoshop image/x-pcx image/x-exr video/mlt-playlist audio/x-flac audio/mp4", this);
     } else list.append(givenUrl);
     if (list.isEmpty()) return;
 
     QString groupId = QString();
     if (group.isEmpty()) {
         ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
-        if (item && item->clipType() != FOLDER) {
+        if (item && !item->isGroup()) {
             while (item->parent()) {
                 item = static_cast <ProjectItem*>(item->parent());
-                if (item->clipType() == FOLDER) break;
+                if (item->isGroup()) break;
             }
         }
-        if (item && item->clipType() == FOLDER) {
+        if (item && item->isGroup()) {
             group = item->groupName();
             groupId = item->clipId();
         }
@@ -378,13 +427,13 @@ void ProjectList::slotAddColorClip() {
         QString group = QString();
         QString groupId = QString();
         ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
-        if (item && item->clipType() != FOLDER) {
+        if (item && !item->isGroup()) {
             while (item->parent()) {
                 item = static_cast <ProjectItem*>(item->parent());
-                if (item->clipType() == FOLDER) break;
+                if (item->isGroup()) break;
             }
         }
-        if (item && item->clipType() == FOLDER) {
+        if (item && item->isGroup()) {
             group = item->groupName();
             groupId = item->clipId();
         }
@@ -405,13 +454,13 @@ void ProjectList::slotAddSlideshowClip() {
         QString group = QString();
         QString groupId = QString();
         ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
-        if (item && item->clipType() != FOLDER) {
+        if (item && !item->isGroup()) {
             while (item->parent()) {
                 item = static_cast <ProjectItem*>(item->parent());
-                if (item->clipType() == FOLDER) break;
+                if (item->isGroup()) break;
             }
         }
-        if (item && item->clipType() == FOLDER) {
+        if (item && item->isGroup()) {
             group = item->groupName();
             groupId = item->clipId();
         }
@@ -425,13 +474,13 @@ void ProjectList::slotAddTitleClip() {
     QString group = QString();
     QString groupId = QString();
     ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
-    if (item && item->clipType() != FOLDER) {
+    if (item && !item->isGroup()) {
         while (item->parent()) {
             item = static_cast <ProjectItem*>(item->parent());
-            if (item->clipType() == FOLDER) break;
+            if (item->isGroup()) break;
         }
     }
-    if (item && item->clipType() == FOLDER) {
+    if (item && item->isGroup()) {
         group = item->groupName();
         groupId = item->clipId();
     }
@@ -514,6 +563,8 @@ void ProjectList::slotSelectClip(const QString &ix) {
     if (p) {
         listView->setCurrentItem(p);
         listView->scrollToItem(p);
+        m_editAction->setEnabled(true);
+        m_deleteAction->setEnabled(true);
     }
 }