]> git.sesse.net Git - kdenlive/commitdiff
Cleanup undo/redo system
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Fri, 7 Mar 2008 13:46:17 +0000 (13:46 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Fri, 7 Mar 2008 13:46:17 +0000 (13:46 +0000)
svn path=/branches/KDE4/; revision=2004

src/kdenlivedoc.cpp
src/kdenlivedoc.h
src/mainwindow.cpp
src/mainwindow.h

index e2418dd34e328b2d62486a55b8cd9a38b36d30a4..7f93841be66f646c13e0d4ecce46a5d7b6a98c94 100644 (file)
@@ -28,7 +28,7 @@
 #include "kdenlivedoc.h"
 #include "docclipbase.h"
 
-KdenliveDoc::KdenliveDoc(const KUrl &url, MltVideoProfile profile, QWidget *parent): QObject(parent), m_render(NULL), m_url(url), m_profile(profile), m_fps((double)profile.frame_rate_num / profile.frame_rate_den), m_width(profile.width), m_height(profile.height), m_commandStack(new KUndoStack()) {
+KdenliveDoc::KdenliveDoc(const KUrl &url, MltVideoProfile profile, QUndoGroup *undoGroup, QWidget *parent): QObject(parent), m_render(NULL), m_url(url), m_profile(profile), m_fps((double)profile.frame_rate_num / profile.frame_rate_den), m_width(profile.width), m_height(profile.height), m_commandStack(new KUndoStack(undoGroup)) {
     m_clipManager = new ClipManager(this);
     if (!url.isEmpty()) {
         QString tmpFile;
index e4e4c05544b803314c6a87fff600d8b5a2b20f79..af970bb22ac0bf7483149adf2f6996e7e1b21938 100644 (file)
@@ -26,6 +26,7 @@
 #include <qmap.h>
 #include <QList>
 #include <QObject>
+#include <QUndoGroup>
 
 #include <KUndoStack>
 #include <kurl.h>
@@ -39,7 +40,7 @@
 class KdenliveDoc: public QObject {
 Q_OBJECT public:
 
-    KdenliveDoc(const KUrl &url, MltVideoProfile profile, QWidget *parent = 0);
+    KdenliveDoc(const KUrl &url, MltVideoProfile profile, QUndoGroup *undoGroup, QWidget *parent = 0);
     ~KdenliveDoc();
     QDomNodeList producersList();
     double fps() const;
index 1890424587c266ad297c171305f6e34c01360c8f..d5087ffe8f94f66979a5f386e3f5ad8d8d9fe47d 100644 (file)
 
 MainWindow::MainWindow(QWidget *parent)
         : KXmlGuiWindow(parent),
-        fileName(QString()), m_activeDocument(NULL), m_activeTimeline(NULL), m_commandStack(NULL) {
+        fileName(QString()), m_activeDocument(NULL), m_activeTimeline(NULL) {
     parseProfiles();
+
+    m_commandStack = new QUndoGroup;
     m_timelineArea = new KTabWidget(this);
     m_timelineArea->setHoverCloseButton(true);
     m_timelineArea->setTabReorderingEnabled(true);
@@ -116,8 +118,10 @@ MainWindow::MainWindow(QWidget *parent)
     undoViewDock = new QDockWidget(i18n("Undo History"), this);
     undoViewDock->setObjectName("undo_history");
     m_undoView = new QUndoView(this);
+    m_undoView->setCleanIcon(KIcon("edit-clear"));
+    m_undoView->setEmptyLabel(i18n("Clean"));
     undoViewDock->setWidget(m_undoView);
-    m_undoView->setStack(m_commandStack);
+    m_undoView->setGroup(m_commandStack);
     addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
 
     overviewDock = new QDockWidget(i18n("Project Overview"), this);
@@ -264,11 +268,11 @@ void MainWindow::setupActions() {
     KStandardAction::preferences(this, SLOT(slotPreferences()),
                                  actionCollection());
 
-    /*KStandardAction::undo(this, SLOT(undo()),
+    KStandardAction::undo(this, SLOT(undo()),
                           actionCollection());
 
     KStandardAction::redo(this, SLOT(redo()),
-                          actionCollection());*/
+                          actionCollection());
 
     connect(actionCollection(), SIGNAL(actionHighlighted(QAction*)),
             this, SLOT(slotDisplayActionMessage(QAction*)));
@@ -276,9 +280,14 @@ void MainWindow::setupActions() {
     //statusBar(), SLOT( clear() ) );
 
     readOptions();
+}
 
-    /*m_redo = m_commandStack->createRedoAction(actionCollection());
-    m_undo = m_commandStack->createUndoAction(actionCollection());*/
+void MainWindow::undo() {
+    m_commandStack->undo();
+}
+
+void MainWindow::redo() {
+    m_commandStack->redo();
 }
 
 void MainWindow::slotDisplayActionMessage(QAction *a) {
@@ -299,7 +308,7 @@ void MainWindow::readOptions() {
 void MainWindow::newFile() {
     MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
-    KdenliveDoc *doc = new KdenliveDoc(KUrl(), prof);
+    KdenliveDoc *doc = new KdenliveDoc(KUrl(), prof, m_commandStack);
     TrackView *trackView = new TrackView(doc);
     m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
     if (m_timelineArea->count() == 1)
@@ -364,7 +373,7 @@ void MainWindow::openFile(const KUrl &url) { //new
     //TODO: get video profile from url before opening it
     MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
-    KdenliveDoc *doc = new KdenliveDoc(url, prof);
+    KdenliveDoc *doc = new KdenliveDoc(url, prof, m_commandStack);
     TrackView *trackView = new TrackView(doc);
     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
@@ -492,28 +501,12 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha
 
     m_monitorManager->setTimecode(doc->timecode());
     doc->setRenderer(m_projectMonitor->render);
-    //m_undoView->setStack(0);
-    m_commandStack = doc->commandStack();
+    m_commandStack->setActiveStack(doc->commandStack());
 
     m_overView->setScene(trackView->projectScene());
     m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
-    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_undoView->setStack(doc->commandStack());
+
     setCaption(doc->description());
     m_activeDocument = doc;
 }
index c4dc6a905cb09622ad98c055ce5b693b851c324b..455bdc1c5027011685a32df00dd8c42b5210cde3 100644 (file)
@@ -87,9 +87,7 @@ private:
 
     QDockWidget *undoViewDock;
     QUndoView *m_undoView;
-    KUndoStack *m_commandStack;
-    QAction *m_undo;
-    QAction *m_redo;
+    QUndoGroup *m_commandStack;
 
     KComboBox *m_timecodeFormat;
 
@@ -109,6 +107,8 @@ public slots:
 
 private slots:
     void newFile();
+    void undo();
+    void redo();
     void activateDocument();
     void closeDocument(QWidget *w);
     void connectDocument(TrackView*, KdenliveDoc*);