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