]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
7d9e238840a37e6153f8a5a3ee43a4b4e7319fc4
[kdenlive] / src / mainwindow.cpp
1
2
3 #include <QTextStream>
4 #include <QTimer>
5 #include <QAction>
6
7 #include <KApplication>
8 #include <KAction>
9 #include <KLocale>
10 #include <KActionCollection>
11 #include <KStandardAction>
12 #include <KFileDialog>
13 #include <KMessageBox>
14 #include <KDebug>
15 #include <KIO/NetAccess>
16 #include <KSaveFile>
17 #include <KRuler>
18 #include <KConfigDialog>
19 #include <KXMLGUIFactory>
20
21 #include <mlt++/Mlt.h>
22
23 #include "mainwindow.h"
24 #include "kdenlivesettings.h"
25 #include "ui_configmisc_ui.h"
26  
27 MainWindow::MainWindow(QWidget *parent)
28     : KXmlGuiWindow(parent),
29       fileName(QString()), m_activeDocument(NULL)
30 {
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);
36
37   m_monitorManager = new MonitorManager();
38   m_commandStack = new KUndoStack(this);
39
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);
45
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);
51   
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);
57   
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);
63
64   Mlt::Factory::init(NULL);
65
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);
71   
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);
77
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);
83
84   setupActions();
85   tabifyDockWidget (projectListDock, effectListDock);
86   tabifyDockWidget (projectListDock, effectStackDock);
87   tabifyDockWidget (projectListDock, transitionConfigDock);
88   tabifyDockWidget (projectListDock, undoViewDock);
89   projectListDock->raise();
90
91   tabifyDockWidget (clipMonitorDock, projectMonitorDock);
92
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);
98
99   newFile();
100 }
101
102
103 void MainWindow::slotRaiseMonitor(bool clipMonitor)
104 {
105   if (clipMonitor) clipMonitorDock->raise();
106   else projectMonitorDock->raise();
107 }
108
109 void MainWindow::slotConnectMonitors()
110 {
111
112   m_projectList->setRenderer(m_clipMonitor->render);
113
114   connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
115
116   connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
117
118   connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
119
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 > &)));
121
122 }
123
124 void MainWindow::setupActions()
125 {
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()));*/
133  
134   KStandardAction::quit(kapp, SLOT(quit()),
135                         actionCollection());
136  
137   KStandardAction::open(this, SLOT(openFile()),
138                         actionCollection());
139  
140   KStandardAction::save(this, SLOT(saveFile()),
141                         actionCollection());
142  
143   KStandardAction::saveAs(this, SLOT(saveFileAs()),
144                         actionCollection());
145  
146   KStandardAction::openNew(this, SLOT(newFile()),
147                         actionCollection());
148
149   /*KStandardAction::undo(this, SLOT(undo()),
150                         actionCollection());
151
152   KStandardAction::redo(this, SLOT(redo()),
153                         actionCollection());*/
154
155   KStandardAction::preferences(this, SLOT(slotPreferences()),
156             actionCollection());
157
158   /*m_redo = m_commandStack->createRedoAction(actionCollection());
159   m_undo = m_commandStack->createUndoAction(actionCollection());*/
160
161   setupGUI();
162
163
164 }
165  
166 void MainWindow::newFile()
167 {
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);
173 }
174
175 void MainWindow::activateDocument()
176 {
177   TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
178   KdenliveDoc *currentDoc = currentTab->document();
179   connectDocument(currentTab, currentDoc);
180 }
181  
182 void MainWindow::saveFileAs(const QString &outputFileName)
183 {
184   KSaveFile file(outputFileName);
185   file.open();
186   
187   QByteArray outputByteArray;
188   //outputByteArray.append(textArea->toPlainText());
189   file.write(outputByteArray);
190   file.finalize();
191   file.close();
192   
193   fileName = outputFileName;
194 }
195
196 void MainWindow::saveFileAs()
197 {
198   saveFileAs(KFileDialog::getSaveFileName());
199 }
200  
201 void MainWindow::saveFile()
202 {
203   if(!fileName.isEmpty())
204   {
205     saveFileAs(fileName);
206   }
207   else
208   {
209     saveFileAs();
210   }
211 }
212  
213 void MainWindow::openFile() //changed
214 {
215   openFile(KFileDialog::getOpenFileName(KUrl(), "application/vnd.kde.kdenlive"));
216 }
217  
218 void MainWindow::openFile(const QString &inputFileName) //new
219 {
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);
224   
225 }
226
227 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //changed
228 {
229   //m_projectMonitor->stop();
230   if (m_activeDocument) {
231     m_activeDocument->setProducers(m_projectList->producersList());
232     m_activeDocument->setRenderer(NULL);
233   }
234   m_projectList->setDocument(doc);
235   m_monitorManager->setTimecode(doc->timecode());
236   doc->setRenderer(m_projectMonitor->render);
237   m_commandStack = doc->commandStack();
238
239   QAction *redo = m_commandStack->createRedoAction(actionCollection());
240   QAction *undo = m_commandStack->createUndoAction(actionCollection());
241
242   QWidget* w = factory()->container("mainToolBar", this);
243   if(w) {
244     if (actionCollection()->action("undo"))
245       delete actionCollection()->action("undo");
246     if(actionCollection()->action("redo"))
247       delete actionCollection()->action("redo");
248
249     actionCollection()->addAction("undo", undo);
250     actionCollection()->addAction("redo", redo);
251     w->addAction(undo);
252     w->addAction(redo);
253   }
254   m_undoView->setStack(m_commandStack);
255   
256   m_activeDocument = doc;
257 }
258
259
260 void MainWindow::slotPreferences()
261 {
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" ) )
266     return;
267
268   // KConfigDialog didn't find an instance of this dialog, so lets
269   // create it :
270   KConfigDialog* dialog = new KConfigDialog(this, "settings",
271                                           KdenliveSettings::self());
272
273   QWidget *page1 = new QWidget;
274   Ui::ConfigMisc_UI* confWdg = new Ui::ConfigMisc_UI( );
275   confWdg->setupUi(page1);
276
277   dialog->addPage( page1, i18n("Misc"), "misc" );
278
279   //User edited the configuration - update your local copies of the
280   //configuration data
281   connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateConfiguration()) );
282
283   dialog->show();
284 }
285
286 #include "mainwindow.moc"