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