comparison layer/TimeInstantLayer.cpp @ 359:020c485aa7e0

* More work on aligning copy/paste between layers. It's a surprisingly complicated business.
author Chris Cannam
date Wed, 06 Feb 2008 12:49:49 +0000
parents 8b69f36c74be
children d58701996fae
comparison
equal deleted inserted replaced
358:8b69f36c74be 359:020c485aa7e0
710 710
711 command->finish(); 711 command->finish();
712 } 712 }
713 713
714 void 714 void
715 TimeInstantLayer::copy(Selection s, Clipboard &to) 715 TimeInstantLayer::copy(View *v, Selection s, Clipboard &to)
716 { 716 {
717 if (!m_model) return; 717 if (!m_model) return;
718 718
719 SparseOneDimensionalModel::PointList points = 719 SparseOneDimensionalModel::PointList points =
720 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 720 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
727 //!!! This fails, because simply being "on the same pane as" a 727 //!!! This fails, because simply being "on the same pane as" a
728 // particular model is not enough to give this layer the same 728 // particular model is not enough to give this layer the same
729 // alignment as it. If it was generated by deriving from another 729 // alignment as it. If it was generated by deriving from another
730 // layer's model, that would be... but it wasn't necessarily 730 // layer's model, that would be... but it wasn't necessarily
731 731
732 point.setReferenceFrame(m_model->alignToReference(i->frame)); 732 point.setReferenceFrame(alignToReference(v, i->frame));
733
734 std::cerr << "TimeInstantLayer::copy: frame = " << i->frame << ", reference frame = " << point.getReferenceFrame() << std::endl;
735
733 to.addPoint(point); 736 to.addPoint(point);
734 } 737 }
735 } 738 }
736 } 739 }
737 740
738 bool 741 bool
739 TimeInstantLayer::clipboardAlignmentDiffers(const Clipboard &clip) const 742 TimeInstantLayer::clipboardAlignmentDiffers(View *v, const Clipboard &clip) const
740 { 743 {
741 //!!! hoist -- all pastable layers will need this 744 //!!! hoist -- all pastable layers will need this
742 745
743 //!!! This fails, because simply being "on the same pane as" a 746 //!!! This fails, because simply being "on the same pane as" a
744 // particular model is not enough to give this layer the same 747 // particular model is not enough to give this layer the same
770 long sourceFrame = i->getFrame(); 773 long sourceFrame = i->getFrame();
771 long referenceFrame = sourceFrame; 774 long referenceFrame = sourceFrame;
772 if (i->haveReferenceFrame()) { 775 if (i->haveReferenceFrame()) {
773 referenceFrame = i->getReferenceFrame(); 776 referenceFrame = i->getReferenceFrame();
774 } 777 }
775 long myMappedFrame = m_model->alignToReference(sourceFrame); 778 long myMappedFrame = alignToReference(v, sourceFrame);
776 779
777 std::cerr << "sourceFrame = " << sourceFrame << ", referenceFrame = " << referenceFrame << " (have = " << i->haveReferenceFrame() << "), myMappedFrame = " << myMappedFrame << std::endl; 780 std::cerr << "sourceFrame = " << sourceFrame << ", referenceFrame = " << referenceFrame << " (have = " << i->haveReferenceFrame() << "), myMappedFrame = " << myMappedFrame << std::endl;
778 781
779 if (myMappedFrame != referenceFrame) return true; 782 if (myMappedFrame != referenceFrame) return true;
780 } 783 }
781 784
782 return false; 785 return false;
783 } 786 }
784 787
785 bool 788 bool
786 TimeInstantLayer::paste(const Clipboard &from, int frameOffset, bool) 789 TimeInstantLayer::paste(View *v, const Clipboard &from, int frameOffset, bool)
787 { 790 {
788 if (!m_model) return false; 791 if (!m_model) return false;
789 792
790 const Clipboard::PointList &points = from.getPoints(); 793 const Clipboard::PointList &points = from.getPoints();
791 794
843 // We either want to be literal all the way through, or aligned 846 // We either want to be literal all the way through, or aligned
844 // all the way through. 847 // all the way through.
845 848
846 bool realign = false; 849 bool realign = false;
847 850
848 if (clipboardAlignmentDiffers(from)) { 851 if (clipboardAlignmentDiffers(v, from)) {
849 852
850 std::cerr << "Offer alignment option..." << std::endl; 853 std::cerr << "Offer alignment option..." << std::endl;
851 854
852 QStringList options; 855 QStringList options;
853 options << "Use times unchanged from the original layer"; 856 options << "Use times unchanged from the original layer";
862 if (!ok) return false; 865 if (!ok) return false;
863 866
864 if (selected == options[1]) realign = true; 867 if (selected == options[1]) realign = true;
865 } 868 }
866 869
867
868 SparseOneDimensionalModel::EditCommand *command = 870 SparseOneDimensionalModel::EditCommand *command =
869 new SparseOneDimensionalModel::EditCommand(m_model, tr("Paste")); 871 new SparseOneDimensionalModel::EditCommand(m_model, tr("Paste"));
870 872
871 for (Clipboard::PointList::const_iterator i = points.begin(); 873 for (Clipboard::PointList::const_iterator i = points.begin();
872 i != points.end(); ++i) { 874 i != points.end(); ++i) {
873 875
874 if (!i->haveFrame()) continue; 876 if (!i->haveFrame()) continue;
877
875 size_t frame = 0; 878 size_t frame = 0;
876 if (frameOffset > 0 || -frameOffset < i->getFrame()) { 879
877 frame = i->getFrame() + frameOffset; 880 if (!realign) {
881
882 frame = i->getFrame();
883
884 } else {
885
886 if (i->haveReferenceFrame()) {
887 frame = i->getReferenceFrame();
888 frame = alignFromReference(v, frame);
889 } else {
890 frame = i->getFrame();
891 }
878 } 892 }
893
894 if (frameOffset > 0) frame += frameOffset;
895 else if (frameOffset < 0) {
896 if (frame > -frameOffset) frame += frameOffset;
897 else frame = 0;
898 }
899
879 SparseOneDimensionalModel::Point newPoint(frame); 900 SparseOneDimensionalModel::Point newPoint(frame);
880 if (i->haveLabel()) { 901 if (i->haveLabel()) {
881 newPoint.label = i->getLabel(); 902 newPoint.label = i->getLabel();
882 } else if (i->haveValue()) { 903 } else if (i->haveValue()) {
883 newPoint.label = QString("%1").arg(i->getValue()); 904 newPoint.label = QString("%1").arg(i->getValue());