! \brief Pastes a selection of TCOs onto the track * * \param tcoPos the position of the TCO slot being pasted on * \param de the DropEvent generated */
| 1415 | * \param de the DropEvent generated |
| 1416 | */ |
| 1417 | bool TrackContentWidget::pasteSelection( MidiTime tcoPos, QDropEvent * de ) |
| 1418 | { |
| 1419 | if( canPasteSelection( tcoPos, de ) == false ) |
| 1420 | { |
| 1421 | return false; |
| 1422 | } |
| 1423 | |
| 1424 | QString type = StringPairDrag::decodeKey( de ); |
| 1425 | QString value = StringPairDrag::decodeValue( de ); |
| 1426 | |
| 1427 | getTrack()->addJournalCheckPoint(); |
| 1428 | |
| 1429 | // value contains XML needed to reconstruct TCOs and place them |
| 1430 | DataFile dataFile( value.toUtf8() ); |
| 1431 | |
| 1432 | // Extract the tco data |
| 1433 | QDomElement tcoParent = dataFile.content().firstChildElement( "tcos" ); |
| 1434 | QDomNodeList tcoNodes = tcoParent.childNodes(); |
| 1435 | |
| 1436 | // Extract the track index that was originally clicked |
| 1437 | QDomElement metadata = dataFile.content().firstChildElement( "copyMetadata" ); |
| 1438 | QDomAttr tiAttr = metadata.attributeNode( "initialTrackIndex" ); |
| 1439 | int initialTrackIndex = tiAttr.value().toInt(); |
| 1440 | QDomAttr tcoPosAttr = metadata.attributeNode( "grabbedTCOPos" ); |
| 1441 | MidiTime grabbedTCOPos = tcoPosAttr.value().toInt(); |
| 1442 | MidiTime grabbedTCOTact = MidiTime( grabbedTCOPos.getTact(), 0 ); |
| 1443 | |
| 1444 | // Snap the mouse position to the beginning of the dropped tact, in ticks |
| 1445 | const TrackContainer::TrackList tracks = getTrack()->trackContainer()->tracks(); |
| 1446 | const int currentTrackIndex = tracks.indexOf( getTrack() ); |
| 1447 | |
| 1448 | bool allowRubberband = m_trackView->trackContainerView()->allowRubberband(); |
| 1449 | |
| 1450 | // Unselect the old group |
| 1451 | if( allowRubberband == true ) |
| 1452 | { |
| 1453 | const QVector<selectableObject *> so = |
| 1454 | m_trackView->trackContainerView()->selectedObjects(); |
| 1455 | for( QVector<selectableObject *>::const_iterator it = so.begin(); |
| 1456 | it != so.end(); ++it ) |
| 1457 | { |
| 1458 | ( *it )->setSelected( false ); |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | // TODO -- Need to draw the hovericon either way, or ghost the TCOs |
| 1463 | // onto their final position. |
| 1464 | |
| 1465 | for( int i = 0; i<tcoNodes.length(); i++ ) |
| 1466 | { |
| 1467 | QDomElement outerTCOElement = tcoNodes.item( i ).toElement(); |
| 1468 | QDomElement tcoElement = outerTCOElement.firstChildElement(); |
| 1469 | |
| 1470 | int trackIndex = outerTCOElement.attributeNode( "trackIndex" ).value().toInt(); |
| 1471 | int finalTrackIndex = trackIndex + ( currentTrackIndex - initialTrackIndex ); |
| 1472 | Track * t = tracks.at( finalTrackIndex ); |
| 1473 | |
| 1474 | // Compute the final position by moving the tco's pos by |
no test coverage detected