]> git.sesse.net Git - kdenlive/commitdiff
Start of the undo framework
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 5 Jan 2008 19:06:57 +0000 (19:06 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 5 Jan 2008 19:06:57 +0000 (19:06 +0000)
svn path=/branches/KDE4/; revision=1792

src/addclipcommand.h [new file with mode: 0644]
src/definitions.h [new file with mode: 0644]
src/mainwindow.cpp
src/mainwindow.h
src/monitormanager.cpp
src/projectitem.cpp
src/projectitem.h
src/projectlist.cpp
src/projectlist.h
src/renderer.cpp

diff --git a/src/addclipcommand.h b/src/addclipcommand.h
new file mode 100644 (file)
index 0000000..a8b05fa
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef ADDCLIPCOMMAND_H
+#define ADDCLIPCOMMAND_H
+
+#include <QUndoCommand>
+#include <KDebug>
+
+#include "projectlist.h"
+
+class AddClipCommand : public QUndoCommand
+ {
+ public:
+     AddClipCommand(ProjectList *list, const QStringList &names, const QDomElement &xml, const int id, const KUrl &url, bool doIt)
+         : m_list(list), m_names(names), m_xml(xml), m_id(id), m_url(url), m_doIt(doIt) {
+           if (doIt) setText(i18n("Add clip"));
+           else setText(i18n("Delete clip"));
+         }
+     virtual void undo()
+         {
+           kDebug()<<"----  undoing action";
+           if (m_doIt) m_list->deleteClip(m_id);
+           else m_list->addClip(m_names, m_xml, m_id, m_url);
+        }
+     virtual void redo()
+         {
+           kDebug()<<"----  redoing action";
+           if (m_doIt) m_list->addClip(m_names, m_xml, m_id, m_url);
+           else m_list->deleteClip(m_id);
+        }
+ private:
+     ProjectList *m_list;
+     QStringList m_names;
+     QDomElement m_xml;
+     int m_id;
+     KUrl m_url;
+     bool m_doIt;
+ };
+
+#endif
+
diff --git a/src/definitions.h b/src/definitions.h
new file mode 100644 (file)
index 0000000..b1e6f22
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef DEFINITIONS_H
+#define DEFINITIONS_H
+
+#define FRAME_SIZE 90
+
+#endif
index 86240214db4913fef4fdf1bd1c25bdc3880940a8..8befa8fc72e50b520484e20fece9e17c0baf88ab 100644 (file)
@@ -2,7 +2,7 @@
 
 #include <QTextStream>
 #include <QTimer>
+
 #include <KApplication>
 #include <KAction>
 #include <KLocale>
@@ -35,9 +35,11 @@ MainWindow::MainWindow(QWidget *parent)
 
   m_monitorManager = new MonitorManager();
 
+  m_commandStack = new KUndoStack(this);
+
   projectListDock = new QDockWidget(i18n("Project Tree"), this);
   projectListDock->setObjectName("project_tree");
-  m_projectList = new ProjectList(this);
+  m_projectList = new ProjectList(m_commandStack, this);
   projectListDock->setWidget(m_projectList);
   addDockWidget(Qt::TopDockWidgetArea, projectListDock);
 
@@ -137,12 +139,18 @@ void MainWindow::setupActions()
   KStandardAction::openNew(this, SLOT(newFile()),
                         actionCollection());
 
-  KStandardAction::openNew(this, SLOT(newFile()),
+  /*KStandardAction::undo(this, SLOT(undo()),
                         actionCollection());
 
+  KStandardAction::redo(this, SLOT(redo()),
+                        actionCollection());*/
+
   KStandardAction::preferences(this, SLOT(slotPreferences()),
            actionCollection());
+
+  QAction * redo = m_commandStack->createRedoAction(actionCollection());
+  QAction * undo = m_commandStack->createUndoAction(actionCollection());
+
   setupGUI();
 }
  
@@ -175,7 +183,7 @@ void MainWindow::saveFileAs(const QString &outputFileName)
   
   fileName = outputFileName;
 }
