]> git.sesse.net Git - kdenlive/blobdiff - src/mainwindow.cpp
cleanup
[kdenlive] / src / mainwindow.cpp
index d390f31da6e3692d70cbf6a35083d2f5cdd48dd9..65c78640562dbc3200e235732903926873fe6d1f 100644 (file)
 #include "renderer.h"
 #include "jogshuttle.h"
 #include "clipproperties.h"
+#include "wizard.h"
 
-#define ID_STATUS_MSG 1
-#define ID_EDITMODE_MSG 2
-#define ID_TIMELINE_MSG 3
-#define ID_TIMELINE_BUTTONS 5
-#define ID_TIMELINE_POS 6
-#define ID_TIMELINE_FORMAT 7
+static const int ID_STATUS_MSG = 1;
+static const int ID_EDITMODE_MSG = 2;
+static const int ID_TIMELINE_MSG = 3;
+static const int ID_TIMELINE_BUTTONS = 5;
+static const int ID_TIMELINE_POS = 6;
+static const int ID_TIMELINE_FORMAT = 7;
 
 namespace Mlt {
 class Producer;
@@ -96,8 +97,8 @@ MainWindow::MainWindow(QWidget *parent)
         : KXmlGuiWindow(parent),
         m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL), m_findActivated(false), m_initialized(false) {
     setlocale(LC_NUMERIC, "POSIX");
-    parseProfiles();
     setFont(KGlobalSettings::toolBarFont());
+    parseProfiles();
     m_commandStack = new QUndoGroup;
     m_timelineArea = new KTabWidget(this);
     m_timelineArea->setTabReorderingEnabled(true);
@@ -143,6 +144,10 @@ MainWindow::MainWindow(QWidget *parent)
     transitionConfigDock->setWidget(transitionConfig);
     addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
 
+    KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
+    m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
+                       actionCollection());
+    readOptions();
 
     clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
     clipMonitorDock->setObjectName("clip_monitor");
@@ -164,6 +169,7 @@ MainWindow::MainWindow(QWidget *parent)
     addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
 
     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
+    connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
 
     undoViewDock = new QDockWidget(i18n("Undo History"), this);
     undoViewDock->setObjectName("undo_history");
@@ -243,6 +249,7 @@ MainWindow::MainWindow(QWidget *parent)
     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
 
     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
+    m_timelineContextClipMenu->addAction(actionCollection()->action("change_clip_speed"));
     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
     m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
     m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
@@ -314,7 +321,7 @@ void MainWindow::readProperties(KConfig *config) {
 void MainWindow::slotReloadEffects() {
     initEffects::parseCustomEffectsFile();
     m_customEffectsMenu->clear();
-    QStringList effects = customEffects.effectNames();
+    const QStringList effects = customEffects.effectNames();
     QAction *action;
     foreach(const QString &name, effects) {
         action = new QAction(name, this);
@@ -402,6 +409,9 @@ void MainWindow::slotConnectMonitors() {
     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
     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, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(int, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)));
+
+    connect(m_clipMonitor->render, SIGNAL(removeInvalidClip(int)), m_projectList, SLOT(slotRemoveInvalidClip(int)));
+
     connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
 }
 
@@ -623,6 +633,10 @@ void MainWindow::setupActions() {
     actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
     connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
 
+    KAction* editTimelineClipSpeed = new KAction(KIcon("edit-delete"), i18n("Change Clip Speed"), this);
+    actionCollection()->addAction("change_clip_speed", editTimelineClipSpeed);
+    connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));
+
     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
     actionCollection()->addAction("cut_timeline_clip", cutTimelineClip);
@@ -670,9 +684,6 @@ void MainWindow::setupActions() {
     KStandardAction::open(this, SLOT(openFile()),
                           actionCollection());
 
-    m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
-                       actionCollection());
-
     KStandardAction::save(this, SLOT(saveFile()),
                           actionCollection());
 
@@ -691,11 +702,15 @@ void MainWindow::setupActions() {
     KStandardAction::paste(this, SLOT(slotPaste()),
                            actionCollection());
 
-    KStandardAction::undo(this, SLOT(undo()),
-                          actionCollection());
+    KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()),
+                                          actionCollection());
+    undo->setEnabled(false);
+    connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
 
-    KStandardAction::redo(this, SLOT(redo()),
-                          actionCollection());
+    KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()),
+                                          actionCollection());
+    redo->setEnabled(false);
+    connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
 
     KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
 
@@ -703,16 +718,6 @@ void MainWindow::setupActions() {
             this, SLOT(slotDisplayActionMessage(QAction*)));
     //connect(actionCollection(), SIGNAL( clearStatusText() ),
     //statusBar(), SLOT( clear() ) );
