]> git.sesse.net Git - kdenlive/commitdiff
Implement clipmanager
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 16 Feb 2008 22:53:33 +0000 (22:53 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 16 Feb 2008 22:53:33 +0000 (22:53 +0000)
svn path=/branches/KDE4/; revision=1849

19 files changed:
src/CMakeLists.txt
src/addclipcommand.cpp
src/addclipcommand.h
src/clipitem.cpp
src/clipitem.h
src/clipmanager.cpp [new file with mode: 0644]
src/clipmanager.h [new file with mode: 0644]
src/customtrackview.cpp
src/customtrackview.h
src/docclipbase.cpp
src/docclipbase.h
src/kdenlivedoc.cpp
src/kdenlivedoc.h
src/mainwindow.cpp
src/projectitem.cpp
src/projectitem.h
src/projectlist.cpp
src/projectlist.h
src/projectlistview.cpp

index fa8df4819d6cdea0973173e75484dbc6a80e4b76..a682066a8b9f5622ee043183552a9edbbed5baf0 100644 (file)
@@ -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 )
index 1e8b961e2436b57d98aa79c511dabcafbd2b4e53..1408a5b5f859509e15d5207551d618c7a5a0eabb 100644 (file)
@@ -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"
index 705815dd5fbbbc4ea5d36c2b68e47b128569d829..afa2068a4cf5acad7a346375753be9d32abe0788 100644 (file)
 #include <QUndoCommand>
 #include <KDebug>
 
-#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
index 01334ae0f6abc20063e6d5e8826cd5d749ab3497..a09b3096082ffeaa84d0216d5ea032b50d10f5b0 100644 (file)
@@ -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: "<<duration;
+  m_xml = clip->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
index 42c5163cf52efdb40c8a42217baab3b8d9b4fc54..1278c6fb76158f70124102e2f38c754bbc64445b 100644 (file)
@@ -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 (file)
index 0000000..d355f61
--- /dev/null
@@ -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 <KDebug>
+#include <KFileDialog>
+
+#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: "<<clipId;
+  for (int i = 0; i < m_clipList.count(); i++) {
+    if (m_clipList.at(i)->getId() == clipId)
+    {
+        kDebug()<<"++++  CLIP MAN, FOUND FOR CLIP ID: "<<clipId;
+      return m_clipList.at(i);
+    }
+  }
+  return NULL;
+}
+
+void ClipManager::slotAddClipFile(const KUrl url, const QString group)
+{
+    kDebug()<<"/////  CLIP MANAGER, ADDING CLIP: "<<url;
+    QDomDocument doc;
+    QDomElement prod = doc.createElement("producer");
+    prod.setAttribute("resource", url.path());
+    uint id = m_clipIdCounter++;
+    prod.setAttribute("id", QString::number(id));
+    if (!group.isEmpty()) prod.setAttribute("group", group);
+    KMimeType::Ptr type = KMimeType::findByUrl(url);
+    if (type->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 (file)
index 0000000..fe708e9
--- /dev/null
@@ -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 <qdom.h>
+#include <QPixmap>
+#include <QObject>
+
+#include <KUrl>
+#include <KUndoStack>
+#include <klocale.h>
+
+#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 <DocClipBase*> m_clipList;
+    /** the document undo stack*/
+    KdenliveDoc *m_doc;
+    int m_clipIdCounter;
+
+};
+
+#endif
index 08f940cebef05292fa59fac443407455cbdebf2f..d8439ed830432615ce26e6185abd88fbcf696228 100644 (file)
@@ -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: "<<event->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 : "<<ids.at(0).toInt();
     addItem(clip, event->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 = "<<out<<", URL: "<<clip->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)
 {
index d0386b3950b09f1422e254008b34624543d0dcb6..4952beae5fe2fe9c0f97639fcb2e4569908fd671 100644 (file)
@@ -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;
index baf922185ca3fd885c1c6fffc1e728209fa33840..69994887b62b47951c556ddefd233d60e1311b21 100644 (file)
 
 #include <KDebug>
 
+#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::
index fadb38ca28c16ba6a664626f3327a6d0fff5d1da..1f2aa96f2274cada5fe2e83fcd663b726e279ca2 100644 (file)
   */
 
 #include <qdom.h>
-#include <qobject.h>
-#include <qpixmap.h>
+#include <QPixmap>
+#include <QObject>
 
-#include <kurl.h>
+#include <KUrl>
 #include <klocale.h>
 
 #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;
index a04b6145b10d288e8597df86f93f719d0e8817f5..dad7c856c3f2b068626954a26ade4568dfcd0b5e 100644 (file)
@@ -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:"<<clipId;
+  DocClipBase *clip = new DocClipBase(elem, clipId);
+  m_clipManager->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: "<<url;
+  m_clipManager->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"
 
index 0c7d93ea64e44ddbe266ea8e7084ffa37c2e5232..2a435a828e970e2fa674c28a812166e7b164fa8d 100644 (file)
@@ -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
index be6354d9227ecd78612cf11bc98ebc9eb14fb6b9..b5e9e2bd4d384a418b84dd7e229946d4b222e85d 100644 (file)
@@ -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);
index 53fde22ad5b6a345c88800c782b04420d3cd4560..342496c9cebbcc24b6eace975844720e37e5af43 100644 (file)
@@ -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: "<<m_duration.frames(25);
+  } else {
            // No duration known, use an arbitrary one until it is.
            m_duration = GenTime(0.0);
            m_durationKnown = false;
@@ -189,7 +208,7 @@ void ProjectItem::setProperties(const QMap < QString, QString > &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();
 
index 95b4e14fb1fed588d78033c016768fe269936eea..1cf05b7d4bdff866442e4c415d738a21c49925c5 100644 (file)
@@ -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
index 026e5b29d1ac91c657edf701166148fe31a0b434..24690255045128b60e19f193518e8a1fadcd7456 100644 (file)
@@ -41,7 +41,6 @@
 #include "kdenlivesettings.h"
 #include "ui_colorclip_ui.h"
 
-#include "addclipcommand.h"
 #include "definitions.h"
 
 #include <QtGui>
@@ -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 <b>%1</b> ?").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: "<<prods.count();
index 9628b3e49a78a25e98d44a4c170abd66476fc5ff..dc1fa24a278e61ae85af42f3b8461f33f8b26e56 100644 (file)
@@ -114,6 +114,7 @@ class ProjectList : public QWidget
     void addProducer(QDomElement producer, int parentId = -1);
     void slotReplyGetImage(int clipId, int pos, const QPixmap &pix, int w, int h);
     void slotReplyGetFileProperties(int clipId, const QMap < QString, QString > &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);
index 400e5a5e7980cf3f553f807e7be52ffe5636649c..1eae496a1f44a077c2925fe7666a33c93707992e 100644 (file)
@@ -156,15 +156,16 @@ void ProjectListView::mouseMoveEvent(QMouseEvent *event)
       QDomDocument doc;
       QList <QTreeWidgetItem *> 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));