]> git.sesse.net Git - kdenlive/commitdiff
Merge branch 'master' into feature/pkey
authorEd Rogalsky <ed.rogalsky@googlemail.com>
Tue, 30 Oct 2012 07:05:15 +0000 (08:05 +0100)
committerEd Rogalsky <ed.rogalsky@googlemail.com>
Tue, 30 Oct 2012 07:05:15 +0000 (08:05 +0100)
1  2 
src/customtrackview.cpp
src/customtrackview.h
src/mainwindow.cpp

diff --combined src/customtrackview.cpp
index d03e745dbc32830696c0262b513685e29ddf4685,84952f9bc9d3aeb10347f8103c766f77a425bead..c9c4df4a8450b326ecc797e8baf24534bdfbe968
@@@ -63,6 -63,7 +63,7 @@@
  #include "commands/configtrackscommand.h"
  #include "commands/rebuildgroupcommand.h"
  #include "commands/razorgroupcommand.h"
+ #include "commands/refreshmonitorcommand.h"
  #include "profilesdialog.h"
  
  #include "lib/audio/audioEnvelope.h"
@@@ -404,15 -405,6 +405,15 @@@ void CustomTrackView::slotCheckPosition
      }
  }
  
 +void CustomTrackView::slotAlignPlayheadToMousePos()
 +{
 +      /* get curser point ref in screen coord */
 +      QPoint ps = QCursor::pos();
 +      /* get xPos in scene coord */
 +      int mappedXPos = qMax((int)(mapToScene(mapFromGlobal(ps)).x() + 0.5), 0);
 +      /* move playhead to new xPos*/
 +      seekCursorPos(mappedXPos);
 +}
  
  // virtual
  void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
  
      if (event->buttons() != Qt::NoButton) {
          bool move = (event->pos() - m_clickEvent).manhattanLength() >= QApplication::startDragDistance();
+       if (m_dragItem && move) m_clipDrag = true;
          if (m_dragItem && m_tool == SELECTTOOL) {
-             if (m_operationMode == MOVE && move) {
-               //m_dragItem->setProperty("y_absolute", event->pos().y());
+             if (m_operationMode == MOVE && m_clipDrag) {
                  QGraphicsView::mouseMoveEvent(event);
                  // If mouse is at a border of the view, scroll
                  if (pos < 5) {
@@@ -735,6 -727,7 +736,7 @@@ void CustomTrackView::mousePressEvent(Q
  {
      setFocus(Qt::MouseFocusReason);
      m_menuPosition = QPoint();
+     m_clipDrag = false;
  
      // special cases (middle click button or ctrl / shift click
      if (event->button() == Qt::MidButton) {
              collisionClip = static_cast <AbstractClipItem *>(collisionList.at(ct));
              if (collisionClip->isItemLocked())
                  break;
-             if (collisionClip == m_dragItem)
+             if (collisionClip == m_dragItem) {
                  collisionClip = NULL;
-             else
+           }
+             else {
                  m_dragItem = collisionClip;
+           }
              found = true;
            m_dragItem->setProperty("y_absolute", mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y());
              m_dragItemInfo = m_dragItem->info();
+           if (m_selectionGroup) m_selectionGroup->setProperty("y_absolute", mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y());
              if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET && m_dragItem->parentItem() != m_selectionGroup) {
-                 // kDebug()<<"// KLIK FOUND GRP: "<<m_dragItem->sceneBoundingRect();
                  dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
+               dragGroup->setProperty("y_absolute", mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y());
              }
              break;
          }
          if (m_dragItem) emit clipItemSelected(NULL);
          m_dragItem = NULL;
      }
- #if QT_VERSION >= 0x040600
+ #if QT_VERSION >= 0x040800
      // Add shadow to dragged item, currently disabled because of painting artifacts
-     //TODO: re-enable when fixed
-     /*QGraphicsDropShadowEffect *eff = new QGraphicsDropShadowEffect();
-     eff->setBlurRadius(5);
-     eff->setOffset(3, 3);
-     m_dragItem->setGraphicsEffect(eff);*/
+     /*if (m_dragItem) {
+       QGraphicsDropShadowEffect *eff = new QGraphicsDropShadowEffect();
+       eff->setBlurRadius(5);
+       eff->setOffset(3, 3);
+       m_dragItem->setGraphicsEffect(eff);
+     }*/
  #endif
      if (m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) {
          // update transition menu action
                      if (item->isItemLocked()) continue;
                      offsetList.append(item->startPos());
                      offsetList.append(item->endPos());
-                     m_selectionGroup->addToGroup(selection.at(i));
-                     selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
+                     m_selectionGroup->addItem(selection.at(i));
                  } else if (/*selection.at(i)->parentItem() == 0 && */selection.at(i)->type() == GROUPWIDGET) {
                      if (static_cast<AbstractGroupItem *>(selection.at(i))->isItemLocked()) continue;
                      QList<QGraphicsItem *> children = selection.at(i)->childItems();
                          offsetList.append(item->startPos());
                          offsetList.append(item->endPos());
                      }
-                     m_selectionGroup->addToGroup(selection.at(i));
-                     selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
+                     m_selectionGroup->addItem(selection.at(i));
                  } else if (selection.at(i)->parentItem() && !selection.contains(selection.at(i)->parentItem())) {
                      if (static_cast<AbstractGroupItem *>(selection.at(i)->parentItem())->isItemLocked()) continue;
-                     //AbstractGroupItem *grp = static_cast<AbstractGroupItem *>(selection.at(i)->parentItem());
-                     m_selectionGroup->addToGroup(selection.at(i)->parentItem());
-                     selection.at(i)->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
+                     m_selectionGroup->addItem(selection.at(i)->parentItem());
                  }
              }
              m_spacerOffset = m_selectionGroup->sceneBoundingRect().left() - (int)(mapToScene(m_clickEvent).x());
          } else {
              seekCursorPos((int)(mapToScene(event->x(), 0).x()));
          }
-         //QGraphicsView::mousePressEvent(event);
+         QGraphicsView::mousePressEvent(event);
          event->ignore();
          return;
      }
      }
  
      bool itemSelected = false;
