]> git.sesse.net Git - kdenlive/commitdiff
One undo stack for each project file
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 5 Jan 2008 21:15:05 +0000 (21:15 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 5 Jan 2008 21:15:05 +0000 (21:15 +0000)
svn path=/branches/KDE4/; revision=1794

src/CMakeLists.txt
src/kdenlivedoc.cpp
src/kdenlivedoc.h
src/kdenliveui.rc
src/mainwindow.cpp
src/mainwindow.h
src/projectitem.cpp
src/projectlist.cpp
src/projectlist.h

index 51ba06db767b77511013ecd74a111c1fcaf97acd..6bdd8332b9f51effa52946a4fd81ef8f67d5daa0 100644 (file)
@@ -57,4 +57,4 @@ target_link_libraries(kdenlive
  
 install(TARGETS kdenlive DESTINATION ${BIN_INSTALL_DIR})
 install( FILES kdenliveui.rc DESTINATION  ${DATA_INSTALL_DIR}/kdenlive )
-install (FILES kdenlive.kcfg DESTINATION share/config.kcfg)
\ No newline at end of file
+install (FILES kdenlivesettings.kcfg DESTINATION share/config.kcfg)
\ No newline at end of file
index ca358cc404d803ffcd61c43b268fc5e36df2445f..3971e62460abec44ade21015b51043ebd2e42a52 100644 (file)
@@ -36,6 +36,8 @@
 
 KdenliveDoc::KdenliveDoc(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(this);
   if (!url.isEmpty()) {
     QString tmpFile;
     if(KIO::NetAccess::download(url.path(), tmpFile, parent))
@@ -102,6 +104,11 @@ KdenliveDoc::~KdenliveDoc()
 {
 }
 
+KUndoStack *KdenliveDoc::commandStack()
+{
+  return m_commandStack;
+}
+
 void KdenliveDoc::setRenderer(Render *render)
 {
   m_render = render;
index 0b491a9bf6026f466df7ccf8575a4f3d8cb0f489..246c4d1ba442d520c49bfb252dfe4de902bb68a8 100644 (file)
@@ -24,6 +24,7 @@
 #include <QList>
 #include <QObject>
 
+#include <KUndoStack>
 #include <kurl.h>
 
 #include "gentime.h"
@@ -44,6 +45,7 @@ class KdenliveDoc:public QObject {
     Timecode timecode();
     QDomDocument toXml();
     void setRenderer(Render *render);
+    KUndoStack *commandStack();
 
   private:
     KUrl m_url;
@@ -54,6 +56,7 @@ class KdenliveDoc:public QObject {
     int m_height;
     Timecode m_timecode;
     Render *m_render;
+    KUndoStack *m_commandStack;
     QDomDocument generateSceneList();
 
   public slots:
index 1fc77acebd2c7099a68ffbdf3e094f818e97612c..1d3967b235953f9a7fef4c810bf7b05b4289885f 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<gui name="kdenlive" version="3">
+<gui name="kdenlive" version="4">
   <ToolBar name="mainToolBar" >
     <text>Main Toolbar</text>
     <Action name="clear" />
index 2a51999b1e3b508e3b3cc0a1de9ddb7dbaf5f2a8..f251a596d7c1cdb400b4d83ce3f1bd8361a834f7 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <QTextStream>
 #include <QTimer>
+#include <QAction>
 
 #include <KApplication>
 #include <KAction>
@@ -15,7 +16,7 @@
 #include <KSaveFile>
 #include <KRuler>
 #include <KConfigDialog>
-
+#include <KXMLGUIFactory>
 
 #include <mlt++/Mlt.h>
 
@@ -34,12 +35,11 @@ MainWindow::MainWindow(QWidget *parent)
   setCentralWidget(m_timelineArea);
 
   m_monitorManager = new MonitorManager();
-
   m_commandStack = new KUndoStack(this);
 
   projectListDock = new QDockWidget(i18n("Project Tree"), this);
   projectListDock->setObjectName("project_tree");
-  m_projectList = new ProjectList(m_commandStack, this);
+  m_projectList = new ProjectList(this);
   projectListDock->setWidget(m_projectList);
   addDockWidget(Qt::TopDockWidgetArea, projectListDock);
 
@@ -108,8 +108,6 @@ void MainWindow::slotConnectMonitors()
 
   connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
 
-  //connect(m_projectList, SIGNAL(getFileProperties(const KUrl &, uint)), m_clipMonitor->render, SLOT(getFileProperties(const KUrl &, uint)));
-
   connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
 
   connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)));
@@ -150,10 +148,12 @@ void MainWindow::setupActions()
   KStandardAction::preferences(this, SLOT(slotPreferences()),
            actionCollection());
 
-  QAction * redo = m_commandStack->createRedoAction(actionCollection());
-  QAction * undo = m_commandStack->createUndoAction(actionCollection());
+  /*m_redo = m_commandStack->createRedoAction(actionCollection());
+  m_undo = m_commandStack->createUndoAction(actionCollection());*/
 
   setupGUI();
+
+
 }
  
 void MainWindow::newFile()
@@ -227,6 +227,24 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //chang
   m_projectList->setDocument(doc);
   m_monitorManager->setTimecode(doc->timecode());
   doc->setRenderer(m_projectMonitor->render);
+  m_commandStack = doc->commandStack();
+
+  QAction *redo = m_commandStack->createRedoAction(actionCollection());
+  QAction *undo = m_commandStack->createUndoAction(actionCollection());
+
+  QWidget* w = factory()->container("mainToolBar", this);
+  if(w) {
+    if (actionCollection()->action("undo"))
+      delete actionCollection()->action("undo");
+    if(actionCollection()->action("redo"))
+      delete actionCollection()->action("redo");
+
+    actionCollection()->addAction("undo", undo);
+    actionCollection()->addAction("redo", redo);
+    w->addAction(undo);
+    w->addAction(redo);
+  }
+  
   m_activeDocument = doc;
 }
 
index 5a9d74b35a406e7c081eeb7355254cb840a5f667..290d7630f9c8cbd882163d6e8f632a2b11b62b35 100644 (file)
@@ -49,6 +49,8 @@ class MainWindow : public KXmlGuiWindow
     Monitor *m_projectMonitor;
 
     KUndoStack *m_commandStack;
+    QAction *m_undo;
+    QAction *m_redo;
  
   private slots:
     void newFile();
index ba9b68ce1e2c163bf91667fdc9173412ac32c06d..16022a2831ca7ae8909e3e1dc309fda38cb253cc 100644 (file)
@@ -21,6 +21,7 @@ ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, QDom
 {
   setSizeHint(0, QSize(65, 45));
   setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
+  if (m_element.isNull()) m_element.setAttribute("id", clipId);
   QString cType = m_element.attribute("type", 0);
   if (!cType.isEmpty()) {
     m_clipType = (DocClipBase::CLIPTYPE) cType.toInt();
index 143b6ecc38df3d45d61b02355ce078ea2650ff4f..41a28d7f3774e1780be07ad13c75035e82a58ce0 100644 (file)
@@ -67,8 +67,8 @@ void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIn
 };
 
 
-ProjectList::ProjectList(KUndoStack *commandStack, QWidget *parent)
-    : QWidget(parent), m_render(NULL), m_fps(-1), m_commandStack(commandStack)
+ProjectList::ProjectList(QWidget *parent)
+    : QWidget(parent), m_render(NULL), m_fps(-1), m_commandStack(NULL)
 {
 
   QWidget *vbox = new QWidget;
@@ -150,6 +150,23 @@ void ProjectList::slotRemoveClip()
 
 }
 
+void ProjectList::selectItemById(const int clipId)
+{
+  QTreeWidgetItem *parent = 0;
+  int count =
+    parent ? parent->childCount() : listView->topLevelItemCount();
+
+  for (int i = 0; i < count; i++)
+  {
+    QTreeWidgetItem *item =
+      parent ? parent->child(i) : listView->topLevelItem(i);
+    if (((ProjectItem *)item)->clipId() == clipId) {
+      listView->setCurrentItem(item);
+      break;
+    }
+  }
+}
+
 void ProjectList::addClip(const QStringList &name, const QDomElement &elem, const int clipId, const KUrl &url)
 {
   ProjectItem *item = new ProjectItem(listView, name, elem, clipId);
@@ -163,6 +180,7 @@ void ProjectList::addClip(const QStringList &name, const QDomElement &elem, cons
     emit getFileProperties(element, clipId);
   }
   else emit getFileProperties(elem, clipId);
+  selectItemById(clipId);
 }
 
 void ProjectList::deleteClip(const int clipId)
@@ -250,7 +268,7 @@ void ProjectList::setDocument(KdenliveDoc *doc)
 {
   m_fps = doc->fps();
   m_timecode = doc->timecode();
-
+  m_commandStack = doc->commandStack();
   QDomNodeList prods = doc->producersList();
   listView->clear();
   for (int i = 0; i <  prods.count () ; i++)
@@ -277,7 +295,7 @@ QDomElement ProjectList::producersList()
       parent ? parent->child(i) : listView->topLevelItem(i);
     prods.appendChild(doc.importNode(((ProjectItem *)item)->toXml(), true));
   }
-  //kDebug()<<"PRODUCERS: \n"<<doc.toString();
+
   return prods;
 }
 
@@ -324,7 +342,16 @@ void ProjectList::slotReplyGetImage(int clipId, int pos, const QPixmap &pix, int
 void ProjectList::addProducer(QDomElement producer)
 {
   DocClipBase::CLIPTYPE type = (DocClipBase::CLIPTYPE) producer.attribute("type").toInt();
-  
+
+    QDomDocument doc;
+    QDomElement prods = doc.createElement("list");
+    prods.appendChild(doc.importNode(producer, true));
+    
+
+  kDebug()<<"//////  ADDING PRODUCER:\n "<<doc.toString()<<"\n+++++++++++++++++";
+  int id = producer.attribute("id").toInt();
+  if (id >= m_clipIdCounter) m_clipIdCounter = id + 1;
+
   if (type == DocClipBase::AUDIO || type == DocClipBase::VIDEO || type == DocClipBase::AV)
   {
     KUrl resource = KUrl(producer.attribute("resource"));
@@ -332,9 +359,10 @@ void ProjectList::addProducer(QDomElement producer)
       QStringList itemEntry;
       itemEntry.append(QString::null);
       itemEntry.append(resource.fileName());
+      addClip(itemEntry, producer, id, resource);
+      /*AddClipCommand *command = new AddClipCommand(this, itemEntry, producer, id, resource, true);
+      m_commandStack->push(command);*/
 
-      AddClipCommand *command = new AddClipCommand(this, itemEntry, producer, producer.attribute("id").toInt(), resource, true);
-      m_commandStack->push(command);
 
       /*ProjectItem *item = new ProjectItem(listView, itemEntry, producer);
       item->setData(1, FullPathRole, resource.path());
@@ -350,9 +378,9 @@ void ProjectList::addProducer(QDomElement producer)
     QStringList itemEntry;
     itemEntry.append(QString::null);
     itemEntry.append(producer.attribute("name"));
-
-    AddClipCommand *command = new AddClipCommand(this, itemEntry, producer, producer.attribute("id").toInt(), KUrl(), true);
-    m_commandStack->push(command);
+    addClip(itemEntry, producer, id, KUrl());
+    /*AddClipCommand *command = new AddClipCommand(this, itemEntry, producer, id, KUrl(), true);
+    m_commandStack->push(command);*/
     //ProjectItem *item = new ProjectItem(listView, itemEntry, producer);
     /*item->setIcon(0, QIcon(pix));
     item->setData(1, ClipTypeRole, (int) type);*/
index f2a2d494ba5ba94956b1cb7070f9b8d368712596..7d8b390baa28c66d36318afb2235c9231c5e1300 100644 (file)
@@ -18,7 +18,7 @@ class ProjectList : public QWidget
   Q_OBJECT
   
   public:
-    ProjectList(KUndoStack *commandStack, QWidget *parent=0);
+    ProjectList(QWidget *parent=0);
 
     QDomElement producersList();
     void setRenderer(Render *projectRender);
@@ -42,6 +42,7 @@ class ProjectList : public QWidget
     QToolBar *m_toolbar;
     KUndoStack *m_commandStack;
     int m_clipIdCounter;
+    void selectItemById(const int clipId);
 
   private slots:
     void slotAddClip();