1 /***************************************************************************
2 keyframeedit.h - description
5 copyright : (C) 2008 by Jean-Baptiste Mardelle
6 email : jb@kdenlive.org
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
18 #ifndef KEYFRAMEEDIT_H
19 #define KEYFRAMEEDIT_H
23 #include <QDomElement>
24 #include <QItemDelegate>
25 #include <QAbstractItemView>
31 #include "ui_keyframeeditor_ui.h"
32 #include "definitions.h"
33 #include "keyframehelper.h"
35 class KeyItemDelegate: public QItemDelegate
39 KeyItemDelegate(int min, int max, QAbstractItemView* parent = 0): QItemDelegate(parent), m_min(min), m_max(max) {
42 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
43 if (index.column() == 1) {
44 QSpinBox *spin = new QSpinBox(parent);
45 connect(spin, SIGNAL(valueChanged(int)), this, SLOT(commitEditorData()));
46 connect(spin, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
49 return QItemDelegate::createEditor(parent, option, index);
54 void setEditorData(QWidget *editor, const QModelIndex &index) const {
55 if (index.column() == 1) {
56 QSpinBox *spin = qobject_cast< QSpinBox* >(editor);
57 spin->setRange(m_min, m_max);
58 spin->setValue(index.model()->data(index).toInt());
60 QItemDelegate::setEditorData(editor, index);
65 void commitAndCloseEditor() {
66 QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
67 emit closeEditor(spin);
70 void commitEditorData() {
71 QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
72 emit commitData(spin);
80 class KeyframeEdit : public QWidget, public Ui::KeyframeEditor_UI
84 explicit KeyframeEdit(QDomElement e, int minFrame, int maxFrame, Timecode tc, int activeKeyframe, QWidget* parent = 0);
85 virtual ~KeyframeEdit();
86 virtual void addParameter(QDomElement e, int activeKeyframe = -1);
87 const QString getValue(const QString &name);
88 /** @brief Updates the timecode display according to settings (frame number or hh:mm:ss:ff) */
89 void updateTimecodeFormat();
91 /** @brief Returns true if the parameter @param name should be shown on the clip in timeline. */
92 bool isVisibleParam(const QString &name);
94 /** @brief Makes the first parameter visible in timeline if no parameter is selected. */
95 void checkVisibleParam();
99 void slotUpdateRange(int inPoint, int outPoint);
102 /** @brief Gets the position of a keyframe from the table.
103 * @param row Row of the keyframe in the table */
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);
109 void generateAllParams();
115 void slotAdjustKeyframeInfo(bool seek = true);
118 QList <QDomElement> m_params;
120 QGridLayout *m_slidersLayout;
121 PositionEdit *m_position;
124 void slotDeleteKeyframe();
125 void slotAddKeyframe();
126 void slotGenerateParams(int row, int column);
127 void slotAdjustKeyframePos(int value);
128 void slotAdjustKeyframeValue(double value);
129 /** @brief Turns the seek to keyframe position setting on/off.
130 * @param seek true = seeking on */
131 void slotSetSeeking(bool seek);
133 /** @brief Shows the keyframe table and adds a second keyframe. */
134 void slotKeyframeMode();
136 /** @brief Resets all parameters of the selected keyframe to their default values. */
137 void slotResetKeyframe();
139 /** @brief Makes the parameter at column @param id the visible (in timeline) one. */
140 void slotUpdateVisibleParameter(int id, bool update = true);
143 void parameterChanged();
145 void showComments(bool show);