- QPointF sc = mapToScene(pos());
- int posx = start.x() + newPos.x(); //projectScene()->getSnapPointForPos(start.x() + sc.x(), KdenliveSettings::snaptopoints());
- //int startx = projectScene()->getSnapPointForPos(start.x(), false);
- //int startx = projectScene()->getSnapPointForPos(start.x(), false);
- kDebug() << "------------------------------------";
- kDebug() << "BRect: " << start.x() << "diff: " << newPos.x() << ",mapd: " << start.x() - sc.x();
- return newPos;
- //kDebug()<<"BR: "<<start.x()<<",NP: "<<newPos.x()<<",MAPD: "<<sc.x()<<",POS: "<<pos().x();
- if (start.x() <= 0) {
- //kDebug()<<"/// GOING UNDER 0, POS: "<<posx<<", ADJUSTED: items.at(i)->sceneBoundingRect();
- return pos();
+ QPointF newPos = value.toPointF();
+ int xpos = projectScene()->getSnapPointForPos((int)(start.x() + newPos.x() - pos().x()), KdenliveSettings::snaptopoints());
+
+ xpos = qMax(xpos, 0);
+ //kDebug()<<"GRP XPOS:"<<xpos<<", START:"<<start.x()<<",NEW:"<<newPos.x()<<"; SCENE:"<<scenePos().x()<<",POS:"<<pos().x();
+ newPos.setX((int)(pos().x() + xpos - (int) start.x()));
+ QStringList lockedTracks = property("locked_tracks").toStringList();
+ int proposedTrack = (property("y_absolute").toInt() + newPos.y()) / trackHeight;
+ // Check if top item is a clip or a transition
+ int offset = 0;
+ int topTrack = -1;
+ QList<int> groupTracks;
+ QList<QGraphicsItem *> children = childItems();
+ for (int i = 0; i < children.count(); ++i) {
+ int currentTrack = 0;
+ if (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET) {
+ currentTrack = static_cast <AbstractClipItem*> (children.at(i))->track();
+ if (!groupTracks.contains(currentTrack)) groupTracks.append(currentTrack);
+ }
+ else if (children.at(i)->type() == GROUPWIDGET) {
+ currentTrack = static_cast <AbstractGroupItem*> (children.at(i))->track();
+ }
+ else continue;
+ if (children.at(i)->type() == AVWIDGET) {
+ if (topTrack == -1 || currentTrack <= topTrack) {
+ offset = 0;
+ topTrack = currentTrack;
+ }
+ } else if (children.at(i)->type() == TRANSITIONWIDGET) {
+ if (topTrack == -1 || currentTrack < topTrack) {
+ offset = (int)(trackHeight / 3 * 2 - 1);
+ topTrack = currentTrack;
+ }
+ } else if (children.at(i)->type() == GROUPWIDGET) {
+ QList<QGraphicsItem *> subchildren = children.at(i)->childItems();
+ bool clipGroup = false;
+ for (int j = 0; j < subchildren.count(); j++) {
+ if (subchildren.at(j)->type() == AVWIDGET || subchildren.at(j)->type() == TRANSITIONWIDGET) {
+ int subTrack = static_cast <AbstractClipItem*> (subchildren.at(j))->track();
+ if (!groupTracks.contains(subTrack)) groupTracks.append(subTrack);
+ clipGroup = true;
+ }
+ }
+ if (clipGroup) {
+ if (topTrack == -1 || currentTrack <= topTrack) {
+ offset = 0;
+ topTrack = currentTrack;
+ }
+ } else {
+ if (topTrack == -1 || currentTrack < topTrack) {
+ offset = (int)(trackHeight / 3 * 2 - 1);
+ topTrack = currentTrack;
+ }
+ }
+ }
+ }
+ // Check no clip in the group goes outside of existing tracks
+ int maximumTrack = projectScene()->tracksCount() - 1;
+ int groupHeight = 0;
+ for (int i = 0; i < groupTracks.count(); ++i) {
+ int offset = groupTracks.at(i) - topTrack;
+ if (offset > groupHeight) groupHeight = offset;
+ }
+ maximumTrack -= groupHeight;
+ proposedTrack = qMin(proposedTrack, maximumTrack);
+ proposedTrack = qMax(proposedTrack, 0);
+ int groupOffset = proposedTrack - topTrack;
+ if (!lockedTracks.isEmpty()) {
+ for (int i = 0; i < groupTracks.count(); ++i) {
+ if (lockedTracks.contains(QString::number(groupTracks.at(i) + groupOffset))) {
+ return pos();
+ }
+ }