1 /***************************************************************************
2 effecstackedit.h - description
5 copyright : (C) 2008 by Marco Gittler
6 email : g.marco@freenet.de
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
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"
31 TransitionSettings::TransitionSettings(Monitor *monitor, QWidget* parent) :
33 m_usedTransition(NULL),
34 m_autoTrackTransition(0)
37 QVBoxLayout *vbox1 = new QVBoxLayout(frame);
38 m_effectEdit = new EffectStackEdit(monitor, frame);
39 vbox1->setContentsMargins(0, 0, 0, 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)));
46 QList<QStringList> transitionsList;
47 int max = MainWindow::transitions.effectNames().count();
48 QStringList transitionInfo;
51 for (; ix < max; ix++) {
52 transitionInfo = MainWindow::transitions.effectIdInfo(ix);
53 transitionInfo << QString::number(ix);
54 transitionsList.append(transitionInfo);
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);
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)));
70 void TransitionSettings::updateProjectFormat(MltVideoProfile profile, Timecode t, const QList <TrackInfo> info)
72 m_effectEdit->updateProjectFormat(profile, t);
77 void TransitionSettings::updateTimecodeFormat()
79 m_effectEdit->updateTimecodeFormat();
82 void TransitionSettings::updateTrackList()
84 transitionTrack->blockSignals(true);
85 int current = transitionTrack->itemData(transitionTrack->currentIndex()).toInt();
86 transitionTrack->clear();
87 transitionTrack->addItem(i18n("Auto"), -1);
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);
100 transitionTrack->addItem(i18n("Black"), 0);
101 transitionTrack->setCurrentIndex(transitionTrack->findData(current));
102 transitionTrack->blockSignals(false);
106 void TransitionSettings::slotTransitionChanged(bool reinit, bool updateCurrent)
108 QDomElement e = m_usedTransition->toXML().cloneNode().toElement();
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);
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);
124 slotCheckMonitorPosition(m_effectEdit->monitor()->render->seekFramePosition());
127 void TransitionSettings::slotTransitionTrackChanged()
129 if (m_usedTransition == NULL) return;
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");
137 ix = m_autoTrackTransition;
138 m_usedTransition->setForcedTrack(false, ix);
139 m_effectEdit->updateParameter("force_track", "0");
141 emit transitionUpdated(m_usedTransition, oldxml);
142 m_effectEdit->updateParameter("transition_btrack", QString::number(ix));
145 void TransitionSettings::slotTransitionItemSelected(Transition* t, int nextTrack, QPoint p, bool update)
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;
154 transitionTrack->blockSignals(true);
156 if (t->forcedTrack()) transitionTrack->setCurrentIndex(transitionTrack->findData(t->transitionEndTrack()));
157 else transitionTrack->setCurrentIndex(0);
158 transitionTrack->blockSignals(false);
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);
166 } else if (update) return;
168 m_transitionDuration = t->cropDuration();
169 m_transitionStart = t->startPos();
170 transitionTrack->blockSignals(true);
171 m_usedTransition = t;
173 if (!t->forcedTrack())
174 transitionTrack->setCurrentIndex(0);
176 transitionTrack->setCurrentIndex(transitionTrack->findData(t->transitionEndTrack()));
177 transitionTrack->blockSignals(false);
178 int ix = transitionList->findData(t->transitionInfo(), Qt::UserRole, Qt::MatchExactly);
180 transitionList->blockSignals(true);
181 transitionList->setCurrentIndex(ix);
182 slotTransitionChanged(false, false);
183 transitionList->blockSignals(false);
185 if (m_effectEdit->needsMonitorEffectScene()) {
186 connect(m_effectEdit->monitor(), SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
189 // null transition selected
190 m_usedTransition = NULL;
192 m_effectEdit->transferParamDesc(QDomElement(), info, false);
196 void TransitionSettings::slotUpdateEffectParams(const QDomElement oldparam, const QDomElement param)
198 if (m_usedTransition) {
199 m_usedTransition->setTransitionParameters(param);
200 m_usedTransition->update();
202 //oldparam must be also first given to Transition and then return the toXML()
203 if (oldparam != param)
204 emit transitionUpdated(m_usedTransition, oldparam);
207 void TransitionSettings::raiseWindow(QWidget* dock)
209 if (dock && m_usedTransition)
213 void TransitionSettings::slotRenderPos(int pos)
215 if (m_usedTransition) {
216 m_effectEdit->slotSyncEffectsPos(pos - m_usedTransition->startPos().frames(KdenliveSettings::project_fps()));
217 if (isEnabled()) slotCheckMonitorPosition(pos);
221 void TransitionSettings::slotSeekTimeline(int pos)
223 if (m_usedTransition)
224 emit seekTimeline(m_usedTransition->startPos().frames(KdenliveSettings::project_fps()) + pos);
227 void TransitionSettings::slotCheckMonitorPosition(int renderPos)
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);
236 m_effectEdit->monitor()->slotShowEffectScene(false);
240 m_effectEdit->monitor()->slotShowEffectScene(false);
245 #include "transitionsettings.moc"