]> git.sesse.net Git - kdenlive/blob - src/effectstackedit.cpp
Fix label
[kdenlive] / src / effectstackedit.cpp
1 /***************************************************************************
2                           effecstackedit.cpp  -  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 #include "effectstackedit.h"
19 #include "effectstack/effectstackview2.h"
20 #include "effectslist.h"
21 #include "monitor.h"
22 #include "kdenlivesettings.h"
23
24 #include <KDebug>
25 #include <KLocale>
26 #include <KFileDialog>
27 #include <KComboBox>
28
29 #include <QVBoxLayout>
30 #include <QLabel>
31 #include <QPushButton>
32 #include <QCheckBox>
33 #include <QScrollArea>
34 #include <QScrollBar>
35 #include <QProgressBar>
36 #include <QWheelEvent>
37
38 // For QDomNode debugging (output into files); leaving here as sample code.
39 //#define DEBUG_ESE
40
41
42 EffectStackEdit::EffectStackEdit(Monitor *monitor, QWidget *parent) :
43     QScrollArea(parent),
44     m_paramWidget(NULL)
45 {
46     m_baseWidget = new QWidget(this);
47     m_metaInfo.monitor = monitor;
48     m_metaInfo.trackMode = false;
49     setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
50     setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
51     setFrameStyle(QFrame::NoFrame);
52     setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
53     
54     setStyleSheet(EffectStackView2::getStyleSheet());
55     setWidget(m_baseWidget);
56     /*m_vbox = new QVBoxLayout(m_baseWidget);
57     m_vbox->setContentsMargins(0, 0, 0, 0);
58     m_vbox->setSpacing(2);    */
59     setWidgetResizable(true);
60 }
61
62 EffectStackEdit::~EffectStackEdit()
63 {
64     delete m_baseWidget;
65 }
66
67 Monitor *EffectStackEdit::monitor()
68 {
69     return m_metaInfo.monitor;
70 }
71
72 void EffectStackEdit::updateProjectFormat(const MltVideoProfile &profile, const Timecode &t)
73 {
74     m_metaInfo.profile = profile;
75     m_metaInfo.timecode = t;
76 }
77
78 void EffectStackEdit::setFrameSize(const QPoint &p)
79 {
80     m_metaInfo.frameSize = p;
81 }
82
83 void EffectStackEdit::updateTimecodeFormat()
84 {
85     if (m_paramWidget) m_paramWidget->updateTimecodeFormat();
86 }
87
88 void EffectStackEdit::updateParameter(const QString &name, const QString &value)
89 {
90     m_paramWidget->updateParameter(name, value);
91
92     if (name == "disable") {
93         // if effect is disabled, disable parameters widget
94         bool enabled = value.toInt() == 0 || !KdenliveSettings::disable_effect_parameters();
95         setEnabled(enabled);
96         emit effectStateChanged(enabled);
97     }
98 }
99
100 bool EffectStackEdit::eventFilter( QObject * o, QEvent * e ) 
101 {
102     if (e->type() == QEvent::Wheel) {
103         QWheelEvent *we = static_cast<QWheelEvent *>(e);
104         bool filterWheel = verticalScrollBar() && verticalScrollBar()->isVisible();
105         if (!filterWheel || we->modifiers() != Qt::NoModifier) {
106             e->accept();
107             return false;
108         }
109         if (qobject_cast<QAbstractSpinBox*>(o)) {
110             if(qobject_cast<QAbstractSpinBox*>(o)->focusPolicy() == Qt::WheelFocus)
111             {
112                 e->accept();
113                 return false;
114             }
115             else
116             {
117                 e->ignore();
118                 return true;
119             }
120         }
121         if (qobject_cast<KComboBox*>(o)) {
122             if(qobject_cast<KComboBox*>(o)->focusPolicy() == Qt::WheelFocus)
123             {
124                 e->accept();
125                 return false;
126             }
127             else
128             {
129                 e->ignore();
130                 return true;
131             }
132         }
133         if (qobject_cast<QProgressBar*>(o)) {
134             if(qobject_cast<QProgressBar*>(o)->focusPolicy() == Qt::WheelFocus)
135             {
136                 e->accept();
137                 return false;
138             }
139             else
140             {
141                 e->ignore();
142                 return true;
143             }
144         }
145     }
146     return QWidget::eventFilter(o, e);
147 }
148
149 void EffectStackEdit::transferParamDesc(const QDomElement &d, ItemInfo info, bool /*isEffect*/)
150 {
151     if (m_paramWidget) delete m_paramWidget;
152     m_paramWidget = new ParameterContainer(d, info, &m_metaInfo, m_baseWidget);
153     connect (m_paramWidget, SIGNAL(parameterChanged(QDomElement,QDomElement,int)), this, SIGNAL(parameterChanged(QDomElement,QDomElement,int)));
154     
155     connect(m_paramWidget, SIGNAL(startFilterJob(QString,QString,QString,QString,QMap<QString,QString>)), this, SIGNAL(startFilterJob(QString,QString,QString,QString,QMap<QString,QString>)));
156     
157     connect (this, SIGNAL(syncEffectsPos(int)), m_paramWidget, SIGNAL(syncEffectsPos(int)));
158     connect (m_paramWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
159     connect (m_paramWidget, SIGNAL(seekTimeline(int)), this, SIGNAL(seekTimeline(int)));
160     connect (m_paramWidget, SIGNAL(importClipKeyframes()), this, SIGNAL(importClipKeyframes()));
161     
162     Q_FOREACH( QSpinBox * sp, m_baseWidget->findChildren<QSpinBox*>() ) {
163         sp->installEventFilter( this );
164         sp->setFocusPolicy( Qt::StrongFocus );
165     }
166     Q_FOREACH( KComboBox * cb, m_baseWidget->findChildren<KComboBox*>() ) {
167         cb->installEventFilter( this );
168         cb->setFocusPolicy( Qt::StrongFocus );
169     }
170     Q_FOREACH( QProgressBar * cb, m_baseWidget->findChildren<QProgressBar*>() ) {
171         cb->installEventFilter( this );
172         cb->setFocusPolicy( Qt::StrongFocus );
173     }
174 }
175
176 void EffectStackEdit::slotSyncEffectsPos(int pos)
177 {
178     emit syncEffectsPos(pos);
179 }
180
181 bool EffectStackEdit::needsMonitorEffectScene() const
182 {
183     if (!m_paramWidget) return false;
184     return m_paramWidget->needsMonitorEffectScene();
185 }
186
187 void EffectStackEdit::setKeyframes(const QString &data, int maximum)
188 {
189     if (!m_paramWidget) return;
190     m_paramWidget->setKeyframes(data, maximum);
191 }
192
193
194 #include "effectstackedit.moc"