]> git.sesse.net Git - kdenlive/blob - src/transitionsettings.cpp
remove some debug
[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 #include "monitoreditwidget.h"
27 #include "monitorscene.h"
28
29 #include <KDebug>
30
31 TransitionSettings::TransitionSettings(Monitor *monitor, QWidget* parent) :
32         QWidget(parent),
33         m_usedTransition(NULL),
34         m_autoTrackTransition(0)
35 {
36     setupUi(this);
37     QVBoxLayout *vbox1 = new QVBoxLayout(frame);
38     m_effectEdit = new EffectStackEdit(monitor, frame);
39     vbox1->setContentsMargins(0, 0, 0, 0);
40     vbox1->setSpacing(0);
41     vbox1->addWidget(m_effectEdit);
42     frame->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
43     connect(m_effectEdit, SIGNAL(seekTimeline(int)), this, SLOT(slotSeekTimeline(int)));
44     setEnabled(false);
45
46     QList<QStringList> transitionsList;
47     int max = MainWindow::transitions.effectNames().count();
48     QStringList transitionInfo;
49     int ix = 0;
50
51     for (; ix < max; ix++) {
52         transitionInfo = MainWindow::transitions.effectIdInfo(ix);
53         transitionInfo << QString::number(ix);
54         transitionsList.append(transitionInfo);
55     }
56     ix = 0;
57     foreach(const QStringList &value, transitionsList) {
58         QStringList data = value;
59         if (!data.isEmpty()) data.removeLast();
60         transitionList->addItem(value.at(0), data);
61         transitionList->setItemData(ix, MainWindow::transitions.getInfoFromIndex(value.last().toInt()), Qt::ToolTipRole);
62         ix++;
63     }
64
65     connect(transitionList, SIGNAL(activated(int)), this, SLOT(slotTransitionChanged()));
66     connect(transitionTrack, SIGNAL(activated(int)), this, SLOT(slotTransitionTrackChanged()));
67     connect(m_effectEdit, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement)));
68 }
69
70 void TransitionSettings::updateProjectFormat(MltVideoProfile profile, Timecode t, const QList <TrackInfo> info)
71 {
72     m_effectEdit->updateProjectFormat(profile, t);
73     m_tracks = info;
74     updateTrackList();
75 }
76
77 void TransitionSettings::updateTimecodeFormat()
78 {
79     m_effectEdit->updateTimecodeFormat();
80 }
81
82 void TransitionSettings::updateTrackList()
83 {
84     transitionTrack->blockSignals(true);
85     int current = transitionTrack->itemData(transitionTrack->currentIndex()).toInt();
86     transitionTrack->clear();
87     transitionTrack->addItem(i18n("Auto"), -1);
88     int limit = 1;
89     if (m_usedTransition)
90         limit = m_usedTransition->track() + 1;
91     //kDebug() << "/ / TRANS TRK: " << limit;
92     KIcon videoIcon("kdenlive-show-video");
93     KIcon audioIcon("kdenlive-show-audio");
94     for (int i = limit; i < m_tracks.count(); i++) {
95         int ix = m_tracks.count() - i - 1;
96         transitionTrack->addItem(m_tracks.at(ix).type == VIDEOTRACK ? videoIcon : audioIcon,
97                                  m_tracks.at(ix).trackName.isEmpty() ? QString::number(i) : m_tracks.at(ix).trackName + " (" + QString::number(i) + ")",
98                                  m_tracks.count() - i);
99     }
100     transitionTrack->addItem(i18n("Black"), 0);
101     transitionTrack->setCurrentIndex(transitionTrack->findData(current));
102     transitionTrack->blockSignals(false);
103 }
104
105
106 void TransitionSettings::slotTransitionChanged(bool reinit, bool updateCurrent)
107 {
108     QDomElement e = m_usedTransition->toXML().cloneNode().toElement();
109     if (reinit) {
110         // Reset the transition parameters to the default one
111         QDomElement newTransition = MainWindow::transitions.getEffectByName(transitionList->currentText()).cloneNode().toElement();
112         slotUpdateEffectParams(e, newTransition);
113         m_effectEdit->transferParamDesc(newTransition, m_usedTransition->info(), false);
114     } else if (!updateCurrent) {
115         // Transition changed, update parameters dialog
116         //slotUpdateEffectParams(e, e);
117         m_effectEdit->transferParamDesc(e, m_usedTransition->info(), false);
118     } else {
119         // Same transition, we just want to update the parameters value
120         slotUpdateEffectParams(e, e);
121         if (m_usedTransition->hasGeometry())
122             m_effectEdit->transferParamDesc(m_usedTransition->toXML(), m_usedTransition->info(), false);
123     }
124     slotCheckMonitorPosition(m_effectEdit->monitor()->render->seekFramePosition());
125 }
126
127 void TransitionSettings::slotTransitionTrackChanged()
128 {
129     if (m_usedTransition == NULL) return;
130     int ix = 0;
131     QDomElement oldxml = m_usedTransition->toXML().cloneNode().toElement();
132     if (transitionTrack->currentIndex() > 0) {
133         ix = transitionTrack->itemData(transitionTrack->currentIndex()).toInt();
134         m_usedTransition->setForcedTrack(true, ix);
135         m_effectEdit->updateParameter("force_track", "1");
136     } else {
137         ix = m_autoTrackTransition;
138         m_usedTransition->setForcedTrack(false, ix);
139         m_effectEdit->updateParameter("force_track", "0");
140     }
141     emit transitionUpdated(m_usedTransition, oldxml);
142     m_effectEdit->updateParameter("transition_btrack", QString::number(ix));
143 }
144
145 void TransitionSettings::slotTransitionItemSelected(Transition* t, int nextTrack, QPoint p, bool update)
146 {
147     setEnabled(t != NULL);
148     m_effectEdit->setFrameSize(p);
149     m_autoTrackTransition = nextTrack;
150     disconnect(m_effectEdit->monitor(), SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
151     if (t == m_usedTransition) {
152         if (t == NULL) return;
153         if (update) {
154             transitionTrack->blockSignals(true);
155             updateTrackList();
156             if (t->forcedTrack()) transitionTrack->setCurrentIndex(transitionTrack->findData(t->transitionEndTrack()));
157             else transitionTrack->setCurrentIndex(0);
158             transitionTrack->blockSignals(false);
159         }
160         if (update || t->cropDuration() != m_transitionDuration || t->startPos() != m_transitionStart) {
161             m_transitionDuration = t->cropDuration();
162             m_transitionStart = t->startPos();
163             slotTransitionChanged(false, true);
164         }
165         return;
166     } else if (update) return;
167     if (t) {
168         m_transitionDuration = t->cropDuration();
169         m_transitionStart = t->startPos();
170         transitionTrack->blockSignals(true);
171         m_usedTransition = t;
172         updateTrackList();
173         if (!t->forcedTrack())
174             transitionTrack->setCurrentIndex(0);
175         else
176             transitionTrack->setCurrentIndex(transitionTrack->findData(t->transitionEndTrack()));
177         transitionTrack->blockSignals(false);
178         int ix = transitionList->findData(t->transitionInfo(), Qt::UserRole, Qt::MatchExactly);
179         if (ix != -1) {
180             transitionList->blockSignals(true);
181             transitionList->setCurrentIndex(ix);
182             slotTransitionChanged(false, false);
183             transitionList->blockSignals(false);
184         }
185         if (m_effectEdit->needsMonitorEffectScene()) {
186             connect(m_effectEdit->monitor(), SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
187         }
188     } else {
189         // null transition selected
190         m_usedTransition = NULL;
191         ItemInfo info;
192         m_effectEdit->transferParamDesc(QDomElement(), info, false);
193     }
194 }
195
196 void TransitionSettings::slotUpdateEffectParams(const QDomElement oldparam, const QDomElement param)
197 {
198     if (m_usedTransition) {
199         m_usedTransition->setTransitionParameters(param);
200         m_usedTransition->update();
201     }
202     //oldparam must be also first given to Transition and then return the toXML()
203     if (oldparam != param)
204         emit transitionUpdated(m_usedTransition, oldparam);
205 }
206
207 void TransitionSettings::raiseWindow(QWidget* dock)
208 {
209     if (dock && m_usedTransition)
210         dock->raise();
211 }
212
213 void TransitionSettings::slotRenderPos(int pos)
214 {
215     if (m_usedTransition) {
216         m_effectEdit->slotSyncEffectsPos(pos - m_usedTransition->startPos().frames(KdenliveSettings::project_fps()));
217         if (isEnabled()) slotCheckMonitorPosition(pos);
218     }
219 }
220
221 void TransitionSettings::slotSeekTimeline(int pos)
222 {
223     if (m_usedTransition)
224         emit seekTimeline(m_usedTransition->startPos().frames(KdenliveSettings::project_fps()) + pos);
225 }
226
227 void TransitionSettings::slotCheckMonitorPosition(int renderPos)
228 {
229     if (!isEnabled()) return;
230     if (m_effectEdit->needsMonitorEffectScene()) {
231         if (renderPos >= m_usedTransition->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_usedTransition->endPos().frames(KdenliveSettings::project_fps())) {
232             if (!m_effectEdit->monitor()->effectSceneDisplayed()) {
233                 m_effectEdit->monitor()->slotShowEffectScene(true);
234             }
235         } else {
236             m_effectEdit->monitor()->slotShowEffectScene(false);
237         }
238     }
239     else {
240         m_effectEdit->monitor()->slotShowEffectScene(false);
241     }
242 }
243
244
245 #include "transitionsettings.moc"