From 5ce773f25ef854677cc391ccb4a9ddf76208706e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Mon, 1 Dec 2008 10:08:03 +0000 Subject: [PATCH] Show error message when there is a problem deleting a clip, fix problem when selecting several clips including a transition: http://www.kdenlive.org:80/mantis/view.php?id=417 svn path=/branches/KDE4/; revision=2741 --- src/abstractclipitem.cpp | 6 ++++++ src/abstractclipitem.h | 1 + src/abstractgroupitem.cpp | 33 ++++++++++++++++++++++++++++----- src/clipitem.cpp | 3 +-- src/customtrackview.cpp | 27 ++++++++++++++++++--------- 5 files changed, 54 insertions(+), 16 deletions(-) diff --git a/src/abstractclipitem.cpp b/src/abstractclipitem.cpp index 9c8d7d94..eca35ba0 100644 --- a/src/abstractclipitem.cpp +++ b/src/abstractclipitem.cpp @@ -28,6 +28,7 @@ #include "abstractclipitem.h" #include "customtrackscene.h" +#include "kdenlivesettings.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), m_keyframeFactor(1) { setFlags(/*QGraphicsItem::ItemClipsToShape | */QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); @@ -65,6 +66,11 @@ void AbstractClipItem::setCropStart(GenTime pos) { m_cropStart = pos; } +void AbstractClipItem::updateItem() { + m_track = (int)(scenePos().y() / KdenliveSettings::trackheight()); + m_startPos = GenTime((int) scenePos().x(), m_fps); +} + void AbstractClipItem::updateRectGeometry() { setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height()); } diff --git a/src/abstractclipitem.h b/src/abstractclipitem.h index dbc75d47..33138bfd 100644 --- a/src/abstractclipitem.h +++ b/src/abstractclipitem.h @@ -41,6 +41,7 @@ public: ItemInfo info() const; CustomTrackScene* projectScene(); void updateRectGeometry(); + void updateItem(); virtual OPERATIONTYPE operationMode(QPointF pos) = 0; virtual GenTime startPos() const ; diff --git a/src/abstractgroupitem.cpp b/src/abstractgroupitem.cpp index 5d581c22..f7ee7bea 100644 --- a/src/abstractgroupitem.cpp +++ b/src/abstractgroupitem.cpp @@ -84,6 +84,7 @@ void AbstractGroupItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWi QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant &value) { if (change == ItemPositionChange && scene()) { // calculate new position. + const int trackHeight = KdenliveSettings::trackheight(); QPointF newPos = value.toPointF(); int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints()); xpos = qMax(xpos, 0); @@ -93,12 +94,35 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant QPointF start = pos();//sceneBoundingRect().topLeft(); int posx = start.x() + newPos.x(); //projectScene()->getSnapPointForPos(start.x() + sc.x(), KdenliveSettings::snaptopoints()); - int startTrack = (start.y() + KdenliveSettings::trackheight() / 2) / KdenliveSettings::trackheight(); - int newTrack = (newPos.y()) / KdenliveSettings::trackheight(); + int startTrack = (start.y() + trackHeight / 2) / trackHeight; + int newTrack = (newPos.y()) / trackHeight; //kDebug()<<"// GROUP NEW T:"<tracksCount() - 1; - newTrack = qMin(newTrack, projectScene()->tracksCount() - (int)(boundingRect().height() + 5) / KdenliveSettings::trackheight()); + newTrack = qMin(newTrack, projectScene()->tracksCount() - (int)(boundingRect().height() + 5) / trackHeight); newTrack = qMax(newTrack, 0); - newPos.setY((int)((newTrack) * KdenliveSettings::trackheight())); + + // Check if top item is a clip or a transition + int offset = 0; + int topTrack = -1; + QList children = childItems(); + for (int i = 0; i < children.count(); i++) { + int currentTrack = (int)(children.at(i)->scenePos().y() / trackHeight); + if (children.at(i)->type() == AVWIDGET) { + kDebug() << "// CLIP ITEM TRK: " << currentTrack << "; POS: " << children.at(i)->scenePos().y(); + if (topTrack == -1 || currentTrack <= topTrack) { + offset = 0; + topTrack = currentTrack; + } + } else if (children.at(i)->type() == TRANSITIONWIDGET) { + kDebug() << "// TRANS ITEM TRK: " << currentTrack << "; POS: " << children.at(i)->scenePos().y(); + if (topTrack == -1 || currentTrack < topTrack) { + offset = (int)(trackHeight / 3 * 2 - 1); + topTrack = currentTrack; + } + } + } + kDebug() << "// OFFSET: " << offset << "\n------------------------------------\n------------"; + + newPos.setY((int)((newTrack) * trackHeight) + offset); //kDebug() << "------------------------------------GRUOP MOVE"; @@ -109,7 +133,6 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant QPolygonF sceneShape = groupShape(newPos - pos()); QList collindingItems = scene()->items(sceneShape, Qt::IntersectsItemShape); - QList children = childItems(); for (int i = 0; i < children.count(); i++) { collindingItems.removeAll(children.at(i)); } diff --git a/src/clipitem.cpp b/src/clipitem.cpp index d1b277c1..3f86891f 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -1000,7 +1000,6 @@ void ClipItem::checkEffectsKeyframesPos(const int previous, const int current, b if (m_selectedEffect >= 0) setSelectedEffect(m_selectedEffect); } - //virtual QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value) { if (change == ItemPositionChange && scene()) { @@ -1011,7 +1010,7 @@ QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value) int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints()); xpos = qMax(xpos, 0); newPos.setX(xpos); - int newTrack = (newPos.y() + KdenliveSettings::trackheight() / 2) / KdenliveSettings::trackheight(); + int newTrack = newPos.y() / KdenliveSettings::trackheight(); newTrack = qMin(newTrack, projectScene()->tracksCount() - 1); newTrack = qMax(newTrack, 0); newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + 1)); diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 6c7829be..1d7752b3 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -1086,6 +1086,10 @@ void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut) { m_blockRefresh = false; return; } + if (m_document->renderer()->mltRemoveClip(m_scene->m_tracksList.count() - info.track, cutTime) == false) { + emit displayMessage(i18n("Error removing clip at %1 on track %2", cutTime.frames(m_document->fps()), info.track), ErrorMessage); + return; + } kDebug() << "// UNCUTTING CLIPS: ITEM 1 (" << item->startPos().frames(25) << "x" << item->endPos().frames(25) << ")"; kDebug() << "// UNCUTTING CLIPS: ITEM 2 (" << dup->startPos().frames(25) << "x" << dup->endPos().frames(25) << ")"; @@ -1098,7 +1102,6 @@ void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut) { m_document->updateClip(dup->baseClip()->getId()); scene()->removeItem(dup); delete dup; - m_document->renderer()->mltRemoveClip(m_scene->m_tracksList.count() - info.track, cutTime); ItemInfo clipinfo = item->info(); clipinfo.track = m_scene->m_tracksList.count() - clipinfo.track; @@ -1554,9 +1557,14 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) { AbstractClipItem *item = static_cast (items.at(i)); ItemInfo info = item->info(); if (item->type() == AVWIDGET) { - ClipItem *clip = static_cast (item); - new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), info, clip->effectList(), false, true, moveClips); - m_document->renderer()->mltRemoveClip(m_scene->m_tracksList.count() - info.track, info.startPos); + if (m_document->renderer()->mltRemoveClip(m_scene->m_tracksList.count() - info.track, info.startPos) == false) { + // error, clip cannot be removed from playlist + emit displayMessage(i18n("Error removing clip at %1 on track %2", info.startPos.frames(m_document->fps()), info.track), ErrorMessage); + } else { + // clip removed from playlist, create command + ClipItem *clip = static_cast (item); + new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), info, clip->effectList(), false, true, moveClips); + } } else { Transition *tr = static_cast (item); new AddTransitionCommand(this, info, tr->transitionEndTrack(), tr->toXML(), true, false, moveClips); @@ -1567,10 +1575,11 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) { for (int i = 0; i < items.count(); i++) { // re-add items in correct place AbstractClipItem *item = static_cast (items.at(i)); + item->updateItem(); ItemInfo info = item->info(); - info.startPos = info.startPos + timeOffset; + /*info.startPos = info.startPos + timeOffset; info.endPos = info.endPos + timeOffset; - info.track = info.track + trackOffset; + info.track = info.track + trackOffset;*/ if (item->type() == AVWIDGET) { ClipItem *clip = static_cast (item); new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), info, clip->effectList(), false, false, moveClips); @@ -1699,8 +1708,9 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) { void CustomTrackView::deleteClip(ItemInfo info) { ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()) + 1, info.track); - if (!item) { - kDebug() << "----------------  ERROR, CANNOT find clip to delete at...";// << rect.x(); + + if (!item || m_document->renderer()->mltRemoveClip(m_scene->m_tracksList.count() - info.track, info.startPos) == false) { + emit displayMessage(i18n("Error removing clip at %1 on track %2", info.startPos.frames(m_document->fps()), info.track), ErrorMessage); return; } if (item->isSelected()) emit clipItemSelected(NULL); @@ -1719,7 +1729,6 @@ void CustomTrackView::deleteClip(ItemInfo info) { scene()->removeItem(item); if (m_dragItem == item) m_dragItem = NULL; delete item; - m_document->renderer()->mltRemoveClip(m_scene->m_tracksList.count() - info.track, info.startPos); m_document->renderer()->doRefresh(); } -- 2.39.2