]> git.sesse.net Git - kdenlive/blob - src/effectstack/effectstackview2.cpp
New effectstack with collapsible effects, preparing for effect masks and groups
[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_view(NULL),
47         m_trackindex(-1)
48 {
49     m_effectMetaInfo.trackMode = false;
50     m_effectMetaInfo.monitor = monitor;
51
52     m_ui.setupUi(this);
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         kDebug()<<" - - -DELETE LAYOUT";
126         m_effects.clear();
127         delete m_view;
128         m_view = NULL;
129         m_ui.checkAll->setToolTip(QString());
130         m_ui.checkAll->setText(QString());
131         setEnabled(false);
132         return;
133     }
134     setEnabled(true);
135     m_effectMetaInfo.trackMode = false;
136     m_currentEffectList = m_clipref->effectList();
137     setupListView(ix);
138 }
139
140 void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo info)
141 {
142     m_clipref = NULL;
143     m_effectMetaInfo.trackMode = true;
144     m_currentEffectList = info.effectsList;
145     m_trackInfo = info;
146     setEnabled(true);
147     m_ui.checkAll->setToolTip(QString());
148     m_ui.checkAll->setText(i18n("Effects for track %1").arg(info.trackName.isEmpty() ? QString::number(ix) : info.trackName));
149     m_trackindex = ix;
150     setupListView(0);
151 }
152
153 void EffectStackView2::setupListView(int ix)
154 {
155     //TODO: clear list
156
157     kDebug()<<"++++++++++++++++++++++++++++++++   setup +++++++++++"<<ix;
158
159     blockSignals(true);
160     disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
161     m_effects.clear();
162     QLayoutItem *child;
163     QLayout *vbox = NULL;
164     if (m_view) vbox = m_view->layout();
165     if (vbox) {
166         while ((child = vbox->takeAt(0)) != 0) {
167             QWidget *wid = child->widget();
168             delete child;
169             if (wid) delete wid;
170         }
171     }
172     if (m_view) delete m_view;
173     blockSignals(false);
174     m_view = new QWidget(m_ui.container);
175     m_ui.container->setWidget(m_view);
176
177     QVBoxLayout *vbox1 = new QVBoxLayout(m_view);
178     vbox1->setContentsMargins(0, 0, 0, 0);
179     vbox1->setSpacing(0);
180
181     for (int i = 0; i < m_currentEffectList.count(); i++) {
182         QDomElement d = m_currentEffectList.at(i).cloneNode().toElement();
183         if (d.isNull()) {
184             kDebug() << " . . . . WARNING, NULL EFFECT IN STACK!!!!!!!!!";
185             continue;
186         }
187
188         /*QDomDocument doc;
189         doc.appendChild(doc.importNode(d, true));
190         kDebug() << "IMPORTED STK: " << doc.toString();*/
191
192         CollapsibleEffect *currentEffect = new CollapsibleEffect(d, m_clipref->info(), i, &m_effectMetaInfo, i == m_currentEffectList.count() - 1, m_view);
193         m_effects.append(currentEffect);
194         vbox1->addWidget(currentEffect);
195         connect(currentEffect, SIGNAL(parameterChanged(const QDomElement, const QDomElement, int)), this , SLOT(slotUpdateEffectParams(const QDomElement, const QDomElement, int)));
196         connect(currentEffect, SIGNAL(deleteEffect(const QDomElement, int)), this , SLOT(slotDeleteEffect(const QDomElement, int)));
197         connect(currentEffect, SIGNAL(changeEffectPosition(int,bool)), this , SLOT(slotMoveEffect(int , bool)));
198         connect(currentEffect, SIGNAL(effectStateChanged(bool, int)), this, SLOT(slotUpdateEffectState(bool, int)));
199         connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
200         connect(currentEffect, SIGNAL(checkMonitorPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
201         connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
202             //ui.title->setPixmap(icon.pixmap(QSize(12, 12)));
203     }
204     vbox1->addStretch(10);
205     connect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
206 }
207
208 void EffectStackView2::slotUpdateEffectState(bool disable, int index)
209 {
210     if (m_effectMetaInfo.trackMode)
211         emit changeEffectState(NULL, m_trackindex, index, disable);
212     else
213         emit changeEffectState(m_clipref, -1, index, disable);
214 }
215
216
217 void EffectStackView2::raiseWindow(QWidget* dock)
218 {
219     if ((m_clipref || m_effectMetaInfo.trackMode) && dock)
220         dock->raise();
221 }
222
223
224 void EffectStackView2::slotSeekTimeline(int pos)
225 {
226     if (m_effectMetaInfo.trackMode) {
227         emit seekTimeline(pos);
228     } else if (m_clipref) {
229         emit seekTimeline(m_clipref->startPos().frames(KdenliveSettings::project_fps()) + pos);
230     }
231 }
232
233
234 /*void EffectStackView2::slotRegionChanged()
235 {
236     if (!m_trackMode) emit updateClipRegion(m_clipref, m_ui.effectlist->currentRow(), m_ui.region_url->text());
237 }*/
238
239 void EffectStackView2::slotCheckMonitorPosition(int renderPos)
240 {
241     if (m_effectMetaInfo.trackMode || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
242         if (!m_effectMetaInfo.monitor->getEffectEdit()->getScene()->views().at(0)->isVisible())
243             m_effectMetaInfo.monitor->slotEffectScene(true);
244     } else {
245         m_effectMetaInfo.monitor->slotEffectScene(false);
246     }
247 }
248
249 int EffectStackView2::isTrackMode(bool *ok) const
250 {
251     *ok = m_effectMetaInfo.trackMode;
252     return m_trackindex;
253 }
254
255 void EffectStackView2::clear()
256 {
257 }
258
259 void EffectStackView2::updateProjectFormat(MltVideoProfile profile, Timecode t)
260 {
261     m_effectMetaInfo.profile = profile;
262     m_effectMetaInfo.timecode = t;
263 }
264
265 void EffectStackView2::slotItemDel()
266 {
267
268 }
269
270 void EffectStackView2::updateTimecodeFormat()
271 {
272     for (int i = 0; i< m_effects.count(); i++)
273         m_effects.at(i)->updateTimecodeFormat();
274 }
275
276 void EffectStackView2::slotUpdateEffectParams(const QDomElement old, const QDomElement e, int ix)
277 {
278     if (m_effectMetaInfo.trackMode)
279         emit updateEffect(NULL, m_trackindex, old, e, ix);
280     else if (m_clipref) {
281         emit updateEffect(m_clipref, -1, old, e, ix);
282         // Make sure the changed effect is currently displayed
283         slotSetCurrentEffect(ix);
284     }
285 }
286
287 void EffectStackView2::slotSetCurrentEffect(int ix)
288 {
289     if (ix != m_clipref->selectedEffectIndex())
290         m_clipref->setSelectedEffect(ix);
291     for (int i = 0; i < m_effects.count(); i++) {
292         m_effects.at(i)->setActive(i == ix);
293     }
294 }
295
296 void EffectStackView2::slotDeleteEffect(const QDomElement effect, int index)
297 {
298     
299     if (m_effectMetaInfo.trackMode)
300         emit removeEffect(NULL, m_trackindex, effect);
301     else
302         emit removeEffect(m_clipref, -1, effect);
303 }
304
305 void EffectStackView2::slotMoveEffect(int index, bool up)
306 {
307     if (up && index <= 0) return;
308     if (!up && index >= m_currentEffectList.count() - 1) return;
309     int startPos;
310     int endPos;
311     if (up) {
312         startPos =  index + 1;
313         endPos = index;
314     }
315     else {
316         startPos =  index + 1;
317         endPos =  index + 2;
318     }
319     if (m_effectMetaInfo.trackMode) emit changeEffectPosition(NULL, m_trackindex, startPos, endPos);
320     else emit changeEffectPosition(m_clipref, -1, startPos, endPos);
321 }
322
323 #include "effectstackview2.moc"