From: Jean-Baptiste Mardelle Date: Thu, 29 Oct 2009 21:51:27 +0000 (+0000) Subject: Add subclips (dragging a zone from clip monitor to project tree) X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=880efc8572a7df65453dfb5736de6455fe129a86;p=kdenlive Add subclips (dragging a zone from clip monitor to project tree) svn path=/trunk/kdenlive/; revision=4075 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cd99888d..a0ecc3e2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -173,6 +173,8 @@ set(kdenlive_SRCS keyframeedit.cpp positionedit.cpp trackdialog.cpp + subprojectitem.cpp + addclipcutcommand.cpp ) add_definitions( ${KDE4_DEFINITIONS} ) diff --git a/src/abstractclipitem.cpp b/src/abstractclipitem.cpp index 7e7e329d..9c191d36 100644 --- a/src/abstractclipitem.cpp +++ b/src/abstractclipitem.cpp @@ -37,8 +37,8 @@ AbstractClipItem::AbstractClipItem(const ItemInfo info, const QRectF& rect, doub m_selectedKeyframe(0), m_keyframeFactor(1), m_fps(fps) -#if QT_VERSION >= 0x040600 - , m_closeAnimation(NULL) +#if QT_VERSION >= 0x040600 + , m_closeAnimation(NULL) #endif { setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); @@ -51,9 +51,9 @@ AbstractClipItem::~AbstractClipItem() { #if QT_VERSION >= 0x040600 if (m_closeAnimation) delete m_closeAnimation; -#endif -} - +#endif +} + void AbstractClipItem::closeAnimation() { #if QT_VERSION >= 0x040600 diff --git a/src/abstractclipitem.h b/src/abstractclipitem.h index 7cf0d5fa..e49d0db7 100644 --- a/src/abstractclipitem.h +++ b/src/abstractclipitem.h @@ -58,7 +58,7 @@ public: void setItemLocked(bool locked); bool isItemLocked() const; void closeAnimation(); - + virtual OPERATIONTYPE operationMode(QPointF pos) = 0; virtual GenTime startPos() const ; virtual void setTrack(int track); @@ -91,7 +91,7 @@ protected: void drawKeyFrames(QPainter *painter, QRectF exposedRect); int mouseOverKeyFrames(QPointF pos, double maxOffset); virtual void mousePressEvent(QGraphicsSceneMouseEvent * event); - + private: #if QT_VERSION >= 0x040600 QPropertyAnimation *m_closeAnimation; diff --git a/src/addclipcutcommand.cpp b/src/addclipcutcommand.cpp new file mode 100644 index 00000000..717a9c5b --- /dev/null +++ b/src/addclipcutcommand.cpp @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "addclipcutcommand.h" +#include "projectlist.h" + +#include + +AddClipCutCommand::AddClipCutCommand(ProjectList *list, const QString &id, int in, int out, bool remove, QUndoCommand * parent) : + QUndoCommand(parent), + m_list(list), + m_id(id), + m_in(in), + m_out(out), + m_remove(remove) +{ + setText(i18n("Add clip cut")); +} + + +// virtual +void AddClipCutCommand::undo() +{ + if (m_remove) m_list->addClipCut(m_id, m_in, m_out); + else m_list->removeClipCut(m_id, m_in, m_out); +} +// virtual +void AddClipCutCommand::redo() +{ + if (m_remove) m_list->removeClipCut(m_id, m_in, m_out); + else m_list->addClipCut(m_id, m_in, m_out); +} + diff --git a/src/addclipcutcommand.h b/src/addclipcutcommand.h new file mode 100644 index 00000000..7351d041 --- /dev/null +++ b/src/addclipcutcommand.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + + +#ifndef ADDCLIPCUTCOMMAND_H +#define ADDCLIPCUTCOMMAND_H + +#include +#include + +class ProjectList; + +class AddClipCutCommand : public QUndoCommand +{ +public: + AddClipCutCommand(ProjectList *list, const QString &id, int in, int out, bool remove, QUndoCommand * parent = 0); + + virtual void undo(); + virtual void redo(); + +private: + ProjectList *m_list; + QString m_id; + int m_in; + int m_out; + bool m_remove; +}; + +#endif + diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 5c21201c..0b657927 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -1568,7 +1568,7 @@ void ClipItem::setAudioOnly(bool force) colour = colour.replace(0, 2, "#"); m_baseColor = QColor(colour.left(7)); } else if (m_clipType == AUDIO) m_baseColor = QColor(141, 215, 166); - else m_baseColor = QColor(141, 166, 215); + else m_baseColor = QColor(141, 166, 215); } m_audioThumbCachePic.clear(); } diff --git a/src/clipmanager.cpp b/src/clipmanager.cpp index 5a710969..cf7a540d 100644 --- a/src/clipmanager.cpp +++ b/src/clipmanager.cpp @@ -335,6 +335,7 @@ void ClipManager::slotAddClipFile(const KUrl url, const QString group, const QSt m_doc->commandStack()->push(command); } + void ClipManager::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group, const QString &groupId) { QDomDocument doc; diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index a97b314c..54b6f66a 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -3300,7 +3300,7 @@ void CustomTrackView::deleteClip(ItemInfo info, bool refresh) delete item; item = NULL; #endif - + setDocumentModified(); if (refresh) m_document->renderer()->doRefresh(); } diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index 2669a878..6a72de10 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -58,6 +58,14 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin m_properties.insert(attributes.item(i).nodeName(), attributes.item(i).nodeValue()); } + if (xml.hasAttribute("cutzones")) { + QStringList cuts = xml.attribute("cutzones").split(";", QString::SkipEmptyParts); + for (int i = 0; i < cuts.count(); i++) { + QString z = cuts.at(i); + addCutZone(z.section('-', 0, 0).toInt(), z.section('-', 1, 1).toInt()); + } + } + KUrl url = KUrl(xml.attribute("resource")); if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path()); @@ -262,6 +270,13 @@ QDomElement DocClipBase::toXML() const if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value()); } doc.appendChild(clip); + if (!m_cutZones.isEmpty()) { + QStringList cuts; + for (int i = 0; i < m_cutZones.size(); i++) { + cuts << QString::number(m_cutZones.at(i).x()) + "-" + QString::number(m_cutZones.at(i).y()); + } + clip.setAttribute("cutzones", cuts.join(";")); + } //kDebug() << "/// CLIP XML: " << doc.toString(); return doc.documentElement(); } @@ -841,3 +856,37 @@ bool DocClipBase::isPlaceHolder() const return m_placeHolder; } +void DocClipBase::addCutZone(int in, int out) +{ + if (!m_cutZones.contains(QPoint(in, out))) { + m_cutZones.append(QPoint(in, out)); + } +} + +bool DocClipBase::hasCutZone(QPoint p) const +{ + return m_cutZones.contains(p); +} + + +void DocClipBase::removeCutZone(int in, int out) +{ + m_cutZones.removeAll(QPoint(in, out)); +} + +void DocClipBase::updateCutZone(int oldin, int oldout, int in, int out) +{ + QPoint old(oldin, oldout); + for (int i = 0; i < m_cutZones.size(); ++i) { + if (m_cutZones.at(i) == old) { + m_cutZones.replace(i, QPoint(in, out)); + break; + } + } +} + +QList DocClipBase::cutZones() const +{ + return m_cutZones; +} + diff --git a/src/docclipbase.h b/src/docclipbase.h index 907af533..288b3d45 100644 --- a/src/docclipbase.h +++ b/src/docclipbase.h @@ -185,6 +185,12 @@ Q_OBJECT public: bool isPlaceHolder() const; static QString getHash(const QString &path); + void addCutZone(int in, int out); + bool hasCutZone(QPoint p) const; + void removeCutZone(int in, int out); + QList cutZones() const; + void updateCutZone(int oldin, int oldout, int in, int out); + private: // Private attributes /** The number of times this clip is used in the project - the number of references to this clip @@ -212,6 +218,8 @@ private: // Private attributes /** Wheter the clip is a placeholder (clip missing but user wants to see it) */ bool m_placeHolder; + QList m_cutZones; + void setAudioThumbCreated(bool isDone); /** Holds clip infos like fps, size,... */ QMap m_properties; diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index 0b3f05ab..4df0fcf2 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -921,7 +921,6 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem) } } - void KdenliveDoc::setNewClipResource(const QString &id, const QString &path) { QDomNodeList prods = m_document.elementsByTagName("producer"); @@ -1031,7 +1030,7 @@ void KdenliveDoc::deleteClip(const QString &clipId) void KdenliveDoc::slotAddClipList(const KUrl::List urls, const QString group, const QString &groupId) { m_clipManager->slotAddClipList(urls, group, groupId); - emit selectLastAddedClip(QString::number(m_clipManager->lastClipId())); + //emit selectLastAddedClip(QString::number(m_clipManager->lastClipId())); setModified(true); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4fc03234..62243db0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1790,7 +1790,7 @@ void MainWindow::slotEditProjectSettings() // Deselect current effect / transition m_effectStack->slotClipItemSelected(NULL, 0); m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false); - m_clipMonitor->slotSetXml(NULL, 0); + m_clipMonitor->slotSetXml(NULL); bool updateFps = m_activeDocument->setProfilePath(profile); KdenliveSettings::setCurrent_profile(profile); KdenliveSettings::setProject_fps(m_activeDocument->fps()); @@ -1949,7 +1949,7 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //cha m_projectList->setDocument(doc); m_transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), doc->tracksList()); m_effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode()); - connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *))); + connect(m_projectList, SIGNAL(clipSelected(DocClipBase *, QPoint)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, QPoint))); connect(m_projectList, SIGNAL(refreshClip()), m_clipMonitor, SLOT(refreshMonitor())); connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified())); connect(m_projectList, SIGNAL(clipNameChanged(const QString, const QString)), trackView->projectView(), SLOT(clipNameChanged(const QString, const QString))); @@ -2076,7 +2076,7 @@ void MainWindow::slotPreferences(int page, int option) void MainWindow::slotUpdatePreviewSettings() { if (m_activeDocument) { - m_clipMonitor->slotSetXml(NULL, 0); + m_clipMonitor->slotSetXml(NULL); m_activeDocument->updatePreviewSettings(); } } diff --git a/src/monitor.cpp b/src/monitor.cpp index 9c6217d2..1a17c5f1 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -420,7 +420,6 @@ void Monitor::mouseMoveEvent(QMouseEvent *event) mimeData->setData("kdenlive/clip", data); drag->setMimeData(mimeData); QPixmap pix = m_currentClip->thumbnail(); - kDebug() << "/ / / /CLIP DRAGGED PIXMAP: " << pix.width() << "x" << pix.height(); drag->setPixmap(pix); drag->setHotSpot(QPoint(0, 50)); drag->start(Qt::MoveAction); @@ -742,11 +741,11 @@ void Monitor::slotLoopZone() m_playAction->setIcon(m_pauseIcon); } -void Monitor::slotSetXml(DocClipBase *clip, const int position) +void Monitor::slotSetXml(DocClipBase *clip, QPoint zone, const int position) { if (render == NULL) return; activateMonitor(); - if (!clip && m_currentClip != NULL) { + if (clip == NULL && m_currentClip != NULL) { m_currentClip = NULL; render->setProducer(NULL, -1); return; @@ -759,6 +758,10 @@ void Monitor::slotSetXml(DocClipBase *clip, const int position) emit blockMonitors(); } } else if (position != -1) render->seek(GenTime(position, m_monitorManager->timecode().fps())); + if (!zone.isNull()) { + m_ruler->setZone(zone.x(), zone.y()); + render->seek(GenTime(zone.x(), m_monitorManager->timecode().fps())); + } } void Monitor::slotOpenFile(const QString &file) diff --git a/src/monitor.h b/src/monitor.h index 978e080d..1fb41d9e 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -139,7 +139,7 @@ private slots: public slots: void slotOpenFile(const QString &); - void slotSetXml(DocClipBase *clip, const int position = -1); + void slotSetXml(DocClipBase *clip, QPoint zone = QPoint(), const int position = -1); void initMonitor(); void refreshMonitor(bool visible = true); void slotSeek(int pos); diff --git a/src/projectlist.cpp b/src/projectlist.cpp index 9f02425b..5247e978 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -19,6 +19,7 @@ #include "projectlist.h" #include "projectitem.h" +#include "subprojectitem.h" #include "addfoldercommand.h" #include "kdenlivesettings.h" #include "slideshowclip.h" @@ -33,6 +34,8 @@ #include "projectlistview.h" #include "editclipcommand.h" #include "editfoldercommand.h" +#include "addclipcutcommand.h" + #include "ui_templateclip_ui.h" #include @@ -67,7 +70,6 @@ ProjectList::ProjectList(QWidget *parent) : m_reloadAction(NULL), m_transcodeAction(NULL), m_doc(NULL), - m_selectedItem(NULL), m_refreshed(false), m_infoQueue(), m_thumbnailQueue() @@ -103,6 +105,7 @@ ProjectList::ProjectList(QWidget *parent) : connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *))); connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip())); connect(m_listView, SIGNAL(addClip(const QList , const QString &, const QString &)), this, SLOT(slotAddClip(const QList , const QString &, const QString &))); + connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int))); connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int))); connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *))); @@ -192,7 +195,10 @@ void ProjectList::setHeaderInfo(const QByteArray &state) void ProjectList::slotEditClip() { - ProjectItem *item = static_cast (m_listView->currentItem()); + ProjectItem *item; + if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) { + item = static_cast (m_listView->currentItem()->parent()); + } else item = static_cast (m_listView->currentItem()); if (!(item->flags() & Qt::ItemIsDragEnabled)) return; if (item && !item->isGroup()) { emit clipSelected(item->referencedClip()); @@ -202,7 +208,10 @@ void ProjectList::slotEditClip() void ProjectList::slotOpenClip() { - ProjectItem *item = static_cast (m_listView->currentItem()); + ProjectItem *item; + 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->clipType() == IMAGE) { if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog")); @@ -221,6 +230,10 @@ void ProjectList::cleanup() QTreeWidgetItemIterator it(m_listView); ProjectItem *item; while (*it) { + if ((*it)->type() == QTreeWidgetItem::UserType + 1) { + it++; + continue; + } item = static_cast (*it); if (!item->isGroup() && item->numReferences() == 0) item->setSelected(true); it++; @@ -235,6 +248,10 @@ void ProjectList::trashUnusedClips() QStringList ids; QStringList urls; while (*it) { + if ((*it)->type() == QTreeWidgetItem::UserType + 1) { + it++; + continue; + } item = static_cast (*it); if (!item->isGroup() && item->numReferences() == 0) { ids << item->clipId(); @@ -247,6 +264,10 @@ void ProjectList::trashUnusedClips() // Check that we don't use the URL in another clip QTreeWidgetItemIterator it2(m_listView); while (*it2) { + if ((*it2)->type() == QTreeWidgetItem::UserType + 1) { + it2++; + continue; + } item = static_cast (*it2); if (item->numReferences() > 0) { KUrl url = item->clipUrl(); @@ -268,6 +289,7 @@ 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; item = static_cast (selected.at(i)); if (item && !item->isGroup()) { if (item->clipType() == IMAGE) { @@ -291,9 +313,17 @@ void ProjectList::setRenderer(Render *projectRender) void ProjectList::slotClipSelected() { if (m_listView->currentItem()) { - ProjectItem *clip = static_cast (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()) { - m_selectedItem = clip; emit clipSelected(clip->referencedClip()); } m_editAction->setEnabled(true); @@ -362,6 +392,11 @@ void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap type() == QTreeWidgetItem::UserType + 1) { + // this is a sub-item + return; + } + ProjectItem *clip = static_cast (item); if (column == 2) { if (clip->referencedClip()) { @@ -417,7 +452,10 @@ void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item) m_reloadAction->setEnabled(enable); m_transcodeAction->setEnabled(enable); if (enable) { - ProjectItem *clip = static_cast (item); + ProjectItem *clip; + if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) { + clip = static_cast (item->parent()); + } else clip = static_cast (item); if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) { m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp())); m_openAction->setEnabled(true); @@ -435,9 +473,19 @@ void ProjectList::slotRemoveClip() QStringList ids; QMap folderids; QList selected = m_listView->selectedItems(); - ProjectItem *item; + + QUndoCommand *delCommand = new QUndoCommand(); + delCommand->setText(i18n("Delete Clip Zone")); + for (int i = 0; i < selected.count(); i++) { - item = static_cast (selected.at(i)); + if (selected.at(i)->type() == QTreeWidgetItem::UserType + 1) { + // 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) { @@ -451,6 +499,8 @@ void ProjectList::slotRemoveClip() } } } + if (delCommand->childCount() == 0) delete delCommand; + else m_commandStack->push(delCommand); if (!ids.isEmpty()) m_doc->deleteProjectClip(ids); if (!folderids.isEmpty()) deleteProjectFolder(folderids); if (m_listView->topLevelItemCount() == 0) { @@ -590,6 +640,23 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) if (!annotation.isEmpty()) item->setText(2, annotation); item->setText(3, QString::number(f.rating())); } + + // Add cut zones + QList cuts = clip->cutZones(); + if (!cuts.isEmpty()) { + m_listView->blockSignals(true); + for (int i = 0; i < cuts.count(); i++) { + SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).x(), cuts.at(i).y()); + if (!clip->getClipHash().isEmpty()) { + QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).x()) + ".png"; + if (QFile::exists(cachedPixmap)) { + sub->setIcon(0, QPixmap(cachedPixmap)); + } + } + } + m_listView->blockSignals(false); + } + if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false); if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start(); } @@ -624,7 +691,6 @@ void ProjectList::slotProcessNextClipInQueue() m_infoQueue.remove(j.key()); emit getFileProperties(dom, id, false); } - //if (!m_infoQueue.isEmpty() && !m_queueTimer.isActive()) m_queueTimer.start(); } void ProjectList::slotUpdateClip(const QString &id) @@ -644,6 +710,16 @@ void ProjectList::updateAllClips() ProjectItem *item; m_listView->blockSignals(true); while (*it) { + if ((*it)->type() == QTreeWidgetItem::UserType + 1) { + // subitem + SubProjectItem *sub = static_cast (*it); + if (sub->icon(0).isNull()) { + item = static_cast ((*it)->parent()); + requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x())); + } + ++it; + continue; + } item = static_cast (*it); if (!item->isGroup()) { clip = item->referencedClip(); @@ -799,7 +875,11 @@ void ProjectList::slotAddTitleTemplateClip() QStringList ProjectList::getGroup() const { QStringList result; - ProjectItem *item = static_cast (m_listView->currentItem()); + 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()); @@ -859,6 +939,11 @@ QDomElement ProjectList::producersList() kDebug() << "//////////// PRO LIST BUILD PRDSLIST "; QTreeWidgetItemIterator it(m_listView); while (*it) { + if ((*it)->type() == QTreeWidgetItem::UserType + 1) { + // subitem + ++it; + continue; + } if (!((ProjectItem *)(*it))->isGroup()) prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true)); ++it; @@ -883,6 +968,11 @@ void ProjectList::reloadClipThumbnails() m_thumbnailQueue.clear(); QTreeWidgetItemIterator it(m_listView); while (*it) { + if ((*it)->type() == QTreeWidgetItem::UserType + 1) { + // subitem + ++it; + continue; + } if (!((ProjectItem *)(*it))->isGroup()) m_thumbnailQueue << ((ProjectItem *)(*it))->clipId(); ++it; @@ -914,13 +1004,26 @@ void ProjectList::slotProcessNextThumbnail() void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update) { - ProjectItem *item = getItemById(clipId); + QTreeWidgetItem *item = getAnyItemById(clipId); if (item) slotRefreshClipThumbnail(item, update); else slotProcessNextThumbnail(); } -void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update) +void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) { + if (it == NULL) return; + ProjectItem *item = NULL; + bool isSubItem = false; + int frame; + if (it->type() == QTreeWidgetItem::UserType + 1) { + item = static_cast (it->parent()); + frame = static_cast (it)->zone().x(); + isSubItem = true; + } else { + item = static_cast (it); + frame = item->referencedClip()->getClipThumbFrame(); + } + if (item) { DocClipBase *clip = item->referencedClip(); if (!clip) { @@ -928,16 +1031,18 @@ void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update) return; } QPixmap pix; - int height = 50; + int height = it->sizeHint(0).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)); - else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height); + else pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height); + if (!pix.isNull()) { m_listView->blockSignals(true); - item->setIcon(0, pix); + it->setIcon(0, pix); if (m_listView->isEnabled()) m_listView->blockSignals(false); - m_doc->cachePixmap(item->getClipHash(), pix); + if (!isSubItem) m_doc->cachePixmap(item->getClipHash(), pix); + else m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix); } if (update) emit projectModified(); QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail())); @@ -971,6 +1076,10 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce int max = m_doc->clipManager()->clipsCount(); 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); + emit clipSelected(item->referencedClip()); + } QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue())); } @@ -985,11 +1094,50 @@ void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix) } } +QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id) +{ + QTreeWidgetItemIterator it(m_listView); + QString lookId = id; + if (id.contains('#')) { + lookId = id.section('#', 0, 0); + } + + ProjectItem *result = NULL; + while (*it) { + if ((*it)->type() == QTreeWidgetItem::UserType + 1) { + // subitem + ++it; + continue; + } + ProjectItem *item = static_cast(*it); + if (item->clipId() == lookId && item->clipType() != FOLDER) { + result = item; + break; + } + ++it; + } + if (!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()) { + return sub; + } + } + + return NULL; +} + + ProjectItem *ProjectList::getItemById(const QString &id) { ProjectItem *item; QTreeWidgetItemIterator it(m_listView); while (*it) { + if ((*it)->type() == QTreeWidgetItem::UserType + 1) { + // subitem + ++it; + continue; + } item = static_cast(*it); if (item->clipId() == id && item->clipType() != FOLDER) return item; @@ -1033,7 +1181,11 @@ void ProjectList::slotSelectClip(const QString &ix) QString ProjectList::currentClipUrl() const { - ProjectItem *item = static_cast (m_listView->currentItem()); + ProjectItem *item; + if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) { + // subitem + item = static_cast (m_listView->currentItem()->parent()); + } else item = static_cast (m_listView->currentItem()); if (item == NULL) return QString(); return item->clipUrl().path(); } @@ -1073,4 +1225,52 @@ QDomDocument ProjectList::generateTemplateXml(QString path, const QString &repla return doc; } + +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); + m_commandStack->push(command); +} + +void ProjectList::addClipCut(const QString &id, int in, int out) +{ + //m_doc->slotAddClipCut(id, in, out, groupName, groupId); + 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); + m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p); + m_listView->blockSignals(false); + } +} + +void ProjectList::removeClipCut(const QString &id, int in, int out) +{ + //m_doc->slotAddClipCut(id, in, out, groupName, groupId); + ProjectItem *clip = getItemById(id); + if (clip) { + DocClipBase *base = clip->referencedClip(); + base->removeCutZone(in, out); + 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; + } + } + } +} + #include "projectlist.moc" diff --git a/src/projectlist.h b/src/projectlist.h index 85290409..6c868439 100644 --- a/src/projectlist.h +++ b/src/projectlist.h @@ -136,6 +136,8 @@ public: void cleanup(); void trashUnusedClips(); QList documentClipList() const; + void addClipCut(const QString &id, int in, int out); + void removeClipCut(const QString &id, int in, int out); public slots: void setDocument(KdenliveDoc *doc); @@ -146,7 +148,7 @@ public slots: void slotDeleteClip(const QString &clipId); void slotUpdateClip(const QString &id); void slotRefreshClipThumbnail(const QString &clipId, bool update = true); - void slotRefreshClipThumbnail(ProjectItem *item, bool update = true); + void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true); void slotRemoveInvalidClip(const QString &id, bool replace); void slotSelectClip(const QString &ix); void slotRemoveClip(); @@ -170,6 +172,7 @@ private: QUndoStack *m_commandStack; void selectItemById(const QString &clipId); ProjectItem *getItemById(const QString &id); + QTreeWidgetItem *getAnyItemById(const QString &id); ProjectItem *getFolderItemById(const QString &id); QAction *m_editAction; QAction *m_deleteAction; @@ -177,7 +180,6 @@ private: QAction *m_reloadAction; QMenu *m_transcodeAction; KdenliveDoc *m_doc; - ProjectItem *m_selectedItem; ItemDelegate *m_listViewDelegate; bool m_refreshed; QToolButton *m_addButton; @@ -205,10 +207,11 @@ private slots: void slotProcessNextThumbnail(); void slotCheckForEmptyQueue(); void slotPauseMonitor(); + void slotAddClipCut(const QString &id, int in, int out); //void slotShowMenu(const QPoint &pos); signals: - void clipSelected(DocClipBase *); + void clipSelected(DocClipBase *, QPoint zone = QPoint()); void getFileProperties(const QDomElement, const QString &, bool); void receivedClipDuration(const QString &); void showClipProperties(DocClipBase *); diff --git a/src/projectlistview.cpp b/src/projectlistview.cpp index d96f6a7b..17f71189 100644 --- a/src/projectlistview.cpp +++ b/src/projectlistview.cpp @@ -20,6 +20,7 @@ #include "projectlistview.h" #include "projectitem.h" +#include "subprojectitem.h" #include "kdenlivesettings.h" #include @@ -114,7 +115,13 @@ void ProjectListView::contextMenuEvent(QContextMenuEvent * event) // virtual void ProjectListView::mouseDoubleClickEvent(QMouseEvent * event) { - ProjectItem *item = static_cast (itemAt(event->pos())); + QTreeWidgetItem *it = itemAt(event->pos()); + if (!it) return; + ProjectItem *item; + if (it->type() == QTreeWidgetItem::UserType + 1) { + // subitem + item = static_cast (it->parent()); + } else item = static_cast (it); if (!item) { emit addClip(); return; @@ -141,9 +148,16 @@ void ProjectListView::dragEnterEvent(QDragEnterEvent *event) // virtual void ProjectListView::dropEvent(QDropEvent *event) { - kDebug() << "//////////////// DROPPED EVENT"; + ProjectItem *item = NULL; + QTreeWidgetItem *it = itemAt(event->pos()); + if (it) { + if (it->type() == QTreeWidgetItem::UserType + 1) { + // subitem + item = static_cast (it->parent()); + } else item = static_cast (it); + } + if (event->mimeData()->hasUrls()) { - ProjectItem *item = static_cast (itemAt(event->pos())); QString groupName; QString groupId; if (item) { @@ -158,12 +172,10 @@ void ProjectListView::dropEvent(QDropEvent *event) event->accept(); return; } else if (event->mimeData()->hasFormat("kdenlive/producerslist")) { - ProjectItem *item = static_cast (itemAt(event->pos())); if (item) { if (item->parent()) item = static_cast (item->parent()); if (item->isGroup()) { //emit addClip(event->mimeData->text()); - kDebug() << "//////////////// DROPPED RIGHT 1 "; const QList list = selectedItems(); ProjectItem *clone; QString parentId = item->clipId(); @@ -184,7 +196,6 @@ void ProjectListView::dropEvent(QDropEvent *event) } else item = NULL; } if (!item) { - kDebug() << "//////////////// DROPPED ON EMPTY ZONE"; // item dropped in empty zone, move it to top level const QList list = selectedItems(); ProjectItem *clone; @@ -201,6 +212,9 @@ void ProjectListView::dropEvent(QDropEvent *event) } } } + } else if (event->mimeData()->hasFormat("kdenlive/clip")) { + QStringList list = QString(event->mimeData()->data("kdenlive/clip")).split(';'); + emit addClipCut(list.at(0), list.at(1).toInt(), list.at(2).toInt()); } event->acceptProposedAction(); } @@ -235,8 +249,31 @@ void ProjectListView::mouseMoveEvent(QMouseEvent *event) < QApplication::startDragDistance()) return; - { - ProjectItem *clickItem = static_cast (itemAt(m_DragStartPosition)); + QTreeWidgetItem *it = itemAt(m_DragStartPosition); + if (!it) return; + if (it->type() == QTreeWidgetItem::UserType + 1) { + // subitem + SubProjectItem *clickItem = static_cast (it); + if (clickItem && (clickItem->flags() & Qt::ItemIsDragEnabled)) { + ProjectItem *clip = static_cast (it->parent()); + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + + QStringList list; + list.append(clip->clipId()); + QPoint p = clickItem->zone(); + list.append(QString::number(p.x())); + list.append(QString::number(p.y())); + QByteArray data; + data.append(list.join(";").toUtf8()); + mimeData->setData("kdenlive/clip", data); + drag->setMimeData(mimeData); + drag->setPixmap(clickItem->icon(0).pixmap(iconSize())); + drag->setHotSpot(QPoint(0, 50)); + drag->exec(); + } + } else { + ProjectItem *clickItem = static_cast (it); if (clickItem && (clickItem->flags() & Qt::ItemIsDragEnabled)) { QDrag *drag = new QDrag(this); QMimeData *mimeData = new QMimeData; @@ -286,6 +323,7 @@ QStringList ProjectListView::mimeTypes() const qstrList.append("text/uri-list"); qstrList.append("text/plain"); qstrList.append("kdenlive/producerslist"); + qstrList.append("kdenlive/clip"); return qstrList; } diff --git a/src/projectlistview.h b/src/projectlistview.h index bd7b4293..fe1d1aae 100644 --- a/src/projectlistview.h +++ b/src/projectlistview.h @@ -66,6 +66,7 @@ signals: void showProperties(DocClipBase *); void focusMonitor(); void pauseMonitor(); + void addClipCut(const QString&, int, int); }; #endif diff --git a/src/subprojectitem.cpp b/src/subprojectitem.cpp new file mode 100644 index 00000000..110ceca7 --- /dev/null +++ b/src/subprojectitem.cpp @@ -0,0 +1,72 @@ +/*************************************************************************** + * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + + +#include "subprojectitem.h" +#include "timecode.h" +#include "kdenlivesettings.h" +#include "docclipbase.h" + +#include +#include +#include + +const int DurationRole = Qt::UserRole + 1; + +SubProjectItem::SubProjectItem(QTreeWidgetItem * parent, int in, int out) : + QTreeWidgetItem(parent, QTreeWidgetItem::UserType + 1), m_in(in), m_out(out) +{ + setSizeHint(0, QSize(65, 30)); + setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable); + QString name = Timecode::getStringTimecode(in, KdenliveSettings::project_fps()); + setText(1, name); + GenTime duration = GenTime(out - in, KdenliveSettings::project_fps()); + if (duration != GenTime()) setData(1, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps())); + //setFlags(Qt::NoItemFlags); + //kDebug() << "Constructed with clipId: " << m_clipId; +} + + +SubProjectItem::~SubProjectItem() +{ +} + +int SubProjectItem::numReferences() const +{ + return 0; +} + +QDomElement SubProjectItem::toXml() const +{ + //return m_clip->toXML(); + return QDomElement(); +} + +QPoint SubProjectItem::zone() const +{ + QPoint z(m_in, m_out); + return z; +} + +DocClipBase *SubProjectItem::referencedClip() +{ + return NULL; //m_clip; +} + + diff --git a/src/subprojectitem.h b/src/subprojectitem.h new file mode 100644 index 00000000..fc8e4a4f --- /dev/null +++ b/src/subprojectitem.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + + +#ifndef SUBPROJECTITEM_H +#define SUBPROJECTITEM_H + +#include +#include +#include + +#include + +#include "gentime.h" +#include "definitions.h" + +class DocClipBase; + +/** \brief Represents a clip or a folder in the projecttree + * + * This class represents a clip or folder in the projecttree and in the document(?) */ +class SubProjectItem : public QTreeWidgetItem +{ +public: + SubProjectItem(QTreeWidgetItem * parent, int in, int out); + virtual ~SubProjectItem(); + QDomElement toXml() const; + int numReferences() const; + DocClipBase *referencedClip(); + QPoint zone() const; + +private: + int m_in; + int m_out; +}; + +#endif diff --git a/src/transition.h b/src/transition.h index 69ac44e2..8960519b 100644 --- a/src/transition.h +++ b/src/transition.h @@ -97,7 +97,7 @@ private: /** Return the transition type for a given name */ TRANSITIONTYPE getTransitionForName(const QString & type); - + #if QT_VERSION >= 0x040600 QPropertyAnimation *m_startAnimation; #endif