]> git.sesse.net Git - kdenlive/blob - src/keyframeedit.h
const'ref. Fix indent
[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)
39         : QItemDelegate(parent), m_min(min), m_max(max) {
40     }
41
42     QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
43         if (index.column() == 1) {
44             QSpinBox *spin = new QSpinBox(parent);
45             connect(spin, SIGNAL(valueChanged(int)), this, SLOT(commitEditorData()));
46             connect(spin, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
47             return spin;
48         } else {
49             return QItemDelegate::createEditor(parent, option, index);
50         }
51     }
52
53
54     void setEditorData(QWidget *editor, const QModelIndex &index) const {
55         if (index.column() == 1) {
56             QSpinBox *spin = qobject_cast< QSpinBox* >(editor);
57             spin->setRange(m_min, m_max);
58             spin->setValue(index.model()->data(index).toInt());
59         } else {
60             QItemDelegate::setEditorData(editor, index);
61         }
62     }
63
64 private slots:
65     void commitAndCloseEditor() {
66         QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
67         emit closeEditor(spin);
68     }
69
70     void commitEditorData() {
71         QSpinBox *spin = qobject_cast< QSpinBox* >(sender());
72         emit commitData(spin);
73     }
74
75 private:
76     int m_min;
77     int m_max;
78 };
79
80 class KeyframeEdit : public QWidget, public Ui::KeyframeEditor_UI
81 {
82     Q_OBJECT
83 public:
84     explicit KeyframeEdit(const QDomElement &e, int minFrame, int maxFrame, const Timecode &tc, int activeKeyframe, QWidget* parent = 0);
85     virtual ~KeyframeEdit();
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     /** @brief Returns true if the parameter @param name should be shown on the clip in timeline. */
92     bool isVisibleParam(const QString &name);
93
94     /** @brief Makes the first parameter visible in timeline if no parameter is selected. */
95     void checkVisibleParam();
96
97 public slots:
98
99     void slotUpdateRange(int inPoint, int outPoint);
100
101 protected:
102     /** @brief Gets the position of a keyframe from the table.
103      * @param row Row of the keyframe in the table */
104     int getPos(int row);
105     /** @brief Converts a frame value to timecode considering the frames vs. HH:MM:SS:FF setting.
106      * @return timecode */
107     QString getPosString(int pos);
108
109     void generateAllParams();
110
111     int m_min;
112     int m_max;
113
114 protected slots:
115     void slotAdjustKeyframeInfo(bool seek = true);
116
117 private:
118     QList <QDomElement> m_params;
119     Timecode m_timecode;
120     QGridLayout *m_slidersLayout;
121     PositionEdit *m_position;
122
123 private slots:
124     void slotDeleteKeyframe();
125     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     /** @brief Shows the keyframe table and adds a second keyframe. */
134     void slotKeyframeMode();
135
136     /** @brief Resets all parameters of the selected keyframe to their default values. */
137     void slotResetKeyframe();
138
139     /** @brief Makes the parameter at column @param id the visible (in timeline) one. */
140     void slotUpdateVisibleParameter(int id, bool update = true);
141
142 signals:
143     void parameterChanged();
144     void seekToPos(int);
145     void showComments(bool show);
146 };
147
148 #endif