-     if (m_dragItem->isSelected())
+     if (m_dragItem->isSelected()) {
          itemSelected = true;
-     else if (m_dragItem->parentItem() && m_dragItem->parentItem()->isSelected())
+     }
+     else if (m_dragItem->parentItem() && m_dragItem->parentItem()->isSelected()) {
          itemSelected = true;
-     else if (dragGroup && dragGroup->isSelected())
+     }
+     else if (dragGroup && dragGroup->isSelected()) {
          itemSelected = true;
+     }
  
      if ((event->modifiers() == Qt::ControlModifier) || itemSelected == false) {
          if (event->modifiers() != Qt::ControlModifier) {
          if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET) {
              dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
          }
          bool selected = !m_dragItem->isSelected();
-         /*if (dragGroup)
+       QGraphicsView::mousePressEvent(event);
+         
+         if (dragGroup) {
              dragGroup->setSelected(selected);
-         else*/
+           if (dragGroup->parentItem())
+               dragGroup->parentItem()->setSelected(selected);
+       }
+         else
              m_dragItem->setSelected(selected);
        if (selected == false) {
            m_dragItem = NULL;
        }
        else updateClipTypeActions(NULL);
      }
+     else {
+       QGraphicsView::mousePressEvent(event);
+       if (m_selectionGroup) {
+           QList<QGraphicsItem *> children = m_selectionGroup->childItems();
+           for (int i = 0; i < children.count(); i++) {
+               children.at(i)->setSelected(itemSelected);
+           }
+             m_selectionGroup->setSelected(itemSelected);
+           
+       }
+       if (dragGroup)
+             dragGroup->setSelected(itemSelected);
+       m_dragItem->setSelected(itemSelected);
+     }
  
      if (collisionClip != NULL || m_dragItem == NULL) {
          if (m_dragItem && m_dragItem->type() == AVWIDGET && !m_dragItem->isItemLocked()) {
  
      // If clicked item is selected, allow move
      //if (!(event->modifiers() | Qt::ControlModifier) && m_operationMode == NONE)
-     QGraphicsView::mousePressEvent(event);
+     //QGraphicsView::mousePressEvent(event);
  
      if (m_dragItem) {
        m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps())), (int)(event->pos().y() - m_dragItem->pos().y()));
      }
  
      m_blockRefresh = false;
-     //kDebug()<<pos;
-     QGraphicsView::mousePressEvent(event);
  }
  
  void CustomTrackView::rebuildGroup(int childTrack, GenTime childPos)
  void CustomTrackView::rebuildGroup(AbstractGroupItem *group)
  {
      if (group) {
-         resetSelectionGroup(false);
-         m_scene->clearSelection();
          QList <QGraphicsItem *> children = group->childItems();
          m_document->clipManager()->removeGroup(group);
-         scene()->destroyItemGroup(group);
-         for (int i = 0; i < children.count(); i++)
-             children.at(i)->setSelected(true);
-         groupSelectedItems(false, true);
+       /*for (int i = 0; i < children.count(); i++) {
+           group->removeFromGroup(children.at(i));
+       }*/
+       scene()->destroyItemGroup(group);
+         groupSelectedItems(children, false, true, true);
      }
  }
  
@@@ -1204,6 -1216,7 +1225,7 @@@ void CustomTrackView::resetSelectionGro
  
          QList<QGraphicsItem *> children = m_selectionGroup->childItems();
          scene()->destroyItemGroup(m_selectionGroup);
