]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
3d5c8e3acee573157ec8c805ea249b9671f6d884
[kdenlive] / src / mainwindow.cpp
1
2  
3 #include <KApplication>
4 #include <KAction>
5 #include <KLocale>
6 #include <KActionCollection>
7 #include <KStandardAction>
8 #include <KFileDialog>
9 #include <KMessageBox>
10 #include <KDebug>
11 #include <KIO/NetAccess>
12 #include <KSaveFile>
13 #include <KRuler>
14 #include <QTextStream>
15
16 #include <mlt++/Mlt.h>
17
18 #include "mainwindow.h"
19 #include "trackview.h"
20  
21 MainWindow::MainWindow(QWidget *parent)
22     : KXmlGuiWindow(parent),
23       fileName(QString())
24 {
25   m_timelineArea = new KTabWidget(this);
26   m_timelineArea->setHoverCloseButton(true);
27   m_timelineArea->setTabReorderingEnabled(true);
28   connect(m_timelineArea, SIGNAL(currentChanged (int)), this, SLOT(activateDocument()));
29   setCentralWidget(m_timelineArea);
30
31   projectListDock = new QDockWidget(i18n("Project Tree"), this);
32   m_projectList = new ProjectList(NULL, this);
33   projectListDock->setWidget(m_projectList);
34   addDockWidget(Qt::TopDockWidgetArea, projectListDock);
35
36   effectListDock = new QDockWidget(i18n("Effect List"), this);
37   effectList = new KListWidget(this);
38   effectListDock->setWidget(effectList);
39   addDockWidget(Qt::TopDockWidgetArea, effectListDock);
40   
41   effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
42   effectStack = new KListWidget(this);
43   effectStackDock->setWidget(effectStack);
44   addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
45   
46   transitionConfigDock = new QDockWidget(i18n("Transition"), this);
47   transitionConfig = new KListWidget(this);
48   transitionConfigDock->setWidget(transitionConfig);
49   addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
50
51   Mlt::Factory::init(NULL);
52
53   clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
54   m_clipMonitor = new Monitor("clip", this);
55   clipMonitorDock->setWidget(m_clipMonitor);
56   addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
57
58   projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
59   m_projectMonitor = new Monitor("project", this);
60   projectMonitorDock->setWidget(m_projectMonitor);
61   addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
62
63   setupActions();
64   tabifyDockWidget (effectListDock, projectListDock);
65   tabifyDockWidget (effectListDock, effectStackDock);
66   tabifyDockWidget (effectListDock, transitionConfigDock);
67
68   tabifyDockWidget (clipMonitorDock, projectMonitorDock);
69
70   connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_projectMonitor, SLOT(slotSetXml(const QDomElement &)));
71
72   connect(m_projectList, SIGNAL(getFileProperties(const KUrl &, uint)), m_projectMonitor->render, SLOT(getFileProperties(const KUrl &, uint)));
73
74   connect(m_projectMonitor->render, SIGNAL(replyGetImage(const KUrl &, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(const KUrl &, int, const QPixmap &, int, int)));
75
76   connect(m_projectMonitor->render, SIGNAL(replyGetFileProperties(const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(const QMap < QString, QString > &, const QMap < QString, QString > &)));
77
78 }
79  
80 void MainWindow::setupActions()
81 {
82   KAction* clearAction = new KAction(this);
83   clearAction->setText(i18n("Clear"));
84   clearAction->setIcon(KIcon("document-new"));
85   clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
86   actionCollection()->addAction("clear", clearAction);
87   /*connect(clearAction, SIGNAL(triggered(bool)),
88           textArea, SLOT(clear()));*/
89  
90   KStandardAction::quit(kapp, SLOT(quit()),
91                         actionCollection());
92  
93   KStandardAction::open(this, SLOT(openFile()),
94                         actionCollection());
95  
96   KStandardAction::save(this, SLOT(saveFile()),
97                         actionCollection());
98  
99   KStandardAction::saveAs(this, SLOT(saveFileAs()),
100                         actionCollection());
101  
102   KStandardAction::openNew(this, SLOT(newFile()),
103                         actionCollection());
104  
105   setupGUI();
106 }
107  
108 void MainWindow::newFile()
109 {
110   KdenliveDoc *doc = new KdenliveDoc(KUrl(), 25, 720, 576);
111   TrackView *trackView = new TrackView(doc);
112   m_timelineArea->addTab(trackView, "New Project");
113 }
114
115 void MainWindow::activateDocument()
116 {
117   TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
118   KdenliveDoc *currentDoc = currentTab->document();
119   connectDocument(currentDoc);
120 }
121  
122 void MainWindow::saveFileAs(const QString &outputFileName)
123 {
124   KSaveFile file(outputFileName);
125   file.open();
126   
127   QByteArray outputByteArray;
128   //outputByteArray.append(textArea->toPlainText());
129   file.write(outputByteArray);
130   file.finalize();
131   file.close();
132   
133   fileName = outputFileName;
134 }
135  
136 void MainWindow::saveFileAs()
137 {
138   saveFileAs(KFileDialog::getSaveFileName());
139 }
140  
141 void MainWindow::saveFile()
142 {
143   if(!fileName.isEmpty())
144   {
145     saveFileAs(fileName);
146   }
147   else
148   {
149     saveFileAs();
150   }
151 }
152  
153 void MainWindow::openFile() //changed
154 {
155   openFile(KFileDialog::getOpenFileName(KUrl(), "application/vnd.kde.kdenlive"));
156 }
157  
158 void MainWindow::openFile(const QString &inputFileName) //new
159 {
160   KdenliveDoc *doc = new KdenliveDoc(KUrl(inputFileName), 25, 720, 576);
161   TrackView *trackView = new TrackView(doc);
162   m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, QIcon(), doc->documentName()));
163   connectDocument(doc);
164   
165 }
166
167 void MainWindow::connectDocument(KdenliveDoc *doc) //changed
168 {
169   m_projectList->populate(doc->producersList());
170   //connect(doc, SIGNAL(addClip(QDomElement &)), m_projectList, SLOT(slotAddClip(QDomElement &)));
171 }
172
173 #include "mainwindow.moc"