]> git.sesse.net Git - kdenlive/blobdiff - src/mainwindow.cpp
Improve profile selection in First run wizard
[kdenlive] / src / mainwindow.cpp
index 3ffe22e7af2eddf1730a3893b898283851f75643..f4f28149768b730e04ca44d0fb8d70ff472059d8 100644 (file)
@@ -81,6 +81,8 @@
 #include "wizard.h"
 #include "editclipcommand.h"
 #include "titlewidget.h"
+#include "markerdialog.h"
+#include "clipitem.h"
 
 static const int ID_STATUS_MSG = 1;
 static const int ID_EDITMODE_MSG = 2;
@@ -212,7 +214,7 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, QWidget *parent
     //kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
 
     m_projectMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)));
-    m_clipMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)));
+    m_clipMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), static_cast<QMenu*>(factory()->container("marker_menu", this)));
 
     // build effects menus
     QAction *action;
@@ -299,6 +301,7 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, QWidget *parent
     connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
 
     m_timelineContextMenu->addAction(actionCollection()->action("insert_space"));
+    m_timelineContextMenu->addAction(actionCollection()->action("delete_space"));
     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
 
     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
@@ -798,6 +801,22 @@ void MainWindow::setupActions() {
     collection->addAction("insert_space", insertSpace);
     connect(insertSpace, SIGNAL(triggered()), this, SLOT(slotInsertSpace()));
 
+    KAction *removeSpace = new KAction(KIcon(), i18n("Remove Space"), this);
+    collection->addAction("delete_space", removeSpace);
+    connect(removeSpace, SIGNAL(triggered()), this, SLOT(slotRemoveSpace()));
+
+    KAction *insertTrack = new KAction(KIcon(), i18n("Insert Track"), this);
+    collection->addAction("insert_track", insertTrack);
+    connect(insertTrack, SIGNAL(triggered()), this, SLOT(slotInsertTrack()));
+
+    KAction *deleteTrack = new KAction(KIcon(), i18n("Delete Track"), this);
+    collection->addAction("delete_track", deleteTrack);
+    connect(deleteTrack, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
+
+    KAction *changeTrack = new KAction(KIcon(), i18n("Change Track"), this);
+    collection->addAction("change_track", changeTrack);
+    connect(changeTrack, SIGNAL(triggered()), this, SLOT(slotChangeTrack()));
+
     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
     collection->addAction("add_guide", addGuide);
     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
@@ -881,6 +900,13 @@ void MainWindow::readOptions() {
         } else {
             ::exit(1);
         }
+    } else if (initialGroup.readEntry("version") == "0.7") {
+        //Add new settings from 0.7.1
+        if (KdenliveSettings::defaultprojectfolder().isEmpty()) {
+            QString path = QDir::homePath() + "/kdenlive";
+            if (KStandardDirs::makeDir(path)  == false) kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
+            KdenliveSettings::setDefaultprojectfolder(path);
+        }
     }
     KConfigGroup treecolumns(config, "Project Tree");
     const QByteArray state = treecolumns.readEntry("columns", QByteArray());
@@ -891,12 +917,12 @@ void MainWindow::readOptions() {
 void MainWindow::newFile(bool showProjectSettings) {
     QString profileName;
     KUrl projectFolder;
-    QPoint projectTracks(3, 2);
+    QPoint projectTracks(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks());
     if (!showProjectSettings && m_timelineArea->count() == 0) {
         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
         profileName = KdenliveSettings::default_profile();
     } else {
-        ProjectSettings *w = new ProjectSettings;
+        ProjectSettings *w = new ProjectSettings(projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, this);
         if (w->exec() != QDialog::Accepted) return;
         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
         profileName = w->selectedProfile();
@@ -1167,7 +1193,9 @@ void MainWindow::slotEditProfiles() {
 }
 
 void MainWindow::slotEditProjectSettings() {
-    ProjectSettings *w = new ProjectSettings;
+    QPoint p = m_activeDocument->getTracksCount();
+    ProjectSettings *w = new ProjectSettings(p.x(), p.y(), m_activeDocument->projectFolder().path(), true, this);
+
     if (w->exec() == QDialog::Accepted) {
         QString profile = w->selectedProfile();
         m_activeDocument->setProfilePath(profile);
@@ -1281,6 +1309,8 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha
             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
+
+
             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
             disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
@@ -1295,7 +1325,10 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha
             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
-
+            disconnect(m_activeTimeline, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
+            disconnect(m_activeTimeline, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
+            disconnect(m_activeTimeline, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
+            disconnect(m_activeTimeline, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
@@ -1324,6 +1357,9 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha
     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
+    connect(trackView, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
+    connect(trackView, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
+    connect(trackView, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
@@ -1470,26 +1506,120 @@ void MainWindow::slotChangeClipSpeed() {
 }
 
 void MainWindow::slotAddClipMarker() {
-    if (m_activeTimeline) {
-        m_activeTimeline->projectView()->slotAddClipMarker();
+    DocClipBase *clip = NULL;
+    GenTime pos;
+    if (m_projectMonitor->isActive()) {
+        if (m_activeTimeline) {
+            ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
+            if (item) {
+                pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
+                clip = item->baseClip();
+            }
+        }
+    } else {
+        clip = m_clipMonitor->activeClip();
+        pos = m_clipMonitor->position();
+    }
+    if (!clip) {
+        m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
+        return;
     }
+    QString id = clip->getId();
+    CommentedTime marker(pos, i18n("Marker"));
+    MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
+    if (d.exec() == QDialog::Accepted) {
+        m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
+    }
+    if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
 }
 
 void MainWindow::slotDeleteClipMarker() {
-    if (m_activeTimeline) {
-        m_activeTimeline->projectView()->slotDeleteClipMarker();
+    DocClipBase *clip = NULL;
+    GenTime pos;
+    if (m_projectMonitor->isActive()) {
+        if (m_activeTimeline) {
+            ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
+            if (item) {
+                pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
+                clip = item->baseClip();
+            }
+        }
+    } else {
+        clip = m_clipMonitor->activeClip();
+        pos = m_clipMonitor->position();
+    }
+    if (!clip) {
+        m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
+        return;
+    }
+
+    QString id = clip->getId();
+    QString comment = clip->markerComment(pos);
+    if (comment.isEmpty()) {
+        m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
+        return;
     }
+    m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
+    if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
+
 }
 
 void MainWindow::slotDeleteAllClipMarkers() {
-    if (m_activeTimeline) {
-        m_activeTimeline->projectView()->slotDeleteAllClipMarkers();
+    DocClipBase *clip = NULL;
+    if (m_projectMonitor->isActive()) {
+        if (m_activeTimeline) {
+            ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
+            if (item) {
+                clip = item->baseClip();
+            }
+        }
+    } else {
+        clip = m_clipMonitor->activeClip();
+    }
+    if (!clip) {
+        m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
+        return;
     }
+    m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
+    if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
 }
 
 void MainWindow::slotEditClipMarker() {
-    if (m_activeTimeline) {
-        m_activeTimeline->projectView()->slotEditClipMarker();
+    DocClipBase *clip = NULL;
+    GenTime pos;
+    if (m_projectMonitor->isActive()) {
+        if (m_activeTimeline) {
+            ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
+            if (item) {
+                pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
+                clip = item->baseClip();
+            }
+        }
+    } else {
+        clip = m_clipMonitor->activeClip();
+        pos = m_clipMonitor->position();
+    }
+    if (!clip) {
+        m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
+        return;
+    }
+
+    QString id = clip->getId();
+    QString oldcomment = clip->markerComment(pos);
+    if (oldcomment.isEmpty()) {
+        m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
+        return;
+    }
+
+    CommentedTime marker(pos, oldcomment);
+    MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Edit Marker"), this);
+    if (d.exec() == QDialog::Accepted) {
+        m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
+        if (d.newMarker().time() != pos) {
+            // remove old marker
+            m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
+        }
+        if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
     }
 }
 
@@ -1503,6 +1633,29 @@ void MainWindow::slotInsertSpace() {
         m_activeTimeline->projectView()->slotInsertSpace();
 }
 
+void MainWindow::slotRemoveSpace() {
+    if (m_activeTimeline)
+        m_activeTimeline->projectView()->slotRemoveSpace();
+}
+
+void MainWindow::slotInsertTrack(int ix) {
+    m_projectMonitor->activateMonitor();
+    if (m_activeTimeline)
+        m_activeTimeline->projectView()->slotInsertTrack(ix);
+}
+
+void MainWindow::slotDeleteTrack(int ix) {
+    m_projectMonitor->activateMonitor();
+    if (m_activeTimeline)
+        m_activeTimeline->projectView()->slotDeleteTrack(ix);
+}
+
+void MainWindow::slotChangeTrack(int ix) {
+    m_projectMonitor->activateMonitor();
+    if (m_activeTimeline)
+        m_activeTimeline->projectView()->slotChangeTrack(ix);
+}
+
 void MainWindow::slotEditGuide() {
     if (m_activeTimeline)
         m_activeTimeline->projectView()->slotEditGuide();
@@ -1645,14 +1798,14 @@ void MainWindow::slotSnapRewind() {
     if (m_projectMonitor->isActive()) {
         if (m_activeTimeline)
             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
-    }
+    } else m_clipMonitor->slotSeekToPreviousSnap();
 }
 
 void MainWindow::slotSnapForward() {
     if (m_projectMonitor->isActive()) {
         if (m_activeTimeline)
             m_activeTimeline->projectView()->slotSeekToNextSnap();
-    }
+    } else m_clipMonitor->slotSeekToNextSnap();
 }
 
 void MainWindow::slotClipStart() {