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>
29 #include "ui_keyframeeditor_ui.h"
30 #include "definitions.h"
31 #include "keyframehelper.h"
33 class KeyItemDelegate: public QItemDelegate
37 KeyItemDelegate(int min, int max, QAbstractItemView* parent = 0): QItemDelegate(parent), m_min(min), m_max(max) {
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()));
47 return QItemDelegate::createEditor(parent, option, index);
52 void setEditorData(QWidget *editor, const QModelIndex &index) const {
53 if (index.column() == 1) {
54 QSpinBox *spin = qobject_cast< QSpinBox* >(editor);
55 spin->setRange(m_min, m_max);
56 spin->setValue(index.model()->data(index).toInt());
58 QItemDelegate::setEditorData(editor, index);
63 void commitAndCloseEditor() {
64 QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
65 emit closeEditor(spin);
68 void commitEditorData() {
69 QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
70 emit commitData(spin);
78 class KeyframeEdit : public QWidget, public Ui::KeyframeEditor_UI
82 explicit KeyframeEdit(QDomElement e, int minFrame, int maxFrame, Timecode tc, int activeKeyframe, QWidget* parent = 0);
83 virtual ~KeyframeEdit();
84 void addParameter(QDomElement e, int activeKeyframe = -1);
85 const QString getValue(const QString &name);
86 /** @brief Updates the timecode display according to settings (frame number or hh:mm:ss:ff) */
87 void updateTimecodeFormat();
90 QList <QDomElement> m_params;
94 QGridLayout *m_slidersLayout;
96 void generateAllParams();
97 /** @brief Gets the position of a keyframe from the table.
98 * @param row Row of the keyframe in the table */
100 /** @brief Converts a frame value to timecode considering the frames vs. HH:MM:SS:FF setting.
101 * @return timecode */
102 QString getPosString(int pos);
105 void slotDeleteKeyframe();
106 void slotAddKeyframe();
107 void slotGenerateParams(int row, int column);
108 void slotAdjustKeyframeInfo(bool seek = true);
109 void slotAdjustKeyframePos(int value);
110 void slotAdjustKeyframeValue(int value);
111 /** @brief Turns the seek to keyframe position setting on/off.
112 * @param seek true = seeking on */
113 void slotSetSeeking(bool seek);
115 /** @brief Shows the keyframe table and adds a second keyframe. */
116 void slotKeyframeMode();
118 /** @brief Resets all parameters of the selected keyframe to their default values. */
119 void slotResetKeyframe();
122 void parameterChanged();