-
-    readOptions();
-}
-
-void MainWindow::undo() {
-    m_commandStack->undo();
-}
-
-void MainWindow::redo() {
-    m_commandStack->redo();
 }
 
 void MainWindow::slotDisplayActionMessage(QAction *a) {
@@ -729,6 +734,16 @@ void MainWindow::saveOptions() {
 void MainWindow::readOptions() {
     KSharedConfigPtr config = KGlobal::config();
     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
+    KConfigGroup initialGroup(config, "version");
+    if (!initialGroup.exists()) {
+        // this is our first run, show Wizard
+        Wizard *w = new Wizard(this);
+        if (w->exec() == QDialog::Accepted) {
+            w->adjustSettings();
+            initialGroup.writeEntry("version", "0.7");
+        }
+        delete w;
+    }
 }
 
 void MainWindow::newFile() {
@@ -742,13 +757,10 @@ void MainWindow::newFile() {
         projectFolder = w->selectedFolder();
         delete w;
     }
-    MltVideoProfile prof;
-    if (!profileName.isEmpty()) prof = ProfilesDialog::getVideoProfile(profileName);
-    else prof = ProfilesDialog::getVideoProfile("dv_pal");
-    if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
-    KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, prof, m_commandStack, this);
+    KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, this);
+    doc->setProfilePath(profileName);
     TrackView *trackView = new TrackView(doc, this);
-    m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
+    m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
     if (m_timelineArea->count() == 1) {
         connectDocumentInfo(doc);
         connectDocument(trackView, doc);
@@ -812,8 +824,9 @@ void MainWindow::openFile() {
 
 void MainWindow::openLastFile() {
     KSharedConfigPtr config = KGlobal::config();
-    QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
-    openFile(KUrl(Lastproject));
+    KUrl::List urls = m_fileOpenRecent->urls();
+    if (urls.isEmpty()) newFile();
+    else openFile(urls.last());
 }
 
 void MainWindow::openFile(const KUrl &url) {
@@ -834,14 +847,16 @@ void MainWindow::openFile(const KUrl &url) {
     }
 
     //TODO: get video profile from url before opening it
-    MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
+    /*MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
+
+    KdenliveSettings::setCurrent_profile(prof.path);*/
     KdenliveDoc *doc;
     if (recovery) {
-        doc = new KdenliveDoc(recoveryUrl, KUrl(), prof, m_commandStack, this);
+        doc = new KdenliveDoc(recoveryUrl, KUrl(), m_commandStack, this);
         doc->setUrl(url);
         doc->setModified(true);
-    } else doc = new KdenliveDoc(url, KUrl(), prof, m_commandStack, this);
+    } else doc = new KdenliveDoc(url, KUrl(), m_commandStack, this);
     connectDocumentInfo(doc);
     TrackView *trackView = new TrackView(doc, this);
     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
@@ -849,7 +864,6 @@ void MainWindow::openFile(const KUrl &url) {
     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
     slotGotProgressInfo(QString(), -1);
     m_projectMonitor->refreshMonitor(true);
-    //connectDocument(trackView, doc);
 }
 
 
@@ -917,9 +931,10 @@ void MainWindow::slotEditProjectSettings() {
     if (w->exec() == QDialog::Accepted) {
         QString profile = w->selectedProfile();
         m_activeDocument->setProfilePath(profile);
-        m_monitorManager->resetProfiles(profile);
+        KdenliveSettings::setCurrent_profile(profile);
+        KdenliveSettings::setProject_fps(m_activeDocument->fps());
         setCaption(m_activeDocument->description());
-        KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath());
+        m_monitorManager->resetProfiles();
         if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
         m_monitorManager->setTimecode(m_activeDocument->timecode());
         m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
@@ -1035,8 +1050,9 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha
         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
         m_clipMonitor->stop();
     }
+    KdenliveSettings::setCurrent_profile(doc->profilePath());
     KdenliveSettings::setProject_fps(doc->fps());
-    m_monitorManager->resetProfiles(doc->profilePath());
+    m_monitorManager->resetProfiles();
     m_projectList->setDocument(doc);
     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
@@ -1078,7 +1094,6 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha
     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
     m_activeTimeline = trackView;
-    KdenliveSettings::setCurrent_profile(doc->profilePath());
     if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
     m_monitorManager->setTimecode(doc->timecode());
     doc->setRenderer(m_projectMonitor->render);
@@ -1097,18 +1112,22 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha
     m_activeDocument = doc;
 }
 
-void MainWindow::slotPreferences() {
+void MainWindow::slotPreferences(int page, int option) {
     //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"))
+    if (KConfigDialog::showDialog("settings")) {
+        if (page != -1) static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"))->showPage(page, option);
         return;
+    }
 
     // KConfigDialog didn't find an instance of this dialog, so lets
     // create it :
     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
+    connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(resetProfiles()));
     dialog->show();
+    if (page != -1) dialog->showPage(page, option);
 }
 
 void MainWindow::updateConfiguration() {
@@ -1163,6 +1182,12 @@ void MainWindow::slotDeleteTimelineClip() {
     }
 }
 
+void MainWindow::slotChangeClipSpeed() {
+    if (m_activeTimeline) {
+        m_activeTimeline->projectView()->changeClipSpeed();
+    }
+}
+
 void MainWindow::slotAddClipMarker() {
     if (m_activeTimeline) {
         m_activeTimeline->projectView()->slotAddClipMarker();