+
 void MainWindow::saveFileAs()
 {
   saveFileAs(KFileDialog::getSaveFileName());
index 41086b54e6561caf7272f59d48ebc32e94d4423c..5a9d74b35a406e7c081eeb7355254cb840a5f667 100644 (file)
@@ -7,6 +7,7 @@
 #include <KTextEdit>
 #include <KListWidget>
 #include <KTabWidget>
+#include <KUndoStack>
 
 #include "projectlist.h"
 #include "monitor.h"
@@ -46,6 +47,8 @@ class MainWindow : public KXmlGuiWindow
 
     QDockWidget *projectMonitorDock;
     Monitor *m_projectMonitor;
+
+    KUndoStack *m_commandStack;
  
   private slots:
     void newFile();
index c6475dca5954a0bbecfe8361bb44ef95ce9f7c37..6ef4bd80eb1563c49ec17e8949f35d9fc50df839 100644 (file)
@@ -32,15 +32,15 @@ void MonitorManager::initMonitors(Monitor *clipMonitor, Monitor *projectMonitor)
 void MonitorManager::initClipMonitor()
 {
   m_clipMonitor->initMonitor();
-//  initProjectMonitor();
+  initProjectMonitor();
   //QTimer::singleShot(1500, this, SLOT(initProjectMonitor()));
 }
 
 void MonitorManager::initProjectMonitor()
 {
   m_clipMonitor->stop();
-  m_projectMonitor->initMonitor();
-  activateMonitor("project");
+  // m_projectMonitor->initMonitor();
+  // activateMonitor("project");
   emit connectMonitors();
 }
 
index eb2c3c95bff6df5018599b3d510f9b417aa8f60f..3c5dfc844a29f39aa9207b15390952033ffbabb4 100644 (file)
@@ -16,8 +16,8 @@
   const int FullPathRole = NameRole + 2;
   const int ClipTypeRole = NameRole + 3;
 
-ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml, int type)
-    : QTreeWidgetItem(parent, strings, type), m_element(xml), m_clipType(DocClipBase::NONE)
+ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml, int clipId)
+    : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_element(xml), m_clipType(DocClipBase::NONE), m_clipId(clipId)
 {
   setSizeHint(0, QSize(65, 45));
   setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
@@ -33,6 +33,20 @@ ProjectItem::~ProjectItem()
 {
 }
 
+int ProjectItem::clipId()
+{
+  return m_clipId;
+}
+
+QStringList ProjectItem::names()
+{
+  QStringList result;
+  result.append(text(0));
+  result.append(text(1));
+  result.append(text(2));
+  return result;
+}
+
 QDomElement ProjectItem::toXml()
 {
     return m_element;
index e38d30b42ca1671808c2d49793540626d3d76cd2..3422a5b7972ff56b1e9fe9a382c4464bb4b83b4c 100644 (file)
 class ProjectItem : public QTreeWidgetItem
 {
   public:
-    ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml = QDomElement(), int type = QTreeWidgetItem::UserType);
+    ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml, int clipId);
     ~ProjectItem();
     QDomElement toXml();
 
     void setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata);
+    int clipId();
+    QStringList names();
 
   private:
     QDomElement m_element;
     GenTime m_duration;
     bool m_durationKnown;
     DocClipBase::CLIPTYPE m_clipType;
+    int m_clipId;
     void slotSetToolTip();
+
 };
 
 #endif
index dd9b3ea51408c57b051b6884d0ab87918f2fd5fc..baeafea651e3364819168bdfca1b7a45473c2983 100644 (file)
@@ -15,6 +15,8 @@
 #include "kdenlivesettings.h"
 #include "ui_colorclip_ui.h"
 
+#include "addclipcommand.h"
+
 #include <QtGui>
 
   const int NameRole = Qt::UserRole;
