7 #include <KApplication>
10 #include <KActionCollection>
11 #include <KStandardAction>
12 #include <KFileDialog>
13 #include <KMessageBox>
15 #include <KIO/NetAccess>
18 #include <KConfigDialog>
19 #include <KXMLGUIFactory>
21 #include <mlt++/Mlt.h>
23 #include "mainwindow.h"
24 #include "kdenlivesettings.h"
25 #include "ui_configmisc_ui.h"
27 MainWindow::MainWindow(QWidget *parent)
28 : KXmlGuiWindow(parent),
29 fileName(QString()), m_activeDocument(NULL)
31 m_timelineArea = new KTabWidget(this);
32 m_timelineArea->setHoverCloseButton(true);
33 m_timelineArea->setTabReorderingEnabled(true);
34 connect(m_timelineArea, SIGNAL(currentChanged (int)), this, SLOT(activateDocument()));
35 setCentralWidget(m_timelineArea);
37 m_monitorManager = new MonitorManager();
38 m_commandStack = new KUndoStack(this);
40 projectListDock = new QDockWidget(i18n("Project Tree"), this);
41 projectListDock->setObjectName("project_tree");
42 m_projectList = new ProjectList(this);
43 projectListDock->setWidget(m_projectList);
44 addDockWidget(Qt::TopDockWidgetArea, projectListDock);
46 effectListDock = new QDockWidget(i18n("Effect List"), this);
47 effectListDock->setObjectName("effect_list");
48 effectList = new KListWidget(this);
49 effectListDock->setWidget(effectList);
50 addDockWidget(Qt::TopDockWidgetArea, effectListDock);
52 effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
53 effectStackDock->setObjectName("effect_stack");
54 effectStack = new KListWidget(this);
55 effectStackDock->setWidget(effectStack);
56 addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
58 transitionConfigDock = new QDockWidget(i18n("Transition"), this);
59 transitionConfigDock->setObjectName("transition");
60 transitionConfig = new KListWidget(this);
61 transitionConfigDock->setWidget(transitionConfig);
62 addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
64 Mlt::Factory::init(NULL);
66 clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
67 clipMonitorDock->setObjectName("clip_monitor");
68 m_clipMonitor = new Monitor("clip", m_monitorManager, this);
69 clipMonitorDock->setWidget(m_clipMonitor);
70 addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
72 projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
73 projectMonitorDock->setObjectName("project_monitor");
74 m_projectMonitor = new Monitor("project", m_monitorManager, this);
75 projectMonitorDock->setWidget(m_projectMonitor);
76 addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
78 undoViewDock = new QDockWidget(i18n("Undo History"), this);
79 undoViewDock->setObjectName("undo_history");
80 m_undoView = new QUndoView(this);
81 undoViewDock->setWidget(m_undoView);
82 addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
85 tabifyDockWidget (projectListDock, effectListDock);
86 tabifyDockWidget (projectListDock, effectStackDock);
87 tabifyDockWidget (projectListDock, transitionConfigDock);
88 tabifyDockWidget (projectListDock, undoViewDock);
89 projectListDock->raise();
91 tabifyDockWidget (clipMonitorDock, projectMonitorDock);
93 connect(projectMonitorDock, SIGNAL(visibilityChanged (bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
94 connect(clipMonitorDock, SIGNAL(visibilityChanged (bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
95 connect(m_monitorManager, SIGNAL(connectMonitors ()), this, SLOT(slotConnectMonitors()));
96 connect(m_monitorManager, SIGNAL(raiseClipMonitor (bool)), this, SLOT(slotRaiseMonitor(bool)));
97 m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
103 void MainWindow::slotRaiseMonitor(bool clipMonitor)
105 if (clipMonitor) clipMonitorDock->raise();
106 else projectMonitorDock->raise();
109 void MainWindow::slotConnectMonitors()
112 m_projectList->setRenderer(m_clipMonitor->render);
114 connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
116 connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
118 connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
120 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 > &)));
124 void MainWindow::setupActions()
126 KAction* clearAction = new KAction(this);
127 clearAction->setText(i18n("Clear"));
128 clearAction->setIcon(KIcon("document-new"));
129 clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
130 actionCollection()->addAction("clear", clearAction);
131 /*connect(clearAction, SIGNAL(triggered(bool)),
132 textArea, SLOT(clear()));*/
134 KStandardAction::quit(kapp, SLOT(quit()),
137 KStandardAction::open(this, SLOT(openFile()),
140 KStandardAction::save(this, SLOT(saveFile()),
143 KStandardAction::saveAs(this, SLOT(saveFileAs()),
146 KStandardAction::openNew(this, SLOT(newFile()),
149 /*KStandardAction::undo(this, SLOT(undo()),
152 KStandardAction::redo(this, SLOT(redo()),
153 actionCollection());*/
155 KStandardAction::preferences(this, SLOT(slotPreferences()),
158 /*m_redo = m_commandStack->createRedoAction(actionCollection());
159 m_undo = m_commandStack->createUndoAction(actionCollection());*/
166 void MainWindow::newFile()
168 KdenliveDoc *doc = new KdenliveDoc(KUrl(), 25, 720, 576);
169 TrackView *trackView = new TrackView(doc);
170 m_timelineArea->addTab(trackView, "New Project");
171 if (m_timelineArea->count() == 1)
172 connectDocument(trackView, doc);
175 void MainWindow::activateDocument()
177 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
178 KdenliveDoc *currentDoc = currentTab->document();
179 connectDocument(currentTab, currentDoc);
182 void MainWindow::saveFileAs(const QString &outputFileName)
184 KSaveFile file(outputFileName);
187 QByteArray outputByteArray;
188 //outputByteArray.append(textArea->toPlainText());
189 file.write(outputByteArray);
193 fileName = outputFileName;
196 void MainWindow::saveFileAs()
198 saveFileAs(KFileDialog::getSaveFileName());
201 void MainWindow::saveFile()
203 if(!fileName.isEmpty())
205 saveFileAs(fileName);
213 void MainWindow::openFile() //changed
215 openFile(KFileDialog::getOpenFileName(KUrl(), "application/vnd.kde.kdenlive"));
218 void MainWindow::openFile(const QString &inputFileName) //new
220 KdenliveDoc *doc = new KdenliveDoc(KUrl(inputFileName), 25, 720, 576);
221 TrackView *trackView = new TrackView(doc);
222 m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, QIcon(), doc->documentName()));
223 connectDocument(trackView, doc);
227 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //changed
229 //m_projectMonitor->stop();
230 if (m_activeDocument) {
231 m_activeDocument->setProducers(m_projectList->producersList());
232 m_activeDocument->setRenderer(NULL);
234 m_projectList->setDocument(doc);
235 m_monitorManager->setTimecode(doc->timecode());
236 doc->setRenderer(m_projectMonitor->render);
237 m_commandStack = doc->commandStack();
239 QAction *redo = m_commandStack->createRedoAction(actionCollection());
240 QAction *undo = m_commandStack->createUndoAction(actionCollection());
242 QWidget* w = factory()->container("mainToolBar", this);
244 if (actionCollection()->action("undo"))
245 delete actionCollection()->action("undo");
246 if(actionCollection()->action("redo"))
247 delete actionCollection()->action("redo");
249 actionCollection()->addAction("undo", undo);
250 actionCollection()->addAction("redo", redo);
254 m_undoView->setStack(m_commandStack);
256 m_activeDocument = doc;
260 void MainWindow::slotPreferences()
262 //An instance of your dialog could be already created and could be
263 // cached, in which case you want to display the cached dialog
264 // instead of creating another one
265 if ( KConfigDialog::showDialog( "settings" ) )
268 // KConfigDialog didn't find an instance of this dialog, so lets
270 KConfigDialog* dialog = new KConfigDialog(this, "settings",
271 KdenliveSettings::self());
273 QWidget *page1 = new QWidget;
274 Ui::ConfigMisc_UI* confWdg = new Ui::ConfigMisc_UI( );
275 confWdg->setupUi(page1);
277 dialog->addPage( page1, i18n("Misc"), "misc" );
279 //User edited the configuration - update your local copies of the
281 connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateConfiguration()) );
286 #include "mainwindow.moc"