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