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