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