]> git.sesse.net Git - kdenlive/blob - src/keyframeedit.h
Better to use ++i than i++ (minor optimization)
[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 class PositionEdit;
29
30 #include "ui_keyframeeditor_ui.h"
31 #include "definitions.h"
32 #include "keyframehelper.h"
33
34 class KeyItemDelegate: public QItemDelegate
35 {
36     Q_OBJECT
37 public:
38     KeyItemDelegate(int min, int max, QAbstractItemView* parent = 0): QItemDelegate(parent), m_min(min), m_max(max) {
39     }
40
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()));
46             return spin;
47         } else {
48             return QItemDelegate::createEditor(parent, option, index);
49         }
50     }
51
52
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());
58         } else {
59             QItemDelegate::setEditorData(editor, index);
60         }
61     }
62
63 private slots:
64     void commitAndCloseEditor() {
65         QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
66         emit closeEditor(spin);
67     }
68
69     void commitEditorData() {
70         QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
71         emit commitData(spin);
72     }
73
74 private:
75     int m_min;
76     int m_max;
77 };
78
79 class KeyframeEdit : public QWidget, public Ui::KeyframeEditor_UI
80 {
81     Q_OBJECT
82 public:
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();
89
90     /** @brief Returns true if the parameter @param name should be shown on the clip in timeline. */
91     bool isVisibleParam(const QString &name);
92
93     /** @brief Makes the first parameter visible in timeline if no parameter is selected. */
94     void checkVisibleParam();
95
96 public slots:
97
98     void slotUpdateRange(int inPoint, int outPoint);
99
100 protected:
101     /** @brief Gets the position of a keyframe from the table.
102      * @param row Row of the keyframe in the table */
103     int getPos(int row);
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);
107
108     void generateAllParams();
109
110     int m_min;
111     int m_max;
112
113 protected slots:
114     void slotAdjustKeyframeInfo(bool seek = true);
115
116 private:
117     QList <QDomElement> m_params;
118     Timecode m_timecode;
119     QGridLayout *m_slidersLayout;
120     PositionEdit *m_position;
121
122 private slots:
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);
131
132     /** @brief Shows the keyframe table and adds a second keyframe. */
133     void slotKeyframeMode();
134
135     /** @brief Resets all parameters of the selected keyframe to their default values. */
136     void slotResetKeyframe();
137
138     /** @brief Makes the parameter at column @param id the visible (in timeline) one. */
139     void slotUpdateVisibleParameter(int id, bool update = true);
140
141 signals:
142     void parameterChanged();
143     void seekToPos(int);
144     void showComments(bool show);
145 };
146
147 #endif