]> git.sesse.net Git - kdenlive/blob - src/effectstack/collapsibleeffect.h
Fix drag & drop of effects and groups in effect stack:
[kdenlive] / src / effectstack / collapsibleeffect.h
1 /***************************************************************************
2  *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21 #ifndef COLLAPSIBLEEFFECT_H
22 #define COLLAPSIBLEEFFECT_H
23
24
25 #include "ui_collapsiblewidget_ui.h"
26
27 #include "abstractcollapsiblewidget.h"
28 #include "timecode.h"
29 #include "keyframeedit.h"
30
31 #include <QDomElement>
32 #include <QToolButton>
33
34 class QFrame;
35 class Monitor;
36 class GeometryWidget;
37
38 struct EffectMetaInfo {
39     MltVideoProfile profile;
40     Timecode timecode;
41     Monitor *monitor;
42     QPoint frameSize;
43     bool trackMode;
44 };
45
46 enum WIPE_DIRECTON { UP = 0, DOWN = 1, LEFT = 2, RIGHT = 3, CENTER = 4 };
47
48 struct wipeInfo {
49     WIPE_DIRECTON start;
50     WIPE_DIRECTON end;
51     int startTransparency;
52     int endTransparency;
53 };
54
55 class MySpinBox : public QSpinBox
56 {
57     Q_OBJECT
58
59 public:
60     MySpinBox(QWidget * parent = 0);
61     
62 protected:
63     virtual void focusInEvent(QFocusEvent*);
64     virtual void focusOutEvent(QFocusEvent*);
65 };
66
67 class ParameterContainer : public QObject
68 {
69     Q_OBJECT
70
71 public:
72     ParameterContainer(QDomElement effect, ItemInfo info, EffectMetaInfo *metaInfo, QWidget * parent = 0);
73     ~ParameterContainer();
74     void updateTimecodeFormat();
75     void updateProjectFormat(MltVideoProfile profile, Timecode t);
76     void updateParameter(const QString &key, const QString &value);
77
78 private slots:
79     void slotCollectAllParameters();
80     void slotStartFilterJobAction();
81
82 private:
83         /** @brief Updates parameter @param name according to new value of dependency.
84     * @param name Name of the parameter which will be updated
85     * @param type Type of the parameter which will be updated
86     * @param value Value of the dependency parameter */
87     void meetDependency(const QString& name, QString type, QString value);
88     wipeInfo getWipeInfo(QString value);
89     QString getWipeString(wipeInfo info);
90     
91     int m_in;
92     int m_out;
93     QList<QWidget*> m_uiItems;
94     QMap<QString, QWidget*> m_valueItems;
95     Timecode m_timecode;
96     KeyframeEdit *m_keyframeEditor;
97     GeometryWidget *m_geometryWidget;
98     EffectMetaInfo *m_metaInfo;
99     QDomElement m_effect;
100     QVBoxLayout *m_vbox;
101
102 signals:
103     void parameterChanged(const QDomElement, const QDomElement, int);
104     void syncEffectsPos(int);
105     void effectStateChanged(bool);
106     void checkMonitorPosition(int);
107     void seekTimeline(int);
108     void showComments(bool);    
109     /** @brief Start an MLT filter job on this clip. */
110     void startFilterJob(QString filterName, QString filterParams, QString finalFilterName, QString consumer, QString consumerParams, QString properties);
111     
112 };
113
114 /**)
115  * @class CollapsibleEffect
116  * @brief A dialog for editing markers and guides.
117  * @author Jean-Baptiste Mardelle
118  */
119
120 class CollapsibleEffect : public AbstractCollapsibleWidget, public Ui::CollapsibleWidget_UI
121 {
122     Q_OBJECT
123
124 public:
125     CollapsibleEffect(QDomElement effect, QDomElement original_effect, ItemInfo info, EffectMetaInfo *metaInfo, bool lastEffect, QWidget * parent = 0);
126     ~CollapsibleEffect();
127     static QMap<QString, QImage> iconCache;
128     void setupWidget(ItemInfo info, EffectMetaInfo *metaInfo);
129     void updateTimecodeFormat();
130     void setActive(bool activate);
131     /** @brief Install event filter so that scrolling with mouse wheel does not change parameter value. */
132     virtual bool eventFilter( QObject * o, QEvent * e );
133     /** @brief Update effect GUI to reflect parameted changes. */
134     void updateWidget(ItemInfo info, QDomElement effect, EffectMetaInfo *metaInfo);
135     QDomElement effect() const;
136     int groupIndex() const;
137     bool isGroup() const;
138     int effectIndex() const;
139     void setGroupIndex(int ix);
140     void setGroupName(const QString &groupName);
141     /** @brief Remove this effect from its group. */
142     void removeFromGroup();
143     QString infoString() const;
144     bool isActive() const;
145     /** @brief Should the wheel event be sent to parent widget for scrolling. */
146     bool filterWheelEvent;
147     /** @brief Return the stylesheet required for effect parameters. */
148     static const QString getStyleSheet();
149     /** @brief Parent group was collapsed, update. */
150     void groupStateChanged(bool collapsed);
151
152 public slots:
153     void slotSyncEffectsPos(int pos);
154     void slotEnable(bool enable, bool updateMainStatus = true);
155     void slotResetEffect();
156
157 private slots:
158     void slotSwitch();
159     void slotShow(bool show);
160     void slotDeleteEffect();
161     void slotEffectUp();
162     void slotEffectDown();
163     void slotSaveEffect();
164     void slotCreateGroup();
165     void slotCreateRegion();
166     void slotUnGroup();
167     /** @brief A sub effect parameter was changed */
168     void slotUpdateRegionEffectParams(const QDomElement /*old*/, const QDomElement /*e*/, int /*ix*/);
169
170 private:
171     ParameterContainer *m_paramWidget;
172     QList <CollapsibleEffect *> m_subParamWidgets;
173     QDomElement m_effect;
174     QDomElement m_original_effect;
175     QList <QDomElement> m_subEffects;
176     bool m_lastEffect;
177     int m_in;
178     int m_out;
179     QMenu *m_menu;
180     QPoint m_clickPoint;
181     EffectInfo m_info;
182     /** @brief True if this is a region effect, which behaves in a special way, like a group. */
183     bool m_regionEffect;
184     /** @brief Check if collapsed state changed and inform MLT. */
185     void updateCollapsedState();
186     
187 protected:
188     virtual void mouseDoubleClickEvent ( QMouseEvent * event );
189     virtual void mouseReleaseEvent( QMouseEvent *event );
190     virtual void dragEnterEvent(QDragEnterEvent *event);
191     virtual void dragLeaveEvent(QDragLeaveEvent *event);
192     virtual void dropEvent(QDropEvent *event);
193     
194 signals:
195     void parameterChanged(const QDomElement, const QDomElement, int);
196     void syncEffectsPos(int);
197     void effectStateChanged(bool, int ix = -1, bool updateMainStatus = true);
198     void deleteEffect(const QDomElement);
199     void changeEffectPosition(int, bool);
200     void activateEffect(int);
201     void checkMonitorPosition(int);
202     void seekTimeline(int);
203     /** @brief Start an MLT filter job on this clip. */
204     void startFilterJob(QString filterName, QString filterParams, QString finalFilterName, QString consumer, QString consumerParams, QString properties);
205     /** @brief An effect was saved, trigger effect list reload. */
206     void reloadEffects();
207     /** @brief An effect was reset, trigger param reload. */
208     void resetEffect(int ix);
209     /** @brief Ask for creation of a group. */
210     void createGroup(int ix);
211     void moveEffect(QList <int> current_pos, int new_pos, int groupIndex, QString groupName);
212     void unGroup(CollapsibleEffect *);
213     void addEffect(QDomElement e);
214     void createRegion(int, KUrl);
215     void deleteGroup(QDomDocument);
216 };
217
218
219 #endif
220