]> git.sesse.net Git - kdenlive/blob - src/trackview.cpp
41ea52094802dfffa506b171a54323781aeadc99
[kdenlive] / src / trackview.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21 #include "trackview.h"
22 #include "headertrack.h"
23 #include "clipitem.h"
24 #include "transition.h"
25 #include "kdenlivesettings.h"
26 #include "clipmanager.h"
27 #include "customruler.h"
28 #include "kdenlivedoc.h"
29 #include "mainwindow.h"
30 #include "customtrackview.h"
31 #include "initeffects.h"
32 #include "profilesdialog.h"
33 #include "configtrackscommand.h"
34
35 #include <KDebug>
36 #include <KMessageBox>
37 #include <KIO/NetAccess>
38
39 #include <QScrollBar>
40 #include <QInputDialog>
41
42 TrackView::TrackView(KdenliveDoc *doc, bool *ok, QWidget *parent) :
43     QWidget(parent),
44     m_scale(1.0),
45     m_projectTracks(0),
46     m_doc(doc),
47     m_verticalZoom(1)
48 {
49
50     setupUi(this);
51 //    ruler_frame->setMaximumHeight();
52 //    size_frame->setMaximumHeight();
53     m_scene = new CustomTrackScene(doc);
54     m_trackview = new CustomTrackView(doc, m_scene, parent);
55     m_trackview->scale(1, 1);
56     m_trackview->setAlignment(Qt::AlignLeft | Qt::AlignTop);
57
58     m_ruler = new CustomRuler(doc->timecode(), m_trackview);
59     connect(m_ruler, SIGNAL(zoneMoved(int, int)), this, SIGNAL(zoneMoved(int, int)));
60     connect(m_ruler, SIGNAL(adjustZoom(int)), this, SIGNAL(setZoom(int)));
61     QHBoxLayout *layout = new QHBoxLayout;
62     layout->setContentsMargins(m_trackview->frameWidth(), 0, 0, 0);
63     layout->setSpacing(0);
64     ruler_frame->setLayout(layout);
65     layout->addWidget(m_ruler);
66
67     QHBoxLayout *sizeLayout = new QHBoxLayout;
68     sizeLayout->setContentsMargins(0, 0, 0, 0);
69     sizeLayout->setSpacing(0);
70     size_frame->setLayout(sizeLayout);
71
72     QToolButton *butSmall = new QToolButton(this);
73     butSmall->setIcon(KIcon("kdenlive-zoom-small"));
74     butSmall->setToolTip(i18n("Smaller tracks"));
75     butSmall->setAutoRaise(true);
76     connect(butSmall, SIGNAL(clicked()), this, SLOT(slotVerticalZoomDown()));
77     sizeLayout->addWidget(butSmall);
78
79     QToolButton *butLarge = new QToolButton(this);
80     butLarge->setIcon(KIcon("kdenlive-zoom-large"));
81     butLarge->setToolTip(i18n("Bigger tracks"));
82     butLarge->setAutoRaise(true);
83     connect(butLarge, SIGNAL(clicked()), this, SLOT(slotVerticalZoomUp()));
84     sizeLayout->addWidget(butLarge);
85
86     QHBoxLayout *tracksLayout = new QHBoxLayout;
87     tracksLayout->setContentsMargins(0, 0, 0, 0);
88     tracksLayout->setSpacing(0);
89     tracks_frame->setLayout(tracksLayout);
90
91     headers_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
92     headers_area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
93     headers_area->setFixedWidth(70);
94
95     QVBoxLayout *headersLayout = new QVBoxLayout;
96     headersLayout->setContentsMargins(0, m_trackview->frameWidth(), 0, 0);
97     headersLayout->setSpacing(0);
98     headers_container->setLayout(headersLayout);
99     connect(headers_area->verticalScrollBar(), SIGNAL(valueChanged(int)), m_trackview->verticalScrollBar(), SLOT(setValue(int)));
100
101     tracksLayout->addWidget(m_trackview);
102     connect(m_trackview->verticalScrollBar(), SIGNAL(valueChanged(int)), headers_area->verticalScrollBar(), SLOT(setValue(int)));
103     connect(m_trackview, SIGNAL(trackHeightChanged()), this, SLOT(slotRebuildTrackHeaders()));
104     connect(m_trackview, SIGNAL(tracksChanged()), this, SLOT(slotReloadTracks()));
105     connect(m_trackview, SIGNAL(updateTrackHeaders()), this, SLOT(slotRepaintTracks()));
106     connect(m_trackview, SIGNAL(showTrackEffects(int, TrackInfo)), this, SIGNAL(showTrackEffects(int, TrackInfo)));
107     connect(m_trackview, SIGNAL(updateTrackEffectState(int)), this, SLOT(slotUpdateTrackEffectState(int)));
108
109
110     parseDocument(m_doc->toXml());
111     if (m_doc->setSceneList() == -1) *ok = false;
112     else *ok = true;
113     connect(m_trackview, SIGNAL(cursorMoved(int, int)), m_ruler, SLOT(slotCursorMoved(int, int)));
114     connect(m_trackview->horizontalScrollBar(), SIGNAL(valueChanged(int)), m_ruler, SLOT(slotMoveRuler(int)));
115     connect(m_trackview->horizontalScrollBar(), SIGNAL(rangeChanged(int, int)), this, SLOT(slotUpdateVerticalScroll(int, int)));
116     connect(m_trackview, SIGNAL(mousePosition(int)), this, SIGNAL(mousePosition(int)));
117     connect(m_trackview, SIGNAL(doTrackLock(int, bool)), this, SLOT(slotChangeTrackLock(int, bool)));
118
119     slotChangeZoom(m_doc->zoom().x(), m_doc->zoom().y());
120     slotSetZone(m_doc->zone(), false);
121 }
122
123 TrackView::~TrackView()
124 {
125     delete m_ruler;
126     delete m_trackview;
127 }
128
129 //virtual
130 void TrackView::keyPressEvent(QKeyEvent * event)
131 {
132     if (event->key() == Qt::Key_Up) {
133         m_trackview->slotTrackUp();
134         event->accept();
135     } else if (event->key() == Qt::Key_Down) {
136         m_trackview->slotTrackDown();
137         event->accept();
138     } else QWidget::keyPressEvent(event);
139 }
140
141 int TrackView::duration() const
142 {
143     return m_trackview->duration();
144 }
145
146 int TrackView::tracksNumber() const
147 {
148     return m_projectTracks - 1;
149 }
150
151 bool TrackView::checkProjectAudio() const
152 {
153     bool hasAudio = false;
154     const QList <TrackInfo> list = m_doc->tracksList();
155     int max = list.count();
156     for (int i = 0; i < max; i++) {
157         TrackInfo info = list.at(max - i - 1);
158         if (!info.isMute && m_trackview->hasAudio(i)) {
159             hasAudio = true;
160             break;
161         }
162     }
163     return hasAudio;
164 }
165
166 int TrackView::inPoint() const
167 {
168     return m_ruler->inPoint();
169 }
170
171 int TrackView::outPoint() const
172 {
173     return m_ruler->outPoint();
174 }
175
176 void TrackView::slotSetZone(QPoint p, bool updateDocumentProperties)
177 {
178     m_ruler->setZone(p);
179     if (updateDocumentProperties) m_doc->setZone(p.x(), p.y());
180 }
181
182 void TrackView::setDuration(int dur)
183 {
184     m_trackview->setDuration(dur);
185     m_ruler->setDuration(dur);
186 }
187
188 void TrackView::parseDocument(QDomDocument doc)
189 {
190     //int cursorPos = 0;
191     m_documentErrors.clear();
192     m_replacementProducerIds.clear();
193
194     //kDebug() << "//// DOCUMENT: " << doc.toString();
195     /*QDomNode props = doc.elementsByTagName("properties").item(0);
196     if (!props.isNull()) {
197         cursorPos = props.toElement().attribute("timeline_position").toInt();
198     }*/
199
200     // parse project tracks
201     QDomElement mlt = doc.firstChildElement("mlt");
202     QDomElement tractor = mlt.firstChildElement("tractor");
203     QDomNodeList tracks = tractor.elementsByTagName("track");
204     QDomNodeList playlists = doc.elementsByTagName("playlist");
205     int duration = 300;
206     m_projectTracks = tracks.count();
207     int trackduration = 0;
208     QDomElement e;
209     QDomElement p;
210
211     int pos = m_projectTracks - 1;
212     m_invalidProducers.clear();
213     QDomNodeList producers = doc.elementsByTagName("producer");
214     for (int i = 0; i < producers.count(); i++) {
215         // Check for invalid producers
216         QDomNode n = producers.item(i);
217         e = n.toElement();
218
219         /*
220         // Check for invalid markup
221         QDomNodeList params = e.elementsByTagName("property");
222         for (int j = 0; j < params.count(); j++) {
223             QDomElement p = params.item(j).toElement();
224             if (p.attribute("name") == "markup") {
225          QString val = p.text().toUtf8().data();
226          kDebug()<<"//FOUND MARKUP, VAL: "<<val;
227          //e.setAttribute("value", value);
228          n.removeChild(params.item(j));
229          break;
230             }
231         }
232         */
233
234         if (e.hasAttribute("in") == false && e.hasAttribute("out") == false) continue;
235         int in = e.attribute("in").toInt();
236         int out = e.attribute("out").toInt();
237         if (in >= out) {
238             // invalid producer, remove it
239             QString id = e.attribute("id");
240             m_invalidProducers.append(id);
241             m_documentErrors.append(i18n("Invalid clip producer %1\n", id));
242             doc.documentElement().removeChild(producers.at(i));
243             i--;
244         }
245     }
246
247     int trackIndex = 0;
248     for (int i = 0; i < m_projectTracks; i++) {
249         e = tracks.item(i).toElement();
250         QString playlist_name = e.attribute("producer");
251         if (playlist_name != "black_track" && playlist_name != "playlistmain") {
252             // find playlist related to this track
253             p = QDomElement();
254             for (int j = 0; j < m_projectTracks; j++) {
255                 p = playlists.item(j).toElement();
256                 if (p.attribute("id") == playlist_name) {
257                     // playlist found, check track effects
258                     QDomNodeList trackEffects = p.childNodes();
259                     slotAddProjectEffects(trackEffects, p, NULL, trackIndex++);
260                     break;
261                 }
262             }
263             if (p.attribute("id") != playlist_name) { // then it didn't work.
264                 kDebug() << "NO PLAYLIST FOUND FOR TRACK " + pos;
265             }
266             if (e.attribute("hide") == "video") {
267                 m_doc->switchTrackVideo(i - 1, true);
268             } else if (e.attribute("hide") == "audio") {
269                 m_doc->switchTrackAudio(i - 1, true);
270             } else if (e.attribute("hide") == "both") {
271                 m_doc->switchTrackVideo(i - 1, true);
272                 m_doc->switchTrackAudio(i - 1, true);
273             }
274
275             trackduration = slotAddProjectTrack(pos, p, m_doc->isTrackLocked(i - 1), producers);
276             pos--;
277             //kDebug() << " PRO DUR: " << trackduration << ", TRACK DUR: " << duration;
278             if (trackduration > duration) duration = trackduration;
279         } else {
280             // background black track
281             for (int j = 0; j < m_projectTracks; j++) {
282                 p = playlists.item(j).toElement();
283                 if (p.attribute("id") == playlist_name) break;
284             }
285             pos--;
286         }
287     }
288
289     // parse transitions
290     QDomNodeList transitions = tractor.elementsByTagName("transition");
291
292     //kDebug() << "//////////// TIMELINE FOUND: " << projectTransitions << " transitions";
293     for (int i = 0; i < transitions.count(); i++) {
294         e = transitions.item(i).toElement();
295         QDomNodeList transitionparams = e.childNodes();
296         bool transitionAdd = true;
297         int a_track = 0;
298         int b_track = 0;
299         bool isAutomatic = false;
300         bool forceTrack = false;
301         QString mlt_geometry;
302         QString mlt_service;
303         QString transitionId;
304         for (int k = 0; k < transitionparams.count(); k++) {
305             p = transitionparams.item(k).toElement();
306             if (!p.isNull()) {
307                 QString paramName = p.attribute("name");
308                 // do not add audio mixing transitions
309                 if (paramName == "internal_added" && p.text() == "237") {
310                     transitionAdd = false;
311                     //kDebug() << "//  TRANSITRION " << i << " IS NOT VALID (INTERN ADDED)";
312                     //break;
313                 } else if (paramName == "a_track") {
314                     a_track = qMax(0, p.text().toInt());
315                     a_track = qMin(m_projectTracks - 1, a_track);
316                     if (a_track != p.text().toInt()) {
317                         // the transition track was out of bounds
318                         m_documentErrors.append(i18n("Transition %1 had an invalid track: %2 > %3", e.attribute("id"), p.text().toInt(), a_track) + '\n');
319                         EffectsList::setProperty(e, "a_track", QString::number(a_track));
320                     }
321                 } else if (paramName == "b_track") {
322                     b_track = qMax(0, p.text().toInt());
323                     b_track = qMin(m_projectTracks - 1, b_track);
324                     if (b_track != p.text().toInt()) {
325                         // the transition track was out of bounds
326                         m_documentErrors.append(i18n("Transition %1 had an invalid track: %2 > %3", e.attribute("id"), p.text().toInt(), b_track) + '\n');
327                         EffectsList::setProperty(e, "b_track", QString::number(b_track));
328                     }
329                 } else if (paramName == "mlt_service") mlt_service = p.text();
330                 else if (paramName == "kdenlive_id") transitionId = p.text();
331                 else if (paramName == "geometry") mlt_geometry = p.text();
332                 else if (paramName == "automatic" && p.text() == "1") isAutomatic = true;
333                 else if (paramName == "force_track" && p.text() == "1") forceTrack = true;
334             }
335         }
336         if (a_track == b_track || b_track == 0) {
337             // invalid transition, remove it
338             m_documentErrors.append(i18n("Removed invalid transition: %1", e.attribute("id")) + '\n');
339             tractor.removeChild(transitions.item(i));
340             i--;
341             continue;
342         }
343         if (transitionAdd || mlt_service != "mix") {
344             // Transition should be added to the scene
345             ItemInfo transitionInfo;
346             if (mlt_service == "composite" && transitionId.isEmpty()) {
347                 // When adding composite transition, check if it is a wipe transition
348                 if (mlt_geometry.count(';') == 1) {
349                     mlt_geometry.remove(QChar('%'), Qt::CaseInsensitive);
350                     mlt_geometry.replace(QChar('x'), QChar(','), Qt::CaseInsensitive);
351                     QString start = mlt_geometry.section(';', 0, 0);
352                     start = start.section(':', 0, 1);
353                     start.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
354                     QString end = mlt_geometry.section('=', 1, 1);
355                     end = end.section(':', 0, 1);
356                     end.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
357                     start.append(',' + end);
358                     QStringList numbers = start.split(',', QString::SkipEmptyParts);
359                     bool isWipeTransition = true;
360                     int checkNumber;
361                     for (int i = 0; i < numbers.size(); ++i) {
362                         checkNumber = qAbs(numbers.at(i).toInt());
363                         if (checkNumber != 0 && checkNumber != 100) {
364                             isWipeTransition = false;
365                             break;
366                         }
367                     }
368                     if (isWipeTransition) transitionId = "slide";
369                 }
370             }
371
372             QDomElement base = MainWindow::transitions.getEffectByTag(mlt_service, transitionId).cloneNode().toElement();
373
374             if (!base.isNull()) for (int k = 0; k < transitionparams.count(); k++) {
375                     p = transitionparams.item(k).toElement();
376                     if (!p.isNull()) {
377                         QString paramName = p.attribute("name");
378                         QString paramValue = p.text();
379
380                         QDomNodeList params = base.elementsByTagName("parameter");
381                         if (paramName != "a_track" && paramName != "b_track") for (int i = 0; i < params.count(); i++) {
382                                 QDomElement e = params.item(i).toElement();
383                                 if (!e.isNull() && e.attribute("tag") == paramName) {
384                                     if (e.attribute("type") == "double") {
385                                         QString factor = e.attribute("factor", "1");
386                                         if (factor != "1") {
387                                             double fact;
388                                             if (factor.contains('%')) {
389                                                 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
390                                             } else fact = factor.toDouble();
391                                             double val = paramValue.toDouble() * fact;
392                                             paramValue = QString::number(val);
393                                         }
394                                     }
395                                     e.setAttribute("value", paramValue);
396                                     break;
397                                 }
398                             }
399                     }
400                 }
401
402             /*QDomDocument doc;
403             doc.appendChild(doc.importNode(base, true));
404             kDebug() << "///////  TRANSITION XML: "<< doc.toString();*/
405
406             transitionInfo.startPos = GenTime(e.attribute("in").toInt(), m_doc->fps());
407             transitionInfo.endPos = GenTime(e.attribute("out").toInt() + 1, m_doc->fps());
408             transitionInfo.track = m_projectTracks - 1 - b_track;
409
410             //kDebug() << "///////////////   +++++++++++  ADDING TRANSITION ON TRACK: " << b_track << ", TOTAL TRKA: " << m_projectTracks;
411             if (transitionInfo.startPos >= transitionInfo.endPos || base.isNull()) {
412                 // invalid transition, remove it.
413                 m_documentErrors.append(i18n("Removed invalid transition: (%1, %2, %3)", e.attribute("id"), mlt_service, transitionId) + '\n');
414                 kDebug() << "///// REMOVED INVALID TRANSITION: " << e.attribute("id");
415                 tractor.removeChild(transitions.item(i));
416                 i--;
417             } else if (m_trackview->canBePastedTo(transitionInfo, TRANSITIONWIDGET)) {
418                 Transition *tr = new Transition(transitionInfo, a_track, m_doc->fps(), base, isAutomatic);
419                 if (forceTrack) tr->setForcedTrack(true, a_track);
420                 m_scene->addItem(tr);
421                 if (b_track > 0 && m_doc->isTrackLocked(b_track - 1)) {
422                     tr->setItemLocked(true);
423                 }
424             }
425             else {
426                 m_documentErrors.append(i18n("Removed overlapping transition: (%1, %2, %3)", e.attribute("id"), mlt_service, transitionId) + '\n');
427                 tractor.removeChild(transitions.item(i));
428                 i--;
429             }
430         }
431     }
432
433
434     QDomElement infoXml = mlt.firstChildElement("kdenlivedoc");
435
436     // Add guides
437     QDomNodeList guides = infoXml.elementsByTagName("guide");
438     for (int i = 0; i < guides.count(); i++) {
439         e = guides.item(i).toElement();
440         const QString comment = e.attribute("comment");
441         const GenTime pos = GenTime(e.attribute("time").toDouble());
442         m_trackview->addGuide(pos, comment);
443     }
444
445     // Rebuild groups
446     QDomNodeList groups = infoXml.elementsByTagName("group");
447     m_trackview->loadGroups(groups);
448     m_trackview->setDuration(duration);
449     kDebug() << "///////////  TOTAL PROJECT DURATION: " << duration;
450
451     // Remove Kdenlive extra info from xml doc before sending it to MLT
452     mlt.removeChild(infoXml);
453
454     slotRebuildTrackHeaders();
455     if (!m_documentErrors.isNull()) KMessageBox::sorry(this, m_documentErrors);
456     if (infoXml.hasAttribute("upgraded") || infoXml.hasAttribute("modified")) {
457         // Our document was upgraded, create a backup copy just in case
458         QString baseFile = m_doc->url().path().section(".kdenlive", 0, 0);
459         int ct = 0;
460         QString backupFile = baseFile + "_backup" + QString::number(ct) + ".kdenlive";
461         while (QFile::exists(backupFile)) {
462             ct++;
463             backupFile = baseFile + "_backup" + QString::number(ct) + ".kdenlive";
464         }
465         QString message;
466         if (infoXml.hasAttribute("upgraded"))
467             message = i18n("Your project file was upgraded to the latest Kdenlive document version.\nTo make sure you don't lose data, a backup copy called %1 was created.", backupFile);
468         else
469             message = i18n("Your project file was modified by Kdenlive.\nTo make sure you don't lose data, a backup copy called %1 was created.", backupFile);
470         if (KIO::NetAccess::file_copy(m_doc->url(), KUrl(backupFile), this))
471             KMessageBox::information(this, message);
472         else
473             KMessageBox::information(this, i18n("Your project file was upgraded to the latest Kdenlive document version, but it was not possible to create a backup copy.", backupFile));
474     }
475     //m_trackview->setCursorPos(cursorPos);
476     //m_scrollBox->setGeometry(0, 0, 300 * zoomFactor(), m_scrollArea->height());
477 }
478
479 void TrackView::slotDeleteClip(const QString &clipId)
480 {
481     m_trackview->deleteClip(clipId);
482 }
483
484 void TrackView::setCursorPos(int pos)
485 {
486     m_trackview->setCursorPos(pos);
487 }
488
489 void TrackView::moveCursorPos(int pos)
490 {
491     m_trackview->setCursorPos(pos, false);
492 }
493
494 void TrackView::slotChangeZoom(int horizontal, int vertical)
495 {
496     m_ruler->setPixelPerMark(horizontal);
497     m_scale = (double) FRAME_SIZE / m_ruler->comboScale[horizontal];
498
499     if (vertical == -1) {
500         // user called zoom
501         m_doc->setZoom(horizontal, m_verticalZoom);
502         m_trackview->setScale(m_scale, m_scene->scale().y());
503     } else {
504         m_verticalZoom = vertical;
505         if (m_verticalZoom == 0)
506             m_trackview->setScale(m_scale, 0.5);
507         else
508             m_trackview->setScale(m_scale, m_verticalZoom);
509         adjustTrackHeaders();
510     }
511 }
512
513 int TrackView::fitZoom() const
514 {
515     int zoom = (int)((duration() + 20 / m_scale) * FRAME_SIZE / m_trackview->width());
516     int i;
517     for (i = 0; i < 13; i++)
518         if (m_ruler->comboScale[i] > zoom) break;
519     return i;
520 }
521
522 KdenliveDoc *TrackView::document()
523 {
524     return m_doc;
525 }
526
527 void TrackView::refresh()
528 {
529     m_trackview->viewport()->update();
530 }
531
532 void TrackView::slotRepaintTracks()
533 {
534     QList<HeaderTrack *> widgets = findChildren<HeaderTrack *>();
535     for (int i = 0; i < widgets.count(); i++) {
536         if (widgets.at(i)) widgets.at(i)->setSelectedIndex(m_trackview->selectedTrack());
537     }
538 }
539
540 void TrackView::slotReloadTracks()
541 {
542     slotRebuildTrackHeaders();
543     emit updateTracksInfo();
544 }
545
546 void TrackView::slotRebuildTrackHeaders()
547 {
548     const QList <TrackInfo> list = m_doc->tracksList();
549     QLayoutItem *child;
550     while ((child = headers_container->layout()->takeAt(0)) != 0) {
551         QWidget *wid = child->widget();
552         delete child;
553         if (wid) wid->deleteLater();
554     }
555     int max = list.count();
556     int height = KdenliveSettings::trackheight() * m_scene->scale().y() - 1;
557     HeaderTrack *header = NULL;
558     QFrame *frame = NULL;
559     for (int i = 0; i < max; i++) {
560         frame = new QFrame(headers_container);
561         frame->setFrameStyle(QFrame::HLine);
562         frame->setFixedHeight(1);
563         headers_container->layout()->addWidget(frame);
564         TrackInfo info = list.at(max - i - 1);
565         header = new HeaderTrack(i, info, height, headers_container);
566         header->setSelectedIndex(m_trackview->selectedTrack());
567         connect(header, SIGNAL(switchTrackVideo(int)), m_trackview, SLOT(slotSwitchTrackVideo(int)));
568         connect(header, SIGNAL(switchTrackAudio(int)), m_trackview, SLOT(slotSwitchTrackAudio(int)));
569         connect(header, SIGNAL(switchTrackLock(int)), m_trackview, SLOT(slotSwitchTrackLock(int)));
570         connect(header, SIGNAL(selectTrack(int)), m_trackview, SLOT(slotSelectTrack(int)));
571         connect(header, SIGNAL(deleteTrack(int)), this, SIGNAL(deleteTrack(int)));
572         connect(header, SIGNAL(insertTrack(int)), this, SIGNAL(insertTrack(int)));
573         connect(header, SIGNAL(renameTrack(int, QString)), this, SLOT(slotRenameTrack(int, QString)));
574         connect(header, SIGNAL(configTrack(int)), this, SIGNAL(configTrack(int)));
575         connect(header, SIGNAL(addTrackInfo(const QDomElement, int)), m_trackview, SLOT(slotAddTrackEffect(const QDomElement, int)));
576         connect(header, SIGNAL(showTrackEffects(int)), this, SLOT(slotShowTrackEffects(int)));
577         headers_container->layout()->addWidget(header);
578     }
579     frame = new QFrame(this);
580     frame->setFrameStyle(QFrame::HLine);
581     frame->setFixedHeight(1);
582     headers_container->layout()->addWidget(frame);
583 }
584
585
586 void TrackView::adjustTrackHeaders()
587 {
588     int height = KdenliveSettings::trackheight() * m_scene->scale().y() - 1;
589     QList<HeaderTrack *> widgets = findChildren<HeaderTrack *>();
590     for (int i = 0; i < widgets.count(); i++) {
591         if (widgets.at(i)) widgets.at(i)->adjustSize(height);
592     }
593 }
594
595 int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked, QDomNodeList producers)
596 {
597     // parse track
598     int position = 0;
599     QMap <QString, QString> producerReplacementIds;
600     QDomNodeList children = xml.childNodes();
601     for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) {
602         QDomNode n = children.item(nodeindex);
603         QDomElement elem = n.toElement();
604         if (elem.tagName() == "blank") {
605             position += elem.attribute("length").toInt();
606         } else if (elem.tagName() == "entry") {
607             // Found a clip
608             int in = elem.attribute("in").toInt();
609             int out = elem.attribute("out").toInt();
610             if (in > out || /*in == out ||*/ m_invalidProducers.contains(elem.attribute("producer"))) {
611                 m_documentErrors.append(i18n("Invalid clip removed from track %1 at %2\n", ix, position));
612                 xml.removeChild(children.at(nodeindex));
613                 nodeindex--;
614                 continue;
615             }
616             QString idString = elem.attribute("producer");
617             if (producerReplacementIds.contains(idString)) {
618                 // replace id
619                 elem.setAttribute("producer", producerReplacementIds.value(idString));
620                 idString = elem.attribute("producer");
621             }
622             QString id = idString;
623             double speed = 1.0;
624             int strobe = 1;
625             if (idString.startsWith("slowmotion")) {
626                 id = idString.section(':', 1, 1);
627                 speed = idString.section(':', 2, 2).toDouble();
628                 strobe = idString.section(':', 3, 3).toInt();
629                 if (strobe == 0) strobe = 1;
630             }
631             id = id.section('_', 0, 0);
632             DocClipBase *clip = m_doc->clipManager()->getClipById(id);
633             if (clip == NULL) {
634                 // The clip in playlist was not listed in the kdenlive producers,
635                 // something went wrong, repair required.
636                 kWarning() << "CANNOT INSERT CLIP " << id;
637                 QString docRoot = m_doc->toXml().documentElement().attribute("root");
638                 if (!docRoot.endsWith('/')) docRoot.append('/');
639                 clip = getMissingProducer(idString);
640                 if (clip) {
641                     // We found the original producer in Kdenlive's producers
642                     // Found correct producer
643                     m_documentErrors.append(i18n("Replaced wrong clip producer %1 with %2", id, clip->getId()) + '\n');
644                     QString prodId = clip->getId();
645                     if (clip->clipType() == PLAYLIST || clip->clipType() == AV || clip->clipType() == AUDIO) {
646                         // We need producer for the track
647                         prodId.append("_" + QString::number(ix));
648                     }
649                     elem.setAttribute("producer", prodId);
650                     producerReplacementIds.insert(idString, prodId);
651                     // now adjust the mlt producer
652                     bool found = false;
653                     for (int i = 0; i < producers.count(); i++) {
654                         QDomElement prod = producers.at(i).toElement();
655                         if (prod.attribute("id") == prodId) {
656                             // ok, producer already exists
657                             found = true;
658                             break;
659                         }
660                     }
661                     if (!found) {
662                         for (int i = 0; i < producers.count(); i++) {
663                             QDomElement prod = producers.at(i).toElement();
664                             if (prod.attribute("id") == idString) {
665                                 prod.setAttribute("id", prodId);
666                                 m_replacementProducerIds.insert(idString, prodId);
667                                 found = true;
668                                 break;
669                             }
670                         }
671                     }
672                     if (!found) {
673                         // We didn't find the producer for this track, find producer for another track and duplicate
674                         for (int i = 0; i < producers.count(); i++) {
675                             QDomElement prod = producers.at(i).toElement();
676                             QString mltProdId = prod.attribute("id");
677                             if (mltProdId == prodId || mltProdId.startsWith(prodId + "_")) {
678                                 // Found parent producer, clone it
679                                 QDomElement clone = prod.cloneNode().toElement();
680                                 clone.setAttribute("id", prodId);
681                                 m_doc->toXml().documentElement().insertBefore(clone, xml);
682                                 break;
683                             }
684                         }
685                     }                    
686                 }
687                 else {
688                     // We cannot find the producer, something is really wrong, add
689                     // placeholder color clip
690                     QDomDocument doc;
691                     QDomElement producerXml = doc.createElement("producer");
692                     doc.appendChild(producerXml);
693                     bool foundMltProd = false;
694                     for (int i = 0; i < producers.count(); i++) {
695                         QDomElement prod = producers.at(i).toElement();
696                         if (prod.attribute("id") == id) {
697                             QString service = EffectsList::property(prod, "mlt_service");
698                             QString type = EffectsList::property(prod, "mlt_type");
699                             QString resource = EffectsList::property(prod, "resource");
700                             if (!resource.startsWith('/') && service != "colour") resource.prepend(docRoot);
701                             QString length = EffectsList::property(prod, "length");
702                             producerXml.setAttribute("mlt_service", service);
703                             producerXml.setAttribute("mlt_type", type);
704                             producerXml.setAttribute("resource", resource);
705                             producerXml.setAttribute("duration", length);
706                             if (service == "colour") producerXml.setAttribute("type", COLOR);
707                             else if (service == "qimage" || service == "pixbuf") producerXml.setAttribute("type", IMAGE);
708                             else if (service == "kdenlivetitle") producerXml.setAttribute("type", TEXT);
709                             else producerXml.setAttribute("type", AV);
710                             clip = new DocClipBase(m_doc->clipManager(), doc.documentElement(), id);
711                             m_doc->clipManager()->addClip(clip);
712                             m_documentErrors.append(i18n("Broken clip producer %1, recreated base clip: %2", id, resource) + '\n');
713                             foundMltProd = true;
714                             break;
715                         }
716                     }
717                     if (!foundMltProd) {
718                         // Cannot recover, replace with blank
719                         int duration = elem.attribute("out").toInt() - elem.attribute("in").toInt();
720                         elem.setAttribute("length", duration);
721                         elem.setTagName("blank");
722                         m_documentErrors.append(i18n("Broken clip producer %1, removed from project", id) + '\n');
723                     }
724                 }
725                 m_doc->setModified(true);
726             }
727
728             if (clip != NULL) {
729                 ItemInfo clipinfo;
730                 clipinfo.startPos = GenTime(position, m_doc->fps());
731                 clipinfo.endPos = clipinfo.startPos + GenTime(out - in + 1, m_doc->fps());
732                 clipinfo.cropStart = GenTime(in, m_doc->fps());
733                 clipinfo.cropDuration = clipinfo.endPos - clipinfo.startPos;
734
735                 clipinfo.track = ix;
736                 //kDebug() << "// INSERTING CLIP: " << in << "x" << out << ", track: " << ix << ", ID: " << id << ", SCALE: " << m_scale << ", FPS: " << m_doc->fps();
737                 ClipItem *item = new ClipItem(clip, clipinfo, m_doc->fps(), speed, strobe, false);
738                 if (idString.endsWith("_video")) item->setVideoOnly(true);
739                 else if (idString.endsWith("_audio")) item->setAudioOnly(true);
740                 m_scene->addItem(item);
741                 if (locked) item->setItemLocked(true);
742                 clip->addReference();
743                 position += (out - in + 1);
744                 if (speed != 1.0 || strobe > 1) {
745                     QDomElement speedeffect = MainWindow::videoEffects.getEffectByTag(QString(), "speed").cloneNode().toElement();
746                     EffectsList::setParameter(speedeffect, "speed", QString::number((int)(100 * speed + 0.5)));
747                     EffectsList::setParameter(speedeffect, "strobe", QString::number(strobe));
748                     item->addEffect(speedeffect, false);
749                     item->effectsCounter();
750                 }
751
752                 // parse clip effects
753                 QDomNodeList effects = elem.elementsByTagName("filter");
754                 slotAddProjectEffects(effects, elem, item, -1);
755             }
756         }
757     }
758     kDebug() << "*************  ADD DOC TRACK " << ix << ", DURATION: " << position;
759     return position;
760 }
761
762 void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNode, ClipItem *clip, int trackIndex)
763 {
764     int effectNb = 0;
765     for (int ix = 0; ix < effects.count(); ix++) {
766         bool disableeffect = false;
767         QDomElement effect = effects.at(ix).toElement();
768         if (effect.tagName() != "filter") continue;
769         effectNb++;
770         // add effect to clip
771         QString effecttag;
772         QString effectid;
773         QString effectindex = QString::number(effectNb);
774         QString ladspaEffectFile;
775         // Get effect tag & index
776         for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
777             // parse effect parameters
778             QDomElement effectparam = n3.toElement();
779             if (effectparam.attribute("name") == "tag") {
780                 effecttag = effectparam.text();
781             } else if (effectparam.attribute("name") == "kdenlive_id") {
782                 effectid = effectparam.text();
783             } else if (effectparam.attribute("name") == "disable" && effectparam.text().toInt() == 1) {
784                 // Fix effects index
785                 disableeffect = true;
786             } else if (effectparam.attribute("name") == "kdenlive_ix") {
787                 // Fix effects index
788                 effectparam.firstChild().setNodeValue(effectindex);
789             } else if (effectparam.attribute("name") == "src") {
790                 ladspaEffectFile = effectparam.text();
791                 if (!QFile::exists(ladspaEffectFile)) {
792                     // If the ladspa effect file is missing, recreate it
793                     kDebug() << "// MISSING LADSPA FILE: " << ladspaEffectFile;
794                     ladspaEffectFile = m_doc->getLadspaFile();
795                     effectparam.firstChild().setNodeValue(ladspaEffectFile);
796                     kDebug() << "// ... REPLACED WITH: " << ladspaEffectFile;
797                 }
798             }
799         }
800         //kDebug() << "+ + CLIP EFF FND: " << effecttag << ", " << effectid << ", " << effectindex;
801         // get effect standard tags
802         QDomElement clipeffect = MainWindow::customEffects.getEffectByTag(QString(), effectid);
803         if (clipeffect.isNull()) {
804             clipeffect = MainWindow::videoEffects.getEffectByTag(effecttag, effectid);
805         }
806         if (clipeffect.isNull()) {
807             clipeffect = MainWindow::audioEffects.getEffectByTag(effecttag, effectid);
808         }
809         if (clipeffect.isNull()) {
810             kDebug() << "///  WARNING, EFFECT: " << effecttag << ": " << effectid << " not found, removing it from project";
811             m_documentErrors.append(i18n("Effect %1:%2 not found in MLT, it was removed from this project\n", effecttag, effectid));
812             if (parentNode.removeChild(effects.at(ix)).isNull()) kDebug() << "///  PROBLEM REMOVING EFFECT: " << effecttag;
813             ix--;
814         } else {
815             QDomElement currenteffect = clipeffect.cloneNode().toElement();
816             currenteffect.setAttribute("kdenlive_ix", effectindex);
817             QDomNodeList clipeffectparams = currenteffect.childNodes();
818
819             if (MainWindow::videoEffects.hasKeyFrames(currenteffect)) {
820                 //kDebug() << " * * * * * * * * * * ** CLIP EFF WITH KFR FND  * * * * * * * * * * *";
821                 // effect is key-framable, read all effects to retrieve keyframes
822                 QString factor;
823                 QString starttag;
824                 QString endtag;
825                 QDomNodeList params = currenteffect.elementsByTagName("parameter");
826                 for (int i = 0; i < params.count(); i++) {
827                     QDomElement e = params.item(i).toElement();
828                     if (e.attribute("type") == "keyframe") {
829                         starttag = e.attribute("starttag", "start");
830                         endtag = e.attribute("endtag", "end");
831                         factor = e.attribute("factor", "1");
832                         break;
833                     }
834                 }
835                 QString keyframes;
836                 int effectin = effect.attribute("in").toInt();
837                 int effectout = effect.attribute("out").toInt();
838                 double startvalue = 0;
839                 double endvalue = 0;
840                 double fact;
841                 if (factor.isEmpty()) fact = 1;
842                 else if (factor.contains('%')) {
843                     fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
844                 } else fact = factor.toDouble();
845                 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
846                     // parse effect parameters
847                     QDomElement effectparam = n3.toElement();
848                     if (effectparam.attribute("name") == starttag)
849                         startvalue = effectparam.text().toDouble() * fact;
850                     if (effectparam.attribute("name") == endtag)
851                         endvalue = effectparam.text().toDouble() * fact;
852                 }
853                 // add first keyframe
854                 if (effectout <= effectin) {
855                     // there is only one keyframe
856                     keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';');
857                 } else keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';');
858                 QDomNode lastParsedEffect;
859                 ix++;
860                 QDomNode n2 = effects.at(ix);
861                 bool continueParsing = true;
862                 for (; !n2.isNull() && continueParsing; n2 = n2.nextSibling()) {
863                     // parse all effects
864                     QDomElement kfreffect = n2.toElement();
865                     int effectout = kfreffect.attribute("out").toInt();
866
867                     for (QDomNode n4 = kfreffect.firstChild(); !n4.isNull(); n4 = n4.nextSibling()) {
868                         // parse effect parameters
869                         QDomElement subeffectparam = n4.toElement();
870                         if (subeffectparam.attribute("name") == "kdenlive_ix" && subeffectparam.text() != effectindex) {
871                             //We are not in the same effect, stop parsing
872                             lastParsedEffect = n2.previousSibling();
873                             ix--;
874                             continueParsing = false;
875                             break;
876                         } else if (subeffectparam.attribute("name") == endtag) {
877                             endvalue = subeffectparam.text().toDouble() * fact;
878                             break;
879                         }
880                     }
881                     if (continueParsing) {
882                         keyframes.append(QString::number(effectout) + ':' + QString::number(endvalue) + ';');
883                         ix++;
884                     }
885                 }
886
887                 params = currenteffect.elementsByTagName("parameter");
888                 for (int i = 0; i < params.count(); i++) {
889                     QDomElement e = params.item(i).toElement();
890                     if (e.attribute("type") == "keyframe") e.setAttribute("keyframes", keyframes);
891                 }
892                 if (!continueParsing) {
893                     n2 = lastParsedEffect;
894                 }
895             } else {
896                 // Check if effect has in/out points
897                 if (effect.hasAttribute("in")) {
898                     EffectsList::setParameter(currenteffect, "in",  effect.attribute("in"));
899                 }
900                 if (effect.hasAttribute("out")) {
901                     EffectsList::setParameter(currenteffect, "out",  effect.attribute("out"));
902                 }
903             }
904
905             // adjust effect parameters
906             for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
907                 // parse effect parameters
908                 QDomElement effectparam = n3.toElement();
909                 QString paramname = effectparam.attribute("name");
910                 QString paramvalue = effectparam.text();
911
912                 // try to find this parameter in the effect xml
913                 QDomElement e;
914                 for (int k = 0; k < clipeffectparams.count(); k++) {
915                     e = clipeffectparams.item(k).toElement();
916                     if (!e.isNull() && e.tagName() == "parameter" && e.attribute("name") == paramname) {
917                         QString type = e.attribute("type");
918                         QString factor = e.attribute("factor", "1");
919                         double fact;
920                         if (factor.contains('%')) {
921                             fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
922                         } else {
923                             fact = factor.toDouble();
924                         }
925                         if (type == "simplekeyframe") {
926                             QStringList kfrs = paramvalue.split(";");
927                             for (int l = 0; l < kfrs.count(); l++) {
928                                 QString fr = kfrs.at(l).section('=', 0, 0);
929                                 double val = kfrs.at(l).section('=', 1, 1).toDouble();
930                                 kfrs[l] = fr + ":" + QString::number((int)(val * fact));
931                             }
932                             e.setAttribute("keyframes", kfrs.join(";"));
933                         } else if (type == "double" || type == "constant") {
934                             bool ok;
935                             e.setAttribute("value", paramvalue.toDouble(&ok) * fact);
936                             if (!ok)
937                                 e.setAttribute("value", paramvalue);
938                         } else {
939                             e.setAttribute("value", paramvalue);
940                         }
941                         break;
942                     }
943                 }
944             }
945             // Old LADSPA filter, deprecated
946             /*if (effecttag == "ladspa") {
947                 //QString ladspaEffectFile = EffectsList::parameter(effect, "src", "property");
948
949                 if (!QFile::exists(ladspaEffectFile)) {
950                     // If the ladspa effect file is missing, recreate it
951                     initEffects::ladspaEffectFile(ladspaEffectFile, currenteffect.attribute("ladspaid").toInt(), m_trackview->getLadspaParams(currenteffect));
952                 }
953                 currenteffect.setAttribute("src", ladspaEffectFile);
954             }*/
955             
956             if (disableeffect) currenteffect.setAttribute("disable", "1");
957             if (clip)
958                 clip->addEffect(currenteffect, false);
959             else
960                 m_doc->addTrackEffect(trackIndex, currenteffect);
961         }
962     }
963 }
964
965
966 DocClipBase *TrackView::getMissingProducer(const QString id) const
967 {
968     QDomElement missingXml;
969     QDomDocument doc = m_doc->toXml();
970     QString docRoot = doc.documentElement().attribute("root");
971     if (!docRoot.endsWith('/')) docRoot.append('/');
972     QDomNodeList prods = doc.elementsByTagName("producer");
973     int maxprod = prods.count();
974     bool slowmotionClip = false;
975     for (int i = 0; i < maxprod; i++) {
976         QDomNode m = prods.at(i);
977         QString prodId = m.toElement().attribute("id");
978         if (prodId.startsWith("slowmotion")) {
979             slowmotionClip = true;
980             prodId = prodId.section(':', 1, 1);
981         }
982         prodId = prodId.section('_', 0, 0);
983         if (prodId == id) {
984             missingXml =  m.toElement();
985             break;
986         }
987     }
988     if (missingXml == QDomElement()) {
989         // Check if producer id was replaced in another track
990         if (m_replacementProducerIds.contains(id)) {
991             QString newId = m_replacementProducerIds.value(id);
992             slowmotionClip = false;
993             for (int i = 0; i < maxprod; i++) {
994                 QDomNode m = prods.at(i);
995                 QString prodId = m.toElement().attribute("id");
996                 if (prodId.startsWith("slowmotion")) {
997                     slowmotionClip = true;
998                     prodId = prodId.section(':', 1, 1);
999                 }
1000                 prodId = prodId.section('_', 0, 0);
1001                 if (prodId == id) {
1002                     missingXml =  m.toElement();
1003                     break;
1004                 }
1005             }       
1006         }
1007     }
1008     if (missingXml == QDomElement()) return NULL;
1009     QString resource = EffectsList::property(missingXml, "resource");
1010     QString service = EffectsList::property(missingXml, "mlt_service");
1011
1012     if (slowmotionClip) resource = resource.section('?', 0, 0);
1013     // prepend MLT XML document root if no path in clip resource and not a color clip
1014     if (!resource.startsWith('/') && service != "colour") resource.prepend(docRoot);
1015     DocClipBase *missingClip = NULL;
1016     if (!resource.isEmpty()) {
1017         QList <DocClipBase *> list = m_doc->clipManager()->getClipByResource(resource);
1018         if (!list.isEmpty()) missingClip = list.at(0);
1019     }
1020     return missingClip;
1021 }
1022
1023 QGraphicsScene *TrackView::projectScene()
1024 {
1025     return m_scene;
1026 }
1027
1028 CustomTrackView *TrackView::projectView()
1029 {
1030     return m_trackview;
1031 }
1032
1033 void TrackView::setEditMode(const QString & editMode)
1034 {
1035     m_editMode = editMode;
1036 }
1037
1038 const QString & TrackView::editMode() const
1039 {
1040     return m_editMode;
1041 }
1042
1043 void TrackView::slotChangeTrackLock(int ix, bool lock)
1044 {
1045     QList<HeaderTrack *> widgets = findChildren<HeaderTrack *>();
1046     widgets.at(ix)->setLock(lock);
1047 }
1048
1049
1050 void TrackView::slotVerticalZoomDown()
1051 {
1052     if (m_verticalZoom == 0) return;
1053     m_verticalZoom--;
1054     m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
1055     if (m_verticalZoom == 0)
1056         m_trackview->setScale(m_scene->scale().x(), 0.5);
1057     else
1058         m_trackview->setScale(m_scene->scale().x(), 1);
1059     adjustTrackHeaders();
1060     m_trackview->verticalScrollBar()->setValue(headers_area->verticalScrollBar()->value());
1061 }
1062
1063 void TrackView::slotVerticalZoomUp()
1064 {
1065     if (m_verticalZoom == 2) return;
1066     m_verticalZoom++;
1067     m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
1068     if (m_verticalZoom == 2)
1069         m_trackview->setScale(m_scene->scale().x(), 2);
1070     else
1071         m_trackview->setScale(m_scene->scale().x(), 1);
1072     adjustTrackHeaders();
1073     m_trackview->verticalScrollBar()->setValue(headers_area->verticalScrollBar()->value());
1074 }
1075
1076 void TrackView::updateProjectFps()
1077 {
1078     m_ruler->updateProjectFps(m_doc->timecode());
1079     m_trackview->updateProjectFps();
1080 }
1081
1082 void TrackView::slotRenameTrack(int ix, QString name)
1083 {
1084     int tracknumber = m_doc->tracksCount() - ix;
1085     QList <TrackInfo> tracks = m_doc->tracksList();
1086     tracks[tracknumber - 1].trackName = name;
1087     ConfigTracksCommand *configTracks = new ConfigTracksCommand(m_trackview, m_doc->tracksList(), tracks);
1088     m_doc->commandStack()->push(configTracks);
1089     m_doc->setModified(true);
1090 }
1091
1092 void TrackView::slotUpdateVerticalScroll(int /*min*/, int max)
1093 {
1094     int height = 0;
1095     if (max > 0) height = m_trackview->horizontalScrollBar()->height() - 1;
1096     headers_container->layout()->setContentsMargins(0, m_trackview->frameWidth(), 0, height);
1097 }
1098
1099 void TrackView::updateRuler()
1100 {
1101     m_ruler->update();
1102 }
1103
1104 void TrackView::slotShowTrackEffects(int ix)
1105 {
1106     m_trackview->clearSelection();
1107     emit showTrackEffects(m_doc->tracksCount() - ix, m_doc->trackInfoAt(m_doc->tracksCount() - ix - 1));
1108 }
1109
1110 void TrackView::slotUpdateTrackEffectState(int ix)
1111 {
1112     QList<HeaderTrack *> widgets = findChildren<HeaderTrack *>();
1113     if (ix < 0 || ix >= widgets.count()) {
1114         kDebug() << "ERROR, Trying to access a non existant track: " << ix;
1115         return;
1116     }
1117     widgets.at(m_doc->tracksCount() - ix - 1)->updateEffectLabel(m_doc->trackInfoAt(ix).effectsList.effectNames());
1118 }
1119
1120 void TrackView::slotSaveTimelinePreview(const QString path)
1121 {
1122     QImage img(width(), height(), QImage::Format_ARGB32_Premultiplied);
1123     img.fill(palette().base().color().rgb());
1124     QPainter painter(&img);
1125     render(&painter);
1126     painter.end();
1127     img = img.scaledToWidth(600, Qt::SmoothTransformation);
1128     img.save(path);
1129 }
1130
1131
1132 #include "trackview.moc"
1133
1134
1135