]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
Fix project view thumbnails
[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 QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
110
111   //connect(m_projectList, SIGNAL(getFileProperties(const KUrl &, uint)), m_clipMonitor->render, SLOT(getFileProperties(const KUrl &, uint)));
112
113   connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
114
115   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 > &)));
116
117 }
118
119 void MainWindow::setupActions()
120 {
121   KAction* clearAction = new KAction(this);
122   clearAction->setText(i18n("Clear"));
123   clearAction->setIcon(KIcon("document-new"));
124   clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
125   actionCollection()->addAction("clear", clearAction);
126   /*connect(clearAction, SIGNAL(triggered(bool)),
127           textArea, SLOT(clear()));*/
128  
129   KStandardAction::quit(kapp, SLOT(quit()),
130                         actionCollection());
131  
132   KStandardAction::open(this, SLOT(openFile()),
133                         actionCollection());
134  
135   KStandardAction::save(this, SLOT(saveFile()),
136                         actionCollection());
137  
138   KStandardAction::saveAs(this, SLOT(saveFileAs()),
139                         actionCollection());
140  
141   KStandardAction::openNew(this, SLOT(newFile()),
142                         actionCollection());
143
144   /*KStandardAction::undo(this, SLOT(undo()),
145                         actionCollection());
146
147   KStandardAction::redo(this, SLOT(redo()),
148                         actionCollection());*/
149
150   KStandardAction::preferences(this, SLOT(slotPreferences()),
151             actionCollection());
152
153   QAction * redo = m_commandStack->createRedoAction(actionCollection());
154   QAction * undo = m_commandStack->createUndoAction(actionCollection());
155
156   setupGUI();
157 }
158  
159 void MainWindow::newFile()
160 {
161   KdenliveDoc *doc = new KdenliveDoc(KUrl(), 25, 720, 576);
162   TrackView *trackView = new TrackView(doc);
163   m_timelineArea->addTab(trackView, "New Project");
164   if (m_timelineArea->count() == 1)
165     connectDocument(trackView, doc);
166 }
167
168 void MainWindow::activateDocument()
169 {
170   TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
171   KdenliveDoc *currentDoc = currentTab->document();
172   connectDocument(currentTab, currentDoc);
173 }
174  
175 void MainWindow::saveFileAs(const QString &outputFileName)
176 {
177   KSaveFile file(outputFileName);
178   file.open();
179   
180   QByteArray outputByteArray;
181   //outputByteArray.append(textArea->toPlainText());
182   file.write(outputByteArray);
183   file.finalize();
184   file.close();
185   
186   fileName = outputFileName;
187 }
188
189 void MainWindow::saveFileAs()
190 {
191   saveFileAs(KFileDialog::getSaveFileName());
192 }
193  
194 void MainWindow::saveFile()
195 {
196   if(!fileName.isEmpty())
197   {
198     saveFileAs(fileName);
199   }
200   else
201   {
202     saveFileAs();
203   }
204 }
205  
206 void MainWindow::openFile() //changed
207 {
208   openFile(KFileDialog::getOpenFileName(KUrl(), "application/vnd.kde.kdenlive"));
209 }
210  
211 void MainWindow::openFile(const QString &inputFileName) //new
212 {
213   KdenliveDoc *doc = new KdenliveDoc(KUrl(inputFileName), 25, 720, 576);
214   TrackView *trackView = new TrackView(doc);
215   m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, QIcon(), doc->documentName()));
216   connectDocument(trackView, doc);
217   
218 }
219
220 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //changed
221 {
222   //m_projectMonitor->stop();
223   if (m_activeDocument) {
224     m_activeDocument->setProducers(m_projectList->producersList());
225     m_activeDocument->setRenderer(NULL);
226   }
227   m_projectList->setDocument(doc);
228   m_monitorManager->setTimecode(doc->timecode());
229   doc->setRenderer(m_projectMonitor->render);
230   m_activeDocument = doc;
231 }
232
233
234 void MainWindow::slotPreferences()
235 {
236   //An instance of your dialog could be already created and could be
237   // cached, in which case you want to display the cached dialog
238   // instead of creating another one
239   if ( KConfigDialog::showDialog( "settings" ) )
240     return;
241
242   // KConfigDialog didn't find an instance of this dialog, so lets
243   // create it :
244   KConfigDialog* dialog = new KConfigDialog(this, "settings",
245                                           KdenliveSettings::self());
246
247   QWidget *page1 = new QWidget;
248   Ui::ConfigMisc_UI* confWdg = new Ui::ConfigMisc_UI( );
249   confWdg->setupUi(page1);
250
251   dialog->addPage( page1, i18n("Misc"), "misc" );
252
253   //User edited the configuration - update your local copies of the
254   //configuration data
255   connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateConfiguration()) );
256
257   dialog->show();
258 }
259
260 #include "mainwindow.moc"