@@ -65,13 +67,14 @@ void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIn
 };
 
 
-ProjectList::ProjectList(QWidget *parent)
-    : QWidget(parent), m_render(NULL), m_fps(-1)
+ProjectList::ProjectList(KUndoStack *commandStack, QWidget *parent)
+    : QWidget(parent), m_render(NULL), m_fps(-1), m_commandStack(commandStack)
 {
 
   QWidget *vbox = new QWidget;
   listView = new QTreeWidget(this);;
   QVBoxLayout *layout = new QVBoxLayout;
+  m_clipIdCounter = 0;
 
   // setup toolbar
   searchView = new KTreeWidgetSearchLine (this);
@@ -140,9 +143,37 @@ void ProjectList::slotEditClip()
 
 void ProjectList::slotRemoveClip()
 {
-  kDebug()<<"//////////  SLOT REMOVE";
   if (!listView->currentItem()) return;
-  delete listView->currentItem();
+  ProjectItem *item = ((ProjectItem *)listView->currentItem());
+  AddClipCommand *command = new AddClipCommand(this, item->names(), item->toXml(), item->clipId(), KUrl(item->data(1, FullPathRole).toString()), false);
+  m_commandStack->push(command);
+
+}
+
+void ProjectList::addClip(const QStringList &name, const QDomElement &elem, const int clipId, const KUrl &url)
+{
+  ProjectItem *item = new ProjectItem(listView, name, elem, clipId);
+  if (!url.isEmpty()) {
+    item->setData(1, FullPathRole, url.path());
+    emit getFileProperties(url, elem.attribute("frame_thumbnail", 0).toInt());
+  }
+}
+
+void ProjectList::deleteClip(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) {
+      delete item;
+      break;
+    }
+  }
 }
 
 void ProjectList::slotAddClip()
@@ -152,17 +183,18 @@ void ProjectList::slotAddClip()
   if (list.isEmpty()) return;
   KUrl::List::Iterator it;
   KUrl url;
-  ProjectItem *item;
+//  ProjectItem *item;
 
   for (it = list.begin(); it != list.end(); it++) {
       QStringList itemEntry;
       itemEntry.append(QString::null);
       itemEntry.append((*it).fileName());
-      item = new ProjectItem(listView, itemEntry, QDomElement());
-      item->setData(1, FullPathRole, (*it).path());
-      emit getFileProperties((*it), 0);
+      AddClipCommand *command = new AddClipCommand(this, itemEntry, QDomElement(), m_clipIdCounter++, *it, true);
+      m_commandStack->push(command);
+      //item = new ProjectItem(listView, itemEntry, QDomElement());
+      //item->setData(1, FullPathRole, (*it).path());
   }
-  listView->setCurrentItem(item);
+  //listView->setCurrentItem(item);
 }
 
 void ProjectList::slotAddColorClip()
@@ -187,11 +219,13 @@ void ProjectList::slotAddColorClip()
     QStringList itemEntry;
     itemEntry.append(QString::null);
     itemEntry.append(dia_ui->clip_name->text());
-    ProjectItem *item = new ProjectItem(listView, itemEntry, element);
-    QPixmap pix(60, 40);
+    AddClipCommand *command = new AddClipCommand(this, itemEntry, element, m_clipIdCounter++, KUrl(), true);
+    m_commandStack->push(command);
+    //ProjectItem *item = new ProjectItem(listView, itemEntry, element);
+    /*QPixmap pix(60, 40);
     pix.fill(dia_ui->clip_color->color());
-    item->setIcon(0, QIcon(pix));
-    listView->setCurrentItem(item);
+    item->setIcon(0, QIcon(pix));*/
+    //listView->setCurrentItem(item);
     
   }
   delete dia_ui;
