}
// draw keyframes
- QMap<int, double>::const_iterator i = m_keyframes.constBegin();
+ QMap<int, int>::const_iterator i = m_keyframes.constBegin();
QColor color(Qt::blue);
x1 = br.x() + maxw * (i.key() - cropStart().frames(m_fps));
y1 = br.bottom() - i.value() * maxh;
double maxw = br.width() / cropDuration().frames(m_fps);
double maxh = br.height() / 100.0 * m_keyframeFactor;
if (m_keyframes.count() > 1) {
- QMap<int, double>::const_iterator i = m_keyframes.constBegin();
+ QMap<int, int>::const_iterator i = m_keyframes.constBegin();
double x1;
double y1;
while (i != m_keyframes.constEnd()) {
newval = qMin(newval, 100.0);
newval = newval / m_keyframeFactor;
if (m_selectedKeyframe != newpos) m_keyframes.remove(m_selectedKeyframe);
- m_keyframes[newpos] = newval;
+ m_keyframes[newpos] = (int) newval;
m_selectedKeyframe = newpos;
update();
}
{
QRectF br = sceneBoundingRect();
double maxh = 100.0 / br.height() / m_keyframeFactor;
- double newval = (br.bottom() - value) * maxh;
+ int newval = (br.bottom() - value) * maxh;
kDebug() << "Rect: " << br << "/ SCENE: " << sceneBoundingRect() << ", VALUE: " << value << ", MAX: " << maxh << ", NEWVAL: " << newval;
int newpos = (int) pos.frames(m_fps) ;
m_keyframes[newpos] = newval;
GenTime m_cropDuration;
GenTime m_startPos;
GenTime m_maxDuration;
- QMap <int, double> m_keyframes;
+ QMap <int, int> m_keyframes;
double m_keyframeFactor;
double m_keyframeDefault;
double m_fps;
if (!e.isNull() && e.attribute("type") == "keyframe") {
QString keyframes;
if (m_keyframes.count() > 1) {
- QMap<int, double>::const_iterator i = m_keyframes.constBegin();
+ QMap<int, int>::const_iterator i = m_keyframes.constBegin();
while (i != m_keyframes.constEnd()) {
keyframes.append(QString::number(i.key()) + ':' + QString::number(i.value()) + ';');
++i;
} else if (type == "keyframe") {
// keyframe editor widget
kDebug() << "min: " << m_in << ", MAX: " << m_out;
- KeyframeEdit *geo = new KeyframeEdit(pa, m_out - m_in, m_timecode);
+ KeyframeEdit *geo = new KeyframeEdit(pa, m_out - m_in, pa.attribute("min").toInt(), pa.attribute("max").toInt(), m_timecode);
//geo->setupParam(100, pa.attribute("min").toInt(), pa.attribute("max").toInt(), pa.attribute("keyframes"));
//connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int)));
//geo->setupParam(pa, minFrame, maxFrame);
#include "kdenlivesettings.h"
#include <KDebug>
+#include <KGlobalSettings>
+
#include <QHeaderView>
-KeyframeEdit::KeyframeEdit(QDomElement e, int max, Timecode tc, QWidget* parent) :
+KeyframeEdit::KeyframeEdit(QDomElement e, int maxFrame, int minVal, int maxVal, Timecode tc, QWidget* parent) :
QWidget(parent),
m_param(e),
- m_max(max),
+ m_max(maxFrame),
+ m_minVal(minVal),
+ m_maxVal(maxVal),
m_timecode(tc),
m_previousPos(0)
{
m_ui.setupUi(this);
+ m_ui.keyframe_list->setFont(KGlobalSettings::generalFont());
m_ui.keyframe_list->setHeaderLabels(QStringList() << i18n("Position") << i18n("Value"));
//setResizeMode(1, QHeaderView::Interactive);
m_ui.button_add->setIcon(KIcon("document-new"));
connect(m_ui.keyframe_list, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotSaveCurrentParam(QTreeWidgetItem *, int)));
connect(m_ui.keyframe_pos, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustKeyframeValue(int)));
m_ui.keyframe_pos->setPageStep(1);
+ m_ui.keyframe_list->setItemDelegate(new KeyItemDelegate(minVal, maxVal));
}
void KeyframeEdit::setupParam(QDomElement e)
#include <QWidget>
#include <QDomElement>
+#include <QItemDelegate>
+#include <QAbstractItemView>
+#include <QSpinBox>
#include "ui_keyframeeditor_ui.h"
#include "definitions.h"
#include "keyframehelper.h"
-//class QGraphicsScene;
+class KeyItemDelegate: public QItemDelegate
+{
+ Q_OBJECT
+public:
+ KeyItemDelegate(int min, int max, QAbstractItemView* parent = 0): QItemDelegate(parent), m_min(min), m_max(max) {
+ }
+
+ 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;
+ } else return QItemDelegate::createEditor(parent, option, index);
+ }
+
+
+ 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());
+ } else QItemDelegate::setEditorData(editor, index);
+ }
+
+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;
+};
class KeyframeEdit : public QWidget
{
Q_OBJECT
public:
- explicit KeyframeEdit(QDomElement e, int max, Timecode tc, QWidget* parent = 0);
+ explicit KeyframeEdit(QDomElement e, int maxFrame, int minVal, int maxVal, Timecode tc, QWidget* parent = 0);
void setupParam(QDomElement e = QDomElement());
private:
Ui::KeyframeEditor_UI m_ui;
QDomElement m_param;
int m_max;
+ int m_minVal;
+ int m_maxVal;
Timecode m_timecode;
int m_previousPos;