]> git.sesse.net Git - kdenlive/blob - src/keyframeedit.h
corners widget: fix on-monitor controls not showing up when effect is added
[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 QButtonGroup;
29 class PositionEdit;
30
31 #include "ui_keyframeeditor_ui.h"
32 #include "definitions.h"
33 #include "keyframehelper.h"
34
35 class KeyItemDelegate: public QItemDelegate
36 {
37     Q_OBJECT
38 public:
39     KeyItemDelegate(int min, int max, QAbstractItemView* parent = 0): 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(QDomElement e, int minFrame, int maxFrame, Timecode tc, int activeKeyframe, QWidget* parent = 0);
85     virtual ~KeyframeEdit();
86     virtual void addParameter(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 protected:
98     /** @brief Gets the position of a keyframe from the table.
99      * @param row Row of the keyframe in the table */
100     int getPos(int row);
101
102 protected slots:
103     void slotAdjustKeyframeInfo(bool seek = true);
104
105 private:
106     QList <QDomElement> m_params;
107     int m_min;
108     int m_max;
109     Timecode m_timecode;
110     QGridLayout *m_slidersLayout;
111     QButtonGroup *m_showButtons;
112     PositionEdit *m_position;
113
114     void generateAllParams();
115     /** @brief Converts a frame value to timecode considering the frames vs. HH:MM:SS:FF setting.
116     * @return timecode */
117     QString getPosString(int pos);
118
119 private slots:
120     void slotDeleteKeyframe();
121     void slotAddKeyframe();
122     void slotGenerateParams(int row, int column);
123     void slotAdjustKeyframePos(int value);
124     void slotAdjustKeyframeValue(int value);
125     /** @brief Turns the seek to keyframe position setting on/off.
126     * @param seek true = seeking on */
127     void slotSetSeeking(bool seek);
128
129     /** @brief Shows the keyframe table and adds a second keyframe. */
130     void slotKeyframeMode();
131
132     /** @brief Resets all parameters of the selected keyframe to their default values. */
133     void slotResetKeyframe();
134
135     /** @brief Makes the parameter at column @param id the visible (in timeline) one. */
136     void slotUpdateVisibleParameter(int id, bool update = true);
137
138 signals:
139     void parameterChanged();
140     void seekToPos(int);
141     void showComments();
142 };
143
144 #endif