+       m_selectionGroup = NULL;
          for (int i = 0; i < children.count(); i++) {
              if (children.at(i)->parentItem() == 0 && (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET)) {
                  if (!static_cast <AbstractClipItem *>(children.at(i))->isItemLocked()) {
                  children.at(i)->setSelected(selectItems);
              }
          }
-         m_selectionGroup = NULL;
          KdenliveSettings::setSnaptopoints(snap);
      }
  }
  
- void CustomTrackView::groupSelectedItems(bool force, bool createNewGroup)
+ void CustomTrackView::groupSelectedItems(QList <QGraphicsItem *> selection, bool force, bool createNewGroup, bool selectNewGroup)
  {
      if (m_selectionGroup) {
          kDebug() << "///// ERROR, TRYING TO OVERRIDE EXISTING GROUP";
          return;
      }
-     QList<QGraphicsItem *> selection = m_scene->selectedItems();
-     if (m_dragItem && !selection.contains(m_dragItem)) {
-       selection << m_dragItem;
+     if (selection.isEmpty()) selection = m_scene->selectedItems();
+     // Split groups and items
+     QSet <QGraphicsItemGroup *> groupsList;
+     QSet <QGraphicsItem *> itemsList;
+     for (int i = 0; i < selection.count(); i++) {
+       if (selection.at(i)->type() == GROUPWIDGET) {
+           groupsList.insert(static_cast<AbstractGroupItem*> (selection.at(i)));
+       }
+     }
+     for (int i = 0; i < selection.count(); i++) {
+       if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET) {
+           if (selection.at(i)->parentItem() && selection.at(i)->parentItem()->type() == GROUPWIDGET) {
+               groupsList.insert(static_cast <QGraphicsItemGroup *> (selection.at(i)->parentItem()));
+           }
+           else {
+               itemsList.insert(selection.at(i));
+           }
+       }
      }
-     if (selection.isEmpty()) return;
+     if (itemsList.isEmpty() && groupsList.isEmpty()) return;
+     
      QRectF rectUnion;
      // Find top left position of selection
-     for (int i = 0; i < selection.count(); i++) {
-         if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
-             rectUnion = rectUnion.united(selection.at(i)->sceneBoundingRect());
-         } else if (selection.at(i)->parentItem()) {
-             rectUnion = rectUnion.united(selection.at(i)->parentItem()->sceneBoundingRect());
-         }
+     foreach (const QGraphicsItemGroup *value, groupsList) {
+         rectUnion = rectUnion.united(value->sceneBoundingRect());
+     }
+     foreach (const QGraphicsItem *value, itemsList) {
+         rectUnion = rectUnion.united(value->sceneBoundingRect());
      }
      if (force || selection.count() > 1) {
          bool snap = KdenliveSettings::snaptopoints();
          KdenliveSettings::setSnaptopoints(false);
              //newGroup->translate((int) -rectUnion.left(), (int) -rectUnion.top() + 1);
  
              scene()->addItem(newGroup);
              // Check if we are trying to include a group in a group
-             QList <AbstractGroupItem *> groups;
-             for (int i = 0; i < selection.count(); i++) {
-                 if (selection.at(i)->type() == GROUPWIDGET && !groups.contains(static_cast<AbstractGroupItem *>(selection.at(i))))
-                     groups.append(static_cast<AbstractGroupItem *>(selection.at(i)));
-                 else if (selection.at(i)->parentItem() && !groups.contains(static_cast<AbstractGroupItem *>(selection.at(i)->parentItem())))
-                     groups.append(static_cast<AbstractGroupItem *>(selection.at(i)->parentItem()));
-             }
-             if (!groups.isEmpty()) {
-                 // ungroup previous groups
-                 while (!groups.isEmpty()) {
-                     AbstractGroupItem *grp = groups.takeFirst();
-                     m_document->clipManager()->removeGroup(grp);
-                     scene()->destroyItemGroup(grp);
-                 }
-                 selection = m_scene->selectedItems();
-             }
+           foreach (QGraphicsItemGroup *value, groupsList) {
+               QList<QGraphicsItem *> children = value->childItems();
+               for (int i = 0; i < children.count(); i++) {
+                   if (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET)
+                       itemsList.insert(children.at(i));
+               }
+               AbstractGroupItem *grp = static_cast<AbstractGroupItem *>(value);
+               m_document->clipManager()->removeGroup(grp);
+               scene()->destroyItemGroup(grp);
+           }
  
-             for (int i = 0; i < selection.count(); i++) {
-                 if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET) {
-                     newGroup->addToGroup(selection.at(i));
-                     selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
-                 }
+           foreach (QGraphicsItem *value, itemsList) {
+                 newGroup->addItem(value);
              }
              KdenliveSettings::setSnaptopoints(snap);
+           if (selectNewGroup) newGroup->setSelected(true);
          } else {
              m_selectionGroup = new AbstractGroupItem(m_document->fps());
              m_selectionGroup->setPos(rectUnion.left(), rectUnion.top() - 1);
              m_selectionGroup->translate(- diff.x(), -diff.y());
  
              scene()->addItem(m_selectionGroup);
-             for (int i = 0; i < selection.count(); i++) {
-                 if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
-                     m_selectionGroup->addToGroup(selection.at(i));
-                     selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
-                 }
+             foreach (QGraphicsItemGroup *value, groupsList) {
+                 m_selectionGroup->addItem(value);
+             }
+             foreach (QGraphicsItem *value, itemsList) {
+                 m_selectionGroup->addItem(value);
              }
              KdenliveSettings::setSnaptopoints(snap);
              if (m_selectionGroup) {
                  m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps());
                  m_selectionGroupInfo.track = m_selectionGroup->track();
+               if (selectNewGroup) m_selectionGroup->setSelected(true);
              }
          }
      } else resetSelectionGroup();
