]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
8befa8fc72e50b520484e20fece9e17c0baf88ab
[kdenlive] / src / mainwindow.cpp
1
2
3 #include <QTextStream>
4 #include <QTimer>
5
6 #include <KApplication>
7 #include <KAction>
8 #include <KLocale>
9 #include <KActionCollection>
10 #include <KStandardAction>
11 #include <KFileDialog>
12 #include <KMessageBox>
13 #include <KDebug>
14 #include <KIO/NetAccess>
15 #include <KSaveFile>
16 #include <KRuler>
17 #include <KConfigDialog>
18
19
20 #include <mlt++/Mlt.h>
21
22 #include "mainwindow.h"
23 #include "kdenlivesettings.h"
24 #include "ui_configmisc_ui.h"
25  
26 MainWindow::MainWindow(QWidget *parent)
27     : KXmlGuiWindow(parent),
28       fileName(QString()), m_activeDocument(NULL)
29 {
30   m_timelineArea = new KTabWidget(this);
31   m_timelineArea->setHoverCloseButton(true);
32   m_timelineArea->setTabReorderingEnabled(true);
33   connect(m_timelineArea, SIGNAL(currentChanged (int)), this, SLOT(activateDocument()));
34   setCentralWidget(m_timelineArea);
35
36   m_monitorManager = new MonitorManager();
37
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(m_commandStack, 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   setupActions();
79   tabifyDockWidget (projectListDock, effectListDock);
80   tabifyDockWidget (projectListDock, effectStackDock);
81   tabifyDockWidget (projectListDock, transitionConfigDock);
82   projectListDock->raise();
83
84   tabifyDockWidget (clipMonitorDock, projectMonitorDock);
85
86   connect(projectMonitorDock, SIGNAL(visibilityChanged (bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
87   connect(clipMonitorDock, SIGNAL(visibilityChanged (bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
88   connect(m_monitorManager, SIGNAL(connectMonitors ()), this, SLOT(slotConnectMonitors()));
89   connect(m_monitorManager, SIGNAL(raiseClipMonitor (bool)), this, SLOT(slotRaiseMonitor(bool)));
90   m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
91
92   newFile();
93 }
94
95
96 void MainWindow::slotRaiseMonitor(bool clipMonitor)
97 {
98   if (clipMonitor) clipMonitorDock->raise();
99   else projectMonitorDock->raise();
100 }
101
102 void MainWindow::slotConnectMonitors()
103 {
104
105   m_projectList->setRenderer(m_clipMonitor->render);
106
107   connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
108
109   connect(m_projectList, SIGNAL(getFileProperties(const KUrl &, uint)), m_clipMonitor->render, SLOT(getFileProperties(const KUrl &, uint)));
110
111   connect(m_clipMonitor->render, SIGNAL(replyGetImage(const KUrl &, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(const KUrl &, int, const QPixmap &, int, int)));
112
113   connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(const QMap < QString, QString > &, const QMap < QString, QString > &)));
114
115 }
116
117 void MainWindow::setupActions()
118 {
119   KAction* clearAction = new KAction(this);
120   clearAction->setText(i18n("Clear"));
121   clearAction->setIcon(KIcon("document-new"));
122   clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
123   actionCollection()->addAction("clear", clearAction);
124   /*connect(clearAction, SIGNAL(triggered(bool)),
125           textArea, SLOT(clear()));*/
126  
127   KStandardAction::quit(kapp, SLOT(quit()),
128                         actionCollection());
129  
130   KStandardAction::open(this, SLOT(openFile()),
131                         actionCollection());
132  
133   KStandardAction::save(this, SLOT(saveFile()),
134                         actionCollection());
135  
136   KStandardAction::saveAs(this, SLOT(saveFileAs()),
137                         actionCollection());
138  
139   KStandardAction::openNew(this, SLOT(newFile()),
140                         actionCollection());
141
142   /*KStandardAction::undo(this, SLOT(undo()),
143                         actionCollection());
144
145   KStandardAction::redo(this, SLOT(redo()),
146                         actionCollection());*/
147
148   KStandardAction::preferences(this, SLOT(slotPreferences()),
149             actionCollection());
150
151   QAction * redo = m_commandStack->createRedoAction(actionCollection());
152   QAction * undo = m_commandStack->createUndoAction(actionCollection());
153
154   setupGUI();
155 }
156  
157 void MainWindow::newFile()
158 {
159   KdenliveDoc *doc = new KdenliveDoc(KUrl(), 25, 720, 576);
160   TrackView *trackView = new TrackView(doc);
161   m_timelineArea->addTab(trackView, "New Project");
162   if (m_timelineArea->count() == 1)
163     connectDocument(trackView, doc);
164 }
165
166 void MainWindow::activateDocument()
167 {
168   TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
169   KdenliveDoc *currentDoc = currentTab->document();
170   connectDocument(currentTab, currentDoc);
171 }
172  
173 void MainWindow::saveFileAs(const QString &outputFileName)
174 {
175   KSaveFile file(outputFileName);
176   file.open();
177   
178   QByteArray outputByteArray;
179   //outputByteArray.append(textArea->toPlainText());
180   file.write(outputByteArray);
181   file.finalize();
182   file.close();
183   
184   fileName = outputFileName;
185 }
186
187 void MainWindow::saveFileAs()
188 {
189   saveFileAs(KFileDialog::getSaveFileName());
190 }
191  
192 void MainWindow::saveFile()
193 {
194   if(!fileName.isEmpty())
195   {
196     saveFileAs(fileName);
197   }
198   else
199   {
200     saveFileAs();
201   }
202 }
203  
204 void MainWindow::openFile() //changed
205 {
206   openFile(KFileDialog::getOpenFileName(KUrl(), "application/vnd.kde.kdenlive"));
207 }
208  
209 void MainWindow::openFile(const QString &inputFileName) //new
210 {
211   KdenliveDoc *doc = new KdenliveDoc(KUrl(inputFileName), 25, 720, 576);
212   TrackView *trackView = new TrackView(doc);
213   m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, QIcon(), doc->documentName()));
214   connectDocument(trackView, doc);
215   
216 }
217
218 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //changed
219 {
220   //m_projectMonitor->stop();
221   if (m_activeDocument) {
222     m_activeDocument->setProducers(m_projectList->producersList());
223     m_activeDocument->setRenderer(NULL);
224   }
225   m_projectList->setDocument(doc);
226   m_monitorManager->setTimecode(doc->timecode());
227   doc->setRenderer(m_projectMonitor->render);
228   m_activeDocument = doc;
229 }
230
231
232 void MainWindow::slotPreferences()
233 {
234   //An instance of your dialog could be already created and could be
235   // cached, in which case you want to display the cached dialog
236   // instead of creating another one
237   if ( KConfigDialog::showDialog( "settings" ) )
238     return;
239
240   // KConfigDialog didn't find an instance of this dialog, so lets
241   // create it :
242   KConfigDialog* dialog = new KConfigDialog(this, "settings",
243                                           KdenliveSettings::self());
244
245   QWidget *page1 = new QWidget;
246   Ui::ConfigMisc_UI* confWdg = new Ui::ConfigMisc_UI( );
247   confWdg->setupUi(page1);
248
249   dialog->addPage( page1, i18n("Misc"), "misc" );
250
251   //User edited the configuration - update your local copies of the
252   //configuration data
253   connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateConfiguration()) );
254
255   dialog->show();
256 }
257
258 #include "mainwindow.moc"