1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
22 #include <QTextStream>
26 #include <KApplication>
29 #include <KActionCollection>
30 #include <KStandardAction>
31 #include <KFileDialog>
32 #include <KMessageBox>
34 #include <KIO/NetAccess>
37 #include <KConfigDialog>
38 #include <KXMLGUIFactory>
40 #include <mlt++/Mlt.h>
42 #include "mainwindow.h"
43 #include "kdenlivesettings.h"
44 #include "ui_configmisc_ui.h"
46 MainWindow::MainWindow(QWidget *parent)
47 : KXmlGuiWindow(parent),
48 fileName(QString()), m_activeDocument(NULL), m_commandStack(NULL)
50 m_timelineArea = new KTabWidget(this);
51 m_timelineArea->setHoverCloseButton(true);
52 m_timelineArea->setTabReorderingEnabled(true);
53 connect(m_timelineArea, SIGNAL(currentChanged (int)), this, SLOT(activateDocument()));
55 m_monitorManager = new MonitorManager();
57 projectListDock = new QDockWidget(i18n("Project Tree"), this);
58 projectListDock->setObjectName("project_tree");
59 m_projectList = new ProjectList(this);
60 projectListDock->setWidget(m_projectList);
61 addDockWidget(Qt::TopDockWidgetArea, projectListDock);
63 effectListDock = new QDockWidget(i18n("Effect List"), this);
64 effectListDock->setObjectName("effect_list");
65 effectList = new KListWidget(this);
66 effectListDock->setWidget(effectList);
67 addDockWidget(Qt::TopDockWidgetArea, effectListDock);
69 effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
70 effectStackDock->setObjectName("effect_stack");
71 effectStack = new KListWidget(this);
72 effectStackDock->setWidget(effectStack);
73 addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
75 transitionConfigDock = new QDockWidget(i18n("Transition"), this);
76 transitionConfigDock->setObjectName("transition");
77 transitionConfig = new KListWidget(this);
78 transitionConfigDock->setWidget(transitionConfig);
79 addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
81 Mlt::Factory::init(NULL);
83 clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
84 clipMonitorDock->setObjectName("clip_monitor");
85 m_clipMonitor = new Monitor("clip", m_monitorManager, this);
86 clipMonitorDock->setWidget(m_clipMonitor);
87 addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
89 projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
90 projectMonitorDock->setObjectName("project_monitor");
91 m_projectMonitor = new Monitor("project", m_monitorManager, this);
92 projectMonitorDock->setWidget(m_projectMonitor);
93 addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
95 undoViewDock = new QDockWidget(i18n("Undo History"), this);
96 undoViewDock->setObjectName("undo_history");
97 m_undoView = new QUndoView(this);
98 undoViewDock->setWidget(m_undoView);
99 m_undoView->setStack(m_commandStack);
100 addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
102 overviewDock = new QDockWidget(i18n("Project Overview"), this);
103 overviewDock->setObjectName("project_overview");
104 m_overView = new CustomTrackView(NULL, NULL, this);
105 overviewDock->setWidget(m_overView);
106 addDockWidget(Qt::TopDockWidgetArea, overviewDock);
109 tabifyDockWidget (projectListDock, effectListDock);
110 tabifyDockWidget (projectListDock, effectStackDock);
111 tabifyDockWidget (projectListDock, transitionConfigDock);
112 tabifyDockWidget (projectListDock, undoViewDock);
113 projectListDock->raise();
115 tabifyDockWidget (clipMonitorDock, projectMonitorDock);
116 setCentralWidget(m_timelineArea);
117 setupGUI(Default, "kdenliveui.rc");
119 connect(projectMonitorDock, SIGNAL(visibilityChanged (bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
120 connect(clipMonitorDock, SIGNAL(visibilityChanged (bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
121 connect(m_monitorManager, SIGNAL(connectMonitors ()), this, SLOT(slotConnectMonitors()));
122 connect(m_monitorManager, SIGNAL(raiseClipMonitor (bool)), this, SLOT(slotRaiseMonitor(bool)));
123 m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
125 setAutoSaveSettings();
130 bool MainWindow::queryClose()
133 switch ( KMessageBox::warningYesNoCancel( this, i18n("Save changes to document ?")) ) {
134 case KMessageBox::Yes :
135 // save document here. If saving fails, return false;
137 case KMessageBox::No :
144 void MainWindow::slotRaiseMonitor(bool clipMonitor)
146 if (clipMonitor) clipMonitorDock->raise();
147 else projectMonitorDock->raise();
150 void MainWindow::slotSetClipDuration(int id, int duration)
152 if (!m_activeDocument) return;
153 m_activeDocument->setProducerDuration(id, duration);
156 void MainWindow::slotConnectMonitors()
159 m_projectList->setRenderer(m_clipMonitor->render);
161 connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
163 connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
165 connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
167 connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
169 connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)));
173 void MainWindow::setupActions()
175 KAction* clearAction = new KAction(this);
176 clearAction->setText(i18n("Clear"));
177 clearAction->setIcon(KIcon("document-new"));
178 clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
179 actionCollection()->addAction("clear", clearAction);
180 /*connect(clearAction, SIGNAL(triggered(bool)),
181 textArea, SLOT(clear()));*/
183 KStandardAction::quit(kapp, SLOT(quit()),
186 KStandardAction::open(this, SLOT(openFile()),
189 m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
192 KStandardAction::save(this, SLOT(saveFile()),
195 KStandardAction::saveAs(this, SLOT(saveFileAs()),
198 KStandardAction::openNew(this, SLOT(newFile()),
201 /*KStandardAction::undo(this, SLOT(undo()),
204 KStandardAction::redo(this, SLOT(redo()),
205 actionCollection());*/
209 /*m_redo = m_commandStack->createRedoAction(actionCollection());
210 m_undo = m_commandStack->createUndoAction(actionCollection());*/
213 void MainWindow::saveOptions()
215 KSharedConfigPtr config = KGlobal::config ();
216 m_fileOpenRecent->saveEntries(KConfigGroup (config, "Recent Files"));
220 void MainWindow::readOptions()
222 KSharedConfigPtr config = KGlobal::config ();
223 m_fileOpenRecent->loadEntries(KConfigGroup (config, "Recent Files"));
226 void MainWindow::newFile()
228 KdenliveDoc *doc = new KdenliveDoc(KUrl(), 25, 720, 576);
229 TrackView *trackView = new TrackView(doc);
230 m_timelineArea->addTab(trackView, "New Project");
231 if (m_timelineArea->count() == 1)
232 connectDocument(trackView, doc);
235 void MainWindow::activateDocument()
237 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
238 KdenliveDoc *currentDoc = currentTab->document();
239 connectDocument(currentTab, currentDoc);
242 void MainWindow::saveFileAs(const QString &outputFileName)
244 KSaveFile file(outputFileName);
247 QByteArray outputByteArray;
248 //outputByteArray.append(textArea->toPlainText());
249 file.write(outputByteArray);
253 fileName = outputFileName;
256 void MainWindow::saveFileAs()
258 saveFileAs(KFileDialog::getSaveFileName());
261 void MainWindow::saveFile()
263 if(!fileName.isEmpty())
265 saveFileAs(fileName);
273 void MainWindow::openFile() //changed
275 KUrl url = KFileDialog::getOpenUrl(KUrl(), "application/vnd.kde.kdenlive;*.kdenlive");
276 if (url.isEmpty()) return;
277 m_fileOpenRecent->addUrl (url);
281 void MainWindow::openFile(const KUrl &url) //new
283 KdenliveDoc *doc = new KdenliveDoc(url, 25, 720, 576);
284 TrackView *trackView = new TrackView(doc);
285 m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, QIcon(), doc->documentName()));
286 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
287 //connectDocument(trackView, doc);
290 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //changed
292 //m_projectMonitor->stop();
293 if (m_activeDocument) {
294 if (m_activeDocument == doc) return;
295 m_activeDocument->setProducers(m_projectList->producersList());
296 m_activeDocument->setRenderer(NULL);
298 m_projectList->setDocument(doc);
299 m_monitorManager->setTimecode(doc->timecode());
300 doc->setRenderer(m_projectMonitor->render);
301 //m_undoView->setStack(0);
302 m_commandStack = doc->commandStack();
304 m_overView->setScene(trackView->projectScene());
305 m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
306 //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
307 QAction *redo = m_commandStack->createRedoAction(actionCollection());
308 QAction *undo = m_commandStack->createUndoAction(actionCollection());
310 QWidget* w = factory()->container("mainToolBar", this);
312 if (actionCollection()->action("undo"))
313 delete actionCollection()->action("undo");
314 if(actionCollection()->action("redo"))
315 delete actionCollection()->action("redo");
317 actionCollection()->addAction("undo", undo);
318 actionCollection()->addAction("redo", redo);
322 m_undoView->setStack(doc->commandStack());
323 m_activeDocument = doc;
327 void MainWindow::slotPreferences()
329 //An instance of your dialog could be already created and could be
330 // cached, in which case you want to display the cached dialog
331 // instead of creating another one
332 if ( KConfigDialog::showDialog( "settings" ) )
335 // KConfigDialog didn't find an instance of this dialog, so lets
337 KConfigDialog* dialog = new KConfigDialog(this, "settings",
338 KdenliveSettings::self());
340 QWidget *page1 = new QWidget;
341 Ui::ConfigMisc_UI* confWdg = new Ui::ConfigMisc_UI( );
342 confWdg->setupUi(page1);
344 dialog->addPage( page1, i18n("Misc"), "misc" );
346 //User edited the configuration - update your local copies of the
348 connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateConfiguration()) );
353 #include "mainwindow.moc"