-}
-void Transition::paint(QPainter *painter,
- const QStyleOptionGraphicsItem *option,
- QWidget *widget) {
- QRect rectInView = visibleRect();//this is the rect that is visible by the user
-
- if (rectInView.isNull())
- return;
- QPainterPath clippath;
- clippath.addRect(rectInView);
- QRectF br = rect();
- QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
-
- QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
-
- painter->setClipPath(resultClipPath.intersected(clippath), Qt::IntersectClip);
- //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
- painter->fillRect(br.intersected(rectInView), QBrush(QColor(200, 200, 0, 160)/*,Qt::Dense4Pattern*/));
- painter->setClipRect(option->exposedRect);
- painter->drawPixmap((int)(br.x() + 10), (int)(br.y() + 10), transitionPixmap());
- painter->drawPath(resultClipPath.intersected(clippath));
- painter->setPen(QColor(0, 0, 0, 180));
- painter->drawText((int)br.x() + 31, (int)br.y() + 21, transitionName());
- painter->setPen(QColor(255, 255, 255, 180));
- painter->drawText((int)br.x() + 30, (int)br.y() + 20, transitionName());
- QPen pen = painter->pen();
- if (isSelected()) {
- pen.setColor(Qt::red);
- pen.setWidth(2);
- } else {
- pen.setColor(Qt::black);
- pen.setWidth(1);
+ 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);
+ QStringList lockedTracks = property("locked_tracks").toStringList();
+ if (lockedTracks.contains(QString::number(newTrack))) {
+ // Trying to move to a locked track
+ return pos();
+ }
+ 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;