]> git.sesse.net Git - kdenlive/blob - src/keyframeedit.h
Do not show the keyframe table if only one keyframe exists. Instead show a button...
[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
29 #include "ui_keyframeeditor_ui.h"
30 #include "definitions.h"
31 #include "keyframehelper.h"
32
33 class KeyItemDelegate: public QItemDelegate
34 {
35     Q_OBJECT
36 public:
37     KeyItemDelegate(int min, int max, QAbstractItemView* parent = 0): QItemDelegate(parent), m_min(min), m_max(max) {
38     }
39
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()));
45             return spin;
46         } else {
47             return QItemDelegate::createEditor(parent, option, index);
48         }
49     }
50
51
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());
57         } else {
58             QItemDelegate::setEditorData(editor, index);
59         }
60     }
61
62 private slots:
63     void commitAndCloseEditor() {
64         QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
65         emit closeEditor(spin);
66     }
67
68     void commitEditorData() {
69         QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
70         emit commitData(spin);
71     }
72
73 private:
74     int m_min;
75     int m_max;
76 };
77
78 class KeyframeEdit : public QWidget, public Ui::KeyframeEditor_UI
79 {
80     Q_OBJECT
81 public:
82     explicit KeyframeEdit(QDomElement e, int minFrame, int maxFrame, int minVal, int maxVal, Timecode tc, int active_keyframe, QWidget* parent = 0);
83     virtual ~KeyframeEdit();
84     void setupParam();
85     void addParameter(QDomElement e);
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 private:
91     QList <QDomElement> m_params;
92     int m_min;
93     int m_max;
94     int m_minVal;
95     int m_maxVal;
96     Timecode m_timecode;
97     int m_previousPos;
98     //KeyItemDelegate *m_delegate;
99     void generateAllParams();
100     QGridLayout *m_slidersLayout;
101     int m_active_keyframe;
102
103     /** @brief Gets the position of a keyframe from the table.
104     * @param row Row of the keyframe in the table */
105     int getPos(int row);
106     /** @brief Converts a frame value to timecode considering the frames vs. HH:MM:SS:FF setting.
107     * @return timecode */
108     QString getPosString(int pos);
109
110 private slots:
111     void slotDeleteKeyframe();
112     void slotAddKeyframe();
113     void slotGenerateParams(int row, int column);
114     void slotAdjustKeyframeInfo(bool seek = true);
115     void slotAdjustKeyframePos(int value);
116     void slotAdjustKeyframeValue(int value);
117     /** @brief Turns the seek to keyframe position setting on/off.
118     * @param state State of the associated checkbox */
119     void slotSetSeeking(int state);
120
121     /** @brief Shows the keyframe table and adds a second keyframe. */
122     void slotKeyframeMode();
123     //void slotSaveCurrentParam(QTreeWidgetItem *item, int column);
124
125 signals:
126     void parameterChanged();
127     void seekToPos(int);
128 };
129
130 #endif