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()));
54 setCentralWidget(m_timelineArea);
56 m_monitorManager = new MonitorManager();
58 projectListDock = new QDockWidget(i18n("Project Tree"), this);
59 projectListDock->setObjectName("project_tree");
60 m_projectList = new ProjectList(this);
61 projectListDock->setWidget(m_projectList);
62 addDockWidget(Qt::TopDockWidgetArea, projectListDock);
64 effectListDock = new QDockWidget(i18n("Effect List"), this);
65 effectListDock->setObjectName("effect_list");
66 effectList = new KListWidget(this);
67 effectListDock->setWidget(effectList);
68 addDockWidget(Qt::TopDockWidgetArea, effectListDock);
70 effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
71 effectStackDock->setObjectName("effect_stack");
72 effectStack = new KListWidget(this);
73 effectStackDock->setWidget(effectStack);
74 addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
76 transitionConfigDock = new QDockWidget(i18n("Transition"), this);
77 transitionConfigDock->setObjectName("transition");
78 transitionConfig = new KListWidget(this);
79 transitionConfigDock->setWidget(transitionConfig);
80 addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
82 Mlt::Factory::init(NULL);
84 clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
85 clipMonitorDock->setObjectName("clip_monitor");
86 m_clipMonitor = new Monitor("clip", m_monitorManager, this);
87 clipMonitorDock->setWidget(m_clipMonitor);
88 addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
90 projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
91 projectMonitorDock->setObjectName("project_monitor");
92 m_projectMonitor = new Monitor("project", m_monitorManager, this);
93 projectMonitorDock->setWidget(m_projectMonitor);
94 addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
96 undoViewDock = new QDockWidget(i18n("Undo History"), this);
97 undoViewDock->setObjectName("undo_history");
98 m_undoView = new QUndoView(this);
99 undoViewDock->setWidget(m_undoView);
100 m_undoView->setStack(m_commandStack);
101 addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
104 tabifyDockWidget (projectListDock, effectListDock);
105 tabifyDockWidget (projectListDock, effectStackDock);
106 tabifyDockWidget (projectListDock, transitionConfigDock);
107 tabifyDockWidget (projectListDock, undoViewDock);
108 projectListDock->raise();
110 tabifyDockWidget (clipMonitorDock, projectMonitorDock);
112 connect(projectMonitorDock, SIGNAL(visibilityChanged (bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
113 connect(clipMonitorDock, SIGNAL(visibilityChanged (bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
114 connect(m_monitorManager, SIGNAL(connectMonitors ()), this, SLOT(slotConnectMonitors()));
115 connect(m_monitorManager, SIGNAL(raiseClipMonitor (bool)), this, SLOT(slotRaiseMonitor(bool)));
116 m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
122 void MainWindow::slotRaiseMonitor(bool clipMonitor)
124 if (clipMonitor) clipMonitorDock->raise();
125 else projectMonitorDock->raise();
128 void MainWindow::slotConnectMonitors()
131 m_projectList->setRenderer(m_clipMonitor->render);
133 connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
135 connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
137 connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
139 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 > &)));
143 void MainWindow::setupActions()
145 KAction* clearAction = new KAction(this);
146 clearAction->setText(i18n("Clear"));
147 clearAction->setIcon(KIcon("document-new"));
148 clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
149 actionCollection()->addAction("clear", clearAction);
150 /*connect(clearAction, SIGNAL(triggered(bool)),
151 textArea, SLOT(clear()));*/
153 KStandardAction::quit(kapp, SLOT(quit()),
156 KStandardAction::open(this, SLOT(openFile()),
159 KStandardAction::save(this, SLOT(saveFile()),
162 KStandardAction::saveAs(this, SLOT(saveFileAs()),
165 KStandardAction::openNew(this, SLOT(newFile()),
168 /*KStandardAction::undo(this, SLOT(undo()),
171 KStandardAction::redo(this, SLOT(redo()),
172 actionCollection());*/
174 KStandardAction::preferences(this, SLOT(slotPreferences()),
177 /*m_redo = m_commandStack->createRedoAction(actionCollection());
178 m_undo = m_commandStack->createUndoAction(actionCollection());*/
185 void MainWindow::newFile()
187 KdenliveDoc *doc = new KdenliveDoc(KUrl(), 25, 720, 576);
188 TrackView *trackView = new TrackView(doc);
189 m_timelineArea->addTab(trackView, "New Project");
190 if (m_timelineArea->count() == 1)
191 connectDocument(trackView, doc);
194 void MainWindow::activateDocument()
196 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
197 KdenliveDoc *currentDoc = currentTab->document();
198 connectDocument(currentTab, currentDoc);
201 void MainWindow::saveFileAs(const QString &outputFileName)
203 KSaveFile file(outputFileName);
206 QByteArray outputByteArray;
207 //outputByteArray.append(textArea->toPlainText());
208 file.write(outputByteArray);
212 fileName = outputFileName;
215 void MainWindow::saveFileAs()
217 saveFileAs(KFileDialog::getSaveFileName());
220 void MainWindow::saveFile()
222 if(!fileName.isEmpty())
224 saveFileAs(fileName);
232 void MainWindow::openFile() //changed
234 openFile(KFileDialog::getOpenFileName(KUrl(), "application/vnd.kde.kdenlive,*.kdenlive"));
237 void MainWindow::openFile(const QString &inputFileName) //new
239 KdenliveDoc *doc = new KdenliveDoc(KUrl(inputFileName), 25, 720, 576);
240 TrackView *trackView = new TrackView(doc);
241 m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, QIcon(), doc->documentName()));
242 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
243 //connectDocument(trackView, doc);
246 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //changed
248 //m_projectMonitor->stop();
249 if (m_activeDocument) {
250 if (m_activeDocument == doc) return;
251 m_activeDocument->setProducers(m_projectList->producersList());
252 m_activeDocument->setRenderer(NULL);
254 m_projectList->setDocument(doc);
255 m_monitorManager->setTimecode(doc->timecode());
256 doc->setRenderer(m_projectMonitor->render);
257 //m_undoView->setStack(0);
258 m_commandStack = doc->commandStack();
260 QAction *redo = m_commandStack->createRedoAction(actionCollection());
261 QAction *undo = m_commandStack->createUndoAction(actionCollection());
263 QWidget* w = factory()->container("mainToolBar", this);
265 if (actionCollection()->action("undo"))
266 delete actionCollection()->action("undo");
267 if(actionCollection()->action("redo"))
268 delete actionCollection()->action("redo");
270 actionCollection()->addAction("undo", undo);
271 actionCollection()->addAction("redo", redo);
275 m_undoView->setStack(doc->commandStack());
276 m_activeDocument = doc;
280 void MainWindow::slotPreferences()
282 //An instance of your dialog could be already created and could be
283 // cached, in which case you want to display the cached dialog
284 // instead of creating another one
285 if ( KConfigDialog::showDialog( "settings" ) )
288 // KConfigDialog didn't find an instance of this dialog, so lets
290 KConfigDialog* dialog = new KConfigDialog(this, "settings",
291 KdenliveSettings::self());
293 QWidget *page1 = new QWidget;
294 Ui::ConfigMisc_UI* confWdg = new Ui::ConfigMisc_UI( );
295 confWdg->setupUi(page1);
297 dialog->addPage( page1, i18n("Misc"), "misc" );
299 //User edited the configuration - update your local copies of the
301 connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateConfiguration()) );
306 #include "mainwindow.moc"