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