]> git.sesse.net Git - kdenlive/blobdiff - src/mainwindow.cpp
Start of the undo framework
[kdenlive] / src / mainwindow.cpp
index 822d82c89256d0acc0fa81102ed5e793f08607da..8befa8fc72e50b520484e20fece9e17c0baf88ab 100644 (file)
@@ -1,5 +1,8 @@
 
+
+#include <QTextStream>
+#include <QTimer>
+
 #include <KApplication>
 #include <KAction>
 #include <KLocale>
 #include <KIO/NetAccess>
 #include <KSaveFile>
 #include <KRuler>
-#include <QTextStream>
+#include <KConfigDialog>
+
 
 #include <mlt++/Mlt.h>
 
 #include "mainwindow.h"
-#include "trackview.h"
+#include "kdenlivesettings.h"
+#include "ui_configmisc_ui.h"
  
 MainWindow::MainWindow(QWidget *parent)
     : KXmlGuiWindow(parent),
-      fileName(QString())
+      fileName(QString()), m_activeDocument(NULL)
 {
   m_timelineArea = new KTabWidget(this);
   m_timelineArea->setHoverCloseButton(true);
@@ -28,26 +33,30 @@ MainWindow::MainWindow(QWidget *parent)
   connect(m_timelineArea, SIGNAL(currentChanged (int)), this, SLOT(activateDocument()));
   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(NULL, this);
+  m_projectList = new ProjectList(m_commandStack, this);
   projectListDock->setWidget(m_projectList);
   addDockWidget(Qt::TopDockWidgetArea, projectListDock);
 
   effectListDock = new QDockWidget(i18n("Effect List"), this);
-  effectListDock->setObjectName("project_tree");
+  effectListDock->setObjectName("effect_list");
   effectList = new KListWidget(this);
   effectListDock->setWidget(effectList);
   addDockWidget(Qt::TopDockWidgetArea, effectListDock);
   
   effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
-  effectStackDock->setObjectName("project_tree");
+  effectStackDock->setObjectName("effect_stack");
   effectStack = new KListWidget(this);
   effectStackDock->setWidget(effectStack);
   addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
   
   transitionConfigDock = new QDockWidget(i18n("Transition"), this);
-  transitionConfigDock->setObjectName("project_tree");
+  transitionConfigDock->setObjectName("transition");
   transitionConfig = new KListWidget(this);
   transitionConfigDock->setWidget(transitionConfig);
   addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
@@ -55,34 +64,56 @@ MainWindow::MainWindow(QWidget *parent)
   Mlt::Factory::init(NULL);
 
   clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
-  clipMonitorDock->setObjectName("project_tree");
-  m_clipMonitor = new Monitor("clip", this);
+  clipMonitorDock->setObjectName("clip_monitor");
+  m_clipMonitor = new Monitor("clip", m_monitorManager, this);
   clipMonitorDock->setWidget(m_clipMonitor);
   addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
-
+  
   projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
-  projectMonitorDock->setObjectName("project_tree");
-  m_projectMonitor = new Monitor("project", this);
+  projectMonitorDock->setObjectName("project_monitor");
+  m_projectMonitor = new Monitor("project", m_monitorManager, this);
   projectMonitorDock->setWidget(m_projectMonitor);
   addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
 
   setupActions();
-  tabifyDockWidget (effectListDock, projectListDock);
-  tabifyDockWidget (effectListDock, effectStackDock);
-  tabifyDockWidget (effectListDock, transitionConfigDock);
+  tabifyDockWidget (projectListDock, effectListDock);
+  tabifyDockWidget (projectListDock, effectStackDock);
+  tabifyDockWidget (projectListDock, transitionConfigDock);
+  projectListDock->raise();
 
   tabifyDockWidget (clipMonitorDock, projectMonitorDock);
 
-  connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_projectMonitor, SLOT(slotSetXml(const QDomElement &)));
+  connect(projectMonitorDock, SIGNAL(visibilityChanged (bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
+  connect(clipMonitorDock, SIGNAL(visibilityChanged (bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
+  connect(m_monitorManager, SIGNAL(connectMonitors ()), this, SLOT(slotConnectMonitors()));
+  connect(m_monitorManager, SIGNAL(raiseClipMonitor (bool)), this, SLOT(slotRaiseMonitor(bool)));
+  m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
 
-  connect(m_projectList, SIGNAL(getFileProperties(const KUrl &, uint)), m_projectMonitor->render, SLOT(getFileProperties(const KUrl &, uint)));
+  newFile();
+}
 
-  connect(m_projectMonitor->render, SIGNAL(replyGetImage(const KUrl &, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(const KUrl &, int, const QPixmap &, int, int)));
 
-  connect(m_projectMonitor->render, SIGNAL(replyGetFileProperties(const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(const QMap < QString, QString > &, const QMap < QString, QString > &)));
+void MainWindow::slotRaiseMonitor(bool clipMonitor)
+{
+  if (clipMonitor) clipMonitorDock->raise();
+  else projectMonitorDock->raise();
+}
+
+void MainWindow::slotConnectMonitors()
+{
+
+  m_projectList->setRenderer(m_clipMonitor->render);
+
+  connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
+
+  connect(m_projectList, SIGNAL(getFileProperties(const KUrl &, uint)), m_clipMonitor->render, SLOT(getFileProperties(const KUrl &, uint)));
+
+  connect(m_clipMonitor->render, SIGNAL(replyGetImage(const KUrl &, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(const KUrl &, int, const QPixmap &, int, int)));
+
+  connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(const QMap < QString, QString > &, const QMap < QString, QString > &)));
 
 }
+
 void MainWindow::setupActions()
 {
   KAction* clearAction = new KAction(this);
@@ -107,7 +138,19 @@ void MainWindow::setupActions()
  
   KStandardAction::openNew(this, SLOT(newFile()),
                         actionCollection());
+
+  /*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();
 }
  
@@ -116,13 +159,15 @@ void MainWindow::newFile()
   KdenliveDoc *doc = new KdenliveDoc(KUrl(), 25, 720, 576);
   TrackView *trackView = new TrackView(doc);
   m_timelineArea->addTab(trackView, "New Project");
+  if (m_timelineArea->count() == 1)
+    connectDocument(trackView, doc);
 }
 
 void MainWindow::activateDocument()
 {
   TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
   KdenliveDoc *currentDoc = currentTab->document();
-  connectDocument(currentDoc);
+  connectDocument(currentTab, currentDoc);
 }
  
 void MainWindow::saveFileAs(const QString &outputFileName)
@@ -138,7 +183,7 @@ void MainWindow::saveFileAs(const QString &outputFileName)
   
   fileName = outputFileName;
 }
+
 void MainWindow::saveFileAs()
 {
   saveFileAs(KFileDialog::getSaveFileName());
@@ -166,14 +211,48 @@ void MainWindow::openFile(const QString &inputFileName) //new
   KdenliveDoc *doc = new KdenliveDoc(KUrl(inputFileName), 25, 720, 576);
   TrackView *trackView = new TrackView(doc);
   m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, QIcon(), doc->documentName()));
-  connectDocument(doc);
+  connectDocument(trackView, doc);
   
 }
 
-void MainWindow::connectDocument(KdenliveDoc *doc) //changed
+void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //changed
 {
-  m_projectList->populate(doc->producersList());
-  //connect(doc, SIGNAL(addClip(QDomElement &)), m_projectList, SLOT(slotAddClip(QDomElement &)));
+  //m_projectMonitor->stop();
+  if (m_activeDocument) {
+    m_activeDocument->setProducers(m_projectList->producersList());
+    m_activeDocument->setRenderer(NULL);
+  }
+  m_projectList->setDocument(doc);
+  m_monitorManager->setTimecode(doc->timecode());
+  doc->setRenderer(m_projectMonitor->render);
+  m_activeDocument = doc;
+}
+
+
+void MainWindow::slotPreferences()
+{
+  //An instance of your dialog could be already created and could be
+  // cached, in which case you want to display the cached dialog
+  // instead of creating another one
+  if ( KConfigDialog::showDialog( "settings" ) )
+    return;
+
+  // KConfigDialog didn't find an instance of this dialog, so lets
+  // create it :
+  KConfigDialog* dialog = new KConfigDialog(this, "settings",
+                                          KdenliveSettings::self());
+
+  QWidget *page1 = new QWidget;
+  Ui::ConfigMisc_UI* confWdg = new Ui::ConfigMisc_UI( );
+  confWdg->setupUi(page1);
+
+  dialog->addPage( page1, i18n("Misc"), "misc" );
+
+  //User edited the configuration - update your local copies of the
+  //configuration data
+  connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateConfiguration()) );
+
+  dialog->show();
 }
 
 #include "mainwindow.moc"