X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fkeyframehelper.cpp;h=168a863cf811d572f43284b89c6a7b762eddb1e2;hb=aa37ed1efa7f18af7b851c0bb3aaadb9ff8ebe3e;hp=91d926ba77b2c3b1c76bc68de91f92569d57be37;hpb=f555964fc8fd3452f2aa6d8217d20e2aa4013334;p=kdenlive diff --git a/src/keyframehelper.cpp b/src/keyframehelper.cpp index 91d926ba..168a863c 100644 --- a/src/keyframehelper.cpp +++ b/src/keyframehelper.cpp @@ -36,15 +36,17 @@ const int cursorWidth = 6; #define SEEK_INACTIVE (-1) KeyframeHelper::KeyframeHelper(QWidget *parent) : - QWidget(parent), - m_geom(NULL), - m_position(0), - m_scale(0), - m_movingKeyframe(false), - m_lineHeight(9), - m_drag(false), - m_hoverKeyframe(-1), - m_seekPosition(SEEK_INACTIVE) + QWidget(parent) + , frameLength(1) + , m_geom(NULL) + , m_position(0) + , m_scale(0) + , m_movingKeyframe(false) + , m_movingItem() + , m_lineHeight(9) + , m_drag(false) + , m_hoverKeyframe(-1) + , m_seekPosition(SEEK_INACTIVE) { setFont(KGlobalSettings::toolBarFont()); setMouseTracking(true); @@ -80,16 +82,16 @@ void KeyframeHelper::mousePressEvent(QMouseEvent * event) while (!m_extraMovingItems.isEmpty()) { Mlt::GeometryItem *gitem = m_extraMovingItems.takeFirst(); - delete gitem; + if (gitem) delete gitem; } - for (int i = 0; i < m_extraGeometries.count(); i++) { - Mlt::GeometryItem *item2 = new Mlt::GeometryItem(); + for (int i = 0; i < m_extraGeometries.count(); ++i) { if (m_extraGeometries.at(i)->next_key(item, mousePos) == 0) { + Mlt::GeometryItem *item2 = new Mlt::GeometryItem(); item2->x(item.x()); item2->frame(item.frame()); m_extraMovingItems.append(item2); } else { - delete(item2); + m_extraMovingItems.append(NULL); } } @@ -100,10 +102,13 @@ void KeyframeHelper::mousePressEvent(QMouseEvent * event) } } if (event->y() >= m_lineHeight && event->y() < height()) { - m_drag = true; - m_seekPosition = xPos / m_scale; - emit requestSeek(m_seekPosition); - update(); + int seekRequest = xPos / m_scale; + m_drag = true; + if (seekRequest != m_position) { + m_seekPosition = seekRequest; + emit requestSeek(m_seekPosition); + update(); + } } } @@ -158,14 +163,14 @@ void KeyframeHelper::mouseMoveEvent(QMouseEvent * event) if ((QPoint(xPos, event->y()) - m_dragStart).manhattanLength() < QApplication::startDragDistance()) return; m_dragStart = QPoint(); m_geom->remove(m_movingItem.frame()); - for (int i = 0; i < m_extraGeometries.count(); i++) + for (int i = 0; i < m_extraGeometries.count(); ++i) m_extraGeometries[i]->remove(m_movingItem.frame()); } int pos = qBound(0, (int)(xPos / m_scale), frameLength); if (KdenliveSettings::snaptopoints() && qAbs(pos - m_position) < 5) pos = m_position; m_movingItem.frame(pos); - for (int i = 0; i < m_extraMovingItems.count(); i++) { - m_extraMovingItems[i]->frame(pos); + for (int i = 0; i < m_extraMovingItems.count(); ++i) { + if (m_extraMovingItems.at(i)) m_extraMovingItems[i]->frame(pos); } update(); return; @@ -205,8 +210,8 @@ void KeyframeHelper::mouseReleaseEvent(QMouseEvent * event) m_geom->insert(m_movingItem); m_movingKeyframe = false; - for (int i = 0; i < m_extraGeometries.count(); i++) { - m_extraGeometries[i]->insert(m_extraMovingItems.at(i)); + for (int i = 0; i < m_extraGeometries.count(); ++i) { + if (m_extraMovingItems.at(i)) m_extraGeometries[i]->insert(m_extraMovingItems.at(i)); } emit keyframeMoved(m_position); @@ -289,7 +294,7 @@ void KeyframeHelper::paintEvent(QPaintEvent *e) p.setPen(palette().dark().color()); p.drawLine(margin, m_lineHeight, width() - margin - 1, m_lineHeight); p.drawLine(margin, m_lineHeight - 3, margin, m_lineHeight + 3); - p.drawLine(width() - margin - 1, m_lineHeight - 3, width() - margin - 1, m_lineHeight + 3); + p.drawLine(width() - margin, m_lineHeight - 3, width() - margin, m_lineHeight + 3); // draw pointer if (m_seekPosition != SEEK_INACTIVE) { @@ -323,11 +328,7 @@ void KeyframeHelper::setValue(const int pos) void KeyframeHelper::setKeyGeometry(Mlt::Geometry *geom, const int length) { m_geom = geom; - frameLength = length; - while (!m_extraGeometries.isEmpty()) { - Mlt::Geometry *geom = m_extraGeometries.takeFirst(); - delete geom; - } + frameLength = qMax(1, length); update(); }