]> git.sesse.net Git - kdenlive/blob - src/keyframeedit.h
First steps for effects with several keyframable parameters
[kdenlive] / src / keyframeedit.h
1 /***************************************************************************
2                           keyframeedit.h  -  description
3                              -------------------
4     begin                : 22 Jun 2009
5     copyright            : (C) 2008 by Jean-Baptiste Mardelle
6     email                : jb@kdenlive.org
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 #ifndef KEYFRAMEEDIT_H
19 #define KEYFRAMEEDIT_H
20
21
22 #include <QWidget>
23 #include <QDomElement>
24 #include <QItemDelegate>
25 #include <QAbstractItemView>
26 #include <QSpinBox>
27
28
29 #include "ui_keyframeeditor_ui.h"
30 #include "definitions.h"
31 #include "keyframehelper.h"
32
33 class KeyItemDelegate: public QItemDelegate
34 {
35     Q_OBJECT
36 public:
37     KeyItemDelegate(int min, int max, QAbstractItemView* parent = 0): QItemDelegate(parent), m_min(min), m_max(max) {
38     }
39
40     QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
41         if (index.column() == 1) {
42             QSpinBox *spin = new QSpinBox(parent);
43             connect(spin, SIGNAL(valueChanged(int)), this, SLOT(commitEditorData()));
44             connect(spin, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
45             return spin;
46         } else return QItemDelegate::createEditor(parent, option, index);
47     }
48
49
50     void setEditorData(QWidget *editor, const QModelIndex &index) const {
51         if (index.column() == 1) {
52             QSpinBox *spin = qobject_cast< QSpinBox* >(editor);
53             spin->setRange(m_min, m_max);
54             spin->setValue(index.model()->data(index).toInt());
55         } else QItemDelegate::setEditorData(editor, index);
56     }
57
58 private slots:
59     void commitAndCloseEditor() {
60         QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
61         emit closeEditor(spin);
62     }
63
64     void commitEditorData() {
65         QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
66         emit commitData(spin);
67     }
68
69 private:
70     int m_min;
71     int m_max;
72 };
73
74 class KeyframeEdit : public QWidget, public Ui::KeyframeEditor_UI
75 {
76     Q_OBJECT
77 public:
78     explicit KeyframeEdit(QDomElement e, int maxFrame, int minVal, int maxVal, Timecode tc, const QString paramName = QString(), QWidget* parent = 0);
79     virtual ~KeyframeEdit();
80     void setupParam(QDomElement e = QDomElement());
81     void addParameter(QDomElement e);
82
83 private:
84     QDomElement m_param;
85     int m_max;
86     int m_minVal;
87     int m_maxVal;
88     Timecode m_timecode;
89     int m_previousPos;
90     KeyItemDelegate *m_delegate;
91
92 public slots:
93
94
95 private slots:
96     void slotDeleteKeyframe();
97     void slotAddKeyframe();
98     void slotGenerateParams(QTreeWidgetItem *item = NULL, int column = -1);
99     void slotAdjustKeyframeInfo();
100     void slotAdjustKeyframePos(int value);
101     void slotAdjustKeyframeValue(int value);
102     void slotSaveCurrentParam(QTreeWidgetItem *item, int column);
103
104 signals:
105     void parameterChanged();
106     void seekToPos(int);
107 };
108
109 #endif