1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "projectlist.h"
21 #include "projectitem.h"
22 #include "addfoldercommand.h"
23 #include "kdenlivesettings.h"
24 #include "slideshowclip.h"
25 #include "ui_colorclip_ui.h"
26 #include "titlewidget.h"
27 #include "definitions.h"
28 #include "clipmanager.h"
29 #include "docclipbase.h"
30 #include "kdenlivedoc.h"
33 #include "projectlistview.h"
34 #include "editclipcommand.h"
35 #include "editclipcutcommand.h"
36 #include "editfoldercommand.h"
37 #include "addclipcutcommand.h"
39 #include "ui_templateclip_ui.h"
44 #include <KFileDialog>
45 #include <KInputDialog>
46 #include <KMessageBox>
47 #include <KIO/NetAccess>
50 #include <nepomuk/global.h>
51 #include <nepomuk/resourcemanager.h>
52 //#include <nepomuk/tag.h>
55 #include <QMouseEvent>
56 #include <QStylePainter>
61 #include <QHeaderView>
63 ProjectList::ProjectList(QWidget *parent) :
72 m_transcodeAction(NULL),
79 m_listView = new ProjectListView(this);;
80 QVBoxLayout *layout = new QVBoxLayout;
81 layout->setContentsMargins(0, 0, 0, 0);
84 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine(this);
85 m_toolbar = new QToolBar("projectToolBar", this);
86 m_toolbar->addWidget(searchView);
87 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
88 m_toolbar->setIconSize(QSize(s, s));
89 searchView->setTreeWidget(m_listView);
91 m_addButton = new QToolButton(m_toolbar);
92 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
93 m_toolbar->addWidget(m_addButton);
95 layout->addWidget(m_toolbar);
96 layout->addWidget(m_listView);
99 m_queueTimer.setInterval(100);
100 connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue()));
101 m_queueTimer.setSingleShot(true);
104 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
105 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
106 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
107 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
108 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
109 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
110 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
111 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
112 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
113 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
115 m_listViewDelegate = new ItemDelegate(m_listView);
116 m_listView->setItemDelegate(m_listViewDelegate);
118 if (KdenliveSettings::activate_nepomuk()) {
119 Nepomuk::ResourceManager::instance()->init();
120 if (!Nepomuk::ResourceManager::instance()->initialized()) {
121 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
122 KdenliveSettings::setActivate_nepomuk(false);
128 ProjectList::~ProjectList()
132 m_listView->blockSignals(true);
134 delete m_listViewDelegate;
137 void ProjectList::focusTree() const
139 m_listView->setFocus();
142 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
144 QList <QAction *> actions = addMenu->actions();
145 for (int i = 0; i < actions.count(); i++) {
146 if (actions.at(i)->data().toString() == "clip_properties") {
147 m_editAction = actions.at(i);
148 m_toolbar->addAction(m_editAction);
151 } else if (actions.at(i)->data().toString() == "delete_clip") {
152 m_deleteAction = actions.at(i);
153 m_toolbar->addAction(m_deleteAction);
156 } else if (actions.at(i)->data().toString() == "edit_clip") {
157 m_openAction = actions.at(i);
160 } else if (actions.at(i)->data().toString() == "reload_clip") {
161 m_reloadAction = actions.at(i);
167 QMenu *m = new QMenu();
168 m->addActions(actions);
169 m_addButton->setMenu(m);
170 m_addButton->setDefaultAction(defaultAction);
171 m_menu = new QMenu();
172 m_menu->addActions(addMenu->actions());
175 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu)
177 if (!addMenu) return;
178 QMenu *menu = m_addButton->menu();
179 menu->addMenu(addMenu);
180 m_addButton->setMenu(menu);
182 m_menu->addMenu(addMenu);
183 if (addMenu->isEmpty()) addMenu->setEnabled(false);
184 m_menu->addMenu(transcodeMenu);
185 if (transcodeMenu->isEmpty()) transcodeMenu->setEnabled(false);
186 m_transcodeAction = transcodeMenu;
187 m_menu->addAction(m_reloadAction);
188 m_menu->addAction(m_editAction);
189 m_menu->addAction(m_openAction);
190 m_menu->addAction(m_deleteAction);
191 m_menu->insertSeparator(m_deleteAction);
195 QByteArray ProjectList::headerInfo() const
197 return m_listView->header()->saveState();
200 void ProjectList::setHeaderInfo(const QByteArray &state)
202 m_listView->header()->restoreState(state);
205 void ProjectList::slotEditClip()
207 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
208 if (list.count() > 1) {
209 editClipSelection(list);
213 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return;
214 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
215 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
216 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
217 if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
219 emit clipSelected(item->referencedClip());
220 emit showClipProperties(item->referencedClip());
224 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
226 // Gather all common properties
227 QMap <QString, QString> commonproperties;
228 QList <DocClipBase *> clipList;
229 commonproperties.insert("force_aspect_ratio", "-");
230 commonproperties.insert("force_fps", "-");
231 commonproperties.insert("force_progressive", "-");
232 commonproperties.insert("threads", "-");
233 commonproperties.insert("video_index", "-");
234 commonproperties.insert("audio_index", "-");
237 for (int i = 0; i < list.count(); i++) {
239 if (list.at(i)->type() == PROJECTFOLDERTYPE) continue;
240 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
241 item = static_cast <ProjectItem*>(list.at(i)->parent());
242 } else item = static_cast <ProjectItem*>(list.at(i));
243 if (!(item->flags() & Qt::ItemIsDragEnabled)) continue;
246 DocClipBase *clip = item->referencedClip();
247 if (clipList.contains(clip)) continue;
248 clipList.append(clip);
249 QMap <QString, QString> clipprops = clip->properties();
250 QMapIterator<QString, QString> p(commonproperties);
251 while (p.hasNext()) {
253 if (p.value().isEmpty()) continue;
254 if (clipprops.contains(p.key())) {
255 if (p.value() == "-") commonproperties.insert(p.key(), clipprops.value(p.key()));
256 else if (p.value() != clipprops.value(p.key())) commonproperties.insert(p.key(), QString());
257 } else commonproperties.insert(p.key(), QString());
261 QMapIterator<QString, QString> p(commonproperties);
262 while (p.hasNext()) {
264 kDebug() << "Result: " << p.key() << " = " << p.value();
266 emit showClipProperties(clipList, commonproperties);
269 void ProjectList::slotOpenClip()
272 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return;
273 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
274 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
275 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
277 if (item->clipType() == IMAGE) {
278 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
279 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
281 if (item->clipType() == AUDIO) {
282 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
283 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
288 void ProjectList::cleanup()
290 m_listView->clearSelection();
291 QTreeWidgetItemIterator it(m_listView);
294 if ((*it)->type() != PROJECTCLIPTYPE) {
298 item = static_cast <ProjectItem *>(*it);
299 if (item->numReferences() == 0) item->setSelected(true);
305 void ProjectList::trashUnusedClips()
307 QTreeWidgetItemIterator it(m_listView);
312 if ((*it)->type() != PROJECTCLIPTYPE) {
316 item = static_cast <ProjectItem *>(*it);
317 if (item->numReferences() == 0) {
318 ids << item->clipId();
319 KUrl url = item->clipUrl();
320 if (!url.isEmpty() && !urls.contains(url.path())) urls << url.path();
325 // Check that we don't use the URL in another clip
326 QTreeWidgetItemIterator it2(m_listView);
328 if ((*it2)->type() != PROJECTCLIPTYPE) {
332 item = static_cast <ProjectItem *>(*it2);
333 if (item->numReferences() > 0) {
334 KUrl url = item->clipUrl();
335 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
340 m_doc->deleteProjectClip(ids);
341 for (int i = 0; i < urls.count(); i++) {
342 KIO::NetAccess::del(KUrl(urls.at(i)), this);
346 void ProjectList::slotReloadClip(const QString &id)
348 QList<QTreeWidgetItem *> selected;
349 if (id.isEmpty()) selected = m_listView->selectedItems();
350 else selected.append(getItemById(id));
352 for (int i = 0; i < selected.count(); i++) {
353 if (selected.at(i)->type() != PROJECTCLIPTYPE) continue;
354 item = static_cast <ProjectItem *>(selected.at(i));
356 if (item->clipType() == IMAGE) {
357 item->referencedClip()->producer()->set("force_reload", 1);
358 } else if (item->clipType() == TEXT) {
359 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item);
361 //requestClipInfo(item->toXml(), item->clipId(), true);
362 // Clear the file_hash value, which will cause a complete reload of the clip
363 emit getFileProperties(item->toXml(), item->clipId(), m_listView->iconSize().height(), true);
368 void ProjectList::setRenderer(Render *projectRender)
370 m_render = projectRender;
371 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
374 void ProjectList::slotClipSelected()
376 if (m_listView->currentItem()) {
377 if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
378 emit clipSelected(NULL);
379 m_editAction->setEnabled(false);
380 m_deleteAction->setEnabled(true);
381 m_openAction->setEnabled(false);
382 m_reloadAction->setEnabled(false);
383 m_transcodeAction->setEnabled(false);
386 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
387 // this is a sub item, use base clip
388 m_deleteAction->setEnabled(true);
389 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
390 if (clip == NULL) kDebug() << "-----------ERROR";
391 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
392 emit clipSelected(clip->referencedClip(), sub->zone());
395 clip = static_cast <ProjectItem*>(m_listView->currentItem());
396 emit clipSelected(clip->referencedClip());
397 m_editAction->setEnabled(true);
398 m_deleteAction->setEnabled(true);
399 m_reloadAction->setEnabled(true);
400 m_transcodeAction->setEnabled(true);
401 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
402 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
403 m_openAction->setEnabled(true);
404 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
405 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
406 m_openAction->setEnabled(true);
407 } else m_openAction->setEnabled(false);
410 emit clipSelected(NULL);
411 m_editAction->setEnabled(false);
412 m_deleteAction->setEnabled(false);
413 m_openAction->setEnabled(false);
414 m_reloadAction->setEnabled(false);
415 m_transcodeAction->setEnabled(false);
419 void ProjectList::slotPauseMonitor()
421 if (m_render) m_render->pause();
424 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
426 ProjectItem *item = getItemById(id);
428 slotUpdateClipProperties(item, properties);
429 if (properties.contains("out") || properties.contains("force_fps")) {
431 } else if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
432 slotRefreshClipThumbnail(item);
438 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
441 clip->setProperties(properties);
442 if (properties.contains("name")) {
443 m_listView->blockSignals(true);
444 clip->setText(0, properties.value("name"));
445 m_listView->blockSignals(false);
446 emit clipNameChanged(clip->clipId(), properties.value("name"));
448 if (properties.contains("description")) {
449 CLIPTYPE type = clip->clipType();
450 m_listView->blockSignals(true);
451 clip->setText(1, properties.value("description"));
452 m_listView->blockSignals(false);
454 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
455 // Use Nepomuk system to store clip description
456 Nepomuk::Resource f(clip->clipUrl().path());
457 f.setDescription(properties.value("description"));
460 emit projectModified();
464 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
466 if (item->type() == PROJECTSUBCLIPTYPE) {
467 // this is a sub-item
469 // user edited description
470 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
471 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
472 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
473 m_commandStack->push(command);
474 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
478 if (item->type() == PROJECTFOLDERTYPE) {
479 if (column != 0) return;
480 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
481 editFolder(item->text(0), folder->groupName(), folder->clipId());
482 folder->setGroupName(item->text(0));
483 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
484 const int children = item->childCount();
485 for (int i = 0; i < children; i++) {
486 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
487 child->setProperty("groupname", item->text(0));
492 ProjectItem *clip = static_cast <ProjectItem*>(item);
494 if (clip->referencedClip()) {
495 QMap <QString, QString> oldprops;
496 QMap <QString, QString> newprops;
497 oldprops["description"] = clip->referencedClip()->getProperty("description");
498 newprops["description"] = item->text(1);
500 if (clip->clipType() == TEXT) {
501 // This is a text template clip, update the image
502 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
503 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
504 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
505 newprops.insert("templatetext", item->text(1));
507 slotUpdateClipProperties(clip->clipId(), newprops);
508 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
509 m_commandStack->push(command);
511 } else if (column == 0) {
512 if (clip->referencedClip()) {
513 QMap <QString, QString> oldprops;
514 QMap <QString, QString> newprops;
515 oldprops["name"] = clip->referencedClip()->getProperty("name");
516 newprops["name"] = item->text(0);
517 slotUpdateClipProperties(clip, newprops);
518 emit projectModified();
519 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
520 m_commandStack->push(command);
525 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
531 m_editAction->setEnabled(enable);
532 m_deleteAction->setEnabled(enable);
533 m_reloadAction->setEnabled(enable);
534 m_transcodeAction->setEnabled(enable);
536 ProjectItem *clip = NULL;
537 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
538 clip = static_cast <ProjectItem*>(item->parent());
539 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) clip = static_cast <ProjectItem*>(item);
540 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
541 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
542 m_openAction->setEnabled(true);
543 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
544 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
545 m_openAction->setEnabled(true);
546 } else m_openAction->setEnabled(false);
547 } else m_openAction->setEnabled(false);
551 void ProjectList::slotRemoveClip()
553 if (!m_listView->currentItem()) return;
555 QMap <QString, QString> folderids;
556 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
558 QUndoCommand *delCommand = new QUndoCommand();
559 delCommand->setText(i18n("Delete Clip Zone"));
561 for (int i = 0; i < selected.count(); i++) {
562 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
564 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
565 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
566 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
567 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
569 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
570 folderids[folder->groupName()] = folder->clipId();
571 int children = folder->childCount();
573 if (children > 0 && KMessageBox::questionYesNo(this, i18np("Delete folder <b>%2</b>?<br>This will also remove the clip in that folder", "Delete folder <b>%2</b>?<br>This will also remove the %1 clips in that folder", children, folder->text(1)), i18n("Delete Folder")) != KMessageBox::Yes) return;
574 for (int i = 0; i < children; ++i) {
575 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
576 ids << child->clipId();
579 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
580 ids << item->clipId();
581 if (item->numReferences() > 0) {
582 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;
587 if (delCommand->childCount() == 0) delete delCommand;
588 else m_commandStack->push(delCommand);
589 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
590 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
591 if (m_listView->topLevelItemCount() == 0) {
592 m_editAction->setEnabled(false);
593 m_deleteAction->setEnabled(false);
594 m_openAction->setEnabled(false);
595 m_reloadAction->setEnabled(false);
596 m_transcodeAction->setEnabled(false);
600 void ProjectList::selectItemById(const QString &clipId)
602 ProjectItem *item = getItemById(clipId);
603 if (item) m_listView->setCurrentItem(item);
607 void ProjectList::slotDeleteClip(const QString &clipId)
609 ProjectItem *item = getItemById(clipId);
611 kDebug() << "/// Cannot find clip to delete";
614 m_listView->blockSignals(true);
616 m_doc->clipManager()->deleteClip(clipId);
617 m_listView->blockSignals(false);
622 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
624 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
625 m_commandStack->push(command);
626 m_doc->setModified(true);
629 void ProjectList::slotAddFolder()
631 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
632 m_commandStack->push(command);
635 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
638 FolderProjectItem *item = getFolderItemById(clipId);
640 m_doc->clipManager()->deleteFolder(clipId);
645 FolderProjectItem *item = getFolderItemById(clipId);
647 m_listView->blockSignals(true);
648 item->setGroupName(foldername);
649 m_listView->blockSignals(false);
650 m_doc->clipManager()->addFolder(clipId, foldername);
651 const int children = item->childCount();
652 for (int i = 0; i < children; i++) {
653 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
654 child->setProperty("groupname", foldername);
660 m_listView->blockSignals(true);
661 m_listView->setCurrentItem(new FolderProjectItem(m_listView, text, clipId));
662 m_doc->clipManager()->addFolder(clipId, foldername);
663 m_listView->blockSignals(false);
666 m_doc->setModified(true);
671 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
673 QMapIterator<QString, QString> i(map);
674 QUndoCommand *delCommand = new QUndoCommand();
675 delCommand->setText(i18n("Delete Folder"));
676 while (i.hasNext()) {
678 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
680 m_commandStack->push(delCommand);
683 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
685 m_listView->setEnabled(false);
687 m_listView->blockSignals(true);
689 // remove file_hash so that we load all properties for the clip
690 QDomElement e = clip->toXML().cloneNode().toElement();
691 e.removeAttribute("file_hash");
692 m_infoQueue.insert(clip->getId(), e);
693 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
695 const QString parent = clip->getProperty("groupid");
696 ProjectItem *item = NULL;
697 if (!parent.isEmpty()) {
698 FolderProjectItem *parentitem = getFolderItemById(parent);
701 QString groupName = clip->getProperty("groupname");
702 //kDebug() << "Adding clip to new group: " << groupName;
703 if (groupName.isEmpty()) groupName = i18n("Folder");
705 parentitem = new FolderProjectItem(m_listView, text, parent);
707 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
709 if (parentitem) item = new ProjectItem(parentitem, clip);
711 if (item == NULL) item = new ProjectItem(m_listView, clip);
712 KUrl url = clip->fileURL();
714 if (getProperties == false && !clip->getClipHash().isEmpty()) {
715 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
716 if (QFile::exists(cachedPixmap)) {
717 item->setData(0, Qt::DecorationRole, QPixmap(cachedPixmap));
721 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
722 // if file has Nepomuk comment, use it
723 Nepomuk::Resource f(url.path());
724 QString annotation = f.description();
725 if (!annotation.isEmpty()) item->setText(1, annotation);
726 item->setText(2, QString::number(f.rating()));
730 QList <CutZoneInfo> cuts = clip->cutZones();
731 if (!cuts.isEmpty()) {
732 for (int i = 0; i < cuts.count(); i++) {
733 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
734 if (!clip->getClipHash().isEmpty()) {
735 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
736 if (QFile::exists(cachedPixmap)) {
737 sub->setData(0, Qt::DecorationRole, QPixmap(cachedPixmap));
743 if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false);
744 if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
747 void ProjectList::slotResetProjectList()
750 emit clipSelected(NULL);
751 m_thumbnailQueue.clear();
756 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
759 m_infoQueue.insert(id, xml);
760 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
763 void ProjectList::slotProcessNextClipInQueue()
765 if (m_infoQueue.isEmpty()) {
766 slotProcessNextThumbnail();
770 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
771 if (j != m_infoQueue.constEnd()) {
772 const QDomElement dom = j.value();
773 const QString id = j.key();
774 m_infoQueue.remove(j.key());
775 emit getFileProperties(dom, id, m_listView->iconSize().height(), false);
779 void ProjectList::slotUpdateClip(const QString &id)
781 ProjectItem *item = getItemById(id);
782 m_listView->blockSignals(true);
783 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
784 m_listView->blockSignals(false);
787 void ProjectList::updateAllClips()
789 m_listView->setSortingEnabled(false);
790 kDebug() << "// UPDATE ALL CLPY";
792 QTreeWidgetItemIterator it(m_listView);
795 m_listView->blockSignals(true);
797 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
799 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
800 if (sub->data(0, Qt::DecorationRole).isNull()) {
801 item = static_cast <ProjectItem *>((*it)->parent());
802 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
806 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
811 item = static_cast <ProjectItem *>(*it);
812 clip = item->referencedClip();
813 if (item->referencedClip()->producer() == NULL) {
814 if (clip->isPlaceHolder() == false) {
815 requestClipInfo(clip->toXML(), clip->getId());
816 } else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
818 if (item->data(0, Qt::DecorationRole).isNull()) {
819 requestClipThumbnail(clip->getId());
821 if (item->data(0, DurationRole).toString().isEmpty()) {
822 item->changeDuration(item->referencedClip()->producer()->get_playtime());
825 item->setData(1, UsageRole, QString::number(item->numReferences()));
827 //qApp->processEvents();
830 if (!m_queueTimer.isActive()) m_queueTimer.start();
831 if (m_listView->isEnabled()) m_listView->blockSignals(false);
832 m_listView->setSortingEnabled(true);
833 if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
836 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
838 if (!m_commandStack) {
839 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
842 if (givenList.isEmpty()) {
843 // Build list of mime types
844 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/x-flv" << "application/vnd.rn-realmedia" << "video/x-dv" << "video/dv" << "video/x-msvideo" << "video/x-matroska" << "video/mlt-playlist" << "video/mpeg" << "video/ogg" << "video/x-ms-wmv" << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "application/ogg" << "video/mp4" << "video/quicktime" << "image/gif" << "image/jpeg" << "image/png" << "image/x-tga" << "image/x-bmp" << "image/svg+xml" << "image/tiff" << "image/x-xcf-gimp" << "image/x-vnd.adobe.photoshop" << "image/x-pcx" << "image/x-exr";
846 QString allExtensions;
847 foreach(const QString& mimeType, mimeTypes) {
848 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
850 allExtensions.append(mime->patterns().join(" "));
851 allExtensions.append(' ');
854 const QString dialogFilter = allExtensions.simplified() + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
855 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
858 for (int i = 0; i < givenList.count(); i++)
859 list << givenList.at(i);
862 foreach(const KUrl &file, list) {
863 // Check there is no folder here
864 KMimeType::Ptr type = KMimeType::findByUrl(file);
865 if (type->is("inode/directory")) {
866 // user dropped a folder
867 list.removeAll(file);
871 if (list.isEmpty()) return;
873 if (givenList.isEmpty()) {
874 QStringList groupInfo = getGroup();
875 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
876 } else m_doc->slotAddClipList(list, groupName, groupId);
879 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
881 ProjectItem *item = getItemById(id);
882 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
884 const QString path = item->referencedClip()->fileURL().path();
885 if (!path.isEmpty()) {
886 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
888 if (KMessageBox::questionYesNo(this, i18n("Clip <b>%1</b><br>is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes) replace = true;
893 if (replace) m_doc->deleteProjectClip(ids);
897 void ProjectList::slotAddColorClip()
899 if (!m_commandStack) {
900 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
902 QDialog *dia = new QDialog(this);
903 Ui::ColorClip_UI dia_ui;
905 dia_ui.clip_name->setText(i18n("Color Clip"));
906 dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
907 if (dia->exec() == QDialog::Accepted) {
908 QString color = dia_ui.clip_color->color().name();
909 color = color.replace(0, 1, "0x") + "ff";
910 QStringList groupInfo = getGroup();
911 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
917 void ProjectList::slotAddSlideshowClip()
919 if (!m_commandStack) {
920 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
922 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
924 if (dia->exec() == QDialog::Accepted) {
925 QStringList groupInfo = getGroup();
926 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), groupInfo.at(0), groupInfo.at(1));
931 void ProjectList::slotAddTitleClip()
933 QStringList groupInfo = getGroup();
934 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
937 void ProjectList::slotAddTitleTemplateClip()
939 QStringList groupInfo = getGroup();
940 if (!m_commandStack) {
941 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
944 // Get the list of existing templates
946 filter << "*.kdenlivetitle";
947 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
948 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
950 QDialog *dia = new QDialog(this);
951 Ui::TemplateClip_UI dia_ui;
953 for (int i = 0; i < templateFiles.size(); ++i) {
954 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
956 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
957 //warning: setting base directory doesn't work??
959 dia_ui.template_list->fileDialog()->setUrl(startDir);
960 dia_ui.text_box->setHidden(true);
961 if (dia->exec() == QDialog::Accepted) {
962 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
963 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
964 // Create a cloned template clip
965 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
970 QStringList ProjectList::getGroup() const
973 QTreeWidgetItem *item = m_listView->currentItem();
974 while (item && item->type() != PROJECTFOLDERTYPE) {
975 item = item->parent();
979 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
980 result << folder->groupName();
981 result << folder->clipId();
982 } else result << QString() << QString();
986 void ProjectList::setDocument(KdenliveDoc *doc)
988 m_listView->blockSignals(true);
990 m_listView->setSortingEnabled(false);
991 emit clipSelected(NULL);
992 m_thumbnailQueue.clear();
996 m_timecode = doc->timecode();
997 m_commandStack = doc->commandStack();
1000 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1001 QMapIterator<QString, QString> f(flist);
1002 while (f.hasNext()) {
1004 (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1007 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1008 for (int i = 0; i < list.count(); i++) {
1009 slotAddClip(list.at(i), false);
1012 m_listView->blockSignals(false);
1013 m_toolbar->setEnabled(true);
1014 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1015 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
1018 QList <DocClipBase*> ProjectList::documentClipList() const
1020 if (m_doc == NULL) return QList <DocClipBase*> ();
1021 return m_doc->clipManager()->documentClipList();
1024 QDomElement ProjectList::producersList()
1027 QDomElement prods = doc.createElement("producerlist");
1028 doc.appendChild(prods);
1029 kDebug() << "//////////// PRO LISTÂ BUILD PRDSLIST ";
1030 QTreeWidgetItemIterator it(m_listView);
1032 if ((*it)->type() != PROJECTCLIPTYPE) {
1037 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1043 void ProjectList::slotCheckForEmptyQueue()
1045 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1047 emit loadingIsOver();
1048 emit displayMessage(QString(), -1);
1049 m_listView->blockSignals(false);
1050 m_listView->setEnabled(true);
1051 } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1054 void ProjectList::reloadClipThumbnails()
1056 kDebug() << "////////////// RELOAD CLIPS THUMBNAILS!!!";
1057 m_thumbnailQueue.clear();
1058 QTreeWidgetItemIterator it(m_listView);
1060 if ((*it)->type() != PROJECTCLIPTYPE) {
1065 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
1068 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1071 void ProjectList::requestClipThumbnail(const QString id)
1073 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1076 void ProjectList::slotProcessNextThumbnail()
1078 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1079 slotCheckForEmptyQueue();
1082 if (!m_infoQueue.isEmpty()) {
1083 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1086 if (m_thumbnailQueue.count() > 1) {
1087 int max = m_doc->clipManager()->clipsCount();
1088 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1090 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1093 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1095 QTreeWidgetItem *item = getAnyItemById(clipId);
1096 if (item) slotRefreshClipThumbnail(item, update);
1097 else slotProcessNextThumbnail();
1100 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1102 if (it == NULL) return;
1103 ProjectItem *item = NULL;
1104 bool isSubItem = false;
1106 if (it->type() == PROJECTFOLDERTYPE) return;
1107 if (it->type() == PROJECTSUBCLIPTYPE) {
1108 item = static_cast <ProjectItem *>(it->parent());
1109 frame = static_cast <SubProjectItem *>(it)->zone().x();
1112 item = static_cast <ProjectItem *>(it);
1113 frame = item->referencedClip()->getClipThumbFrame();
1117 DocClipBase *clip = item->referencedClip();
1119 slotProcessNextThumbnail();
1123 int height = m_listView->iconSize().height();
1124 int width = (int)(height * m_render->dar());
1125 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1126 else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1127 else pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1129 if (!pix.isNull()) {
1130 m_listView->blockSignals(true);
1131 it->setData(0, Qt::DecorationRole, pix);
1132 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1133 if (!isSubItem) m_doc->cachePixmap(item->getClipHash(), pix);
1134 else m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1136 if (update) emit projectModified();
1137 QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
1141 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1143 ProjectItem *item = getItemById(clipId);
1144 if (item && producer) {
1145 m_listView->blockSignals(true);
1146 item->setProperties(properties, metadata);
1147 //Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
1148 item->referencedClip()->setProducer(producer, replace);
1149 if (!replace && item->data(0, Qt::DecorationRole).isNull()) {
1150 requestClipThumbnail(clipId);
1152 //emit receivedClipDuration(clipId);
1153 if (m_listView->isEnabled() && replace) {
1154 // update clip in clip monitor
1155 emit clipSelected(NULL);
1156 emit clipSelected(item->referencedClip());
1159 // Check if duration changed.
1160 emit receivedClipDuration(clipId);
1163 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1164 /*if (item->icon(0).isNull()) {
1165 requestClipThumbnail(clipId);
1167 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1168 int max = m_doc->clipManager()->clipsCount();
1169 emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1170 // small delay so that the app can display the progress info
1171 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1172 m_listView->setCurrentItem(item);
1173 emit clipSelected(item->referencedClip());
1175 QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
1178 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1180 ProjectItem *item = getItemById(clipId);
1181 if (item && !pix.isNull()) {
1182 m_listView->blockSignals(true);
1183 item->setData(0, Qt::DecorationRole, pix);
1184 m_doc->cachePixmap(item->getClipHash(), pix);
1185 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1189 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1191 QTreeWidgetItemIterator it(m_listView);
1192 QString lookId = id;
1193 if (id.contains('#')) {
1194 lookId = id.section('#', 0, 0);
1197 ProjectItem *result = NULL;
1199 if ((*it)->type() != PROJECTCLIPTYPE) {
1204 ProjectItem *item = static_cast<ProjectItem *>(*it);
1205 if (item->clipId() == lookId) {
1211 if (result == NULL || !id.contains('#')) return result;
1212 else for (int i = 0; i < result->childCount(); i++) {
1213 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1214 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt()) {
1223 ProjectItem *ProjectList::getItemById(const QString &id)
1226 QTreeWidgetItemIterator it(m_listView);
1228 if ((*it)->type() != PROJECTCLIPTYPE) {
1233 item = static_cast<ProjectItem *>(*it);
1234 if (item->clipId() == id)
1241 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1243 FolderProjectItem *item;
1244 QTreeWidgetItemIterator it(m_listView);
1246 if ((*it)->type() == PROJECTFOLDERTYPE) {
1247 item = static_cast<FolderProjectItem *>(*it);
1248 if (item->clipId() == id) return item;
1255 void ProjectList::slotSelectClip(const QString &ix)
1257 ProjectItem *clip = getItemById(ix);
1259 m_listView->setCurrentItem(clip);
1260 m_listView->scrollToItem(clip);
1261 m_editAction->setEnabled(true);
1262 m_deleteAction->setEnabled(true);
1263 m_reloadAction->setEnabled(true);
1264 m_transcodeAction->setEnabled(true);
1265 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1266 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1267 m_openAction->setEnabled(true);
1268 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1269 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1270 m_openAction->setEnabled(true);
1271 } else m_openAction->setEnabled(false);
1275 QString ProjectList::currentClipUrl() const
1278 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1279 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1281 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1282 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
1283 if (item == NULL) return QString();
1284 return item->clipUrl().path();
1287 void ProjectList::regenerateTemplate(const QString &id)
1289 ProjectItem *clip = getItemById(id);
1290 if (clip) regenerateTemplate(clip);
1293 void ProjectList::regenerateTemplate(ProjectItem *clip)
1295 //TODO: remove this unused method, only force_reload is necessary
1296 clip->referencedClip()->producer()->set("force_reload", 1);
1299 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1303 if (!file.open(QIODevice::ReadOnly)) {
1304 kWarning() << "ERROR, CANNOT READ: " << path;
1307 if (!doc.setContent(&file)) {
1308 kWarning() << "ERROR, CANNOT READ: " << path;
1313 QDomNodeList texts = doc.elementsByTagName("content");
1314 for (int i = 0; i < texts.count(); i++) {
1315 QString data = texts.item(i).firstChild().nodeValue();
1316 data.replace("%s", replaceString);
1317 texts.item(i).firstChild().setNodeValue(data);
1323 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1325 ProjectItem *clip = getItemById(id);
1326 if (clip == NULL) return;
1327 if (clip->referencedClip()->hasCutZone(QPoint(in, out))) return;
1328 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
1329 m_commandStack->push(command);
1332 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
1334 ProjectItem *clip = getItemById(id);
1336 DocClipBase *base = clip->referencedClip();
1337 base->addCutZone(in, out);
1338 m_listView->blockSignals(true);
1339 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
1340 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
1341 if (!clip->isExpanded()) clip->setExpanded(true);
1342 m_listView->editItem(sub, 1);
1344 QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
1345 sub->setData(0, Qt::DecorationRole, p);
1346 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1347 m_listView->blockSignals(false);
1349 emit projectModified();
1352 void ProjectList::removeClipCut(const QString &id, int in, int out)
1354 ProjectItem *clip = getItemById(id);
1356 DocClipBase *base = clip->referencedClip();
1357 base->removeCutZone(in, out);
1358 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
1360 m_listView->blockSignals(true);
1362 m_listView->blockSignals(false);
1365 emit projectModified();
1368 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
1370 SubProjectItem *sub = NULL;
1372 for (int i = 0; i < clip->childCount(); i++) {
1373 QTreeWidgetItem *it = clip->child(i);
1374 if (it->type() == PROJECTSUBCLIPTYPE) {
1375 sub = static_cast <SubProjectItem*>(it);
1376 if (sub->zone() == zone) break;
1384 void ProjectList::slotUpdateClipCut(QPoint p)
1386 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE) return;
1387 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
1388 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1389 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
1390 m_commandStack->push(command);
1393 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
1395 ProjectItem *clip = getItemById(id);
1396 SubProjectItem *sub = getSubItem(clip, oldzone);
1397 if (sub == NULL || clip == NULL) return;
1398 DocClipBase *base = clip->referencedClip();
1399 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
1400 m_listView->blockSignals(true);
1402 sub->setDescription(comment);
1403 m_listView->blockSignals(false);
1404 emit projectModified();
1407 #include "projectlist.moc"