From 0a21eb6dd5c5a44882c51c2c857eec96758d5285 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Sat, 16 Feb 2008 22:53:33 +0000 Subject: [PATCH] Implement clipmanager svn path=/branches/KDE4/; revision=1849 --- src/CMakeLists.txt | 1 + src/addclipcommand.cpp | 14 +++--- src/addclipcommand.h | 11 ++--- src/clipitem.cpp | 55 +++++++++++++++++++--- src/clipitem.h | 5 +- src/clipmanager.cpp | 101 ++++++++++++++++++++++++++++++++++++++++ src/clipmanager.h | 64 +++++++++++++++++++++++++ src/customtrackview.cpp | 18 ++++++- src/customtrackview.h | 1 + src/docclipbase.cpp | 88 +++++++++++++++++++++++++++++----- src/docclipbase.h | 61 ++++++++++++++---------- src/kdenlivedoc.cpp | 42 ++++++++++++++++- src/kdenlivedoc.h | 11 +++++ src/mainwindow.cpp | 3 ++ src/projectitem.cpp | 34 +++++++++++--- src/projectitem.h | 3 ++ src/projectlist.cpp | 63 +++++++++---------------- src/projectlist.h | 2 + src/projectlistview.cpp | 5 +- 19 files changed, 471 insertions(+), 111 deletions(-) create mode 100644 src/clipmanager.cpp create mode 100644 src/clipmanager.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fa8df481..a682066a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,6 +57,7 @@ set(kdenlive_SRCS resizeclipcommand.cpp addtimelineclipcommand.cpp kthumb.cpp + clipmanager.cpp ) kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc ) diff --git a/src/addclipcommand.cpp b/src/addclipcommand.cpp index 1e8b961e..1408a5b5 100644 --- a/src/addclipcommand.cpp +++ b/src/addclipcommand.cpp @@ -21,8 +21,8 @@ #include "addclipcommand.h" -AddClipCommand::AddClipCommand(ProjectList *list, const QStringList &names, const QDomElement &xml, const int id, const KUrl &url, const QString &group, bool doIt) - : m_list(list), m_names(names), m_xml(xml), m_id(id), m_url(url), m_group(group), m_doIt(doIt) { +AddClipCommand::AddClipCommand(KdenliveDoc *doc, const QDomElement &xml, const uint id, bool doIt) + : m_doc(doc), m_xml(xml), m_id(id), m_doIt(doIt) { if (doIt) setText(i18n("Add clip")); else setText(i18n("Delete clip")); } @@ -31,18 +31,16 @@ AddClipCommand::AddClipCommand(ProjectList *list, const QStringList &names, cons // virtual void AddClipCommand::undo() { - if (!m_list) kDebug()<<"---- ERROR, NO LIST FOR undoing action"; kDebug()<<"---- undoing action"; - if (m_doIt) m_list->deleteClip(m_id); - else m_list->addClip(m_names, m_xml, m_id, m_url, m_group); + if (m_doIt) m_doc->deleteClip(m_id); + else m_doc->addClip(m_xml, m_id); } // virtual void AddClipCommand::redo() { - if (!m_list) kDebug()<<"---- ERROR, NO LIST FOR redoing action"; kDebug()<<"---- redoing action"; - if (m_doIt) m_list->addClip(m_names, m_xml, m_id, m_url, m_group); - else m_list->deleteClip(m_id); + if (m_doIt) m_doc->addClip(m_xml, m_id); + else m_doc->deleteClip(m_id); } #include "addclipcommand.moc" diff --git a/src/addclipcommand.h b/src/addclipcommand.h index 705815dd..afa2068a 100644 --- a/src/addclipcommand.h +++ b/src/addclipcommand.h @@ -24,24 +24,21 @@ #include #include -#include "projectlist.h" +#include "kdenlivedoc.h" class AddClipCommand : public QUndoCommand { public: - AddClipCommand(ProjectList *list, const QStringList &names, const QDomElement &xml, const int id, const KUrl &url, const QString &group, bool doIt); + AddClipCommand(KdenliveDoc *list, const QDomElement &xml, const uint id, bool doIt); virtual void undo(); virtual void redo(); private: - ProjectList *m_list; - QStringList m_names; + KdenliveDoc *m_doc; QDomElement m_xml; - int m_id; - KUrl m_url; + uint m_id; bool m_doIt; - QString m_group; }; #endif diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 01334ae0..a09b3096 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -34,7 +34,7 @@ #include "kdenlivesettings.h" ClipItem::ClipItem(QDomElement xml, int track, int startpos, const QRectF & rect, int duration) - : QGraphicsRectItem(rect), m_xml(xml), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_track(track), m_startPos(startpos), m_thumbProd(NULL), startThumbTimer(NULL), endThumbTimer(NULL), m_startFade(0), m_endFade(0) + : QGraphicsRectItem(rect), m_xml(xml), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_track(track), m_startPos(startpos), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), m_startFade(0), m_endFade(0) { //setToolTip(name); @@ -56,9 +56,9 @@ ClipItem::ClipItem(QDomElement xml, int track, int startpos, const QRectF & rect setBrush(QColor(100, 100, 150)); if (m_clipType == VIDEO || m_clipType == AV) { - m_thumbProd = new KThumb(KUrl(xml.attribute("resource")), KdenliveSettings::track_height() * KdenliveSettings::project_display_ratio(), KdenliveSettings::track_height()); - connect(this, SIGNAL(getThumb(int, int)), m_thumbProd, SLOT(extractImage(int, int))); - connect(m_thumbProd, SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap))); + m_hasThumbs = true; + //connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int))); + //connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap))); QTimer::singleShot(300, this, SLOT(slotFetchThumbs())); startThumbTimer = new QTimer(this); @@ -79,11 +79,52 @@ ClipItem::ClipItem(QDomElement xml, int track, int startpos, const QRectF & rect } } +ClipItem::ClipItem(DocClipBase *clip, int track, int startpos, const QRectF & rect, int duration) + : QGraphicsRectItem(rect), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_track(track), m_startPos(startpos), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), m_startFade(0), m_endFade(0) +{ + //setToolTip(name); + kDebug()<<"******* CREATING NEW TML CLIP, DUR: "<toXML(); + m_clipName = clip->name(); + m_producer = clip->getId(); + m_clipType = clip->clipType(); + m_cropStart = 0; + m_maxDuration = duration; + if (duration != -1) m_cropDuration = duration; + else m_cropDuration = m_maxDuration; + + setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemClipsChildrenToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + + setBrush(QColor(100, 100, 150)); + if (m_clipType == VIDEO || m_clipType == AV) { + m_hasThumbs = true; + connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int))); + connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap))); + QTimer::singleShot(300, this, SLOT(slotFetchThumbs())); + + startThumbTimer = new QTimer(this); + startThumbTimer->setSingleShot(true); + connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb())); + endThumbTimer = new QTimer(this); + endThumbTimer->setSingleShot(true); + connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb())); + + } + else if (m_clipType == COLOR) { + QString colour = m_xml.attribute("colour"); + colour = colour.replace(0, 2, "#"); + setBrush(QColor(colour.left(7))); + } + else if (m_clipType == IMAGE) { + m_startPix = KThumb::getImage(KUrl(m_xml.attribute("resource")), 50 * KdenliveSettings::project_display_ratio(), 50); + } +} + + ClipItem::~ClipItem() { if (startThumbTimer) delete startThumbTimer; if (endThumbTimer) delete endThumbTimer; - if (m_thumbProd) delete m_thumbProd; } void ClipItem::slotFetchThumbs() @@ -394,7 +435,7 @@ void ClipItem::resizeStart(int posx, double scale) break; } } - if (m_thumbProd) startThumbTimer->start(100); + if (m_hasThumbs) startThumbTimer->start(100); } void ClipItem::resizeEnd(int posx, double scale) @@ -421,7 +462,7 @@ void ClipItem::resizeEnd(int posx, double scale) break; } } - if (m_thumbProd) endThumbTimer->start(100); + if (m_hasThumbs) endThumbTimer->start(100); } // virtual diff --git a/src/clipitem.h b/src/clipitem.h index 42c5163c..1278c6fb 100644 --- a/src/clipitem.h +++ b/src/clipitem.h @@ -27,6 +27,7 @@ #include "definitions.h" #include "gentime.h" +#include "docclipbase.h" #include "kthumb.h" @@ -36,6 +37,7 @@ class ClipItem : public QObject, public QGraphicsRectItem public: ClipItem(QDomElement xml, int track, int startpos, const QRectF & rect, int duration = -1); + ClipItem(DocClipBase *clip, int track, int startpos, const QRectF & rect, int duration); virtual ~ ClipItem(); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, @@ -67,6 +69,7 @@ class ClipItem : public QObject, public QGraphicsRectItem private: QDomElement m_xml; + DocClipBase *m_clip; int m_textWidth; OPERATIONTYPE m_resizeMode; int m_grabPoint; @@ -81,7 +84,7 @@ class ClipItem : public QObject, public QGraphicsRectItem int m_startPos; QPixmap m_startPix; QPixmap m_endPix; - KThumb *m_thumbProd; + bool m_hasThumbs; QTimer *startThumbTimer; QTimer *endThumbTimer; uint m_startFade; diff --git a/src/clipmanager.cpp b/src/clipmanager.cpp new file mode 100644 index 00000000..d355f61f --- /dev/null +++ b/src/clipmanager.cpp @@ -0,0 +1,101 @@ +/*************************************************************************** + * 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 +#include + +#include "addclipcommand.h" +#include "kdenlivesettings.h" +#include "clipmanager.h" + + +ClipManager::ClipManager(KdenliveDoc *doc):m_doc(doc) +{ + m_clipIdCounter = 1; +} + +ClipManager::~ClipManager() +{ +} + +void ClipManager::addClip(DocClipBase *clip) +{ + m_clipList.append(clip); +} + +void ClipManager::deleteClip(uint clipId) +{ + for (int i = 0; i < m_clipList.count(); i++) { + if (m_clipList.at(i)->getId() == clipId) + m_clipList.removeAt(i); + } +} + +DocClipBase *ClipManager::getClipAt(int pos) +{ + return m_clipList.at(pos); +} + +DocClipBase *ClipManager::getClipById(int clipId) +{ + kDebug()<<"++++ CLIP MAN, LOOKING FOR CLIP ID: "<getId() == clipId) + { + kDebug()<<"++++ CLIP MAN, FOUND FOR CLIP ID: "<name().startsWith("image/")) { + prod.setAttribute("type", (int) IMAGE); + prod.setAttribute("in", "0"); + prod.setAttribute("out", m_doc->getFramePos(KdenliveSettings::image_duration())); + } + AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true); + m_doc->commandStack()->push(command); +} + +void ClipManager::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group) +{ + QDomDocument doc; + QDomElement prod = doc.createElement("producer"); + prod.setAttribute("mlt_service", "colour"); + prod.setAttribute("colour", color); + prod.setAttribute("type", (int) COLOR); + uint id = m_clipIdCounter++; + prod.setAttribute("id", QString::number(id)); + prod.setAttribute("in", "0"); + prod.setAttribute("out", m_doc->getFramePos(duration)); + prod.setAttribute("name", name); + AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true); + m_doc->commandStack()->push(command); +} + diff --git a/src/clipmanager.h b/src/clipmanager.h new file mode 100644 index 00000000..fe708e96 --- /dev/null +++ b/src/clipmanager.h @@ -0,0 +1,64 @@ +/*************************************************************************** + * 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 CLIPMANAGER_H +#define CLIPMANAGER_H + +/**ClipManager manages the list of clips in a document + *@author Jean-Baptiste Mardelle + */ + +#include +#include +#include + +#include +#include +#include + +#include "gentime.h" +#include "definitions.h" +#include "docclipbase.h" + +class KdenliveDoc; + + +class ClipManager:public QObject { + Q_OBJECT public: + + + ClipManager(KdenliveDoc *doc); + virtual ~ ClipManager(); + void addClip(DocClipBase *clip); + DocClipBase *getClipAt(int pos); + void deleteClip(uint clipId); + void slotAddClipFile(const KUrl url, const QString group); + void slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group); + DocClipBase *getClipById(int clipId); + + private: // Private attributes + /** the list of clips in the document */ + QList m_clipList; + /** the document undo stack*/ + KdenliveDoc *m_doc; + int m_clipIdCounter; + +}; + +#endif diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 08f940ce..d8439ed8 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -303,12 +303,28 @@ void CustomTrackView::mousePressEvent ( QMouseEvent * event ) void CustomTrackView::dragEnterEvent ( QDragEnterEvent * event ) { if (event->mimeData()->hasText()) { - QString clip = event->mimeData()->text(); + kDebug()<<"/////////////// DRAG ENTERED, TEXT: "<mimeData()->text(); + QStringList ids = QString(event->mimeData()->text()).split(";"); + //TODO: drop of several clips + for (int i = 0; i < ids.size(); ++i) { + } + DocClipBase *clip = m_document->getBaseClip(ids.at(0).toInt()); + if (clip == NULL) kDebug()<<" WARNING))))))))) CLIP NOT FOUND : "<pos()); event->acceptProposedAction(); } } +void CustomTrackView::addItem(DocClipBase *clip, QPoint pos) +{ + int in =0; + int out = clip->duration().frames(m_document->fps()); + //kdDebug()<<"- - - -CREATING CLIP, duration = "<fileURL(); + int trackTop = ((int) mapToScene(pos).y()/50) * 50 + 1; + m_dropItem = new ClipItem(clip, ((int) mapToScene(pos).y()/50), in, QRectF(mapToScene(pos).x() * m_scale, trackTop, out * m_scale, 49), out); + scene()->addItem(m_dropItem); +} + void CustomTrackView::addItem(QString producer, QPoint pos) { diff --git a/src/customtrackview.h b/src/customtrackview.h index d0386b39..4952beae 100644 --- a/src/customtrackview.h +++ b/src/customtrackview.h @@ -72,6 +72,7 @@ class CustomTrackView : public QGraphicsView ClipItem *m_dropItem; KdenliveDoc *m_document; void addItem(QString producer, QPoint pos); + void addItem(DocClipBase *clip, QPoint pos); QGraphicsLineItem *m_cursorLine; QPointF m_startPos; OPERATIONTYPE m_operationMode; diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index baf92218..69994887 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -17,21 +17,52 @@ #include +#include "kdenlivesettings.h" #include "docclipbase.h" -/*#include "docclipavfile.h" -#include "doccliptextfile.h" -#include "docclipproject.h" -#include "doctrackbase.h"*/ -DocClipBase::DocClipBase(): -m_description(""), m_refcount(0), m_projectThumbFrame(0), audioThumbCreated(false) +DocClipBase::DocClipBase(QDomElement xml, uint id): +m_xml(xml), m_id(id), m_description(""), m_refcount(0), m_projectThumbFrame(0), audioThumbCreated(false), m_duration(GenTime()), m_thumbProd(NULL) { - //thumbCreator = 0; + int type = xml.attribute("type").toInt(); + m_clipType = (CLIPTYPE) type; + m_name = xml.attribute("name"); + m_xml.setAttribute("id", QString::number(id)); + KUrl url = KUrl(xml.attribute("resource")); + int out = xml.attribute("out").toInt(); + if (out != 0) setDuration(GenTime(out, 25)); + if (m_name.isEmpty()) m_name = url.fileName(); + if (!url.isEmpty()) + m_thumbProd = new KThumb(url, KdenliveSettings::track_height() * KdenliveSettings::project_display_ratio(), KdenliveSettings::track_height()); +} + +DocClipBase::DocClipBase(const DocClipBase& clip) +{ + m_xml = clip.toXML(); + m_id = clip.getId(); + m_clipType = clip.clipType(); + m_name = clip.name(); + m_duration = clip.duration(); +} + +DocClipBase & DocClipBase::operator=(const DocClipBase & clip) +{ + DocClipBase::operator=(clip); + m_xml = clip.toXML(); + m_id = clip.getId(); + m_clipType = clip.clipType(); + m_name = clip.name(); + m_duration = clip.duration(); + return *this; } DocClipBase::~DocClipBase() { - //delete thumbCreator; + //if (m_thumbProd) delete m_thumbProd; +} + +KThumb *DocClipBase::thumbProducer() +{ + return m_thumbProd; } void DocClipBase::setName(const QString name) @@ -41,6 +72,7 @@ void DocClipBase::setName(const QString name) const QString & DocClipBase::name() const { + return m_name; } @@ -54,6 +86,23 @@ void DocClipBase::setId( const uint &newId) m_id = newId; } +const CLIPTYPE & DocClipBase::clipType() const +{ + return m_clipType; +} + +void DocClipBase::setClipType(CLIPTYPE type) +{ + m_clipType = type; +} + +const KUrl & DocClipBase::fileURL() const +{ + QString res = m_xml.attribute("resource"); + if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res); + return KUrl(); +} + void DocClipBase::setProjectThumbFrame( const uint &ix) { m_projectThumbFrame = ix; @@ -74,17 +123,34 @@ const QString & DocClipBase::description() const return m_description; } +void DocClipBase::setDuration(GenTime dur) +{ + m_duration = dur; +} + +const GenTime &DocClipBase::duration() const +{ + return m_duration; +} + +bool DocClipBase::hasFileSize() const +{ + return true; +} + + // virtual -QDomDocument DocClipBase::toXML() const +QDomElement DocClipBase::toXML() const { +/* QDomDocument doc; QDomElement clip = doc.createElement("kdenliveclip"); QDomText text = doc.createTextNode(description()); clip.appendChild(text); doc.appendChild(clip); - - return doc; +*/ + return m_xml; } DocClipBase *DocClipBase:: diff --git a/src/docclipbase.h b/src/docclipbase.h index fadb38ca..1f2aa96f 100644 --- a/src/docclipbase.h +++ b/src/docclipbase.h @@ -23,14 +23,15 @@ */ #include -#include -#include +#include +#include -#include +#include #include #include "gentime.h" -// #include "kthumb.h" +#include "definitions.h" + #include "kthumb.h" /* class DocTrackBase; @@ -63,10 +64,10 @@ class DocClipBase:public QObject { * - e.g. if you can have audio and video seperately, it should be possible to combin the two, as is * done here. If a new clip type is added then it should be possible to combine it with both audio * and video. */ - enum CLIPTYPE { NONE = 0, AUDIO = 1, VIDEO = 2, AV = 3, COLOR = - 4, IMAGE = 5, TEXT = 6, SLIDESHOW = 7, VIRTUAL = 8, PLAYLIST = 9}; - DocClipBase(); + DocClipBase(QDomElement xml, uint id); + DocClipBase(const DocClipBase& clip); + DocClipBase & operator=(const DocClipBase & clip); virtual ~ DocClipBase(); /** sets the name of this clip. */ @@ -89,25 +90,29 @@ class DocClipBase:public QObject { bool audioThumbCreated; /** returns the duration of this clip */ - virtual const GenTime & duration() const = 0; + const GenTime & duration() const; + /** returns the duration of this clip */ + void setDuration(GenTime dur); /** returns clip type (audio, text, image,...) */ - virtual const DocClipBase::CLIPTYPE & clipType() const = 0; + const CLIPTYPE & clipType() const; + /** set clip type (audio, text, image,...) */ + void setClipType(CLIPTYPE type); /** remove tmp file if the clip has one (for example text clips) */ - virtual void removeTmpFile() const = 0; + void removeTmpFile() const; /** Returns a url to a file describing this clip. Exactly what this url is, whether it is temporary or not, and whether it provokes a render will depend entirely on what the clip consists of. */ - virtual const KUrl & fileURL() const = 0; + const KUrl & fileURL() const; /** Returns true if the clip duration is known, false otherwise. */ - virtual bool durationKnown() const = 0; + bool durationKnown() const; // Returns the number of frames per second that this clip should play at. - virtual double framesPerSecond() const = 0; + double framesPerSecond() const; - virtual bool isDocClipAVFile() const { + bool isDocClipAVFile() const { return false; } @@ -133,7 +138,7 @@ class DocClipBase:public QObject { /** Returns true if this clip is a project clip, false otherwise. Overridden in DocClipProject, * where it returns true. */ - virtual bool isProjectClip() const { + bool isProjectClip() const { return false; } // Appends scene times for this clip to the passed vector. @@ -142,14 +147,14 @@ class DocClipBase:public QObject { /** Reads in the element structure and creates a clip out of it.*/ // Returns an XML document that describes part of the current scene. - virtual QDomDocument sceneToXML(const GenTime & startTime, - const GenTime & endTime) const = 0; + QDomDocument sceneToXML(const GenTime & startTime, + const GenTime & endTime) const; /** returns a QString containing all of the XML data required to recreate this clip. */ - virtual QDomDocument toXML() const; - virtual QDomDocument generateSceneList(bool addProducers = true, bool rendering = false) const; + QDomElement toXML() const; + QDomDocument generateSceneList(bool addProducers = true, bool rendering = false) const; /** Returns true if the xml passed matches the values in this clip */ - virtual bool matchesXML(const QDomElement & element) const = 0; + bool matchesXML(const QDomElement & element) const; void addReference() { ++m_refcount; @@ -161,18 +166,21 @@ class DocClipBase:public QObject { return m_refcount; } /** Returns true if this clip has a meaningful filesize. */ - virtual bool hasFileSize() const = 0; + bool hasFileSize() const; /** Returns the filesize, or 0 if there is no appropriate filesize. */ - virtual uint fileSize() const = 0; + uint fileSize() const; /** Returns true if this clip refers to the clip passed in. A clip refers to another clip if * it uses it as part of it's own composition. */ - virtual bool referencesClip(DocClipBase * clip) const = 0; + bool referencesClip(DocClipBase * clip) const; /** Sets the thumbnail to be used by this clip */ void setThumbnail(const QPixmap & pixmap); + /** Returns the thumbnail producer used by this clip */ + KThumb *thumbProducer(); + /** Returns the thumbnail used by this clip */ const QPixmap & thumbnail() const; @@ -193,12 +201,17 @@ class DocClipBase:public QObject { * that exist. */ uint m_refcount; + CLIPTYPE m_clipType; + /** A list of snap markers; these markers are added to a clips snap-to points, and are displayed as necessary. */ QList < CommentedTime > m_snapMarkers; - + QDomElement m_xml; /** A thumbnail for this clip */ QPixmap m_thumbnail; + GenTime m_duration; + + KThumb *m_thumbProd; /** a unique numeric id */ uint m_id; diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index a04b6145..dad7c856 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -27,9 +27,9 @@ #include "kdenlivedoc.h" - KdenliveDoc::KdenliveDoc(const KUrl &url, double fps, int width, int height, QWidget *parent):QObject(parent), m_render(NULL), m_url(url), m_fps(fps), m_width(width), m_height(height), m_projectName(NULL), m_commandStack(new KUndoStack()) { + m_clipManager = new ClipManager(this); if (!url.isEmpty()) { QString tmpFile; if(KIO::NetAccess::download(url.path(), tmpFile, parent)) @@ -99,6 +99,12 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, double fps, int width, int height, QWi KdenliveDoc::~KdenliveDoc() { delete m_commandStack; + delete m_clipManager; +} + +ClipManager *KdenliveDoc::clipManager() +{ + return m_clipManager; } KUndoStack *KdenliveDoc::commandStack() @@ -117,6 +123,11 @@ Render *KdenliveDoc::renderer() return m_render; } +int KdenliveDoc::getFramePos(QString duration) +{ + return m_timecode.getFrameCount(duration, m_fps); +} + QString KdenliveDoc::producerName(int id) { QString result = "unnamed"; @@ -238,5 +249,34 @@ KUrl KdenliveDoc::url() return m_url; } +void KdenliveDoc::addClip(const QDomElement &elem, const int clipId) +{ + kDebug()<<"///////// DOCUM, CREATING NEW CLIP, ID:"<addClip(clip); + emit addProjectClip(clip); +} + +void KdenliveDoc::deleteClip(const uint clipId) +{ + m_clipManager->deleteClip(clipId); +} + +void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group) +{ + kDebug()<<"///////// DOCUM, ADD CLP: "<slotAddClipFile(url, group); +} + +DocClipBase *KdenliveDoc::getBaseClip(int clipId) +{ + return m_clipManager->getClipById(clipId); +} + +void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group) +{ + m_clipManager->slotAddColorClipFile(name, color, duration, group); +} + #include "kdenlivedoc.moc" diff --git a/src/kdenlivedoc.h b/src/kdenlivedoc.h index 0c7d93ea..2a435a82 100644 --- a/src/kdenlivedoc.h +++ b/src/kdenlivedoc.h @@ -33,6 +33,7 @@ #include "gentime.h" #include "timecode.h" #include "renderer.h" +#include "clipmanager.h" class KdenliveDoc:public QObject { Q_OBJECT public: @@ -54,6 +55,13 @@ class KdenliveDoc:public QObject { void setProducerDuration(int id, int duration); int getProducerDuration(int id); Render *renderer(); + ClipManager *clipManager(); + void addClip(const QDomElement &elem, const int clipId); + void slotAddClipFile(const KUrl url, const QString group); + void slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group); + void deleteClip(const uint clipId); + int getFramePos(QString duration); + DocClipBase *getBaseClip(int clipId); private: KUrl m_url; @@ -66,9 +74,12 @@ class KdenliveDoc:public QObject { Render *m_render; KUndoStack *m_commandStack; QDomDocument generateSceneList(); + ClipManager *m_clipManager; public slots: + signals: + void addProjectClip(DocClipBase *); }; #endif diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index be6354d9..b5e9e2bd 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -320,6 +320,7 @@ void MainWindow::slotUpdateMousePosition(int pos) void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //changed { //m_projectMonitor->stop(); + kDebug()<<"/////////////////// CONNECTING DOC TO PROJECT VIEW ////////////////"; if (m_activeDocument) { if (m_activeDocument == doc) return; m_activeDocument->setProducers(m_projectList->producersList()); @@ -328,6 +329,8 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //chang connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor())); connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int))); connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int))); + connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *))); + m_projectList->setDocument(doc); m_monitorManager->setTimecode(doc->timecode()); doc->setRenderer(m_projectMonitor->render); diff --git a/src/projectitem.cpp b/src/projectitem.cpp index 53fde22a..342496c9 100644 --- a/src/projectitem.cpp +++ b/src/projectitem.cpp @@ -82,6 +82,23 @@ ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, int setIcon(0, KIcon("folder")); } +ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip) + : QTreeWidgetItem(parent, QStringList(), QTreeWidgetItem::UserType), m_isGroup(false) +{ + setSizeHint(0, QSize(65, 45)); + setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable); + m_clip = clip; + m_element = clip->toXML(); + m_clipId = clip->getId(); + QString name = m_element.attribute("name"); + if (name.isEmpty()) name = KUrl(m_element.attribute("resource")).fileName(); + m_clipType = (CLIPTYPE) m_element.attribute("type").toInt(); + m_groupName = m_element.attribute("group"); + setText(1, name); + kDebug()<<"PROJECT ITE;. ADDING LCIP: "<< m_clipId; +} + + ProjectItem::~ProjectItem() { } @@ -175,12 +192,14 @@ void ProjectItem::slotSetToolTip() void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata) { - if (attributes.contains("duration")) { - if (m_clipType == AUDIO || m_clipType == VIDEO || m_clipType == AV) m_element.setAttribute("duration", attributes["duration"].toInt()); - m_duration = GenTime(attributes["duration"].toInt(), 25); - setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25)); - m_durationKnown = true; - } else { + if (attributes.contains("duration")) { + if (m_clipType == AUDIO || m_clipType == VIDEO || m_clipType == AV) m_element.setAttribute("duration", attributes["duration"].toInt()); + m_duration = GenTime(attributes["duration"].toInt(), 25); + setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25)); + m_durationKnown = true; + m_clip->setDuration(m_duration); + kDebug()<<"//// LOADED CLIP, DURATION SET TO: "< &attributes, con //extend attributes -reh - if (m_clipType == UNKNOWN) { + if (m_clipType == UNKNOWN) { if (attributes.contains("type")) { if (attributes["type"] == "audio") m_clipType = AUDIO; @@ -202,6 +221,7 @@ void ProjectItem::setProperties(const QMap < QString, QString > &attributes, con } else { m_clipType = AV; } + m_clip->setClipType(m_clipType); } slotSetToolTip(); diff --git a/src/projectitem.h b/src/projectitem.h index 95b4e14f..1cf05b7d 100644 --- a/src/projectitem.h +++ b/src/projectitem.h @@ -29,6 +29,7 @@ #include "gentime.h" #include "definitions.h" +#include "docclipbase.h" class ProjectItem : public QTreeWidgetItem { @@ -36,6 +37,7 @@ class ProjectItem : public QTreeWidgetItem ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml, int clipId); ProjectItem(QTreeWidgetItem * parent, const QStringList & strings, QDomElement xml, int clipId); ProjectItem(QTreeWidget * parent, const QStringList & strings, int clipId); + ProjectItem(QTreeWidget * parent, DocClipBase *clip); virtual ~ProjectItem(); QDomElement toXml() const; @@ -57,6 +59,7 @@ class ProjectItem : public QTreeWidgetItem void slotSetToolTip(); bool m_isGroup; QString m_groupName; + DocClipBase *m_clip; }; #endif diff --git a/src/projectlist.cpp b/src/projectlist.cpp index 026e5b29..24690255 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -41,7 +41,6 @@ #include "kdenlivesettings.h" #include "ui_colorclip_ui.h" -#include "addclipcommand.h" #include "definitions.h" #include @@ -86,7 +85,7 @@ ProjectList::ProjectList(QWidget *parent) layout->addWidget( m_toolbar ); layout->addWidget( listView ); setLayout( layout ); - m_toolbar->setEnabled(false); + //m_toolbar->setEnabled(false); searchView->setTreeWidget(listView); listView->setColumnCount(3); @@ -181,13 +180,14 @@ void ProjectList::slotContextMenu( const QPoint &pos, QTreeWidgetItem *item ) void ProjectList::slotRemoveClip() { +/* if (!m_commandStack) kDebug()<<"!!!!!!!!!!!!!!!!  NO CMD STK"; if (!listView->currentItem()) return; ProjectItem *item = ((ProjectItem *)listView->currentItem()); if (!item) kDebug()<<"/////////////// ERROR NOT FOUND"; if (KMessageBox::questionYesNo(this, i18n("Delete clip %1 ?").arg(item->names().at(1)), i18n("Delete Clip")) != KMessageBox::Yes) return; AddClipCommand *command = new AddClipCommand(this, item->names(), item->toXml(), item->clipId(), item->clipUrl(), item->groupName(), false); - m_commandStack->push(command); + m_commandStack->push(command);*/ } void ProjectList::selectItemById(const int clipId) @@ -281,13 +281,27 @@ void ProjectList::deleteClip(const int clipId) void ProjectList::slotAddFolder() { +/* QString folderName = KInputDialog::getText(i18n("New Folder"), i18n("Enter new folder name: ")); if (folderName.isEmpty()) return; QStringList itemEntry; itemEntry.append(QString::null); itemEntry.append(folderName); AddClipCommand *command = new AddClipCommand(this, itemEntry, QDomElement(), m_clipIdCounter++, KUrl(), folderName, true); - m_commandStack->push(command); + m_commandStack->push(command);*/ +} + +void ProjectList::slotAddClip(DocClipBase *clip) +{ + ProjectItem *item = new ProjectItem(listView, clip); + listView->setCurrentItem(item); + /* + if (clip->clipType() != COLOR) { + Nepomuk::Resource f( clip->fileURL().path() ); + QString annotation = f.description(); + if (!annotation.isEmpty()) item->setText(2, annotation); + }*/ + emit getFileProperties(clip->toXML(), clip->getId()); } void ProjectList::slotAddClip(QUrl givenUrl, const QString &group) @@ -299,28 +313,10 @@ void ProjectList::slotAddClip(QUrl givenUrl, const QString &group) else list.append(givenUrl); if (list.isEmpty()) return; KUrl::List::Iterator it; - KUrl url; -// ProjectItem *item; for (it = list.begin(); it != list.end(); it++) { - QStringList itemEntry; - QDomDocument doc; - QDomElement prod = doc.createElement("producer"); - prod.setAttribute("resource", (*it).path()); - itemEntry.append(QString::null); - itemEntry.append((*it).fileName()); - KMimeType::Ptr type = KMimeType::findByUrl(*it); - if (type->name().startsWith("image/")) { - prod.setAttribute("type", (int) IMAGE); - prod.setAttribute("in", "0"); - prod.setAttribute("out", m_timecode.getFrameCount(KdenliveSettings::image_duration(), m_fps)); - } - AddClipCommand *command = new AddClipCommand(this, itemEntry, prod, m_clipIdCounter++, *it, group, true); - m_commandStack->push(command); - //item = new ProjectItem(listView, itemEntry, QDomElement()); - //item->setData(1, FullPathRole, (*it).path()); + m_doc->slotAddClipFile(*it, group); } - //listView->setCurrentItem(item); } void ProjectList::slotAddColorClip() @@ -333,27 +329,9 @@ void ProjectList::slotAddColorClip() dia_ui->clip_duration->setText(KdenliveSettings::color_duration()); if (dia->exec() == QDialog::Accepted) { - QDomDocument doc; - QDomElement element = doc.createElement("producer"); - element.setAttribute("mlt_service", "colour"); QString color = dia_ui->clip_color->color().name(); color = color.replace(0, 1, "0x") + "ff"; - element.setAttribute("colour", color); - element.setAttribute("type", (int) COLOR); - element.setAttribute("in", "0"); - element.setAttribute("out", m_timecode.getFrameCount(dia_ui->clip_duration->text(), m_fps)); - element.setAttribute("name", dia_ui->clip_name->text()); - QStringList itemEntry; - itemEntry.append(QString::null); - itemEntry.append(dia_ui->clip_name->text()); - AddClipCommand *command = new AddClipCommand(this, itemEntry, element, m_clipIdCounter++, KUrl(), QString::null, true); - m_commandStack->push(command); - // ProjectItem *item = new ProjectItem(listView, itemEntry, element, m_clipIdCounter++); - /*QPixmap pix(60, 40); - pix.fill(dia_ui->clip_color->color()); - item->setIcon(0, QIcon(pix));*/ - //listView->setCurrentItem(item); - + m_doc->slotAddColorClipFile(dia_ui->clip_name->text(), color, dia_ui->clip_duration->text(), QString::null); } delete dia_ui; delete dia; @@ -364,6 +342,7 @@ void ProjectList::setDocument(KdenliveDoc *doc) m_fps = doc->fps(); m_timecode = doc->timecode(); m_commandStack = doc->commandStack(); + m_doc = doc; QDomNodeList prods = doc->producersList(); int ct = prods.count(); kDebug()<<"//////////// SETTING DOC, FOUND CLIPS: "< &properties, const QMap < QString, QString > &metadata); + void slotAddClip(DocClipBase *clip); private: @@ -131,6 +132,7 @@ class ProjectList : public QWidget QAction *m_editAction; QAction *m_deleteAction; ItemDelegate *m_listViewDelegate; + KdenliveDoc *m_doc; private slots: void slotAddClip(QUrl givenUrl = QUrl(), const QString &group = QString::null); diff --git a/src/projectlistview.cpp b/src/projectlistview.cpp index 400e5a5e..1eae496a 100644 --- a/src/projectlistview.cpp +++ b/src/projectlistview.cpp @@ -156,15 +156,16 @@ void ProjectListView::mouseMoveEvent(QMouseEvent *event) QDomDocument doc; QList list; list = selectedItems (); + QStringList ids; foreach (QTreeWidgetItem *item, list) { // TODO allow dragging of folders if (!((ProjectItem *) item)->isGroup()) - doc.appendChild(doc.importNode(((ProjectItem *) item)->toXml(), true)); + ids.append(QString::number(((ProjectItem *) item)->clipId())); } //QByteArray data; //data.append(doc.toString().toUtf8()); //mimeData->setData("kdenlive/westley",data ); - mimeData->setText(doc.toString()); + mimeData->setText(ids.join(";")); //doc.toString()); //mimeData->setImageData(image); drag->setMimeData(mimeData); drag->setPixmap(clickItem->icon(0).pixmap(50 *16/9.0, 50)); -- 2.39.2