From f04ed5249bfa9c8ea57421d0cda8ca3f888f8d50 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Mon, 23 Jun 2008 19:53:10 +0000 Subject: [PATCH] keyframes can now be edited through double click svn path=/branches/KDE4/; revision=2264 --- src/CMakeLists.txt | 1 + src/abstractclipitem.cpp | 27 +++++--- src/abstractclipitem.h | 7 +- src/customtrackview.cpp | 20 +++++- src/markerdialog.cpp | 1 - src/widgets/keyframedialog_ui.ui | 112 +++++++++++++++++++++++++++++++ 6 files changed, 155 insertions(+), 13 deletions(-) create mode 100644 src/widgets/keyframedialog_ui.ui diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cf74b7c8..e528b552 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -49,6 +49,7 @@ kde4_add_ui_files(kdenlive_UI widgets/trackheader_ui.ui widgets/clipproperties_ui.ui widgets/markerdialog_ui.ui + widgets/keyframedialog_ui.ui ) set(kdenlive_SRCS diff --git a/src/abstractclipitem.cpp b/src/abstractclipitem.cpp index 160021fc..e012eeda 100644 --- a/src/abstractclipitem.cpp +++ b/src/abstractclipitem.cpp @@ -26,7 +26,7 @@ #include "abstractclipitem.h" -AbstractClipItem::AbstractClipItem(const ItemInfo info, const QRectF& rect, double fps): QGraphicsRectItem(rect), m_track(0), m_fps(fps), m_editedKeyframe(-1), m_selectedKeyframe(0) { +AbstractClipItem::AbstractClipItem(const ItemInfo info, const QRectF& rect, double fps): QGraphicsRectItem(rect), m_track(0), m_fps(fps), m_editedKeyframe(-1), m_selectedKeyframe(0), m_keyframeFactor(1) { setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setTrack(info.track); m_startPos = info.startPos; @@ -289,31 +289,36 @@ void AbstractClipItem::updateSelectedKeyFrame() { update(br.x() + maxw * (m_selectedKeyframe - m_cropStart.frames(m_fps)) - 3, br.bottom() - m_keyframes[m_selectedKeyframe] * maxh - 3, 12, 12); } -void AbstractClipItem::updateKeyFramePos(const GenTime pos, const int value) { +int AbstractClipItem::selectedKeyFramePos() const { + return m_editedKeyframe; +} + +double AbstractClipItem::selectedKeyFrameValue() const { + return m_keyframes[m_editedKeyframe]; +} + +void AbstractClipItem::updateKeyFramePos(const GenTime pos, const double value) { if (!m_keyframes.contains(m_selectedKeyframe)) return; - QRectF br = rect(); - double maxh = 100.0 / br.height(); - double newval = (br.bottom() - value) * maxh; int newpos = (int) pos.frames(m_fps); int start = m_cropStart.frames(m_fps); int end = (m_cropStart + m_cropDuration).frames(m_fps); newpos = qMax(newpos, start); newpos = qMin(newpos, end); - if (newval < -50 && m_selectedKeyframe != start && m_selectedKeyframe != end) { + if (value < -50 && m_selectedKeyframe != start && m_selectedKeyframe != end) { // remove kexframe if it is dragged outside m_keyframes.remove(m_selectedKeyframe); m_selectedKeyframe = -1; update(); return; } - if (newval > 150 && m_selectedKeyframe != start && m_selectedKeyframe != end) { + if (value > 150 && m_selectedKeyframe != start && m_selectedKeyframe != end) { // remove kexframe if it is dragged outside m_keyframes.remove(m_selectedKeyframe); m_selectedKeyframe = -1; update(); return; } - newval = qMax(newval, 0.0); + double newval = qMax(value, 0.0); newval = qMin(newval, 100.0); newval = newval / m_keyframeFactor; if (m_selectedKeyframe != newpos) m_keyframes.remove(m_selectedKeyframe); @@ -322,7 +327,11 @@ void AbstractClipItem::updateKeyFramePos(const GenTime pos, const int value) { update(); } -void AbstractClipItem::addKeyFrame(const GenTime pos, const int value) { +double AbstractClipItem::keyFrameFactor() const { + return m_keyframeFactor; +} + +void AbstractClipItem::addKeyFrame(const GenTime pos, const double value) { QRectF br = rect(); double maxh = 100.0 / br.height() / m_keyframeFactor; double newval = (br.bottom() - value) * maxh; diff --git a/src/abstractclipitem.h b/src/abstractclipitem.h index fdb948b1..6e27d8ea 100644 --- a/src/abstractclipitem.h +++ b/src/abstractclipitem.h @@ -30,9 +30,12 @@ class AbstractClipItem : public QObject , public QGraphicsRectItem { public: AbstractClipItem(const ItemInfo info, const QRectF& rect, double fps); void updateSelectedKeyFrame(); - void updateKeyFramePos(const GenTime pos, const int value); - void addKeyFrame(const GenTime pos, const int value); + void updateKeyFramePos(const GenTime pos, const double value); + void addKeyFrame(const GenTime pos, const double value); bool hasKeyFrames() const; + int selectedKeyFramePos() const; + double selectedKeyFrameValue() const; + double keyFrameFactor() const; virtual OPERATIONTYPE operationMode(QPointF pos, double scale) = 0; virtual GenTime startPos() const ; diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index b056260a..f47b5c2c 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -55,6 +55,7 @@ #include "renderer.h" #include "markerdialog.h" #include "mainwindow.h" +#include "ui_keyframedialog_ui.h" //TODO: @@ -200,7 +201,11 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) { ((ClipItem*) m_dragItem)->setFadeOut((int)(m_dragItem->endPos().frames(m_document->fps()) - pos), m_scale); } else if (m_operationMode == KEYFRAME) { GenTime keyFramePos = GenTime((int)(mapToScene(event->pos()).x() / m_scale), m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart(); - m_dragItem->updateKeyFramePos(keyFramePos, mapToScene(event->pos()).toPoint().y()); + double pos = mapToScene(event->pos()).toPoint().y(); + QRectF br = m_dragItem->rect(); + double maxh = 100.0 / br.height(); + pos = (br.bottom() - pos) * maxh; + m_dragItem->updateKeyFramePos(keyFramePos, pos); } if (m_animation) delete m_animation; @@ -539,6 +544,19 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) { if (m_dragItem && m_dragItem->hasKeyFrames()) { if (m_moveOpMode == KEYFRAME) { // user double clicked on a keyframe, open edit dialog + QDialog d(parentWidget()); + Ui::KeyFrameDialog_UI view; + view.setupUi(&d); + view.kfr_position->setText(m_document->timecode().getTimecode(GenTime(m_dragItem->selectedKeyFramePos(), m_document->fps()), m_document->fps())); + view.kfr_value->setValue(m_dragItem->selectedKeyFrameValue()); + view.kfr_value->setFocus(); + if (d.exec() == QDialog::Accepted) { + int pos = m_document->timecode().getFrameCount(view.kfr_position->text(), m_document->fps()); + m_dragItem->updateKeyFramePos(GenTime(pos, m_document->fps()), (double) view.kfr_value->value() * m_dragItem->keyFrameFactor()); + ClipItem *item = (ClipItem *)m_dragItem; + item->updateKeyframeEffect(); + updateEffect(m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect()); + } } else { // add keyframe diff --git a/src/markerdialog.cpp b/src/markerdialog.cpp index 8b7516b7..49adf09d 100644 --- a/src/markerdialog.cpp +++ b/src/markerdialog.cpp @@ -91,7 +91,6 @@ MarkerDialog::~MarkerDialog() { void MarkerDialog::slotUpdateThumb() { m_previewTimer->stop(); int pos = m_tc.getFrameCount(m_view.marker_position->text(), m_fps); - kDebug() << "// getting thumb for: " << pos; QPixmap p = KThumb::getFrame(*m_producer, pos, (int)(100 * m_dar), 100); if (!p.isNull()) m_view.clip_thumb->setPixmap(p); else kDebug() << "!!!!!!!!!!! ERROR CREATING THUMB"; diff --git a/src/widgets/keyframedialog_ui.ui b/src/widgets/keyframedialog_ui.ui new file mode 100644 index 00000000..4967ef98 --- /dev/null +++ b/src/widgets/keyframedialog_ui.ui @@ -0,0 +1,112 @@ + + KeyFrameDialog_UI + + + + 0 + 0 + 324 + 75 + + + + Edit Keyframe + + + + + + Position + + + + + + + 99:99:99:99; + + + + + + + Value + + + + + + + + + + Qt::Vertical + + + + 147 + 30 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + KDoubleNumInput + QWidget +
knuminput.h
+
+ + KRestrictedLine + KLineEdit +
krestrictedline.h
+
+
+ + + + buttonBox + accepted() + KeyFrameDialog_UI + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + KeyFrameDialog_UI + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
-- 2.39.5