X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fprojectlist.cpp;h=fb099e49153d65e1e4d5e89290fd8639f3192634;hb=459decee5e330552ef73b7cb363dbbe38fdc7e87;hp=0aafc1de694f2b0bc827e2412798f077550a5b08;hpb=45a4a9543b182b7e91166cb14f97054d144d267a;p=kdenlive diff --git a/src/projectlist.cpp b/src/projectlist.cpp index 0aafc1de..fb099e49 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -19,7 +19,6 @@ #include "projectlist.h" #include "projectitem.h" -#include "subprojectitem.h" #include "addfoldercommand.h" #include "kdenlivesettings.h" #include "slideshowclip.h" @@ -33,6 +32,7 @@ #include "kthumb.h" #include "projectlistview.h" #include "editclipcommand.h" +#include "editclipcutcommand.h" #include "editfoldercommand.h" #include "addclipcutcommand.h" @@ -46,10 +46,11 @@ #include #include #include - +#ifdef NEPOMUK #include #include //#include +#endif #include #include @@ -83,6 +84,8 @@ ProjectList::ProjectList(QWidget *parent) : KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine(this); m_toolbar = new QToolBar("projectToolBar", this); m_toolbar->addWidget(searchView); + int s = style()->pixelMetric(QStyle::PM_SmallIconSize); + m_toolbar->setIconSize(QSize(s, s)); searchView->setTreeWidget(m_listView); m_addButton = new QToolButton(m_toolbar); @@ -98,7 +101,7 @@ ProjectList::ProjectList(QWidget *parent) : m_queueTimer.setSingleShot(true); - + connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified())); connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected())); connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected())); connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor())); @@ -111,7 +114,7 @@ ProjectList::ProjectList(QWidget *parent) : m_listViewDelegate = new ItemDelegate(m_listView); m_listView->setItemDelegate(m_listViewDelegate); - +#ifdef NEPOMUK if (KdenliveSettings::activate_nepomuk()) { Nepomuk::ResourceManager::instance()->init(); if (!Nepomuk::ResourceManager::instance()->initialized()) { @@ -119,6 +122,7 @@ ProjectList::ProjectList(QWidget *parent) : KdenliveSettings::setActivate_nepomuk(false); } } +#endif } ProjectList::~ProjectList() @@ -200,24 +204,89 @@ void ProjectList::setHeaderInfo(const QByteArray &state) void ProjectList::slotEditClip() { + QList list = m_listView->selectedItems(); + if (list.count() > 1) { + editClipSelection(list); + return; + } ProjectItem *item; - if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) { + if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return; + if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) { item = static_cast (m_listView->currentItem()->parent()); } else item = static_cast (m_listView->currentItem()); if (!(item->flags() & Qt::ItemIsDragEnabled)) return; - if (item && !item->isGroup()) { + if (item) { emit clipSelected(item->referencedClip()); emit showClipProperties(item->referencedClip()); } } +void ProjectList::editClipSelection(QList list) +{ + // Gather all common properties + QMap commonproperties; + QList clipList; + commonproperties.insert("force_aspect_ratio", "-"); + commonproperties.insert("force_fps", "-"); + commonproperties.insert("force_progressive", "-"); + commonproperties.insert("threads", "-"); + commonproperties.insert("video_index", "-"); + commonproperties.insert("audio_index", "-"); + + bool allowDurationChange = true; + int commonDuration = -1; + ProjectItem *item; + for (int i = 0; i < list.count(); i++) { + item = NULL; + if (list.at(i)->type() == PROJECTFOLDERTYPE) continue; + if (list.at(i)->type() == PROJECTSUBCLIPTYPE) { + item = static_cast (list.at(i)->parent()); + } else item = static_cast (list.at(i)); + if (!(item->flags() & Qt::ItemIsDragEnabled)) continue; + if (item) { + // check properties + DocClipBase *clip = item->referencedClip(); + if (clipList.contains(clip)) continue; + if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT) { + allowDurationChange = false; + } + if (allowDurationChange && commonDuration != 0) { + if (commonDuration == -1) { + commonDuration = clip->duration().frames(m_fps); + } else if (commonDuration != clip->duration().frames(m_fps)) { + commonDuration = 0; + } + } + clipList.append(clip); + QMap clipprops = clip->properties(); + QMapIterator p(commonproperties); + while (p.hasNext()) { + p.next(); + if (p.value().isEmpty()) continue; + if (clipprops.contains(p.key())) { + if (p.value() == "-") commonproperties.insert(p.key(), clipprops.value(p.key())); + else if (p.value() != clipprops.value(p.key())) commonproperties.insert(p.key(), QString()); + } else commonproperties.insert(p.key(), QString()); + } + } + } + if (allowDurationChange) commonproperties.insert("out", QString::number(commonDuration)); + QMapIterator p(commonproperties); + while (p.hasNext()) { + p.next(); + kDebug() << "Result: " << p.key() << " = " << p.value(); + } + emit showClipProperties(clipList, commonproperties); +} + void ProjectList::slotOpenClip() { ProjectItem *item; + if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return; if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) { item = static_cast (m_listView->currentItem()->parent()); } else item = static_cast (m_listView->currentItem()); - if (item && !item->isGroup()) { + if (item) { if (item->clipType() == IMAGE) { if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog")); else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path()); @@ -235,12 +304,12 @@ void ProjectList::cleanup() QTreeWidgetItemIterator it(m_listView); ProjectItem *item; while (*it) { - if ((*it)->type() == QTreeWidgetItem::UserType + 1) { + if ((*it)->type() != PROJECTCLIPTYPE) { it++; continue; } item = static_cast (*it); - if (!item->isGroup() && item->numReferences() == 0) item->setSelected(true); + if (item->numReferences() == 0) item->setSelected(true); it++; } slotRemoveClip(); @@ -253,23 +322,23 @@ void ProjectList::trashUnusedClips() QStringList ids; QStringList urls; while (*it) { - if ((*it)->type() == QTreeWidgetItem::UserType + 1) { + if ((*it)->type() != PROJECTCLIPTYPE) { it++; continue; } item = static_cast (*it); - if (!item->isGroup() && item->numReferences() == 0) { + if (item->numReferences() == 0) { ids << item->clipId(); KUrl url = item->clipUrl(); - if (!url.isEmpty()) urls << url.path(); + if (!url.isEmpty() && !urls.contains(url.path())) urls << url.path(); } it++; } - urls.removeDuplicates(); + // Check that we don't use the URL in another clip QTreeWidgetItemIterator it2(m_listView); while (*it2) { - if ((*it2)->type() == QTreeWidgetItem::UserType + 1) { + if ((*it2)->type() != PROJECTCLIPTYPE) { it2++; continue; } @@ -294,9 +363,9 @@ void ProjectList::slotReloadClip(const QString &id) else selected.append(getItemById(id)); ProjectItem *item; for (int i = 0; i < selected.count(); i++) { - if (selected.at(i)->type() == QTreeWidgetItem::UserType + 1) continue; + if (selected.at(i)->type() != PROJECTCLIPTYPE) continue; item = static_cast (selected.at(i)); - if (item && !item->isGroup()) { + if (item) { if (item->clipType() == IMAGE) { item->referencedClip()->producer()->set("force_reload", 1); } else if (item->clipType() == TEXT) { @@ -304,7 +373,7 @@ void ProjectList::slotReloadClip(const QString &id) } //requestClipInfo(item->toXml(), item->clipId(), true); // Clear the file_hash value, which will cause a complete reload of the clip - emit getFileProperties(item->toXml(), item->clipId(), true); + emit getFileProperties(item->toXml(), item->clipId(), m_listView->iconSize().height(), true); } } } @@ -312,36 +381,47 @@ void ProjectList::slotReloadClip(const QString &id) void ProjectList::setRenderer(Render *projectRender) { m_render = projectRender; - m_listView->setIconSize(QSize(40 * m_render->dar(), 40)); + m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2)); } void ProjectList::slotClipSelected() { if (m_listView->currentItem()) { - ProjectItem *clip; - if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) { - // this is a sub item, use base clip - clip = static_cast (m_listView->currentItem()->parent()); - if (clip == NULL) kDebug() << "-----------ERROR"; - SubProjectItem *sub = static_cast (m_listView->currentItem()); - emit clipSelected(clip->referencedClip(), sub->zone()); - return; - } - clip = static_cast (m_listView->currentItem()); - if (!clip->isGroup()) { - emit clipSelected(clip->referencedClip()); + if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) { + emit clipSelected(NULL); + m_editAction->setEnabled(false); + m_deleteAction->setEnabled(true); + m_openAction->setEnabled(false); + m_reloadAction->setEnabled(false); + m_transcodeAction->setEnabled(false); + } else { + ProjectItem *clip; + if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) { + // this is a sub item, use base clip + m_deleteAction->setEnabled(true); + clip = static_cast (m_listView->currentItem()->parent()); + if (clip == NULL) kDebug() << "-----------ERROR"; + SubProjectItem *sub = static_cast (m_listView->currentItem()); + emit clipSelected(clip->referencedClip(), sub->zone()); + m_transcodeAction->setEnabled(false); + return; + } + clip = static_cast (m_listView->currentItem()); + if (clip) emit clipSelected(clip->referencedClip()); + m_editAction->setEnabled(true); + m_deleteAction->setEnabled(true); + m_reloadAction->setEnabled(true); + m_transcodeAction->setEnabled(true); + if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) { + m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp())); + m_openAction->setEnabled(true); + } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) { + m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp())); + m_openAction->setEnabled(true); + } else m_openAction->setEnabled(false); + // Display relevant transcoding actions only + adjustTranscodeActions(clip); } - m_editAction->setEnabled(true); - m_deleteAction->setEnabled(true); - m_reloadAction->setEnabled(true); - m_transcodeAction->setEnabled(true); - if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) { - m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp())); - m_openAction->setEnabled(true); - } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) { - m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp())); - m_openAction->setEnabled(true); - } else m_openAction->setEnabled(false); } else { emit clipSelected(NULL); m_editAction->setEnabled(false); @@ -352,6 +432,27 @@ void ProjectList::slotClipSelected() } } +void ProjectList::adjustTranscodeActions(ProjectItem *clip) const +{ + if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST) { + m_transcodeAction->setEnabled(false); + return; + } + m_transcodeAction->setEnabled(true); + QList transcodeActions = m_transcodeAction->actions(); + QStringList data; + QString condition; + for (int i = 0; i < transcodeActions.count(); i++) { + data = transcodeActions.at(i)->data().toStringList(); + if (data.count() > 2) { + condition = data.at(2); + if (condition.startsWith("vcodec")) transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section("=", 1, 1))); + else if (condition.startsWith("acodec")) transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section("=", 1, 1))); + } + } + +} + void ProjectList::slotPauseMonitor() { if (m_render) m_render->pause(); @@ -362,7 +463,7 @@ void ProjectList::slotUpdateClipProperties(const QString &id, QMap properties) { if (!clip) return; - if (!clip->isGroup()) clip->setProperties(properties); + clip->setProperties(properties); if (properties.contains("name")) { m_listView->blockSignals(true); - clip->setText(1, properties.value("name")); + clip->setText(0, properties.value("name")); m_listView->blockSignals(false); emit clipNameChanged(clip->clipId(), properties.value("name")); } if (properties.contains("description")) { CLIPTYPE type = clip->clipType(); m_listView->blockSignals(true); - clip->setText(2, properties.value("description")); + clip->setText(1, properties.value("description")); m_listView->blockSignals(false); +#ifdef NEPOMUK if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) { // Use Nepomuk system to store clip description Nepomuk::Resource f(clip->clipUrl().path()); f.setDescription(properties.value("description")); } +#endif emit projectModified(); } } void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column) { - if (item->type() == QTreeWidgetItem::UserType + 1) { + if (item->type() == PROJECTSUBCLIPTYPE) { // this is a sub-item + if (column == 1) { + // user edited description + SubProjectItem *sub = static_cast (item); + ProjectItem *item = static_cast (sub->parent()); + EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true); + m_commandStack->push(command); + //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1)); + } + return; + } + if (item->type() == PROJECTFOLDERTYPE) { + if (column != 0) return; + FolderProjectItem *folder = static_cast (item); + editFolder(item->text(0), folder->groupName(), folder->clipId()); + folder->setGroupName(item->text(0)); + m_doc->clipManager()->addFolder(folder->clipId(), item->text(0)); + const int children = item->childCount(); + for (int i = 0; i < children; i++) { + ProjectItem *child = static_cast (item->child(i)); + child->setProperty("groupname", item->text(0)); + } return; } ProjectItem *clip = static_cast (item); - if (column == 2) { + if (column == 1) { if (clip->referencedClip()) { QMap oldprops; QMap newprops; oldprops["description"] = clip->referencedClip()->getProperty("description"); - newprops["description"] = item->text(2); + newprops["description"] = item->text(1); if (clip->clipType() == TEXT) { // This is a text template clip, update the image /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata")); newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/ oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext")); - newprops.insert("templatetext", item->text(2)); + newprops.insert("templatetext", item->text(1)); } slotUpdateClipProperties(clip->clipId(), newprops); EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false); m_commandStack->push(command); } - } else if (column == 1) { - if (clip->isGroup()) { - editFolder(item->text(1), clip->groupName(), clip->clipId()); - clip->setGroupName(item->text(1)); - m_doc->clipManager()->addFolder(clip->clipId(), item->text(1)); - const int children = item->childCount(); - for (int i = 0; i < children; i++) { - ProjectItem *child = static_cast (item->child(i)); - child->setProperty("groupname", item->text(1)); - } - } else { - if (clip->referencedClip()) { - QMap oldprops; - QMap newprops; - oldprops["name"] = clip->referencedClip()->getProperty("name"); - newprops["name"] = item->text(1); - slotUpdateClipProperties(clip, newprops); - emit projectModified(); - EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false); - m_commandStack->push(command); - } + } else if (column == 0) { + if (clip->referencedClip()) { + QMap oldprops; + QMap newprops; + oldprops["name"] = clip->referencedClip()->getProperty("name"); + newprops["name"] = item->text(0); + slotUpdateClipProperties(clip, newprops); + emit projectModified(); + EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false); + m_commandStack->push(command); } } } @@ -457,17 +570,23 @@ void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item) m_reloadAction->setEnabled(enable); m_transcodeAction->setEnabled(enable); if (enable) { - ProjectItem *clip; - if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) { + ProjectItem *clip = NULL; + if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) { clip = static_cast (item->parent()); - } else clip = static_cast (item); - if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) { + m_transcodeAction->setEnabled(false); + } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) { + clip = static_cast (item); + // Display relevant transcoding actions only + adjustTranscodeActions(clip); + } else m_transcodeAction->setEnabled(false); + if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) { m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp())); m_openAction->setEnabled(true); - } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) { + } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) { m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp())); m_openAction->setEnabled(true); } else m_openAction->setEnabled(false); + } else m_openAction->setEnabled(false); m_menu->popup(pos); } @@ -483,27 +602,31 @@ void ProjectList::slotRemoveClip() delCommand->setText(i18n("Delete Clip Zone")); for (int i = 0; i < selected.count(); i++) { - if (selected.at(i)->type() == QTreeWidgetItem::UserType + 1) { + if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) { // subitem SubProjectItem *sub = static_cast (selected.at(i)); ProjectItem *item = static_cast (sub->parent()); - new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), true, delCommand); - continue; - } - ProjectItem *item = static_cast (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 %2?
This will also remove the clip in timeline", "Delete clip %2?
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, i18np("Delete folder %2?
This will also remove the clip in that folder", "Delete folder %2?
This will also remove the %1 clips in that folder", children, item->names().at(1)), i18n("Delete Folder")) != KMessageBox::Yes) return; + new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand); + } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) { + // folder + FolderProjectItem *folder = static_cast (selected.at(i)); + folderids[folder->groupName()] = folder->clipId(); + int children = folder->childCount(); + + if (children > 0 && KMessageBox::questionYesNo(this, i18np("Delete folder %2?
This will also remove the clip in that folder", "Delete folder %2?
This will also remove the %1 clips in that folder", children, folder->text(1)), i18n("Delete Folder")) != KMessageBox::Yes) return; for (int i = 0; i < children; ++i) { - ProjectItem *child = static_cast (item->child(i)); + ProjectItem *child = static_cast (folder->child(i)); ids << child->clipId(); } + } else { + ProjectItem *item = static_cast (selected.at(i)); + ids << item->clipId(); + if (item->numReferences() > 0) { + if (KMessageBox::questionYesNo(this, i18np("Delete clip %2?
This will also remove the clip in timeline", "Delete clip %2?
This will also remove its %1 clips in timeline", item->numReferences(), item->names().at(1)), i18n("Delete Clip")) != KMessageBox::Yes) return; + } } } + if (delCommand->childCount() == 0) delete delCommand; else m_commandStack->push(delCommand); if (!ids.isEmpty()) m_doc->deleteProjectClip(ids); @@ -555,14 +678,14 @@ void ProjectList::slotAddFolder() void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit) { if (remove) { - ProjectItem *item = getFolderItemById(clipId); + FolderProjectItem *item = getFolderItemById(clipId); if (item) { m_doc->clipManager()->deleteFolder(clipId); delete item; } } else { if (edit) { - ProjectItem *item = getFolderItemById(clipId); + FolderProjectItem *item = getFolderItemById(clipId); if (item) { m_listView->blockSignals(true); item->setGroupName(foldername); @@ -576,13 +699,14 @@ void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, } } else { QStringList text; - text << QString() << foldername; + text << foldername; m_listView->blockSignals(true); - m_listView->setCurrentItem(new ProjectItem(m_listView, text, clipId)); + m_listView->setCurrentItem(new FolderProjectItem(m_listView, text, clipId)); m_doc->clipManager()->addFolder(clipId, foldername); m_listView->blockSignals(false); } } + m_doc->setModified(true); } @@ -597,7 +721,6 @@ void ProjectList::deleteProjectFolder(QMap map) new AddFolderCommand(this, i.key(), i.value(), false, delCommand); } m_commandStack->push(delCommand); - m_doc->setModified(true); } void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) @@ -615,14 +738,14 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) const QString parent = clip->getProperty("groupid"); ProjectItem *item = NULL; if (!parent.isEmpty()) { - ProjectItem *parentitem = getFolderItemById(parent); + FolderProjectItem *parentitem = getFolderItemById(parent); if (!parentitem) { QStringList text; QString groupName = clip->getProperty("groupname"); //kDebug() << "Adding clip to new group: " << groupName; if (groupName.isEmpty()) groupName = i18n("Folder"); - text << QString() << groupName; - parentitem = new ProjectItem(m_listView, text, parent); + text << groupName; + parentitem = new FolderProjectItem(m_listView, text, parent); } else { //kDebug() << "Adding clip to existing group: " << parentitem->groupName(); } @@ -634,27 +757,27 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) if (getProperties == false && !clip->getClipHash().isEmpty()) { QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png"; if (QFile::exists(cachedPixmap)) { - item->setIcon(0, QPixmap(cachedPixmap)); + item->setData(0, Qt::DecorationRole, QPixmap(cachedPixmap)); } } - +#ifdef NEPOMUK if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) { // if file has Nepomuk comment, use it Nepomuk::Resource f(url.path()); QString annotation = f.description(); - if (!annotation.isEmpty()) item->setText(2, annotation); - item->setText(3, QString::number(f.rating())); + if (!annotation.isEmpty()) item->setText(1, annotation); + item->setText(2, QString::number(f.rating())); } - +#endif // Add cut zones - QList cuts = clip->cutZones(); + QList cuts = clip->cutZones(); if (!cuts.isEmpty()) { for (int i = 0; i < cuts.count(); i++) { - SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).x(), cuts.at(i).y()); + SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description); if (!clip->getClipHash().isEmpty()) { - QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).x()) + ".png"; + QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png"; if (QFile::exists(cachedPixmap)) { - sub->setIcon(0, QPixmap(cachedPixmap)); + sub->setData(0, Qt::DecorationRole, QPixmap(cachedPixmap)); } } } @@ -692,7 +815,7 @@ void ProjectList::slotProcessNextClipInQueue() const QDomElement dom = j.value(); const QString id = j.key(); m_infoQueue.remove(j.key()); - emit getFileProperties(dom, id, false); + emit getFileProperties(dom, id, m_listView->iconSize().height(), false); } } @@ -707,45 +830,47 @@ void ProjectList::slotUpdateClip(const QString &id) void ProjectList::updateAllClips() { m_listView->setSortingEnabled(false); + kDebug() << "// UPDATE ALL CLPY"; QTreeWidgetItemIterator it(m_listView); DocClipBase *clip; ProjectItem *item; m_listView->blockSignals(true); while (*it) { - if ((*it)->type() == QTreeWidgetItem::UserType + 1) { + if ((*it)->type() == PROJECTSUBCLIPTYPE) { // subitem SubProjectItem *sub = static_cast (*it); - if (sub->icon(0).isNull()) { + if (sub->data(0, Qt::DecorationRole).isNull()) { item = static_cast ((*it)->parent()); requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x())); } ++it; continue; - } - item = static_cast (*it); - if (!item->isGroup()) { + } else if ((*it)->type() == PROJECTFOLDERTYPE) { + // folder + ++it; + continue; + } else { + item = static_cast (*it); clip = item->referencedClip(); if (item->referencedClip()->producer() == NULL) { if (clip->isPlaceHolder() == false) { requestClipInfo(clip->toXML(), clip->getId()); - } else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + } else if (!clip->isPlaceHolder()) item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); } else { - if (item->icon(0).isNull()) { + if (item->data(0, Qt::DecorationRole).isNull()) { requestClipThumbnail(clip->getId()); } - if (item->data(1, DurationRole).toString().isEmpty()) { + if (item->data(0, DurationRole).toString().isEmpty()) { item->changeDuration(item->referencedClip()->producer()->get_playtime()); } } item->setData(1, UsageRole, QString::number(item->numReferences())); - //qApp->processEvents(); } + //qApp->processEvents(); ++it; } - qApp->processEvents(); if (!m_queueTimer.isActive()) m_queueTimer.start(); - if (m_listView->isEnabled()) m_listView->blockSignals(false); m_listView->setSortingEnabled(true); if (m_infoQueue.isEmpty()) slotProcessNextThumbnail(); @@ -776,6 +901,16 @@ void ProjectList::slotAddClip(const QList givenList, const QString &group for (int i = 0; i < givenList.count(); i++) list << givenList.at(i); } + + foreach(const KUrl &file, list) { + // Check there is no folder here + KMimeType::Ptr type = KMimeType::findByUrl(file); + if (type->is("inode/directory")) { + // user dropped a folder + list.removeAll(file); + } + } + if (list.isEmpty()) return; if (givenList.isEmpty()) { @@ -878,20 +1013,15 @@ void ProjectList::slotAddTitleTemplateClip() QStringList ProjectList::getGroup() const { QStringList result; - ProjectItem *item = NULL; - if (m_listView->currentItem() && m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) { - // sub item selected - item = static_cast (m_listView->currentItem()->parent()); - } else item = static_cast (m_listView->currentItem()); - if (item && !item->isGroup()) { - while (item->parent()) { - item = static_cast (item->parent()); - if (item->isGroup()) break; - } + QTreeWidgetItem *item = m_listView->currentItem(); + while (item && item->type() != PROJECTFOLDERTYPE) { + item = item->parent(); } - if (item && item->isGroup()) { - result << item->groupName(); - result << item->clipId(); + + if (item) { + FolderProjectItem *folder = static_cast (item); + result << folder->groupName(); + result << folder->clipId(); } else result << QString() << QString(); return result; } @@ -914,7 +1044,7 @@ void ProjectList::setDocument(KdenliveDoc *doc) QMapIterator f(flist); while (f.hasNext()) { f.next(); - (void) new ProjectItem(m_listView, QStringList() << QString() << f.value(), f.key()); + (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key()); } QList list = doc->clipManager()->documentClipList(); @@ -942,13 +1072,12 @@ QDomElement ProjectList::producersList() kDebug() << "//////////// PRO LIST BUILD PRDSLIST "; QTreeWidgetItemIterator it(m_listView); while (*it) { - if ((*it)->type() == QTreeWidgetItem::UserType + 1) { + if ((*it)->type() != PROJECTCLIPTYPE) { // subitem ++it; continue; } - if (!((ProjectItem *)(*it))->isGroup()) - prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true)); + prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true)); ++it; } return prods; @@ -971,13 +1100,12 @@ void ProjectList::reloadClipThumbnails() m_thumbnailQueue.clear(); QTreeWidgetItemIterator it(m_listView); while (*it) { - if ((*it)->type() == QTreeWidgetItem::UserType + 1) { + if ((*it)->type() != PROJECTCLIPTYPE) { // subitem ++it; continue; } - if (!((ProjectItem *)(*it))->isGroup()) - m_thumbnailQueue << ((ProjectItem *)(*it))->clipId(); + m_thumbnailQueue << ((ProjectItem *)(*it))->clipId(); ++it; } QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail())); @@ -1000,7 +1128,7 @@ void ProjectList::slotProcessNextThumbnail() } if (m_thumbnailQueue.count() > 1) { int max = m_doc->clipManager()->clipsCount(); - emit displayMessage(i18n("Loading thumbnails"), (int)(100 * (max - m_thumbnailQueue.count()) / max)); + emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max)); } slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false); } @@ -1018,7 +1146,8 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) ProjectItem *item = NULL; bool isSubItem = false; int frame; - if (it->type() == QTreeWidgetItem::UserType + 1) { + if (it->type() == PROJECTFOLDERTYPE) return; + if (it->type() == PROJECTSUBCLIPTYPE) { item = static_cast (it->parent()); frame = static_cast (it)->zone().x(); isSubItem = true; @@ -1034,7 +1163,7 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) return; } QPixmap pix; - int height = it->sizeHint(0).height(); + int height = m_listView->iconSize().height(); int width = (int)(height * m_render->dar()); if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height)); else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height)); @@ -1042,7 +1171,7 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) if (!pix.isNull()) { m_listView->blockSignals(true); - it->setIcon(0, pix); + it->setData(0, Qt::DecorationRole, pix); if (m_listView->isEnabled()) m_listView->blockSignals(false); if (!isSubItem) m_doc->cachePixmap(item->getClipHash(), pix); else m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix); @@ -1058,8 +1187,11 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce if (item && producer) { m_listView->blockSignals(true); item->setProperties(properties, metadata); - Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1()); + //Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1()); item->referencedClip()->setProducer(producer, replace); + if (!replace && item->data(0, Qt::DecorationRole).isNull()) { + requestClipThumbnail(clipId); + } //emit receivedClipDuration(clipId); if (m_listView->isEnabled() && replace) { // update clip in clip monitor @@ -1072,12 +1204,12 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce delete producer; }*/ if (m_listView->isEnabled()) m_listView->blockSignals(false); - if (item->icon(0).isNull()) { + /*if (item->icon(0).isNull()) { requestClipThumbnail(clipId); - } + }*/ } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS..."; int max = m_doc->clipManager()->clipsCount(); - emit displayMessage(i18n("Loading clips"), (int)(100 * (max - m_infoQueue.count()) / max)); + emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max)); // small delay so that the app can display the progress info if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) { m_listView->setCurrentItem(item); @@ -1091,7 +1223,7 @@ void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix) ProjectItem *item = getItemById(clipId); if (item && !pix.isNull()) { m_listView->blockSignals(true); - item->setIcon(0, pix); + item->setData(0, Qt::DecorationRole, pix); m_doc->cachePixmap(item->getClipHash(), pix); if (m_listView->isEnabled()) m_listView->blockSignals(false); } @@ -1107,19 +1239,19 @@ QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id) ProjectItem *result = NULL; while (*it) { - if ((*it)->type() == QTreeWidgetItem::UserType + 1) { + if ((*it)->type() != PROJECTCLIPTYPE) { // subitem ++it; continue; } ProjectItem *item = static_cast(*it); - if (item->clipId() == lookId && item->clipType() != FOLDER) { + if (item->clipId() == lookId) { result = item; break; } ++it; } - if (!id.contains('#')) return result; + if (result == NULL || !id.contains('#')) return result; else for (int i = 0; i < result->childCount(); i++) { SubProjectItem *sub = static_cast (result->child(i)); if (sub && sub->zone().x() == id.section('#', 1, 1).toInt()) { @@ -1136,27 +1268,28 @@ ProjectItem *ProjectList::getItemById(const QString &id) ProjectItem *item; QTreeWidgetItemIterator it(m_listView); while (*it) { - if ((*it)->type() == QTreeWidgetItem::UserType + 1) { + if ((*it)->type() != PROJECTCLIPTYPE) { // subitem ++it; continue; } item = static_cast(*it); - if (item->clipId() == id && item->clipType() != FOLDER) + if (item->clipId() == id) return item; ++it; } return NULL; } -ProjectItem *ProjectList::getFolderItemById(const QString &id) +FolderProjectItem *ProjectList::getFolderItemById(const QString &id) { - ProjectItem *item; + FolderProjectItem *item; QTreeWidgetItemIterator it(m_listView); while (*it) { - item = static_cast(*it); - if (item->clipId() == id && item->clipType() == FOLDER) - return item; + if ((*it)->type() == PROJECTFOLDERTYPE) { + item = static_cast(*it); + if (item->clipId() == id) return item; + } ++it; } return NULL; @@ -1185,7 +1318,8 @@ void ProjectList::slotSelectClip(const QString &ix) QString ProjectList::currentClipUrl() const { ProjectItem *item; - if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) { + if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString(); + if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) { // subitem item = static_cast (m_listView->currentItem()->parent()); } else item = static_cast (m_listView->currentItem()); @@ -1193,6 +1327,29 @@ QString ProjectList::currentClipUrl() const return item->clipUrl().path(); } +KUrl::List ProjectList::getConditionalUrls(const QString &condition) const +{ + KUrl::List result; + ProjectItem *item; + QList list = m_listView->selectedItems(); + for (int i = 0; i < list.count(); i++) { + if (list.at(i)->type() == PROJECTFOLDERTYPE) continue; + if (list.at(i)->type() == PROJECTSUBCLIPTYPE) { + // subitem + item = static_cast (list.at(i)->parent()); + } else item = static_cast (list.at(i)); + if (item == NULL) continue; + if (item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT) continue; + DocClipBase *clip = item->referencedClip(); + if (!condition.isEmpty()) { + if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section("=", 1, 1))) continue; + else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section("=", 1, 1))) continue; + } + result.append(item->clipUrl()); + } + return result; +} + void ProjectList::regenerateTemplate(const QString &id) { ProjectItem *clip = getItemById(id); @@ -1234,24 +1391,28 @@ void ProjectList::slotAddClipCut(const QString &id, int in, int out) ProjectItem *clip = getItemById(id); if (clip == NULL) return; if (clip->referencedClip()->hasCutZone(QPoint(in, out))) return; - AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, false); + AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false); m_commandStack->push(command); } -void ProjectList::addClipCut(const QString &id, int in, int out) +void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem) { ProjectItem *clip = getItemById(id); if (clip) { DocClipBase *base = clip->referencedClip(); base->addCutZone(in, out); m_listView->blockSignals(true); - SubProjectItem *sub = new SubProjectItem(clip, in, out); - - QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height()); - sub->setIcon(0, p); + SubProjectItem *sub = new SubProjectItem(clip, in, out, desc); + if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) { + if (!clip->isExpanded()) clip->setExpanded(true); + m_listView->editItem(sub, 1); + } + QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2); + sub->setData(0, Qt::DecorationRole, p); m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p); m_listView->blockSignals(false); } + emit projectModified(); } void ProjectList::removeClipCut(const QString &id, int in, int out) @@ -1260,18 +1421,53 @@ void ProjectList::removeClipCut(const QString &id, int in, int out) if (clip) { DocClipBase *base = clip->referencedClip(); base->removeCutZone(in, out); + SubProjectItem *sub = getSubItem(clip, QPoint(in, out)); + if (sub) { + m_listView->blockSignals(true); + delete sub; + m_listView->blockSignals(false); + } + } + emit projectModified(); +} + +SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone) +{ + SubProjectItem *sub = NULL; + if (clip) { for (int i = 0; i < clip->childCount(); i++) { QTreeWidgetItem *it = clip->child(i); - if (it->type() != QTreeWidgetItem::UserType + 1) continue; - SubProjectItem *sub = static_cast (it); - if (sub->zone() == QPoint(in, out)) { - m_listView->blockSignals(true); - delete it; - m_listView->blockSignals(false); - break; + if (it->type() == PROJECTSUBCLIPTYPE) { + sub = static_cast (it); + if (sub->zone() == zone) break; + else sub = NULL; } } } + return sub; +} + +void ProjectList::slotUpdateClipCut(QPoint p) +{ + if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE) return; + SubProjectItem *sub = static_cast (m_listView->currentItem()); + ProjectItem *item = static_cast (sub->parent()); + EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true); + m_commandStack->push(command); +} + +void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment) +{ + ProjectItem *clip = getItemById(id); + SubProjectItem *sub = getSubItem(clip, oldzone); + if (sub == NULL || clip == NULL) return; + DocClipBase *base = clip->referencedClip(); + base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment); + m_listView->blockSignals(true); + sub->setZone(zone); + sub->setDescription(comment); + m_listView->blockSignals(false); + emit projectModified(); } #include "projectlist.moc"