-}
-void Transition::paint(QPainter *painter,
- const QStyleOptionGraphicsItem *option,
- QWidget *widget) {
- QRect rectInView;//this is the rect that is visible by the user
- if (scene()->views().size() > 0) {
- rectInView = scene()->views()[0]->viewport()->rect();
- rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(), scene()->views()[0]->verticalScrollBar()->value());
- rectInView.adjust(-10, -10, 10, 10);//make view rect 10 pixel greater on each site, or repaint after scroll event
- //kDebug() << scene()->views()[0]->viewport()->rect() << " " << scene()->views()[0]->horizontalScrollBar()->value();
+ if (change == ItemPositionChange && scene()) {
+ // calculate new position.
+ QPointF newPos = value.toPointF();
+ int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
+ xpos = qMax(xpos, 0);
+ newPos.setX(xpos);
+ int newTrack = newPos.y() / KdenliveSettings::trackheight();
+ newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
+ newTrack = qMax(newTrack, 0);
+ newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + itemOffset() + 1));
+ // Only one clip is moving
+ QRectF sceneShape = rect();
+ sceneShape.translate(newPos);
+ QList<QGraphicsItem*> items;
+ // TODO: manage transitions in OVERWRITE MODE
+ //if (projectScene()->editMode() == NORMALEDIT)
+ items = scene()->items(sceneShape, Qt::IntersectsItemShape);
+ items.removeAll(this);
+
+ bool forwardMove = newPos.x() > pos().x();
+ int offset = 0;
+ if (!items.isEmpty()) {
+ for (int i = 0; i < items.count(); i++) {
+ if (!items.at(i)->isEnabled()) continue;
+ if (items.at(i)->type() == type()) {
+ // Collision!
+ QPointF otherPos = items.at(i)->pos();
+ if ((int) otherPos.y() != (int) pos().y()) {
+ return pos();
+ }
+ if (forwardMove) {
+ offset = qMax(offset, (int)(newPos.x() - (static_cast < AbstractClipItem* >(items.at(i))->startPos() - cropDuration()).frames(m_fps)));
+ } else {
+ offset = qMax(offset, (int)((static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps)) - newPos.x()));
+ }
+
+ if (offset > 0) {
+ if (forwardMove) {
+ sceneShape.translate(QPointF(-offset, 0));
+ newPos.setX(newPos.x() - offset);
+ } else {
+ sceneShape.translate(QPointF(offset, 0));
+ newPos.setX(newPos.x() + offset);
+ }
+ QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
+ subitems.removeAll(this);
+ for (int j = 0; j < subitems.count(); j++) {
+ if (!subitems.at(j)->isEnabled()) continue;
+ if (subitems.at(j)->type() == type()) {
+ // move was not successful, revert to previous pos
+ m_info.startPos = GenTime((int) pos().x(), m_fps);
+ return pos();
+ }
+ }
+ }
+
+ m_info.track = newTrack;
+ m_info.startPos = GenTime((int) newPos.x(), m_fps);
+
+ return newPos;
+ }
+ }
+ }
+
+ m_info.track = newTrack;
+ m_info.startPos = GenTime((int) newPos.x(), m_fps);
+ //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
+ return newPos;