keyframeedit.h 4.86 KB
Newer Older
1
/***************************************************************************
Vincent Pinon's avatar
Vincent Pinon committed
2
                          keyframeedit.h  -  description
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
                             -------------------
    begin                : 22 Jun 2009
    copyright            : (C) 2008 by Jean-Baptiste Mardelle
    email                : jb@kdenlive.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KEYFRAMEEDIT_H
#define KEYFRAMEEDIT_H

Vincent Pinon's avatar
Vincent Pinon committed
21 22 23 24
#include "keyframehelper.h"

#include "ui_keyframeeditor_ui.h"
#include "definitions.h"
25 26 27

#include <QWidget>
#include <QDomElement>
28 29 30
#include <QItemDelegate>
#include <QAbstractItemView>
#include <QSpinBox>
31

32
class PositionEdit;
33

34 35 36 37
class KeyItemDelegate: public QItemDelegate
{
    Q_OBJECT
public:
38 39
    KeyItemDelegate(int min, int max, QAbstractItemView* parent = 0)
        : QItemDelegate(parent), m_min(min), m_max(max) {
40 41 42 43 44 45 46 47
    }

    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
        if (index.column() == 1) {
            QSpinBox *spin = new QSpinBox(parent);
            connect(spin, SIGNAL(valueChanged(int)), this, SLOT(commitEditorData()));
            connect(spin, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
            return spin;
48 49 50
        } else {
            return QItemDelegate::createEditor(parent, option, index);
        }
51 52 53 54 55 56 57 58
    }


    void setEditorData(QWidget *editor, const QModelIndex &index) const {
        if (index.column() == 1) {
            QSpinBox *spin = qobject_cast< QSpinBox* >(editor);
            spin->setRange(m_min, m_max);
            spin->setValue(index.model()->data(index).toInt());
59 60 61
        } else {
            QItemDelegate::setEditorData(editor, index);
        }
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    }

private slots:
    void commitAndCloseEditor() {
        QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
        emit closeEditor(spin);
    }

    void commitEditorData() {
        QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
        emit commitData(spin);
    }

private:
    int m_min;
    int m_max;
};
79

80
class KeyframeEdit : public QWidget, public Ui::KeyframeEditor_UI
81 82 83
{
    Q_OBJECT
public:
84
    explicit KeyframeEdit(const QDomElement &e, int minFrame, int maxFrame, const Timecode &tc, int activeKeyframe, QWidget* parent = 0);
85
    virtual ~KeyframeEdit();
Laurent Montel's avatar
Laurent Montel committed
86
    virtual void addParameter(const 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();
90

91 92 93
    /** @brief Returns true if the parameter @param name should be shown on the clip in timeline. */
    bool isVisibleParam(const QString &name);

94 95 96
    /** @brief Makes the first parameter visible in timeline if no parameter is selected. */
    void checkVisibleParam();

97 98 99 100
public slots:

    void slotUpdateRange(int inPoint, int outPoint);

Till Theato's avatar
Till Theato committed
101 102 103 104
protected:
    /** @brief Gets the position of a keyframe from the table.
     * @param row Row of the keyframe in the table */
    int getPos(int row);
105 106 107 108 109
    /** @brief Converts a frame value to timecode considering the frames vs. HH:MM:SS:FF setting.
     * @return timecode */
    QString getPosString(int pos);

    void generateAllParams();
Till Theato's avatar
Till Theato committed
110

111 112 113
    int m_min;
    int m_max;

Till Theato's avatar
Till Theato committed
114 115 116
protected slots:
    void slotAdjustKeyframeInfo(bool seek = true);

117
private:
118
    QList <QDomElement> m_params;
119
    Timecode m_timecode;
120
    QGridLayout *m_slidersLayout;
121
    PositionEdit *m_position;
122 123

private slots:
124 125
    void slotDeleteKeyframe();
    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);
132 133 134

    /** @brief Shows the keyframe table and adds a second keyframe. */
    void slotKeyframeMode();
135 136 137 138

    /** @brief Resets all parameters of the selected keyframe to their default values. */
    void slotResetKeyframe();

139
    /** @brief Makes the parameter at column @param id the visible (in timeline) one. */
140
    void slotUpdateVisibleParameter(int id, bool update = true);
141

142 143 144
signals:
    void parameterChanged();
    void seekToPos(int);
145
    void showComments(bool show);
146 147 148
};

#endif
Vincent Pinon's avatar
Vincent Pinon committed
149