@@@ -1576,8 -1594,7 +1603,7 @@@ bool CustomTrackView::insertDropClips(c
          }
          m_selectionGroup = new AbstractGroupItem(m_document->fps());
          ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, getFrameWidth());
-         m_selectionGroup->addToGroup(item);
-         item->setFlag(QGraphicsItem::ItemIsMovable, false);
+         m_selectionGroup->addItem(item);
  
          QList <GenTime> offsetList;
          offsetList.append(info.endPos);
              start += info.cropDuration;
              offsetList.append(start);
              ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, getFrameWidth(), false);
-             item->setFlag(QGraphicsItem::ItemIsMovable, false);
-             m_selectionGroup->addToGroup(item);
+             m_selectionGroup->addItem(item);
              if (!clip->isPlaceHolder()) m_waitingThumbs.append(item);
          }
  
@@@ -2615,6 -2631,7 +2640,7 @@@ void CustomTrackView::dropEvent(QDropEv
      if (m_selectionGroup && m_clipDrag) {
          QList<QGraphicsItem *> items = m_selectionGroup->childItems();
          resetSelectionGroup();
+       m_dragItem = NULL;
          m_scene->clearSelection();
          bool hasVideoClip = false;
          QUndoCommand *addCommand = new QUndoCommand();
  
          m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
          if (items.count() > 1) {
-             groupSelectedItems(true);
+             groupSelectedItems(items, true);
          } else if (items.count() == 1) {
              m_dragItem = static_cast <AbstractClipItem *>(items.at(0));
              emit clipItemSelected((ClipItem*) m_dragItem, false);
          }
+         m_document->renderer()->refreshIfActive();
          event->setDropAction(Qt::MoveAction);
          event->accept();
  
@@@ -2882,8 -2900,7 +2909,7 @@@ void CustomTrackView::addTrack(TrackInf
          scene()->addItem(m_selectionGroup);
          for (int i = 0; i < selection.count(); i++) {
              if ((!selection.at(i)->parentItem()) && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
-                 m_selectionGroup->addToGroup(selection.at(i));
-                 selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
+                 m_selectionGroup->addItem(selection.at(i));
              }
          }
          // Move graphic items
@@@ -2967,8 -2984,7 +2993,7 @@@ void CustomTrackView::removeTrack(int i
      scene()->addItem(m_selectionGroup);
      for (int i = 0; i < selection.count(); i++) {
          if ((!selection.at(i)->parentItem()) && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
-             m_selectionGroup->addToGroup(selection.at(i));
-             selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
+             m_selectionGroup->addItem(selection.at(i));
          }
      }
      // Move graphic items
@@@ -3345,11 -3361,9 +3370,9 @@@ void CustomTrackView::insertSpace(QList
              clip = getClipItemAtStart(clipsToMove.at(i).startPos + offset, clipsToMove.at(i).track);
              if (clip) {
                  if (clip->parentItem()) {
-                     m_selectionGroup->addToGroup(clip->parentItem());
-                     clip->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
+                     m_selectionGroup->addItem(clip->parentItem());
                  } else {
-                     m_selectionGroup->addToGroup(clip);
-                     clip->setFlag(QGraphicsItem::ItemIsMovable, false);
+                     m_selectionGroup->addItem(clip);
                  }
                  if (trackClipStartList.value(m_document->tracksCount() - clipsToMove.at(i).track) == -1 || clipsToMove.at(i).startPos.frames(m_document->fps()) < trackClipStartList.value(m_document->tracksCount() - clipsToMove.at(i).track))
                      trackClipStartList[m_document->tracksCount() - clipsToMove.at(i).track] = clipsToMove.at(i).startPos.frames(m_document->fps());
              transition = getTransitionItemAtStart(transToMove.at(i).startPos + offset, transToMove.at(i).track);
              if (transition) {
                  if (transition->parentItem()) {
-                     m_selectionGroup->addToGroup(transition->parentItem());
-                     transition->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
+                     m_selectionGroup->addItem(transition->parentItem());
                  } else {
-                     m_selectionGroup->addToGroup(transition);
-                     transition->setFlag(QGraphicsItem::ItemIsMovable, false);
+                     m_selectionGroup->addItem(transition);
                  }
                  if (trackTransitionStartList.value(m_document->tracksCount() - transToMove.at(i).track) == -1 || transToMove.at(i).startPos.frames(m_document->fps()) < trackTransitionStartList.value(m_document->tracksCount() - transToMove.at(i).track))
                      trackTransitionStartList[m_document->tracksCount() - transToMove.at(i).track] = transToMove.at(i).startPos.frames(m_document->fps());
@@@ -3417,8 -3429,10 +3438,10 @@@ void CustomTrackView::deleteClip(const 
          delete deleteCommand;
      } else {
          updateTrackDuration(-1, deleteCommand);
+       new RefreshMonitorCommand(this, false, deleteCommand);
          m_commandStack->push(deleteCommand);
      }
+     m_document->renderer()->doRefresh();    
  }
  
  void CustomTrackView::seekCursorPos(int pos)
@@@ -3483,16 -3497,22 +3506,22 @@@ void CustomTrackView::checkScrolling(
  void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
  {
      if (m_moveOpMode == SEEK) m_moveOpMode = NONE;
-     if (!m_controlModifier) QGraphicsView::mouseReleaseEvent(event);
-     setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
- #if QT_VERSION >= 0x040600
-     if (m_dragItem) m_dragItem->setGraphicsEffect(NULL);
+     if (!m_controlModifier && m_operationMode != RUBBERSELECTION) {
+       //event->accept();
+       if (m_clipDrag) QGraphicsView::mouseReleaseEvent(event);
+     }
+     m_clipDrag = false;
+     //setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
+ #if QT_VERSION >= 0x040800
+     if (m_dragItem) {
+       m_dragItem->setGraphicsEffect(NULL);
+     }
  #endif
      if (m_scrollTimer.isActive()) m_scrollTimer.stop();
      if (event->button() == Qt::MidButton) {
          return;
      }
-     setDragMode(QGraphicsView::NoDrag);
      if (m_operationMode == MOVEGUIDE) {
          setCursor(Qt::ArrowCursor);
          m_operationMode = NONE;
                  updateTrackDuration(track, command);
                  m_commandStack->push(command);
                  if (track != -1) track = m_document->tracksCount() - track;
-                 kDebug() << "SPACER TRACK:" << track;
                  m_document->renderer()->mltInsertSpace(trackClipStartList, trackTransitionStartList, track, timeOffset, GenTime());
                  setDocumentModified();
              }
          }
-         for (int i = 0; i < groups.count(); i++)
+         resetSelectionGroup();
+         for (int i = 0; i < groups.count(); i++) {
            rebuildGroup(groups.at(i));
+       }
  
-       resetSelectionGroup();
        
          clearSelection();
        
          m_operationMode = NONE;
      } else if (m_operationMode == RUBBERSELECTION) {
+       //event->accept();
+       QGraphicsView::mouseReleaseEvent(event);
+       setDragMode(QGraphicsView::NoDrag);
+       setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
+       if (event->modifiers() != Qt::ControlModifier) m_dragItem = NULL;
          resetSelectionGroup();
          groupSelectedItems();
          m_operationMode = NONE;
              // Moving several clips. We need to delete them and readd them to new position,
              // or they might overlap each other during the move
              QGraphicsItemGroup *group;
-             if (m_selectionGroup)
+             if (m_selectionGroup) {
                  group = static_cast <QGraphicsItemGroup *>(m_selectionGroup);
-             else
+           }
+             else {
                  group = static_cast <QGraphicsItemGroup *>(m_dragItem->parentItem());
+           }
              QList<QGraphicsItem *> items = group->childItems();
              QList<ItemInfo> clipsToMove;
              QList<ItemInfo> transitionsToMove;
                  if (m_selectionGroup) {
                      m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps());
                      m_selectionGroupInfo.track = m_selectionGroup->track();
-                   QList <AbstractGroupItem*> groupList;
-                     for (int i = 0; i < items.count(); ++i) {
-                         if (items.at(i)->type() == GROUPWIDGET) {
-                           AbstractGroupItem* group = (AbstractGroupItem*)items.at(i);
-                           if (!groupList.contains(group)) groupList.append(group);
-                             items.removeAt(i);
-                             --i;
+                   items = m_selectionGroup->childItems();
+                   resetSelectionGroup(false);
+                   QSet <QGraphicsItem*> groupList;
+                   QSet <QGraphicsItem*> itemList;
+                   while (!items.isEmpty()) {
+                       QGraphicsItem *first = items.takeFirst();
+                       if (first->type() == GROUPWIDGET) {
+                           if (first != m_selectionGroup) {
+                               groupList.insert(first);
+                           }
                          }
-                     }
-                     for (int i = 0; i < groupList.count(); ++i) {
-                       rebuildGroup(groupList.at(i));
+                         else if (first->type() == AVWIDGET || first->type() == TRANSITIONWIDGET) {
+                           if (first->parentItem() && first->parentItem()->type() == GROUPWIDGET) {
+                               if (first->parentItem() != m_selectionGroup) {
+                                   groupList.insert(first->parentItem());
+                               }
+                               else itemList.insert(first);
+                           }
+                           else itemList.insert(first);
+                       }
                    }
-                     
-                     for (int i = 0; i < items.count(); ++i) {
-                         if (items.at(i)) {
-                             items.at(i)->setSelected(true);
-                             if (items.at(i)->parentItem())
-                                 items.at(i)->parentItem()->setSelected(true);
-                         }
+                   foreach(QGraphicsItem *item, groupList) {
+                       itemList.unite(item->childItems().toSet());
+                       rebuildGroup(static_cast <AbstractGroupItem*>(item));
+                   }
+                     foreach(QGraphicsItem *item, itemList) {
+                       item->setSelected(true);
+                         if (item->parentItem())
+                             item->parentItem()->setSelected(true);
                      }
                      resetSelectionGroup();
-                     groupSelectedItems();
+                     groupSelectedItems(itemList.toList());
                  } else {
-                     rebuildGroup((AbstractGroupItem *)group);
+                   AbstractGroupItem *grp = static_cast <AbstractGroupItem *>(group);
+                     rebuildGroup(grp);
                  }
                  setDocumentModified();
              }
@@@ -4161,7 -4200,9 +4209,9 @@@ void CustomTrackView::deleteSelectedCli
          deleteSelected->setText(i18np("Delete selected transition", "Delete selected transitions", transitionCount));
      else deleteSelected->setText(i18n("Delete selected items"));
      updateTrackDuration(-1, deleteSelected);
+     new RefreshMonitorCommand(this, false, deleteSelected);
      m_commandStack->push(deleteSelected);
+     m_document->renderer()->doRefresh();
  }
  
  
@@@ -4353,21 -4394,22 +4403,22 @@@ void CustomTrackView::doGroupClips(QLis
          setDocumentModified();
          return;
      }
-     QList <QGraphicsItemGroup *> groups;
+     QList <QGraphicsItem *>list;
      for (int i = 0; i < clipInfos.count(); i++) {
          ClipItem *clip = getClipItemAt(clipInfos.at(i).startPos, clipInfos.at(i).track);
          if (clip) {
-             clip->setSelected(true);
+           list.append(clip);
+             //clip->setSelected(true);
          }
      }
      for (int i = 0; i < transitionInfos.count(); i++) {
          Transition *clip = getTransitionItemAt(transitionInfos.at(i).startPos, transitionInfos.at(i).track);
          if (clip) {
-             clip->setSelected(true);
+           list.append(clip);
+             //clip->setSelected(true);
          }
      }
-     groupSelectedItems(false, true);
+     groupSelectedItems(list, false, true);
      setDocumentModified();
  }
  
@@@ -4650,11 -4692,9 +4701,9 @@@ void CustomTrackView::moveGroup(QList <
          if (clip) {
              clip->setItemLocked(false);
              if (clip->parentItem()) {
-                 m_selectionGroup->addToGroup(clip->parentItem());
-                 clip->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
+                 m_selectionGroup->addItem(clip->parentItem());
              } else {
-                 m_selectionGroup->addToGroup(clip);
-                 clip->setFlag(QGraphicsItem::ItemIsMovable, false);
+                 m_selectionGroup->addItem(clip);
              }
              m_document->renderer()->mltRemoveClip(m_document->tracksCount() - startClip.at(i).track, startClip.at(i).startPos);
          } else kDebug() << "//MISSING CLIP AT: " << startClip.at(i).startPos.frames(25);
          if (tr) {
              tr->setItemLocked(false);
              if (tr->parentItem()) {
-                 m_selectionGroup->addToGroup(tr->parentItem());
-                 tr->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
+                 m_selectionGroup->addItem(tr->parentItem());
              } else {
-                 m_selectionGroup->addToGroup(tr);
-                 tr->setFlag(QGraphicsItem::ItemIsMovable, false);
+                 m_selectionGroup->addItem(tr);
              }
              m_document->renderer()->mltDeleteTransition(tr->transitionTag(), tr->transitionEndTrack(), m_document->tracksCount() - startTransition.at(i).track, startTransition.at(i).startPos, startTransition.at(i).endPos, tr->toXML());
          } else kDebug() << "//MISSING TRANSITION AT: " << startTransition.at(i).startPos.frames(25);
          }
  
          resetSelectionGroup(false);
-       for (int i = 0; i < groupList.count(); i++)
+       for (int i = 0; i < groupList.count(); i++) {
            rebuildGroup(groupList.at(i));
+       }
  
          clearSelection();
  
@@@ -5977,6 -6016,7 +6025,7 @@@ void CustomTrackView::pasteClip(
          }
      }
      updateTrackDuration(-1, pasteClips);
+     new RefreshMonitorCommand(this, false, pasteClips);
      m_commandStack->push(pasteClips);
  }
  
@@@ -6422,19 -6462,20 +6471,20 @@@ void CustomTrackView::loadGroups(const 
      for (int i = 0; i < groups.count(); i++) {
          QDomNodeList children = groups.at(i).childNodes();
          scene()->clearSelection();
+       QList <QGraphicsItem*>list;
          for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) {
              QDomElement elem = children.item(nodeindex).toElement();
              int pos = elem.attribute("position").toInt();
              int track = elem.attribute("track").toInt();
              if (elem.tagName() == "clipitem") {
                  ClipItem *clip = getClipItemAt(pos, track); //m_document->tracksCount() - transitiontrack);
-                 if (clip) clip->setSelected(true);
+                 if (clip) list.append(clip);//clip->setSelected(true);
              } else {
                  Transition *clip = getTransitionItemAt(pos, track); //m_document->tracksCount() - transitiontrack);
-                 if (clip) clip->setSelected(true);
+                 if (clip) list.append(clip);//clip->setSelected(true);
              }
          }
-         groupSelectedItems(false, true);
+         groupSelectedItems(list, false, true);
      }
  }
  
@@@ -6631,28 -6672,25 +6681,25 @@@ void CustomTrackView::doSplitAudio(cons
                  }
              }
          }
-         kDebug() << "GOT TRK: " << track;
          if (freetrack == 0) {
              emit displayMessage(i18n("No empty space to put clip audio"), ErrorMessage);
          } else {
              ItemInfo info = clip->info();
              info.track = m_document->tracksCount() - freetrack;
-             addClip(clip->xml(), clip->clipProducer(), info, clip->effectList());
-             scene()->clearSelection();
+           QDomElement xml = clip->xml();
+           xml.setAttribute("audio_only", 1);
+           scene()->clearSelection();
+             addClip(xml, clip->clipProducer(), info, clip->effectList(), false, false, false);
              clip->setSelected(true);
              ClipItem *audioClip = getClipItemAt(start, info.track);
              if (audioClip) {
+               clip->setVideoOnly(true);
                  Mlt::Tractor *tractor = m_document->renderer()->lockService();
-                 clip->setVideoOnly(true);
                  if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - track, start, clip->baseClip()->videoProducer(info.track)) == false) {
                      emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
                  }
-                 if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - info.track, start, clip->baseClip()->audioProducer(info.track)) == false) {
-                     emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, info.track), ErrorMessage);
-                 }
                  m_document->renderer()->unlockService(tractor);
                  audioClip->setSelected(true);
