]> git.sesse.net Git - kdenlive/commitdiff
Should solve most problems with group move:
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 1 Dec 2008 22:58:46 +0000 (22:58 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 1 Dec 2008 22:58:46 +0000 (22:58 +0000)
http://www.kdenlive.org:80/mantis/view.php?id=421

svn path=/branches/KDE4/; revision=2742

src/abstractgroupitem.cpp
src/clipitem.cpp
src/customtrackview.cpp
src/customtrackview.h
src/transition.cpp

index f7ee7bea1d24de899b78133fda2ea4637fbb23fb..7e4cbb93bbdfe90db3eec78b8b774884168727e9 100644 (file)
@@ -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: "<<pos().y()<<"->"<<newPos.y();
         QPointF start = pos();//sceneBoundingRect().topLeft();
         int posx = start.x() + newPos.x(); //projectScene()->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);
 
index 3f86891f9c925f57aba085e2001d85889918efb7..e1810bf531c70e07945e43ac498a42cfc7abf695 100644 (file)
@@ -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);
index 1d7752b301b17adda2757afc2b9b694fe33c72e2..c89092b9840887546bf09c68425979df85c2efa9 100644 (file)
@@ -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<QGraphicsItem *> 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<QGraphicsItem *> 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<QGraphicsItem *> 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<QGraphicsItem *> 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 <ClipItem *>(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<QGraphicsItem *> 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;
     }
 
index 838b9d09e2452ce8eb55e7955df21143a1ce0a98..ffe62e8aa813439fae15d3aec9f8aa933c647caa 100644 (file)
@@ -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();
index e5ecebfe62cdec063671a382c8597e386cfeb676..ea43261b7e2be33254058e4a9c4c857509075450 100644 (file)
@@ -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);
 }