]> git.sesse.net Git - kdenlive/commitdiff
Improve keyframe editor (keyframe value can now be adjusted with mouse wheel)
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 21 Jul 2009 13:36:28 +0000 (13:36 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 21 Jul 2009 13:36:28 +0000 (13:36 +0000)
svn path=/trunk/kdenlive/; revision=3753

src/abstractclipitem.cpp
src/abstractclipitem.h
src/clipitem.cpp
src/effectstackedit.cpp
src/keyframeedit.cpp
src/keyframeedit.h

index d6a8f391f0b58f979f28fece3a54d2da8457a29f..605b42dc566b5f72d09741e3d4e5c7c52041309c 100644 (file)
@@ -267,7 +267,7 @@ void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF /*exposedRect*/)
     }
 
     // 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;
@@ -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<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()) {
@@ -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;
index dd3277d5a8a5a64a55a91ad753b8ff3960044c54..55e392b99ee5b1da0cc9f4cd1fa36495735c4c37 100644 (file)
@@ -68,7 +68,7 @@ protected:
     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;
index 8fba86baae59e811e760e2098e7621433e4f1c4d..8d76725d3f0b584641ae2e9b44c86d5ddd4d535b 100644 (file)
@@ -399,7 +399,7 @@ void ClipItem::updateKeyframeEffect()
         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;
index 5bb586ad7bda6d338660ae73cf89654d144f9bad..5786291eb4ea54daf7bbaeb462a70e41268bb9ae 100644 (file)
@@ -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);
index f0e390c43282a389f29352246c1dd51f1526fef8..66604ae98f867e9b6f54f3e1501be76132dff978 100644 (file)
 #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"));
@@ -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)
index e9bca17bf76d55d9f1e011a4a1af922854198749..82621c80048c962dd962267007464949ca8587fc 100644 (file)
 
 #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;