-                 audioClip->setAudioOnly(true);
  
                  // keep video effects, move audio effects to audio clip
                  int videoIx = 0;
                          videoIx++;
                      }
                  }
-                 groupSelectedItems(false, true);
+                 groupSelectedItems(QList <QGraphicsItem*>()<<clip<<audioClip, false, true);
              }
          }
      } else {
@@@ -6792,6 -6829,11 +6838,11 @@@ void CustomTrackView::setAudioAndVideo(
      m_commandStack->push(videoCommand);
  }
  
+ void CustomTrackView::monitorRefresh()
+ {
+     m_document->renderer()->doRefresh();
+ }
  void CustomTrackView::doChangeClipType(const GenTime &pos, int track, bool videoOnly, bool audioOnly)
  {
      ClipItem *clip = getClipItemAt(pos, track);
@@@ -6937,13 -6979,13 +6988,13 @@@ void CustomTrackView::updateProjectFps(
              m_scene->addItem(grp);
              scene()->destroyItemGroup(grp);
              scene()->clearSelection();
-             for (int j = 0; j < children.count(); j++) {
+             /*for (int j = 0; j < children.count(); j++) {
                  if (children.at(j)->type() == AVWIDGET || children.at(j)->type() == TRANSITIONWIDGET) {
                      //children.at(j)->setParentItem(0);
                      children.at(j)->setSelected(true);
                  }
-             }
-             groupSelectedItems(true, true);
+             }*/
+             groupSelectedItems(children, true, true);
          } else if (itemList.at(i)->type() == GUIDEITEM) {
              Guide *g = static_cast<Guide *>(itemList.at(i));
              g->updatePos();
@@@ -7018,26 -7060,22 +7069,22 @@@ void CustomTrackView::slotSelectClipsIn
      QRectF rect(0, m_selectedTrack * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), m_tracksHeight / 2 - 1);
      QList<QGraphicsItem *> selection = m_scene->items(rect);
      m_scene->clearSelection();
+     QList<QGraphicsItem *> list;
      for (int i = 0; i < selection.count(); i++) {
          if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET) {
-             selection.at(i)->setSelected(true);
+           list.append(selection.at(i));
          }
      }    
      resetSelectionGroup();
-     groupSelectedItems();
+     groupSelectedItems(list);
  }
  
  void CustomTrackView::slotSelectAllClips()
  {
      QList<QGraphicsItem *> selection = m_scene->items();
      m_scene->clearSelection();
-     for (int i = 0; i < selection.count(); i++) {
-         if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET  || selection.at(i)->type() == GROUPWIDGET) {
-             selection.at(i)->setSelected(true);
-         }
-     }
      resetSelectionGroup();
-     groupSelectedItems();
+     groupSelectedItems(selection);
  }
  
  void CustomTrackView::selectClip(bool add, bool group, int track, int pos)
