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>
30 #include "ui_keyframeeditor_ui.h"
31 #include "definitions.h"
32 #include "keyframehelper.h"
34 class KeyItemDelegate: public QItemDelegate
38 KeyItemDelegate(int min, int max, QAbstractItemView* parent = 0): QItemDelegate(parent), m_min(min), m_max(max) {
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()));
48 return QItemDelegate::createEditor(parent, option, index);
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());
59 QItemDelegate::setEditorData(editor, index);
64 void commitAndCloseEditor() {
65 QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
66 emit closeEditor(spin);
69 void commitEditorData() {
70 QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
71 emit commitData(spin);
79 class KeyframeEdit : public QWidget, public Ui::KeyframeEditor_UI
83 explicit KeyframeEdit(const QDomElement &e, int minFrame, int maxFrame, Timecode tc, int activeKeyframe, QWidget* parent = 0);
84 virtual ~KeyframeEdit();
85 virtual 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();
90 /** @brief Returns true if the parameter @param name should be shown on the clip in timeline. */
91 bool isVisibleParam(const QString &name);
93 /** @brief Makes the first parameter visible in timeline if no parameter is selected. */
94 void checkVisibleParam();
98 void slotUpdateRange(int inPoint, int outPoint);
101 /** @brief Gets the position of a keyframe from the table.
102 * @param row Row of the keyframe in the table */
104 /** @brief Converts a frame value to timecode considering the frames vs. HH:MM:SS:FF setting.
105 * @return timecode */
106 QString getPosString(int pos);
108 void generateAllParams();
114 void slotAdjustKeyframeInfo(bool seek = true);
117 QList <QDomElement> m_params;
119 QGridLayout *m_slidersLayout;
120 PositionEdit *m_position;
123 void slotDeleteKeyframe();
124 void slotAddKeyframe();
125 void slotGenerateParams(int row, int column);
126 void slotAdjustKeyframePos(int value);
127 void slotAdjustKeyframeValue(double value);
128 /** @brief Turns the seek to keyframe position setting on/off.
129 * @param seek true = seeking on */
130 void slotSetSeeking(bool seek);
132 /** @brief Shows the keyframe table and adds a second keyframe. */
133 void slotKeyframeMode();
135 /** @brief Resets all parameters of the selected keyframe to their default values. */
136 void slotResetKeyframe();
138 /** @brief Makes the parameter at column @param id the visible (in timeline) one. */
139 void slotUpdateVisibleParameter(int id, bool update = true);
142 void parameterChanged();
144 void showComments(bool show);