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"
29 TransitionSettings::TransitionSettings(Monitor *monitor, QWidget* parent) :
31 m_usedTransition(NULL),
32 m_autoTrackTransition(0)
35 QVBoxLayout *vbox1 = new QVBoxLayout(frame);
36 m_effectEdit = new EffectStackEdit(monitor, frame);
37 vbox1->setContentsMargins(0, 0, 0, 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)));
44 QList<QStringList> transitionsList;
45 int max = MainWindow::transitions.effectNames().count();
46 QStringList transitionInfo;
49 for (; ix < max; ix++) {
50 transitionInfo = MainWindow::transitions.effectIdInfo(ix);
51 transitionInfo << QString::number(ix);
52 transitionsList.append(transitionInfo);
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);
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)));
69 void TransitionSettings::updateProjectFormat(MltVideoProfile profile, Timecode t, const QList <TrackInfo> info)
71 m_effectEdit->updateProjectFormat(profile, t);
76 void TransitionSettings::updateTimecodeFormat()
78 m_effectEdit->updateTimecodeFormat();
81 void TransitionSettings::updateTrackList()
83 transitionTrack->blockSignals(true);
84 int current = transitionTrack->itemData(transitionTrack->currentIndex()).toInt();
85 transitionTrack->clear();
86 transitionTrack->addItem(i18n("Auto"), -1);
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);
99 transitionTrack->addItem(i18n("Black"), 0);
100 transitionTrack->setCurrentIndex(transitionTrack->findData(current));
101 transitionTrack->blockSignals(false);
105 void TransitionSettings::slotTransitionChanged(bool reinit, bool updateCurrent)
107 QDomElement e = m_usedTransition->toXML().cloneNode().toElement();
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);
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);
125 void TransitionSettings::slotTransitionTrackChanged()
127 if (m_usedTransition == NULL) return;
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");
135 ix = m_autoTrackTransition;
136 m_usedTransition->setForcedTrack(false, ix);
137 m_effectEdit->updateParameter("force_track", "0");
139 emit transitionUpdated(m_usedTransition, oldxml);
140 m_effectEdit->updateParameter("transition_btrack", QString::number(ix));
143 void TransitionSettings::slotTransitionItemSelected(Transition* t, int nextTrack, QPoint p, bool update)
145 setEnabled(t != NULL);
146 m_effectEdit->setFrameSize(p);
147 m_autoTrackTransition = nextTrack;
148 if (t == m_usedTransition) {
149 if (t == NULL) return;
151 transitionTrack->blockSignals(true);
153 if (t->forcedTrack()) transitionTrack->setCurrentIndex(transitionTrack->findData(t->transitionEndTrack()));
154 else transitionTrack->setCurrentIndex(0);
155 transitionTrack->blockSignals(false);
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);
163 } else if (update) return;
165 m_transitionDuration = t->cropDuration();
166 m_transitionStart = t->startPos();
167 transitionTrack->blockSignals(true);
168 m_usedTransition = t;
170 if (!t->forcedTrack())
171 transitionTrack->setCurrentIndex(0);
173 transitionTrack->setCurrentIndex(transitionTrack->findData(t->transitionEndTrack()));
174 transitionTrack->blockSignals(false);
175 int ix = transitionList->findData(t->transitionInfo(), Qt::UserRole, Qt::MatchExactly);
177 transitionList->blockSignals(true);
178 transitionList->setCurrentIndex(ix);
179 slotTransitionChanged(false, false);
180 transitionList->blockSignals(false);
183 // null transition selected
184 m_usedTransition = NULL;
186 m_effectEdit->transferParamDesc(QDomElement(), info, false);
191 void TransitionSettings::slotUpdateEffectParams(const QDomElement &oldparam, const QDomElement ¶m)
193 if (m_usedTransition) {
194 m_usedTransition->setTransitionParameters(param);
195 m_usedTransition->update();
197 //oldparam must be also first given to Transition and then return the toXML()
198 if (oldparam != param)
199 emit transitionUpdated(m_usedTransition, oldparam);
202 void TransitionSettings::raiseWindow(QWidget* dock)
204 if (dock && m_usedTransition)
209 void TransitionSettings::slotRenderPos(int pos)
211 if (m_usedTransition)
212 m_effectEdit->slotSyncEffectsPos(pos - m_usedTransition->startPos().frames(KdenliveSettings::project_fps()));
215 #include "transitionsettings.moc"