diff --combined src/customtrackview.h
index bdaa74615ced455dc0a4194b50fccfabb742d120,f27f9710d489ee7a850bf5f1e3d6bcdbd30c49e8..42341874912e805f8d58758e023836bbeca2cd98
@@@ -205,6 -205,9 +205,9 @@@ public
      int getFrameWidth();
      /** @brief Returns last requested seeking pos (or SEEK_INACTIVE if no seek). */
      int seekPosition() const;
+     /** @brief Trigger a monitor refresh. */
+     void monitorRefresh();
      
  public slots:
      /** @brief Send seek request to MLT. */
  
      /** @brief Get effect parameters ready for MLT*/
      static void adjustEffectParameters(EffectsParameterList &parameters, QDomNodeList params, MltVideoProfile profile, const QString &prefix = QString());
 +      /** @brief Move playhead to mouse curser position if defined key is pressed */
 +    void slotAlignPlayheadToMousePos();
  
  protected:
      virtual void drawBackground(QPainter * painter, const QRectF & rect);
@@@ -408,7 -409,7 +411,7 @@@ private
      ClipItem *getClipUnderCursor() const;
      AbstractClipItem *getMainActiveClip() const;
      void resetSelectionGroup(bool selectItems = true);
-     void groupSelectedItems(bool force = false, bool createNewGroup = false);
+     void groupSelectedItems(QList <QGraphicsItem *> selection = QList <QGraphicsItem *>(), bool force = false, bool createNewGroup = false, bool selectNewGroup = false);
      /** Get available space for clip move (min and max free positions) */
      void getClipAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
      /** Get available space for transition move (min and max free positions) */
