]> git.sesse.net Git - kdenlive/blob - src/effectstack/effectstackview2.cpp
Implement reset effect in new effect stack
[kdenlive] / src / effectstack / effectstackview2.cpp
1 /***************************************************************************
2                           effecstackview.cpp2  -  description
3                              -------------------
4     begin                : Feb 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 #include "effectstackview2.h"
20 #include "effectslist.h"
21 #include "clipitem.h"
22 #include "mainwindow.h"
23 #include "docclipbase.h"
24 #include "projectlist.h"
25 #include "kthumb.h"
26 #include "monitoreditwidget.h"
27 #include "monitorscene.h"
28 #include "kdenlivesettings.h"
29
30 #include <KDebug>
31 #include <KLocale>
32 #include <KMessageBox>
33 #include <KStandardDirs>
34 #include <KFileDialog>
35 #include <KColorScheme>
36
37 #include <QMenu>
38 #include <QTextStream>
39 #include <QFile>
40 #include <QInputDialog>
41
42
43 EffectStackView2::EffectStackView2(Monitor *monitor, QWidget *parent) :
44         QWidget(parent),
45         m_clipref(NULL),
46         m_trackindex(-1)
47 {
48     m_effectMetaInfo.trackMode = false;
49     m_effectMetaInfo.monitor = monitor;
50
51     m_ui.setupUi(this);
52     setFont(KGlobalSettings::smallestReadableFont());
53     m_ui.checkAll->setToolTip(i18n("Enable/Disable all effects"));
54     m_ui.buttonShowComments->setIcon(KIcon("help-about"));
55     m_ui.buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
56
57
58     setEnabled(false);
59
60     QPalette p = palette();
61     KColorScheme scheme(p.currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
62     QColor dark_bg = scheme.shade(KColorScheme::DarkShade);
63     QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
64     QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
65     QColor light_bg = scheme.shade(KColorScheme::LightShade);
66     
67     QString stylesheet(QString("QProgressBar:horizontal {border: 1px solid %1;border-radius:0px;border-top-left-radius: 4px;border-bottom-left-radius: 4px;border-right: 0px;background:%4;padding: 0px;text-align:left center}\
68                                 QProgressBar:horizontal#dragOnly {background: %1} QProgressBar:horizontal:hover#dragOnly {background: %3} QProgressBar:horizontal:hover {border: 1px solid %3;border-right: 0px;}\
69                                 QProgressBar::chunk:horizontal {background: %1;} QProgressBar::chunk:horizontal:hover {background: %3;}\
70                                 QProgressBar:horizontal[inTimeline=\"true\"] { border: 1px solid %2;border-right: 0px;background: %4;padding: 0px;text-align:left center } QProgressBar::chunk:horizontal[inTimeline=\"true\"] {background: %2;}\
71                                 QAbstractSpinBox#dragBox {border: 1px solid %1;border-top-right-radius: 4px;border-bottom-right-radius: 4px;padding-right:0px;} QAbstractSpinBox::down-button#dragBox {width:0px;padding:0px;}\
72                                 QAbstractSpinBox::up-button#dragBox {width:0px;padding:0px;} QAbstractSpinBox[inTimeline=\"true\"]#dragBox { border: 1px solid %2;} QAbstractSpinBox:hover#dragBox {border: 1px solid %3;} ")
73                                 .arg(dark_bg.name()).arg(selected_bg.name()).arg(hover_bg.name()).arg(light_bg.name()));
74     setStyleSheet(stylesheet);
75 }
76
77 EffectStackView2::~EffectStackView2()
78 {
79 }
80
81
82 void EffectStackView2::slotRenderPos(int pos)
83 {
84     if (m_effects.isEmpty()) return;
85     if (!m_effectMetaInfo.trackMode && m_clipref) pos = pos - m_clipref->startPos().frames(KdenliveSettings::project_fps());
86
87     for (int i = 0; i< m_effects.count(); i++)
88         m_effects.at(i)->slotSyncEffectsPos(pos);
89 }
90
91 void EffectStackView2::setMenu(QMenu *menu)
92 {
93     //m_ui.buttonNew->setMenu(menu);
94 }
95
96 void EffectStackView2::slotClipItemSelected(ClipItem* c, int ix)
97 {
98     if (c && !c->isEnabled()) return;
99     if (c && c == m_clipref) {
100         
101     } else {
102         m_clipref = c;
103         if (c) {
104             QString cname = m_clipref->clipName();
105             if (cname.length() > 30) {
106                 m_ui.checkAll->setToolTip(i18n("Effects for %1").arg(cname));
107                 cname.truncate(27);
108                 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "...");
109             } else {
110                 m_ui.checkAll->setToolTip(QString());
111                 m_ui.checkAll->setText(i18n("Effects for %1").arg(cname));
112             }
113             ix = c->selectedEffectIndex();
114             QString size = c->baseClip()->getProperty("frame_size");
115             double factor = c->baseClip()->getProperty("aspect_ratio").toDouble();
116             m_effectMetaInfo.frameSize = QPoint((int)(size.section('x', 0, 0).toInt() * factor + 0.5), size.section('x', 1, 1).toInt());
117         } else {
118             ix = 0;
119         }
120     }
121     if (m_clipref == NULL) {
122         //TODO: clear list, reset paramdesc and info
123         //ItemInfo info;
124         //m_effectedit->transferParamDesc(QDomElement(), info);
125         m_effects.clear();
126         QWidget *view = m_ui.container->takeWidget();
127         if (view) {
128             if (view->layout()) clearLayout(view->layout());
129             delete view;
130         }
131         m_ui.checkAll->setToolTip(QString());
132         m_ui.checkAll->setText(QString());
133         setEnabled(false);
134         return;
135     }
136     setEnabled(true);
137     m_effectMetaInfo.trackMode = false;
138     m_currentEffectList = m_clipref->effectList();
139     setupListView(ix);
140 }
141
142 void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
143 {
144     m_clipref = NULL;
145     m_effectMetaInfo.trackMode = true;
146     m_currentEffectList = info.effectsList;
147     m_trackInfo = info;
148     setEnabled(true);
149     m_ui.checkAll->setToolTip(QString());
150     m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
151     m_trackindex = ix;
152     setupListView(0);
153 }
154
155 void EffectStackView2::clearLayout(QLayout *layout)
156 {
157     QLayoutItem *item;
158     while((item = layout->takeAt(0))) {
159         if (item->layout()) {
160             clearLayout(item->layout());
161             delete item->layout();
162         }
163         if (item->widget()) {
164             delete item->widget();
165         }
166         delete item;
167     }
168 }
169
170 void EffectStackView2::setupListView(int ix)
171 {
172     //TODO: clear list
173
174     kDebug()<<"++++++++++++++++++++++++++++++++   setup: "<<children().count();
175
176     blockSignals(true);
177     disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
178     m_effects.clear();
179     QWidget *view = m_ui.container->takeWidget();
180     if (view) {
181         if (view->layout()) clearLayout(view->layout());
182         delete view;
183     }
184     blockSignals(false);
185     view = new QWidget(m_ui.container);
186     m_ui.container->setWidget(view);
187
188     QVBoxLayout *vbox1 = new QVBoxLayout(view);
189     vbox1->setContentsMargins(0, 0, 0, 0);
190     vbox1->setSpacing(0);
191
192     for (int i = 0; i < m_currentEffectList.count(); i++) {
193         QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
194         if (d.isNull()) {
195             kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
196             continue;
197         }
198
199         /*QDomDocument doc;
200         doc.appendChild(doc.importNode(d, true));
201         kDebug() << "IMPORTED STK: " << doc.toString();*/
202
203         CollapsibleEffect *currentEffect = new CollapsibleEffect(d, m_currentEffectList.at(i), m_clipref->info(), i, &m_effectMetaInfo, i == m_currentEffectList.count() - 1, view);
204         m_effects.append(currentEffect);
205         vbox1->addWidget(currentEffect);
206         connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
207         connect(currentEffect, SIGNAL(startFilterJob(QString,QString,QString,QString,QString,QString)), this , SLOT(slotStartFilterJob(QString,QString,QString,QString,QString,QString)));
208         connect(currentEffect, SIGNAL(deleteEffect(const QDomElement, int)), this , SLOT(slotDeleteEffect(const QDomElement, int)));
209         connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
210         connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
211         connect(currentEffect, SIGNAL(changeEffectPosition(int,bool)), this , SLOT(slotMoveEffect(int , bool)));
212         connect(currentEffect, SIGNAL(effectStateChanged(bool, int)), this, SLOT(slotUpdateEffectState(bool, int)));
213         connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
214         connect(currentEffect, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
215         connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
216             //ui.title->setPixmap(icon.pixmap(QSize(12, 12)));
217     }
218     vbox1->addStretch(10);
219     connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
220 }
221
222
223 void EffectStackView2::slotUpdateEffectState(bool disable, int index)
224 {
225     if (m_effectMetaInfo.trackMode)
226         emit changeEffectState(NULL, m_trackindex, index, disable);
227     else
228         emit changeEffectState(m_clipref, -1, index, disable);
229 }
230
231
232 void EffectStackView2::raiseWindow(QWidget* dock)
233 {
234     if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
235         dock->raise();
236 }
237
238
239 void EffectStackView2::slotSeekTimeline(int pos)
240 {
241     if (m_effectMetaInfo.trackMode) {
242         emit seekTimeline(pos);
243     } else if (m_clipref) {
244         emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
245     }
246 }
247
248
249 /*void EffectStackView2::slotRegionChanged()
250 {
251     if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
252 }*/
253
254 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
255 {
256     if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
257         if (!m_effectMetaInfo.monitor->getEffectEdit()->getScene()->views().at(0)->isVisible())
258             m_effectMetaInfo.monitor->slotEffectScene(true);
259     } else {
260         m_effectMetaInfo.monitor->slotEffectScene(false);
261     }
262 }
263
264 int EffectStackView2::isTrackMode(bool *ok) const
265 {
266     *ok = m_effectMetaInfo.trackMode;
267     return m_trackindex;
268 }
269
270 void EffectStackView2::clear()
271 {
272 }
273
274 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
275 {
276     m_effectMetaInfo.profile = profile;
277     m_effectMetaInfo.timecode = t;
278 }
279
280 void EffectStackView2::slotItemDel()
281 {
282
283 }
284
285 void EffectStackView2::updateTimecodeFormat()
286 {
287     for (int i = 0; i< m_effects.count(); i++)
288         m_effects.at(i)->updateTimecodeFormat();
289 }
290
291 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
292 {
293     if (m_effectMetaInfo.trackMode)
294         emit updateEffect(NULL, m_trackindex, old, e, ix);
295     else if (m_clipref) {
296         emit updateEffect(m_clipref, -1, old, e, ix);
297         // Make sure the changed effect is currently displayed
298         slotSetCurrentEffect(ix);
299     }
300 }
301
302 void EffectStackView2::slotSetCurrentEffect(int ix)
303 {
304     if (ix != m_clipref->selectedEffectIndex())
305         m_clipref->setSelectedEffect(ix);
306     for (int i = 0; i < m_effects.count(); i++) {
307         m_effects.at(i)->setActive(i == ix);
308     }
309 }
310
311 void EffectStackView2::slotDeleteEffect(const QDomElement effect, int index)
312 {
313     
314     if (m_effectMetaInfo.trackMode)
315         emit removeEffect(NULL, m_trackindex, effect);
316     else
317         emit removeEffect(m_clipref, -1, effect);
318 }
319
320 void EffectStackView2::slotMoveEffect(int index, bool up)
321 {
322     if (up && index <= 0) return;
323     if (!up && index >= m_currentEffectList.count() - 1) return;
324     int startPos;
325     int endPos;
326     if (up) {
327         startPos =  index + 1;
328         endPos = index;
329     }
330     else {
331         startPos =  index + 1;
332         endPos =  index + 2;
333     }
334     if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, startPos, endPos);
335     else emit changeEffectPosition(m_clipref, -1, startPos, endPos);
336 }
337
338 void EffectStackView2::slotStartFilterJob(const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
339 {
340     if (!m_clipref) return;
341     emit startFilterJob(m_clipref->info(), m_clipref->clipProducer(), filterName, filterParams, finalFilterName, consumer, consumerParams, properties);
342 }
343
344 void EffectStackView2::slotResetEffect(int ix)
345 {
346     QDomElement old = m_currentEffectList.at(ix);
347     QDomElement dom;
348     QString effectId = old.attribute("id");
349     QMap<QString, EffectsList*> effectLists;
350     effectLists["audio"] = &MainWindow::audioEffects;
351     effectLists["video"] = &MainWindow::videoEffects;
352     effectLists["custom"] = &MainWindow::customEffects;
353     foreach(const QString &type, effectLists.keys()) {
354         EffectsList *list = effectLists[type];
355         dom = list->getEffectByTag(QString(), effectId).cloneNode().toElement();
356         if (!dom.isNull()) break;
357     }
358     if (!dom.isNull()) {
359         dom.setAttribute("kdenlive_ix", old.attribute("kdenlive_ix"));
360         //TODO: Track mode
361         /*if (m_trackMode) {
362             EffectsList::setParameter(dom, "in", QString::number(0));
363             EffectsList::setParameter(dom, "out", QString::number(m_trackInfo.duration));
364             ItemInfo info;
365             info.track = m_trackInfo.type;
366             info.cropDuration = GenTime(m_trackInfo.duration, KdenliveSettings::project_fps());
367             info.cropStart = GenTime(0);
368             info.startPos = GenTime(-1);
369             info.track = 0;
370             m_effectedit->transferParamDesc(dom, info);
371             emit updateEffect(NULL, m_trackindex, old, dom, activeRow);
372         } else*/ {
373             m_clipref->initEffect(dom);
374             m_effects.at(ix)->updateWidget(m_clipref->info(), ix, dom, &m_effectMetaInfo);
375             //m_effectedit->transferParamDesc(dom, m_clipref->info());
376             //m_ui.region_url->setUrl(KUrl(dom.attribute("region")));
377             emit updateEffect(m_clipref, -1, old, dom, ix);
378         }
379     }
380
381     /*emit showComments(m_ui.buttonShowComments->isChecked());
382     m_ui.labelComment->setHidden(!m_ui.buttonShowComments->isChecked() || !m_ui.labelComment->text().count());*/
383 }
384
385 #include "effectstackview2.moc"