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_progressive", "-");
231 commonproperties.insert("threads", "-");
232 commonproperties.insert("video_index", "-");
233 commonproperties.insert("audio_index", "-");
236 for (int i = 0; i < list.count(); i++) {
238 if (list.at(i)->type() == PROJECTFOLDERTYPE) continue;
239 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
240 item = static_cast <ProjectItem*>(list.at(i)->parent());
241 } else item = static_cast <ProjectItem*>(list.at(i));
242 if (!(item->flags() & Qt::ItemIsDragEnabled)) continue;
245 DocClipBase *clip = item->referencedClip();
246 if (clipList.contains(clip)) continue;
247 clipList.append(clip);
248 QMap <QString, QString> clipprops = clip->properties();
249 QMapIterator<QString, QString> p(commonproperties);
250 while (p.hasNext()) {
252 if (p.value().isEmpty()) continue;
253 if (clipprops.contains(p.key())) {
254 if (p.value() == "-") commonproperties.insert(p.key(), clipprops.value(p.key()));
255 else if (p.value() != clipprops.value(p.key())) commonproperties.insert(p.key(), QString());
256 } else commonproperties.insert(p.key(), QString());
260 QMapIterator<QString, QString> p(commonproperties);
261 while (p.hasNext()) {
263 kDebug() << "Result: " << p.key() << " = " << p.value();
265 emit showClipProperties(clipList, commonproperties);
268 void ProjectList::slotOpenClip()
271 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return;
272 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
273 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
274 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
276 if (item->clipType() == IMAGE) {
277 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
278 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
280 if (item->clipType() == AUDIO) {
281 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
282 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
287 void ProjectList::cleanup()
289 m_listView->clearSelection();
290 QTreeWidgetItemIterator it(m_listView);
293 if ((*it)->type() != PROJECTCLIPTYPE) {
297 item = static_cast <ProjectItem *>(*it);
298 if (item->numReferences() == 0) item->setSelected(true);
304 void ProjectList::trashUnusedClips()
306 QTreeWidgetItemIterator it(m_listView);
311 if ((*it)->type() != PROJECTCLIPTYPE) {
315 item = static_cast <ProjectItem *>(*it);
316 if (item->numReferences() == 0) {
317 ids << item->clipId();
318 KUrl url = item->clipUrl();
319 if (!url.isEmpty() && !urls.contains(url.path())) urls << url.path();
324 // Check that we don't use the URL in another clip
325 QTreeWidgetItemIterator it2(m_listView);
327 if ((*it2)->type() != PROJECTCLIPTYPE) {
331 item = static_cast <ProjectItem *>(*it2);
332 if (item->numReferences() > 0) {
333 KUrl url = item->clipUrl();
334 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
339 m_doc->deleteProjectClip(ids);
340 for (int i = 0; i < urls.count(); i++) {
341 KIO::NetAccess::del(KUrl(urls.at(i)), this);
345 void ProjectList::slotReloadClip(const QString &id)
347 QList<QTreeWidgetItem *> selected;
348 if (id.isEmpty()) selected = m_listView->selectedItems();
349 else selected.append(getItemById(id));
351 for (int i = 0; i < selected.count(); i++) {
352 if (selected.at(i)->type() != PROJECTCLIPTYPE) continue;
353 item = static_cast <ProjectItem *>(selected.at(i));
355 if (item->clipType() == IMAGE) {
356 item->referencedClip()->producer()->set("force_reload", 1);
357 } else if (item->clipType() == TEXT) {
358 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item);
360 //requestClipInfo(item->toXml(), item->clipId(), true);
361 // Clear the file_hash value, which will cause a complete reload of the clip
362 emit getFileProperties(item->toXml(), item->clipId(), m_listView->iconSize().height(), true);
367 void ProjectList::setRenderer(Render *projectRender)
369 m_render = projectRender;
370 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
373 void ProjectList::slotClipSelected()
375 if (m_listView->currentItem()) {
376 if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
377 emit clipSelected(NULL);
378 m_editAction->setEnabled(false);
379 m_deleteAction->setEnabled(true);
380 m_openAction->setEnabled(false);
381 m_reloadAction->setEnabled(false);
382 m_transcodeAction->setEnabled(false);
385 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
386 // this is a sub item, use base clip
387 m_deleteAction->setEnabled(true);
388 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
389 if (clip == NULL) kDebug() << "-----------ERROR";
390 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
391 emit clipSelected(clip->referencedClip(), sub->zone());
394 clip = static_cast <ProjectItem*>(m_listView->currentItem());
395 emit clipSelected(clip->referencedClip());
396 m_editAction->setEnabled(true);
397 m_deleteAction->setEnabled(true);
398 m_reloadAction->setEnabled(true);
399 m_transcodeAction->setEnabled(true);
400 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
401 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
402 m_openAction->setEnabled(true);
403 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
404 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
405 m_openAction->setEnabled(true);
406 } else m_openAction->setEnabled(false);
409 emit clipSelected(NULL);
410 m_editAction->setEnabled(false);
411 m_deleteAction->setEnabled(false);
412 m_openAction->setEnabled(false);
413 m_reloadAction->setEnabled(false);
414 m_transcodeAction->setEnabled(false);
418 void ProjectList::slotPauseMonitor()
420 if (m_render) m_render->pause();
423 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
425 ProjectItem *item = getItemById(id);
427 slotUpdateClipProperties(item, properties);
428 if (properties.contains("out")) {
430 } else if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
431 slotRefreshClipThumbnail(item);
437 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
440 clip->setProperties(properties);
441 if (properties.contains("name")) {
442 m_listView->blockSignals(true);
443 clip->setText(0, properties.value("name"));
444 m_listView->blockSignals(false);
445 emit clipNameChanged(clip->clipId(), properties.value("name"));
447 if (properties.contains("description")) {
448 CLIPTYPE type = clip->clipType();
449 m_listView->blockSignals(true);
450 clip->setText(1, properties.value("description"));
451 m_listView->blockSignals(false);
453 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
454 // Use Nepomuk system to store clip description
455 Nepomuk::Resource f(clip->clipUrl().path());
456 f.setDescription(properties.value("description"));
459 emit projectModified();
463 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
465 if (item->type() == PROJECTSUBCLIPTYPE) {
466 // this is a sub-item
468 // user edited description
469 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
470 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
471 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
472 m_commandStack->push(command);
473 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
477 if (item->type() == PROJECTFOLDERTYPE) {
478 if (column != 0) return;
479 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
480 editFolder(item->text(0), folder->groupName(), folder->clipId());
481 folder->setGroupName(item->text(0));
482 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
483 const int children = item->childCount();
484 for (int i = 0; i < children; i++) {
485 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
486 child->setProperty("groupname", item->text(0));
491 ProjectItem *clip = static_cast <ProjectItem*>(item);
493 if (clip->referencedClip()) {
494 QMap <QString, QString> oldprops;
495 QMap <QString, QString> newprops;
496 oldprops["description"] = clip->referencedClip()->getProperty("description");
497 newprops["description"] = item->text(1);
499 if (clip->clipType() == TEXT) {
500 // This is a text template clip, update the image
501 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
502 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
503 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
504 newprops.insert("templatetext", item->text(1));
506 slotUpdateClipProperties(clip->clipId(), newprops);
507 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
508 m_commandStack->push(command);
510 } else if (column == 0) {
511 if (clip->referencedClip()) {
512 QMap <QString, QString> oldprops;
513 QMap <QString, QString> newprops;
514 oldprops["name"] = clip->referencedClip()->getProperty("name");
515 newprops["name"] = item->text(0);
516 slotUpdateClipProperties(clip, newprops);
517 emit projectModified();
518 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
519 m_commandStack->push(command);
524 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
530 m_editAction->setEnabled(enable);
531 m_deleteAction->setEnabled(enable);
532 m_reloadAction->setEnabled(enable);
533 m_transcodeAction->setEnabled(enable);
535 ProjectItem *clip = NULL;
536 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
537 clip = static_cast <ProjectItem*>(item->parent());
538 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) clip = static_cast <ProjectItem*>(item);
539 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
540 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
541 m_openAction->setEnabled(true);
542 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
543 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
544 m_openAction->setEnabled(true);
545 } else m_openAction->setEnabled(false);
546 } else m_openAction->setEnabled(false);
550 void ProjectList::slotRemoveClip()
552 if (!m_listView->currentItem()) return;
554 QMap <QString, QString> folderids;
555 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
557 QUndoCommand *delCommand = new QUndoCommand();
558 delCommand->setText(i18n("Delete Clip Zone"));
560 for (int i = 0; i < selected.count(); i++) {
561 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
563 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
564 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
565 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
566 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
568 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
569 folderids[folder->groupName()] = folder->clipId();
570 int children = folder->childCount();
572 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;
573 for (int i = 0; i < children; ++i) {
574 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
575 ids << child->clipId();
578 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
579 ids << item->clipId();
580 if (item->numReferences() > 0) {
581 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;
586 if (delCommand->childCount() == 0) delete delCommand;
587 else m_commandStack->push(delCommand);
588 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
589 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
590 if (m_listView->topLevelItemCount() == 0) {
591 m_editAction->setEnabled(false);
592 m_deleteAction->setEnabled(false);
593 m_openAction->setEnabled(false);
594 m_reloadAction->setEnabled(false);
595 m_transcodeAction->setEnabled(false);
599 void ProjectList::selectItemById(const QString &clipId)
601 ProjectItem *item = getItemById(clipId);
602 if (item) m_listView->setCurrentItem(item);
606 void ProjectList::slotDeleteClip(const QString &clipId)
608 ProjectItem *item = getItemById(clipId);
610 kDebug() << "/// Cannot find clip to delete";
613 m_listView->blockSignals(true);
615 m_doc->clipManager()->deleteClip(clipId);
616 m_listView->blockSignals(false);
621 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
623 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
624 m_commandStack->push(command);
625 m_doc->setModified(true);
628 void ProjectList::slotAddFolder()
630 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
631 m_commandStack->push(command);
634 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
637 FolderProjectItem *item = getFolderItemById(clipId);
639 m_doc->clipManager()->deleteFolder(clipId);
644 FolderProjectItem *item = getFolderItemById(clipId);
646 m_listView->blockSignals(true);
647 item->setGroupName(foldername);
648 m_listView->blockSignals(false);
649 m_doc->clipManager()->addFolder(clipId, foldername);
650 const int children = item->childCount();
651 for (int i = 0; i < children; i++) {
652 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
653 child->setProperty("groupname", foldername);
659 m_listView->blockSignals(true);
660 m_listView->setCurrentItem(new FolderProjectItem(m_listView, text, clipId));
661 m_doc->clipManager()->addFolder(clipId, foldername);
662 m_listView->blockSignals(false);
665 m_doc->setModified(true);
670 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
672 QMapIterator<QString, QString> i(map);
673 QUndoCommand *delCommand = new QUndoCommand();
674 delCommand->setText(i18n("Delete Folder"));
675 while (i.hasNext()) {
677 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
679 m_commandStack->push(delCommand);
682 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
684 m_listView->setEnabled(false);
686 m_listView->blockSignals(true);
688 // remove file_hash so that we load all properties for the clip
689 QDomElement e = clip->toXML().cloneNode().toElement();
690 e.removeAttribute("file_hash");
691 m_infoQueue.insert(clip->getId(), e);
692 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
694 const QString parent = clip->getProperty("groupid");
695 ProjectItem *item = NULL;
696 if (!parent.isEmpty()) {
697 FolderProjectItem *parentitem = getFolderItemById(parent);
700 QString groupName = clip->getProperty("groupname");
701 //kDebug() << "Adding clip to new group: " << groupName;
702 if (groupName.isEmpty()) groupName = i18n("Folder");
704 parentitem = new FolderProjectItem(m_listView, text, parent);
706 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
708 if (parentitem) item = new ProjectItem(parentitem, clip);
710 if (item == NULL) item = new ProjectItem(m_listView, clip);
711 KUrl url = clip->fileURL();
713 if (getProperties == false && !clip->getClipHash().isEmpty()) {
714 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
715 if (QFile::exists(cachedPixmap)) {
716 item->setData(0, Qt::DecorationRole, QPixmap(cachedPixmap));
720 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
721 // if file has Nepomuk comment, use it
722 Nepomuk::Resource f(url.path());
723 QString annotation = f.description();
724 if (!annotation.isEmpty()) item->setText(1, annotation);
725 item->setText(2, QString::number(f.rating()));
729 QList <CutZoneInfo> cuts = clip->cutZones();
730 if (!cuts.isEmpty()) {
731 for (int i = 0; i < cuts.count(); i++) {
732 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
733 if (!clip->getClipHash().isEmpty()) {
734 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
735 if (QFile::exists(cachedPixmap)) {
736 sub->setData(0, Qt::DecorationRole, QPixmap(cachedPixmap));
742 if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false);
743 if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
746 void ProjectList::slotResetProjectList()
749 emit clipSelected(NULL);
750 m_thumbnailQueue.clear();
755 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
758 m_infoQueue.insert(id, xml);
759 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
762 void ProjectList::slotProcessNextClipInQueue()
764 if (m_infoQueue.isEmpty()) {
765 slotProcessNextThumbnail();
769 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
770 if (j != m_infoQueue.constEnd()) {
771 const QDomElement dom = j.value();
772 const QString id = j.key();
773 m_infoQueue.remove(j.key());
774 emit getFileProperties(dom, id, m_listView->iconSize().height(), false);
778 void ProjectList::slotUpdateClip(const QString &id)
780 ProjectItem *item = getItemById(id);
781 m_listView->blockSignals(true);
782 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
783 m_listView->blockSignals(false);
786 void ProjectList::updateAllClips()
788 m_listView->setSortingEnabled(false);
789 kDebug() << "// UPDATE ALL CLPY";
791 QTreeWidgetItemIterator it(m_listView);
794 m_listView->blockSignals(true);
796 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
798 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
799 if (sub->data(0, Qt::DecorationRole).isNull()) {
800 item = static_cast <ProjectItem *>((*it)->parent());
801 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
805 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
810 item = static_cast <ProjectItem *>(*it);
811 clip = item->referencedClip();
812 if (item->referencedClip()->producer() == NULL) {
813 if (clip->isPlaceHolder() == false) {
814 requestClipInfo(clip->toXML(), clip->getId());
815 } else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
817 if (item->data(0, Qt::DecorationRole).isNull()) {
818 requestClipThumbnail(clip->getId());
820 if (item->data(0, DurationRole).toString().isEmpty()) {
821 item->changeDuration(item->referencedClip()->producer()->get_playtime());
824 item->setData(1, UsageRole, QString::number(item->numReferences()));
826 //qApp->processEvents();
829 if (!m_queueTimer.isActive()) m_queueTimer.start();
830 if (m_listView->isEnabled()) m_listView->blockSignals(false);
831 m_listView->setSortingEnabled(true);
832 if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
835 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
837 if (!m_commandStack) {
838 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
841 if (givenList.isEmpty()) {
842 // Build list of mime types
843 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";
845 QString allExtensions;
846 foreach(const QString& mimeType, mimeTypes) {
847 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
849 allExtensions.append(mime->patterns().join(" "));
850 allExtensions.append(' ');
853 const QString dialogFilter = allExtensions.simplified() + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
854 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
857 for (int i = 0; i < givenList.count(); i++)
858 list << givenList.at(i);
861 foreach(const KUrl &file, list) {
862 // Check there is no folder here
863 KMimeType::Ptr type = KMimeType::findByUrl(file);
864 if (type->is("inode/directory")) {
865 // user dropped a folder
866 list.removeAll(file);
870 if (list.isEmpty()) return;
872 if (givenList.isEmpty()) {
873 QStringList groupInfo = getGroup();
874 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
875 } else m_doc->slotAddClipList(list, groupName, groupId);
878 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
880 ProjectItem *item = getItemById(id);
881 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
883 const QString path = item->referencedClip()->fileURL().path();
884 if (!path.isEmpty()) {
885 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
887 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;
892 if (replace) m_doc->deleteProjectClip(ids);
896 void ProjectList::slotAddColorClip()
898 if (!m_commandStack) {
899 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
901 QDialog *dia = new QDialog(this);
902 Ui::ColorClip_UI dia_ui;
904 dia_ui.clip_name->setText(i18n("Color Clip"));
905 dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
906 if (dia->exec() == QDialog::Accepted) {
907 QString color = dia_ui.clip_color->color().name();
908 color = color.replace(0, 1, "0x") + "ff";
909 QStringList groupInfo = getGroup();
910 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
916 void ProjectList::slotAddSlideshowClip()
918 if (!m_commandStack) {
919 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
921 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
923 if (dia->exec() == QDialog::Accepted) {
924 QStringList groupInfo = getGroup();
925 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));
930 void ProjectList::slotAddTitleClip()
932 QStringList groupInfo = getGroup();
933 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
936 void ProjectList::slotAddTitleTemplateClip()
938 QStringList groupInfo = getGroup();
939 if (!m_commandStack) {
940 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
943 // Get the list of existing templates
945 filter << "*.kdenlivetitle";
946 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
947 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
949 QDialog *dia = new QDialog(this);
950 Ui::TemplateClip_UI dia_ui;
952 for (int i = 0; i < templateFiles.size(); ++i) {
953 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
955 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
956 //warning: setting base directory doesn't work??
958 dia_ui.template_list->fileDialog()->setUrl(startDir);
959 dia_ui.text_box->setHidden(true);
960 if (dia->exec() == QDialog::Accepted) {
961 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
962 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
963 // Create a cloned template clip
964 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
969 QStringList ProjectList::getGroup() const
972 QTreeWidgetItem *item = m_listView->currentItem();
973 while (item && item->type() != PROJECTFOLDERTYPE) {
974 item = item->parent();
978 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
979 result << folder->groupName();
980 result << folder->clipId();
981 } else result << QString() << QString();
985 void ProjectList::setDocument(KdenliveDoc *doc)
987 m_listView->blockSignals(true);
989 m_listView->setSortingEnabled(false);
990 emit clipSelected(NULL);
991 m_thumbnailQueue.clear();
995 m_timecode = doc->timecode();
996 m_commandStack = doc->commandStack();
999 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1000 QMapIterator<QString, QString> f(flist);
1001 while (f.hasNext()) {
1003 (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1006 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1007 for (int i = 0; i < list.count(); i++) {
1008 slotAddClip(list.at(i), false);
1011 m_listView->blockSignals(false);
1012 m_toolbar->setEnabled(true);
1013 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1014 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
1017 QList <DocClipBase*> ProjectList::documentClipList() const
1019 if (m_doc == NULL) return QList <DocClipBase*> ();
1020 return m_doc->clipManager()->documentClipList();
1023 QDomElement ProjectList::producersList()
1026 QDomElement prods = doc.createElement("producerlist");
1027 doc.appendChild(prods);
1028 kDebug() << "//////////// PRO LISTÂ BUILD PRDSLIST ";
1029 QTreeWidgetItemIterator it(m_listView);
1031 if ((*it)->type() != PROJECTCLIPTYPE) {
1036 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1042 void ProjectList::slotCheckForEmptyQueue()
1044 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1046 emit loadingIsOver();
1047 emit displayMessage(QString(), -1);
1048 m_listView->blockSignals(false);
1049 m_listView->setEnabled(true);
1050 } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1053 void ProjectList::reloadClipThumbnails()
1055 kDebug() << "////////////// RELOAD CLIPS THUMBNAILS!!!";
1056 m_thumbnailQueue.clear();
1057 QTreeWidgetItemIterator it(m_listView);
1059 if ((*it)->type() != PROJECTCLIPTYPE) {
1064 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
1067 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1070 void ProjectList::requestClipThumbnail(const QString id)
1072 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1075 void ProjectList::slotProcessNextThumbnail()
1077 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1078 slotCheckForEmptyQueue();
1081 if (!m_infoQueue.isEmpty()) {
1082 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1085 if (m_thumbnailQueue.count() > 1) {
1086 int max = m_doc->clipManager()->clipsCount();
1087 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1089 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1092 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1094 QTreeWidgetItem *item = getAnyItemById(clipId);
1095 if (item) slotRefreshClipThumbnail(item, update);
1096 else slotProcessNextThumbnail();
1099 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1101 if (it == NULL) return;
1102 ProjectItem *item = NULL;
1103 bool isSubItem = false;
1105 if (it->type() == PROJECTFOLDERTYPE) return;
1106 if (it->type() == PROJECTSUBCLIPTYPE) {
1107 item = static_cast <ProjectItem *>(it->parent());
1108 frame = static_cast <SubProjectItem *>(it)->zone().x();
1111 item = static_cast <ProjectItem *>(it);
1112 frame = item->referencedClip()->getClipThumbFrame();
1116 DocClipBase *clip = item->referencedClip();
1118 slotProcessNextThumbnail();
1122 int height = m_listView->iconSize().height();
1123 int width = (int)(height * m_render->dar());
1124 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1125 else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1126 else pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1128 if (!pix.isNull()) {
1129 m_listView->blockSignals(true);
1130 it->setData(0, Qt::DecorationRole, pix);
1131 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1132 if (!isSubItem) m_doc->cachePixmap(item->getClipHash(), pix);
1133 else m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1135 if (update) emit projectModified();
1136 QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
1140 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1142 ProjectItem *item = getItemById(clipId);
1143 if (item && producer) {
1144 m_listView->blockSignals(true);
1145 item->setProperties(properties, metadata);
1146 //Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
1147 item->referencedClip()->setProducer(producer, replace);
1148 if (!replace && item->data(0, Qt::DecorationRole).isNull()) {
1149 requestClipThumbnail(clipId);
1151 //emit receivedClipDuration(clipId);
1152 if (m_listView->isEnabled() && replace) {
1153 // update clip in clip monitor
1154 emit clipSelected(NULL);
1155 emit clipSelected(item->referencedClip());
1158 // Check if duration changed.
1159 emit receivedClipDuration(clipId);
1162 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1163 /*if (item->icon(0).isNull()) {
1164 requestClipThumbnail(clipId);
1166 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1167 int max = m_doc->clipManager()->clipsCount();
1168 emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1169 // small delay so that the app can display the progress info
1170 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1171 m_listView->setCurrentItem(item);
1172 emit clipSelected(item->referencedClip());
1174 QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
1177 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1179 ProjectItem *item = getItemById(clipId);
1180 if (item && !pix.isNull()) {
1181 m_listView->blockSignals(true);
1182 item->setData(0, Qt::DecorationRole, pix);
1183 m_doc->cachePixmap(item->getClipHash(), pix);
1184 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1188 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1190 QTreeWidgetItemIterator it(m_listView);
1191 QString lookId = id;
1192 if (id.contains('#')) {
1193 lookId = id.section('#', 0, 0);
1196 ProjectItem *result = NULL;
1198 if ((*it)->type() != PROJECTCLIPTYPE) {
1203 ProjectItem *item = static_cast<ProjectItem *>(*it);
1204 if (item->clipId() == lookId) {
1210 if (result == NULL || !id.contains('#')) return result;
1211 else for (int i = 0; i < result->childCount(); i++) {
1212 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1213 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt()) {
1222 ProjectItem *ProjectList::getItemById(const QString &id)
1225 QTreeWidgetItemIterator it(m_listView);
1227 if ((*it)->type() != PROJECTCLIPTYPE) {
1232 item = static_cast<ProjectItem *>(*it);
1233 if (item->clipId() == id)
1240 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1242 FolderProjectItem *item;
1243 QTreeWidgetItemIterator it(m_listView);
1245 if ((*it)->type() == PROJECTFOLDERTYPE) {
1246 item = static_cast<FolderProjectItem *>(*it);
1247 if (item->clipId() == id) return item;
1254 void ProjectList::slotSelectClip(const QString &ix)
1256 ProjectItem *clip = getItemById(ix);
1258 m_listView->setCurrentItem(clip);
1259 m_listView->scrollToItem(clip);
1260 m_editAction->setEnabled(true);
1261 m_deleteAction->setEnabled(true);
1262 m_reloadAction->setEnabled(true);
1263 m_transcodeAction->setEnabled(true);
1264 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1265 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1266 m_openAction->setEnabled(true);
1267 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1268 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1269 m_openAction->setEnabled(true);
1270 } else m_openAction->setEnabled(false);
1274 QString ProjectList::currentClipUrl() const
1277 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1278 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1280 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1281 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
1282 if (item == NULL) return QString();
1283 return item->clipUrl().path();
1286 void ProjectList::regenerateTemplate(const QString &id)
1288 ProjectItem *clip = getItemById(id);
1289 if (clip) regenerateTemplate(clip);
1292 void ProjectList::regenerateTemplate(ProjectItem *clip)
1294 //TODO: remove this unused method, only force_reload is necessary
1295 clip->referencedClip()->producer()->set("force_reload", 1);
1298 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1302 if (!file.open(QIODevice::ReadOnly)) {
1303 kWarning() << "ERROR, CANNOT READ: " << path;
1306 if (!doc.setContent(&file)) {
1307 kWarning() << "ERROR, CANNOT READ: " << path;
1312 QDomNodeList texts = doc.elementsByTagName("content");
1313 for (int i = 0; i < texts.count(); i++) {
1314 QString data = texts.item(i).firstChild().nodeValue();
1315 data.replace("%s", replaceString);
1316 texts.item(i).firstChild().setNodeValue(data);
1322 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1324 ProjectItem *clip = getItemById(id);
1325 if (clip == NULL) return;
1326 if (clip->referencedClip()->hasCutZone(QPoint(in, out))) return;
1327 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
1328 m_commandStack->push(command);
1331 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
1333 ProjectItem *clip = getItemById(id);
1335 DocClipBase *base = clip->referencedClip();
1336 base->addCutZone(in, out);
1337 m_listView->blockSignals(true);
1338 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
1339 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
1340 if (!clip->isExpanded()) clip->setExpanded(true);
1341 m_listView->editItem(sub, 1);
1343 QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
1344 sub->setData(0, Qt::DecorationRole, p);
1345 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1346 m_listView->blockSignals(false);
1348 emit projectModified();
1351 void ProjectList::removeClipCut(const QString &id, int in, int out)
1353 ProjectItem *clip = getItemById(id);
1355 DocClipBase *base = clip->referencedClip();
1356 base->removeCutZone(in, out);
1357 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
1359 m_listView->blockSignals(true);
1361 m_listView->blockSignals(false);
1364 emit projectModified();
1367 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
1369 SubProjectItem *sub = NULL;
1371 for (int i = 0; i < clip->childCount(); i++) {
1372 QTreeWidgetItem *it = clip->child(i);
1373 if (it->type() == PROJECTSUBCLIPTYPE) {
1374 sub = static_cast <SubProjectItem*>(it);
1375 if (sub->zone() == zone) break;
1383 void ProjectList::slotUpdateClipCut(QPoint p)
1385 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE) return;
1386 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
1387 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1388 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
1389 m_commandStack->push(command);
1392 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
1394 ProjectItem *clip = getItemById(id);
1395 SubProjectItem *sub = getSubItem(clip, oldzone);
1396 if (sub == NULL || clip == NULL) return;
1397 DocClipBase *base = clip->referencedClip();
1398 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
1399 m_listView->blockSignals(true);
1401 sub->setDescription(comment);
1402 m_listView->blockSignals(false);
1403 emit projectModified();
1406 #include "projectlist.moc"