]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
start of the clip tracks view
[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   projectListDock = new QDockWidget(i18n("Project Tree"), this);
39   projectListDock->setObjectName("project_tree");
40   m_projectList = new ProjectList(this);
41   projectListDock->setWidget(m_projectList);
42   addDockWidget(Qt::TopDockWidgetArea, projectListDock);
43
44   effectListDock = new QDockWidget(i18n("Effect List"), this);
45   effectListDock->setObjectName("effect_list");
46   effectList = new KListWidget(this);
47   effectListDock->setWidget(effectList);
48   addDockWidget(Qt::TopDockWidgetArea, effectListDock);
49   
50   effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
51   effectStackDock->setObjectName("effect_stack");
52   effectStack = new KListWidget(this);
53   effectStackDock->setWidget(effectStack);
54   addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
55   
56   transitionConfigDock = new QDockWidget(i18n("Transition"), this);
57   transitionConfigDock->setObjectName("transition");
58   transitionConfig = new KListWidget(this);
59   transitionConfigDock->setWidget(transitionConfig);
60   addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
61
62   Mlt::Factory::init(NULL);
63
64   clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
65   clipMonitorDock->setObjectName("clip_monitor");
66   m_clipMonitor = new Monitor("clip", m_monitorManager, this);
67   clipMonitorDock->setWidget(m_clipMonitor);
68   addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
69   
70   projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
71   projectMonitorDock->setObjectName("project_monitor");
72   m_projectMonitor = new Monitor("project", m_monitorManager, this);
73   projectMonitorDock->setWidget(m_projectMonitor);
74   addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
75
76   setupActions();
77   tabifyDockWidget (projectListDock, effectListDock);
78   tabifyDockWidget (projectListDock, effectStackDock);
79   tabifyDockWidget (projectListDock, transitionConfigDock);
80   projectListDock->raise();
81
82   tabifyDockWidget (clipMonitorDock, projectMonitorDock);
83
84   connect(projectMonitorDock, SIGNAL(visibilityChanged (bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
85   connect(clipMonitorDock, SIGNAL(visibilityChanged (bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
86   connect(m_monitorManager, SIGNAL(connectMonitors ()), this, SLOT(slotConnectMonitors()));
87   connect(m_monitorManager, SIGNAL(raiseClipMonitor (bool)), this, SLOT(slotRaiseMonitor(bool)));
88   m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
89
90   newFile();
91 }
92
93
94 void MainWindow::slotRaiseMonitor(bool clipMonitor)
95 {
96   if (clipMonitor) clipMonitorDock->raise();
97   else projectMonitorDock->raise();
98 }
99
100 void MainWindow::slotConnectMonitors()
101 {
102
103   m_projectList->setRenderer(m_clipMonitor->render);
104
105   connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
106
107   connect(m_projectList, SIGNAL(getFileProperties(const KUrl &, uint)), m_clipMonitor->render, SLOT(getFileProperties(const KUrl &, uint)));
108
109   connect(m_clipMonitor->render, SIGNAL(replyGetImage(const KUrl &, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(const KUrl &, int, const QPixmap &, int, int)));
110
111   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 > &)));
112
113 }
114
115 void MainWindow::setupActions()
116 {
117   KAction* clearAction = new KAction(this);
118   clearAction->setText(i18n("Clear"));
119   clearAction->setIcon(KIcon("document-new"));
120   clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
121   actionCollection()->addAction("clear", clearAction);
122   /*connect(clearAction, SIGNAL(triggered(bool)),
123           textArea, SLOT(clear()));*/
124  
125   KStandardAction::quit(kapp, SLOT(quit()),
126                         actionCollection());
127  
128   KStandardAction::open(this, SLOT(openFile()),
129                         actionCollection());
130  
131   KStandardAction::save(this, SLOT(saveFile()),
132                         actionCollection());
133  
134   KStandardAction::saveAs(this, SLOT(saveFileAs()),
135                         actionCollection());
136  
137   KStandardAction::openNew(this, SLOT(newFile()),
138                         actionCollection());
139
140   KStandardAction::openNew(this, SLOT(newFile()),
141                         actionCollection());
142
143   KStandardAction::preferences(this, SLOT(slotPreferences()),
144             actionCollection());
145  
146   setupGUI();
147 }
148  
149 void MainWindow::newFile()
150 {
151   KdenliveDoc *doc = new KdenliveDoc(KUrl(), 25, 720, 576);
152   TrackView *trackView = new TrackView(doc);
153   m_timelineArea->addTab(trackView, "New Project");
154   if (m_timelineArea->count() == 1)
155     connectDocument(trackView, doc);
156 }
157
158 void MainWindow::activateDocument()
159 {
160   TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
161   KdenliveDoc *currentDoc = currentTab->document();
162   connectDocument(currentTab, currentDoc);
163 }
164  
165 void MainWindow::saveFileAs(const QString &outputFileName)
166 {
167   KSaveFile file(outputFileName);
168   file.open();
169   
170   QByteArray outputByteArray;
171   //outputByteArray.append(textArea->toPlainText());
172   file.write(outputByteArray);
173   file.finalize();
174   file.close();
175   
176   fileName = outputFileName;
177 }
178  
179 void MainWindow::saveFileAs()
180 {
181   saveFileAs(KFileDialog::getSaveFileName());
182 }
183  
184 void MainWindow::saveFile()
185 {
186   if(!fileName.isEmpty())
187   {
188     saveFileAs(fileName);
189   }
190   else
191   {
192     saveFileAs();
193   }
194 }
195  
196 void MainWindow::openFile() //changed
197 {
198   openFile(KFileDialog::getOpenFileName(KUrl(), "application/vnd.kde.kdenlive"));
199 }
200  
201 void MainWindow::openFile(const QString &inputFileName) //new
202 {
203   KdenliveDoc *doc = new KdenliveDoc(KUrl(inputFileName), 25, 720, 576);
204   TrackView *trackView = new TrackView(doc);
205   m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, QIcon(), doc->documentName()));
206   connectDocument(trackView, doc);
207   
208 }
209
210 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //changed
211 {
212   //m_projectMonitor->stop();
213   if (m_activeDocument) {
214     m_activeDocument->setProducers(m_projectList->producersList());
215     m_activeDocument->setRenderer(NULL);
216   }
217   m_projectList->setDocument(doc);
218   m_monitorManager->setTimecode(doc->timecode());
219   doc->setRenderer(m_projectMonitor->render);
220   m_activeDocument = doc;
221 }
222
223
224 void MainWindow::slotPreferences()
225 {
226   //An instance of your dialog could be already created and could be
227   // cached, in which case you want to display the cached dialog
228   // instead of creating another one
229   if ( KConfigDialog::showDialog( "settings" ) )
230     return;
231
232   // KConfigDialog didn't find an instance of this dialog, so lets
233   // create it :
234   KConfigDialog* dialog = new KConfigDialog(this, "settings",
235                                           KdenliveSettings::self());
236
237   QWidget *page1 = new QWidget;
238   Ui::ConfigMisc_UI* confWdg = new Ui::ConfigMisc_UI( );
239   confWdg->setupUi(page1);
240
241   dialog->addPage( page1, i18n("Misc"), "misc" );
242
243   //User edited the configuration - update your local copies of the
244   //configuration data
245   connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateConfiguration()) );
246
247   dialog->show();
248 }
249
250 #include "mainwindow.moc"