]> git.sesse.net Git - kdenlive/blob - src/keyframeedit.h
Make the keyframe parameter which can be edited in timeline selectable
[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 class QButtonGroup;
29
30 #include "ui_keyframeeditor_ui.h"
31 #include "definitions.h"
32 #include "keyframehelper.h"
33
34 class KeyItemDelegate: public QItemDelegate
35 {
36     Q_OBJECT
37 public:
38     KeyItemDelegate(int min, int max, QAbstractItemView* parent = 0): QItemDelegate(parent), m_min(min), m_max(max) {
39     }
40
41     QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
42         if (index.column() == 1) {
43             QSpinBox *spin = new QSpinBox(parent);
44             connect(spin, SIGNAL(valueChanged(int)), this, SLOT(commitEditorData()));
45             connect(spin, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
46             return spin;
47         } else {
48             return QItemDelegate::createEditor(parent, option, index);
49         }
50     }
51
52
53     void setEditorData(QWidget *editor, const QModelIndex &index) const {
54         if (index.column() == 1) {
55             QSpinBox *spin = qobject_cast< QSpinBox* >(editor);
56             spin->setRange(m_min, m_max);
57             spin->setValue(index.model()->data(index).toInt());
58         } else {
59             QItemDelegate::setEditorData(editor, index);
60         }
61     }
62
63 private slots:
64     void commitAndCloseEditor() {
65         QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
66         emit closeEditor(spin);
67     }
68
69     void commitEditorData() {
70         QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
71         emit commitData(spin);
72     }
73
74 private:
75     int m_min;
76     int m_max;
77 };
78
79 class KeyframeEdit : public QWidget, public Ui::KeyframeEditor_UI
80 {
81     Q_OBJECT
82 public:
83     explicit KeyframeEdit(QDomElement e, int minFrame, int maxFrame, Timecode tc, int activeKeyframe, QWidget* parent = 0);
84     virtual ~KeyframeEdit();
85     void addParameter(QDomElement e, int activeKeyframe = -1);
86     const QString getValue(const QString &name);
87     /** @brief Updates the timecode display according to settings (frame number or hh:mm:ss:ff) */
88     void updateTimecodeFormat();
89
90     /** @brief Returns true if the parameter @param name should be shown on the clip in timeline. */
91     bool isVisibleParam(const QString &name);
92
93 private:
94     QList <QDomElement> m_params;
95     int m_min;
96     int m_max;
97     Timecode m_timecode;
98     QGridLayout *m_slidersLayout;
99     QButtonGroup *m_showButtons;
100
101     void generateAllParams();
102     /** @brief Gets the position of a keyframe from the table.
103     * @param row Row of the keyframe in the table */
104     int getPos(int row);
105     /** @brief Converts a frame value to timecode considering the frames vs. HH:MM:SS:FF setting.
106     * @return timecode */
107     QString getPosString(int pos);
108
109 private slots:
110     void slotDeleteKeyframe();
111     void slotAddKeyframe();
112     void slotGenerateParams(int row, int column);
113     void slotAdjustKeyframeInfo(bool seek = true);
114     void slotAdjustKeyframePos(int value);
115     void slotAdjustKeyframeValue(int value);
116     /** @brief Turns the seek to keyframe position setting on/off.
117     * @param seek true = seeking on */
118     void slotSetSeeking(bool seek);
119
120     /** @brief Shows the keyframe table and adds a second keyframe. */
121     void slotKeyframeMode();
122
123     /** @brief Resets all parameters of the selected keyframe to their default values. */
124     void slotResetKeyframe();
125
126     /** @brief Makes the parameter at column @param id the visible (in timeline) one. */
127     void slotUpdateVisibleParameter(int id);
128
129 signals:
130     void parameterChanged();
131     void seekToPos(int);
132 };
133
134 #endif