From 421dd62d67e8bfcaa293f86bfdba1dd30d363873 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Tue, 21 Jul 2009 13:36:28 +0000 Subject: [PATCH] Improve keyframe editor (keyframe value can now be adjusted with mouse wheel) svn path=/trunk/kdenlive/; revision=3753 --- src/abstractclipitem.cpp | 8 +++---- src/abstractclipitem.h | 2 +- src/clipitem.cpp | 2 +- src/effectstackedit.cpp | 2 +- src/keyframeedit.cpp | 10 +++++++-- src/keyframeedit.h | 48 ++++++++++++++++++++++++++++++++++++++-- 6 files changed, 61 insertions(+), 11 deletions(-) diff --git a/src/abstractclipitem.cpp b/src/abstractclipitem.cpp index d6a8f391..605b42dc 100644 --- a/src/abstractclipitem.cpp +++ b/src/abstractclipitem.cpp @@ -267,7 +267,7 @@ void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF /*exposedRect*/) } // draw keyframes - QMap::const_iterator i = m_keyframes.constBegin(); + QMap::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; @@ -297,7 +297,7 @@ int AbstractClipItem::mouseOverKeyFrames(QPointF pos) double maxw = br.width() / cropDuration().frames(m_fps); double maxh = br.height() / 100.0 * m_keyframeFactor; if (m_keyframes.count() > 1) { - QMap::const_iterator i = m_keyframes.constBegin(); + QMap::const_iterator i = m_keyframes.constBegin(); double x1; double y1; while (i != m_keyframes.constEnd()) { @@ -361,7 +361,7 @@ void AbstractClipItem::updateKeyFramePos(const GenTime pos, const double value) 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(); } @@ -375,7 +375,7 @@ void AbstractClipItem::addKeyFrame(const GenTime pos, const double value) { 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; diff --git a/src/abstractclipitem.h b/src/abstractclipitem.h index dd3277d5..55e392b9 100644 --- a/src/abstractclipitem.h +++ b/src/abstractclipitem.h @@ -68,7 +68,7 @@ protected: GenTime m_cropDuration; GenTime m_startPos; GenTime m_maxDuration; - QMap m_keyframes; + QMap m_keyframes; double m_keyframeFactor; double m_keyframeDefault; double m_fps; diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 8fba86ba..8d76725d 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -399,7 +399,7 @@ void ClipItem::updateKeyframeEffect() if (!e.isNull() && e.attribute("type") == "keyframe") { QString keyframes; if (m_keyframes.count() > 1) { - QMap::const_iterator i = m_keyframes.constBegin(); + QMap::const_iterator i = m_keyframes.constBegin(); while (i != m_keyframes.constEnd()) { keyframes.append(QString::number(i.key()) + ':' + QString::number(i.value()) + ';'); ++i; diff --git a/src/effectstackedit.cpp b/src/effectstackedit.cpp index 5bb586ad..5786291e 100644 --- a/src/effectstackedit.cpp +++ b/src/effectstackedit.cpp @@ -243,7 +243,7 @@ void EffectStackEdit::transferParamDesc(const QDomElement& d, int in, int out) } 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); diff --git a/src/keyframeedit.cpp b/src/keyframeedit.cpp index f0e390c4..66604ae9 100644 --- a/src/keyframeedit.cpp +++ b/src/keyframeedit.cpp @@ -19,17 +19,22 @@ #include "kdenlivesettings.h" #include +#include + #include -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")); @@ -43,6 +48,7 @@ KeyframeEdit::KeyframeEdit(QDomElement e, int max, Timecode tc, QWidget* parent) 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) diff --git a/src/keyframeedit.h b/src/keyframeedit.h index e9bca17b..82621c80 100644 --- a/src/keyframeedit.h +++ b/src/keyframeedit.h @@ -21,25 +21,69 @@ #include #include +#include +#include +#include #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; -- 2.39.2