]> git.sesse.net Git - kdenlive/blob - src/transitionsettings.cpp
Rotoscoping: import keyframes generated by tracker.
[kdenlive] / src / transitionsettings.cpp
1 /***************************************************************************
2                           effecstackedit.h  -  description
3                              -------------------
4     begin                : Mar 15 2008
5     copyright            : (C) 2008 by Marco Gittler
6     email                : g.marco@freenet.de
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18
19
20 #include "transitionsettings.h"
21 #include "transition.h"
22 #include "effectslist.h"
23 #include "effectstackedit.h"
24 #include "kdenlivesettings.h"
25 #include "mainwindow.h"
26
27 #include <KDebug>
28
29 TransitionSettings::TransitionSettings(Monitor *monitor, QWidget* parent) :
30         QWidget(parent),
31         m_usedTransition(NULL),
32         m_autoTrackTransition(0)
33 {
34     setupUi(this);
35     QVBoxLayout *vbox1 = new QVBoxLayout(frame);
36     m_effectEdit = new EffectStackEdit(monitor, frame);
37     vbox1->setContentsMargins(0, 0, 0, 0);
38     vbox1->setSpacing(0);
39     vbox1->addWidget(m_effectEdit);
40     frame->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
41     connect(m_effectEdit, SIGNAL(seekTimeline(int)), this, SIGNAL(seekTimeline(int)));
42     setEnabled(false);
43
44     QList<QStringList> transitionsList;
45     int max = MainWindow::transitions.effectNames().count();
46     QStringList transitionInfo;
47     int ix = 0;
48
49     for (; ix < max; ix++) {
50         transitionInfo = MainWindow::transitions.effectIdInfo(ix);
51         transitionInfo << QString::number(ix);
52         transitionsList.append(transitionInfo);
53     }
54     ix = 0;
55     foreach(const QStringList &value, transitionsList) {
56         QStringList data = value;
57         if (!data.isEmpty()) data.removeLast();
58         transitionList->addItem(value.at(0), data);
59         transitionList->setItemData(ix, MainWindow::transitions.getInfoFromIndex(value.last().toInt()), Qt::ToolTipRole);
60         ix++;
61     }
62
63     connect(transitionList, SIGNAL(activated(int)), this, SLOT(slotTransitionChanged()));
64     connect(transitionTrack, SIGNAL(activated(int)), this, SLOT(slotTransitionTrackChanged()));
65     connect(m_effectEdit, SIGNAL(parameterChanged(const QDomElement&, const QDomElement&)), this , SLOT(slotUpdateEffectParams(const QDomElement&, const QDomElement&)));
66     connect(monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
67 }
68
69 void TransitionSettings::updateProjectFormat(MltVideoProfile profile, Timecode t, const QList <TrackInfo> info)
70 {
71     m_effectEdit->updateProjectFormat(profile, t);
72     m_tracks = info;
73     updateTrackList();
74 }
75
76 void TransitionSettings::updateTimecodeFormat()
77 {
78     m_effectEdit->updateTimecodeFormat();
79 }
80
81 void TransitionSettings::updateTrackList()
82 {
83     transitionTrack->blockSignals(true);
84     int current = transitionTrack->itemData(transitionTrack->currentIndex()).toInt();
85     transitionTrack->clear();
86     transitionTrack->addItem(i18n("Auto"), -1);
87     int limit = 1;
88     if (m_usedTransition)
89         limit = m_usedTransition->track() + 1;
90     kDebug() << "/ / TRANS TRK: " << limit;
91     KIcon videoIcon("kdenlive-show-video");
92     KIcon audioIcon("kdenlive-show-audio");
93     for (int i = limit; i < m_tracks.count(); i++) {
94         int ix = m_tracks.count() - i - 1;
95         transitionTrack->addItem(m_tracks.at(ix).type == VIDEOTRACK ? videoIcon : audioIcon,
96                                  m_tracks.at(ix).trackName.isEmpty() ? QString::number(i) : m_tracks.at(ix).trackName + " (" + QString::number(i) + ")",
97                                  m_tracks.count() - i);
98     }
99     transitionTrack->addItem(i18n("Black"), 0);
100     transitionTrack->setCurrentIndex(transitionTrack->findData(current));
101     transitionTrack->blockSignals(false);
102 }
103
104
105 void TransitionSettings::slotTransitionChanged(bool reinit, bool updateCurrent)
106 {
107     QDomElement e = m_usedTransition->toXML().cloneNode().toElement();
108     if (reinit) {
109         // Reset the transition parameters to the default one
110         QDomElement newTransition = MainWindow::transitions.getEffectByName(transitionList->currentText()).cloneNode().toElement();
111         slotUpdateEffectParams(e, newTransition);
112         m_effectEdit->transferParamDesc(newTransition, m_usedTransition->info(), false);
113     } else if (!updateCurrent) {
114         // Transition changed, update parameters dialog
115         //slotUpdateEffectParams(e, e);
116         m_effectEdit->transferParamDesc(e, m_usedTransition->info(), false);
117     } else {
118         // Same transition, we just want to update the parameters value
119         slotUpdateEffectParams(e, e);
120         if (m_usedTransition->hasGeometry())
121             m_effectEdit->transferParamDesc(m_usedTransition->toXML(), m_usedTransition->info(), false);
122     }
123 }
124
125 void TransitionSettings::slotTransitionTrackChanged()
126 {
127     if (m_usedTransition == NULL) return;
128     int ix = 0;
129     QDomElement oldxml = m_usedTransition->toXML().cloneNode().toElement();
130     if (transitionTrack->currentIndex() > 0) {
131         ix = transitionTrack->itemData(transitionTrack->currentIndex()).toInt();
132         m_usedTransition->setForcedTrack(true, ix);
133         m_effectEdit->updateParameter("force_track", "1");
134     } else {
135         ix = m_autoTrackTransition;
136         m_usedTransition->setForcedTrack(false, ix);
137         m_effectEdit->updateParameter("force_track", "0");
138     }
139     emit transitionUpdated(m_usedTransition, oldxml);
140     m_effectEdit->updateParameter("transition_btrack", QString::number(ix));
141 }
142
143 void TransitionSettings::slotTransitionItemSelected(Transition* t, int nextTrack, QPoint p, bool update)
144 {
145     setEnabled(t != NULL);
146     m_effectEdit->setFrameSize(p);
147     m_autoTrackTransition = nextTrack;
148     if (t == m_usedTransition) {
149         if (t == NULL) return;
150         if (update) {
151             transitionTrack->blockSignals(true);
152             updateTrackList();
153             if (t->forcedTrack()) transitionTrack->setCurrentIndex(transitionTrack->findData(t->transitionEndTrack()));
154             else transitionTrack->setCurrentIndex(0);
155             transitionTrack->blockSignals(false);
156         }
157         if (update || t->cropDuration() != m_transitionDuration || t->startPos() != m_transitionStart) {
158             m_transitionDuration = t->cropDuration();
159             m_transitionStart = t->startPos();
160             slotTransitionChanged(false, true);
161         }
162         return;
163     } else if (update) return;
164     if (t) {
165         m_transitionDuration = t->cropDuration();
166         m_transitionStart = t->startPos();
167         transitionTrack->blockSignals(true);
168         m_usedTransition = t;
169         updateTrackList();
170         if (!t->forcedTrack())
171             transitionTrack->setCurrentIndex(0);
172         else
173             transitionTrack->setCurrentIndex(transitionTrack->findData(t->transitionEndTrack()));
174         transitionTrack->blockSignals(false);
175         int ix = transitionList->findData(t->transitionInfo(), Qt::UserRole, Qt::MatchExactly);
176         if (ix != -1) {
177             transitionList->blockSignals(true);
178             transitionList->setCurrentIndex(ix);
179             slotTransitionChanged(false, false);
180             transitionList->blockSignals(false);
181         }
182     } else {
183         // null transition selected
184         m_usedTransition = NULL;
185         ItemInfo info;
186         m_effectEdit->transferParamDesc(QDomElement(), info, false);
187     }
188
189 }
190
191 void TransitionSettings::slotUpdateEffectParams(const QDomElement &oldparam, const QDomElement &param)
192 {
193     if (m_usedTransition) {
194         m_usedTransition->setTransitionParameters(param);
195         m_usedTransition->update();
196     }
197     //oldparam must be also first given to Transition and then return the toXML()
198     if (oldparam != param)
199         emit transitionUpdated(m_usedTransition, oldparam);
200 }
201
202 void TransitionSettings::raiseWindow(QWidget* dock)
203 {
204     if (dock && m_usedTransition)
205         dock->raise();
206
207 }
208
209 void TransitionSettings::slotRenderPos(int pos)
210 {
211     if (m_usedTransition)
212         m_effectEdit->slotSyncEffectsPos(pos - m_usedTransition->startPos().frames(KdenliveSettings::project_fps()));
213 }
214
215 #include "transitionsettings.moc"