diff --combined src/mainwindow.cpp
index 9eadf01bba1eb02cb706e885d0bab17804ccd8dc,9139b6d2ec72b6ef2b6460a0131c4152f61b025a..7355b8d33b3c581b3c63947bb26d5fa55393866a
@@@ -234,7 -234,7 +234,7 @@@ MainWindow::MainWindow(const QString &M
  
      // Connect the project list
      connect(m_projectList, SIGNAL(clipSelected(DocClipBase *, QPoint, bool)), m_clipMonitor, SLOT(slotSetClipProducer(DocClipBase *, QPoint, bool)));
-     connect(m_projectList, SIGNAL(raiseClipMonitor()), m_clipMonitor, SLOT(slotActivateMonitor()));
+     connect(m_projectList, SIGNAL(raiseClipMonitor(bool)), m_clipMonitor, SLOT(slotActivateMonitor(bool)));
      connect(m_projectList, SIGNAL(loadingIsOver()), this, SLOT(slotElapsedTime()));
      connect(m_projectList, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
      connect(m_projectList, SIGNAL(updateRenderStatus()), this, SLOT(slotCheckRenderStatus()));
@@@ -1402,11 -1402,6 +1402,11 @@@ void MainWindow::setupActions(
      collection.addAction("delete_timeline_clip", deleteItem);
      connect(deleteItem, SIGNAL(triggered(bool)), this, SLOT(slotDeleteItem()));
  
 +    KAction* alignPlayhead = new KAction(i18n("Align Playhead to Mouse Position"), this);
 +    alignPlayhead->setShortcut(Qt::Key_P);
 +    collection.addAction("align_playhead", alignPlayhead);
 +    connect(alignPlayhead, SIGNAL(triggered(bool)), this, SLOT(slotAlignPlayheadToMousePos()));
 +
      /*KAction* editTimelineClipSpeed = new KAction(i18n("Change Clip Speed"), this);
      collection.addAction("change_clip_speed", editTimelineClipSpeed);
      editTimelineClipSpeed->setData("change_speed");
@@@ -4592,10 -4587,6 +4592,10 @@@ void MainWindow::slotProcessImportKeyfr
      }
  }
  
 +void MainWindow::slotAlignPlayheadToMousePos()
 +{
 +      m_activeTimeline->projectView()->slotAlignPlayheadToMousePos();
 +}
  
  #include "mainwindow.moc"