From 26f30bafb1668a975be53463a75e8457abb30095 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Mon, 1 Dec 2008 22:58:46 +0000 Subject: [PATCH 1/1] Should solve most problems with group move: http://www.kdenlive.org:80/mantis/view.php?id=421 svn path=/branches/KDE4/; revision=2742 --- src/abstractgroupitem.cpp | 5 +- src/clipitem.cpp | 5 +- src/customtrackview.cpp | 116 +++++++++++++++++++------------------- src/customtrackview.h | 1 + src/transition.cpp | 2 +- 5 files changed, 64 insertions(+), 65 deletions(-) diff --git a/src/abstractgroupitem.cpp b/src/abstractgroupitem.cpp index f7ee7bea..7e4cbb93 100644 --- a/src/abstractgroupitem.cpp +++ b/src/abstractgroupitem.cpp @@ -32,6 +32,7 @@ #include "customtrackscene.h" AbstractGroupItem::AbstractGroupItem(double fps): QGraphicsItemGroup(), m_fps(fps) { + setZValue(2); setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); } @@ -90,6 +91,7 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant xpos = qMax(xpos, 0); newPos.setX(xpos); + //kDebug()<<"// GRP MOVE: "<"<getSnapPointForPos(start.x() + sc.x(), KdenliveSettings::snaptopoints()); @@ -107,20 +109,17 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant 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); diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 3f86891f..e1810bf5 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -42,6 +42,7 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, bool generateThumbs) : AbstractClipItem(info, QRectF(), fps), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), audioThumbWasDrawn(false), m_opacity(1.0), m_timeLine(0), m_startThumbRequested(false), m_endThumbRequested(false), m_startFade(0), m_endFade(0), m_hover(false), m_selectedEffect(-1), m_speed(1.0), framePixelWidth(0), m_startPix(QPixmap()), m_endPix(QPixmap()) { + setZValue(1); setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (double)(KdenliveSettings::trackheight() - 2)); setPos(info.startPos.frames(fps), (double)(info.track * KdenliveSettings::trackheight()) + 1); @@ -1004,9 +1005,9 @@ void ClipItem::checkEffectsKeyframesPos(const int previous, const int current, b QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value) { if (change == ItemPositionChange && scene()) { // calculate new position. - if (group() != 0) return pos(); + if (group()) return pos(); QPointF newPos = value.toPointF(); - //kDebug() << "/// MOVING CLIP ITEM.------------"; + kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++"; int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints()); xpos = qMax(xpos, 0); newPos.setX(xpos); diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 1d7752b3..c89092b9 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -225,6 +225,12 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) { int mappedXPos = (int)(mapToScene(event->pos()).x() + 0.5); emit mousePosition(mappedXPos); if (event->buttons() & Qt::MidButton) return; + if (event->modifiers() == Qt::ControlModifier || event->modifiers() == Qt::ShiftModifier) { + QGraphicsView::mouseMoveEvent(event); + m_moveOpMode = NONE; + return; + } + if (event->buttons() != Qt::NoButton) { bool move = (event->pos() - m_clickEvent).manhattanLength() >= QApplication::startDragDistance(); if (m_dragItem && m_tool == SELECTTOOL) { @@ -536,10 +542,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) { m_operationMode = MOVEGUIDE; // deselect all clips so that only the guide will move m_scene->clearSelection(); - if (m_selectionGroup) { - scene()->destroyItemGroup(m_selectionGroup); - m_selectionGroup = NULL; - } + resetSelectionGroup(); updateSnapPoints(NULL); QGraphicsView::mousePressEvent(event); return; @@ -562,10 +565,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) { if (m_dragItem) { if (!m_dragItem->isSelected()) { m_scene->clearSelection(); - if (m_selectionGroup) { - scene()->destroyItemGroup(m_selectionGroup); - m_selectionGroup = NULL; - } + resetSelectionGroup(); m_dragItem->setSelected(true); } } @@ -579,10 +579,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) { // No item under click if (m_dragItem == NULL || m_tool == SPACERTOOL) { - if (m_selectionGroup) { - scene()->destroyItemGroup(m_selectionGroup); - m_selectionGroup = NULL; - } + resetSelectionGroup(); setCursor(Qt::ArrowCursor); m_scene->clearSelection(); event->accept(); @@ -632,32 +629,38 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) { return; } updateSnapPoints(m_dragItem); - if (m_dragItem && m_dragItem->type() == AVWIDGET) emit clipItemSelected((ClipItem*) m_dragItem); + if (m_dragItem->type() == AVWIDGET) emit clipItemSelected((ClipItem*) m_dragItem); else emit clipItemSelected(NULL); - if (m_selectionGroup) { - // delete selection group - scene()->destroyItemGroup(m_selectionGroup); - m_selectionGroup = NULL; - } - - if (m_dragItem && m_operationMode == NONE) QGraphicsView::mousePressEvent(event); - - QList selection = m_scene->selectedItems(); - if (selection.count() > 1) { - m_selectionGroup = new AbstractGroupItem(m_document->fps()); - scene()->addItem(m_selectionGroup); - for (int i = 0; i < selection.count(); i++) { - if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET) - m_selectionGroup->addToGroup(selection.at(i)); + if (event->modifiers() != Qt::ControlModifier && (m_dragItem->group() || m_dragItem->isSelected())) { + // If clicked item is selected, allow move + event->accept(); + if (m_selectionGroup) m_selectionGroup->setSelected(true); + if (m_operationMode == NONE) QGraphicsView::mousePressEvent(event); + } else { + resetSelectionGroup(); + if (event->modifiers() != Qt::ControlModifier) m_scene->clearSelection(); + m_dragItem->setSelected(!m_dragItem->isSelected()); + QList selection = m_scene->selectedItems(); + if (selection.count() > 1) { + m_selectionGroup = new AbstractGroupItem(m_document->fps()); + scene()->addItem(m_selectionGroup); + for (int i = 0; i < selection.count(); i++) { + if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET) { + m_selectionGroup->addToGroup(selection.at(i)); + selection.at(i)->setFlags(QGraphicsItem::ItemIsSelectable); + } + } + } + if (m_selectionGroup) { + QPointF top = m_selectionGroup->boundingRect().topLeft(); + const int width = m_selectionGroup->boundingRect().width(); + const int height = m_selectionGroup->boundingRect().height(); + m_selectionGroup->setPos(top); + m_selectionGroup->translate(-top.x(), -top.y() + 1); + m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps()); + m_selectionGroupInfo.track = m_selectionGroup->track(); } - QPointF top = m_selectionGroup->boundingRect().topLeft(); - const int width = m_selectionGroup->boundingRect().width(); - const int height = m_selectionGroup->boundingRect().height(); - m_selectionGroup->setPos(top); - m_selectionGroup->translate(-top.x(), -top.y() + 1); - m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps()); - m_selectionGroupInfo.track = m_selectionGroup->track(); } m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps())), (int)(event->pos().y() - m_dragItem->pos().y())); @@ -730,6 +733,19 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) { //QGraphicsView::mousePressEvent(event); } +void CustomTrackView::resetSelectionGroup() { + if (m_selectionGroup) { + // delete selection group + QList children = m_selectionGroup->childItems(); + for (int i = 0; i < children.count(); i++) { + children.at(i)->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + children.at(i)->setSelected(true); + } + scene()->destroyItemGroup(m_selectionGroup); + m_selectionGroup = NULL; + } +} + void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) { kDebug() << "++++++++++++ DBL CLK"; if (m_dragItem && m_dragItem->hasKeyFrames()) { @@ -832,10 +848,7 @@ void CustomTrackView::activateMonitor() { void CustomTrackView::dragEnterEvent(QDragEnterEvent * event) { if (event->mimeData()->hasFormat("kdenlive/clip")) { - if (m_selectionGroup) { - scene()->destroyItemGroup(m_selectionGroup); - m_selectionGroup = NULL; - } + resetSelectionGroup(); QStringList list = QString(event->mimeData()->data("kdenlive/clip")).split(";"); m_selectionGroup = new AbstractGroupItem(m_document->fps()); @@ -856,10 +869,7 @@ void CustomTrackView::dragEnterEvent(QDragEnterEvent * event) { } else if (event->mimeData()->hasFormat("kdenlive/producerslist")) { QStringList ids = QString(event->mimeData()->data("kdenlive/producerslist")).split(";"); m_scene->clearSelection(); - if (m_selectionGroup) { - scene()->destroyItemGroup(m_selectionGroup); - m_selectionGroup = NULL; - } + resetSelectionGroup(); m_selectionGroup = new AbstractGroupItem(m_document->fps()); QPoint pos = QPoint(); @@ -1248,10 +1258,7 @@ void CustomTrackView::dropEvent(QDropEvent * event) { if (m_selectionGroup) { QList items = m_selectionGroup->childItems(); m_scene->clearSelection(); - if (m_selectionGroup) { - scene()->destroyItemGroup(m_selectionGroup); - m_selectionGroup = NULL; - } + resetSelectionGroup(); for (int i = 0; i < items.count(); i++) { ClipItem *item = static_cast (items.at(i)); AddTimelineClipCommand *command = new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false); @@ -1381,10 +1388,7 @@ void CustomTrackView::insertSpace(const GenTime &pos, int track, const GenTime d QList itemList; if (track == -1) itemList = scene()->items(pos.frames(m_document->fps()) , 1, sceneRect().width() - pos.frames(m_document->fps()), sceneRect().height()); else itemList = scene()->items(pos.frames(m_document->fps()) , track * m_tracksHeight + 1, sceneRect().width() - pos.frames(m_document->fps()), m_tracksHeight - 2); - if (m_selectionGroup) { - scene()->destroyItemGroup(m_selectionGroup); - m_selectionGroup = NULL; - } + resetSelectionGroup(); m_selectionGroup = new AbstractGroupItem(m_document->fps()); scene()->addItem(m_selectionGroup); for (int i = 0; i < itemList.count(); i++) { @@ -1401,10 +1405,7 @@ void CustomTrackView::insertSpace(const GenTime &pos, int track, const GenTime d m_selectionGroup->setPos(top); m_selectionGroup->translate(-top.x(), -top.y() + 1); m_selectionGroup->moveBy(diff, 0); - if (m_selectionGroup) { - scene()->destroyItemGroup(m_selectionGroup); - m_selectionGroup = NULL; - } + resetSelectionGroup(); if (track != -1) track = m_scene->m_tracksList.count() - track; if (!add) m_document->renderer()->mltInsertSpace(pos, track, GenTime() - duration); else m_document->renderer()->mltInsertSpace(pos, track, duration); @@ -1492,10 +1493,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) { m_commandStack->push(command); track = m_scene->m_tracksList.count() - track; m_document->renderer()->mltInsertSpace(GenTime(mappedClick, m_document->fps()), track, GenTime(diff, m_document->fps())); - if (m_selectionGroup) { - scene()->destroyItemGroup(m_selectionGroup); - m_selectionGroup = NULL; - } + resetSelectionGroup(); m_operationMode = NONE; } diff --git a/src/customtrackview.h b/src/customtrackview.h index 838b9d09..ffe62e8a 100644 --- a/src/customtrackview.h +++ b/src/customtrackview.h @@ -207,6 +207,7 @@ private: ClipItem *getMainActiveClip() const; ClipItem *getActiveClipUnderCursor() const; bool insertPossible(AbstractGroupItem *group, const QPoint &pos) const; + void resetSelectionGroup(); private slots: void slotRefreshGuides(); diff --git a/src/transition.cpp b/src/transition.cpp index e5ecebfe..ea43261b 100644 --- a/src/transition.cpp +++ b/src/transition.cpp @@ -34,6 +34,7 @@ #include "mainwindow.h" Transition::Transition(const ItemInfo info, int transitiontrack, double fps, QDomElement params, bool automaticTransition) : AbstractClipItem(info, QRectF(), fps), m_gradient(QLinearGradient(0, 0, 0, 0)), m_automaticTransition(automaticTransition), m_forceTransitionTrack(false) { + setZValue(2); setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (qreal)(KdenliveSettings::trackheight() / 3 * 2 - 1)); setPos(info.startPos.frames(fps), (qreal)(info.track * KdenliveSettings::trackheight() + KdenliveSettings::trackheight() / 3 * 2)); @@ -58,7 +59,6 @@ Transition::Transition(const ItemInfo info, int transitiontrack, double fps, QDo m_name = m_parameters.elementsByTagName("name").item(0).toElement().text(); m_secondClip = 0; setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); - setZValue(2); //m_referenceClip->addTransition(this); } -- 2.39.2