@@ -262,7 +296,7 @@ void ProjectList::slotReplyGetFileProperties(const QMap < QString, QString > &pr
 
 void ProjectList::slotReplyGetImage(const KUrl &url, int pos, const QPixmap &pix, int w, int h)
 {
-   QTreeWidgetItem *parent = 0;
+  QTreeWidgetItem *parent = 0;
   int count =
     parent ? parent->childCount() : listView->topLevelItemCount();
 
@@ -272,7 +306,7 @@ void ProjectList::slotReplyGetImage(const KUrl &url, int pos, const QPixmap &pix
       parent ? parent->child(i) : listView->topLevelItem(i);
 
     if (item->data(1, FullPathRole).toString() == url.path()) {
-      item->setIcon(0,pix);
+      item->setIcon(0, pix);
       break;
     }
   }
@@ -291,10 +325,14 @@ void ProjectList::addProducer(QDomElement producer)
       QStringList itemEntry;
       itemEntry.append(QString::null);
       itemEntry.append(resource.fileName());
-      ProjectItem *item = new ProjectItem(listView, itemEntry, producer);
+
+      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());
-      item->setData(1, ClipTypeRole, (int) type);
-      emit getFileProperties(resource, producer.attribute("frame_thumbnail", 0).toInt());
+      item->setData(1, ClipTypeRole, (int) type);*/
+      
     }
   }
   else if (type == DocClipBase::COLOR) {
@@ -305,9 +343,12 @@ void ProjectList::addProducer(QDomElement producer)
     QStringList itemEntry;
     itemEntry.append(QString::null);
     itemEntry.append(producer.attribute("name"));
-    ProjectItem *item = new ProjectItem(listView, itemEntry, producer);
-    item->setIcon(0, QIcon(pix));
-    item->setData(1, ClipTypeRole, (int) type);
+
+    AddClipCommand *command = new AddClipCommand(this, itemEntry, producer, producer.attribute("id").toInt(), 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 3a7daf927b55ec8eface71f274852b956100770e..ced014da7b766279f9bef716063f2a77bcb36e66 100644 (file)
@@ -3,8 +3,9 @@
 
 #include <QDomNodeList>
 #include <QToolBar>
-
 #include <QTreeWidget>
+
+#include <KUndoStack>
 #include <KTreeWidgetSearchLine>
 
 #include "docclipbase.h"
@@ -17,11 +18,14 @@ class ProjectList : public QWidget
   Q_OBJECT
   
   public:
-    ProjectList(QWidget *parent=0);
+    ProjectList(KUndoStack *commandStack, QWidget *parent=0);
 
     QDomElement producersList();
     void setRenderer(Render *projectRender);
 
+    void addClip(const QStringList &name, const QDomElement &elem, const int clipId, const KUrl &url = KUrl());
+    void deleteClip(const int clipId);
+
   public slots:
     void setDocument(KdenliveDoc *doc);
     void addProducer(QDomElement producer);
@@ -36,6 +40,8 @@ class ProjectList : public QWidget
     Timecode m_timecode;
     double m_fps;
     QToolBar *m_toolbar;
+    KUndoStack *m_commandStack;
+    int m_clipIdCounter;
 
   private slots:
     void slotAddClip();
index 93059de128c2afcbad14a5306b6ea5bb1761e5ea..02f048ac75efb3cdeb40d80f94ddc427726b8a13 100644 (file)
@@ -479,6 +479,7 @@ void Render::getFileProperties(const KUrl &url, uint framenb)
             }
        }
        emit replyGetFileProperties(filePropertyMap, metadataPropertyMap);
+       kDebug()<<"REquested fuile info for: "<<url.path();
        delete frame;
 }
 
@@ -709,7 +710,7 @@ void Render::stop()
     kDebug()<<"/////////////   RENDER STOP-------";
     if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
        m_mltConsumer->set("refresh", 0);
-       m_mltConsumer->stop();
+       // m_mltConsumer->stop();
     }
     kDebug()<<"/////////////   RENDER STOP2-------";
     isBlocked = true;