Mercurial > hg > svgui
comparison layer/TimeInstantLayer.cpp @ 358:8b69f36c74be
* some work on realignment when pasting (problems remain)
author | Chris Cannam |
---|---|
date | Mon, 04 Feb 2008 17:45:16 +0000 |
parents | bff85425228c |
children | 020c485aa7e0 |
comparison
equal
deleted
inserted
replaced
357:3e538a90e9b8 | 358:8b69f36c74be |
---|---|
23 #include "base/ColourDatabase.h" | 23 #include "base/ColourDatabase.h" |
24 | 24 |
25 #include "data/model/SparseOneDimensionalModel.h" | 25 #include "data/model/SparseOneDimensionalModel.h" |
26 | 26 |
27 #include "widgets/ItemEditDialog.h" | 27 #include "widgets/ItemEditDialog.h" |
28 #include "widgets/ListInputDialog.h" | |
28 | 29 |
29 #include <QPainter> | 30 #include <QPainter> |
30 #include <QMouseEvent> | 31 #include <QMouseEvent> |
31 #include <QTextStream> | 32 #include <QTextStream> |
32 | 33 |
720 | 721 |
721 for (SparseOneDimensionalModel::PointList::iterator i = points.begin(); | 722 for (SparseOneDimensionalModel::PointList::iterator i = points.begin(); |
722 i != points.end(); ++i) { | 723 i != points.end(); ++i) { |
723 if (s.contains(i->frame)) { | 724 if (s.contains(i->frame)) { |
724 Clipboard::Point point(i->frame, i->label); | 725 Clipboard::Point point(i->frame, i->label); |
726 | |
727 //!!! This fails, because simply being "on the same pane as" a | |
728 // particular model is not enough to give this layer the same | |
729 // alignment as it. If it was generated by deriving from another | |
730 // layer's model, that would be... but it wasn't necessarily | |
731 | |
725 point.setReferenceFrame(m_model->alignToReference(i->frame)); | 732 point.setReferenceFrame(m_model->alignToReference(i->frame)); |
726 to.addPoint(point); | 733 to.addPoint(point); |
727 } | 734 } |
728 } | 735 } |
729 } | 736 } |
730 | 737 |
731 bool | 738 bool |
739 TimeInstantLayer::clipboardAlignmentDiffers(const Clipboard &clip) const | |
740 { | |
741 //!!! hoist -- all pastable layers will need this | |
742 | |
743 //!!! This fails, because simply being "on the same pane as" a | |
744 // particular model is not enough to give this layer the same | |
745 // alignment as it. If it was generated by deriving from another | |
746 // layer's model, that would be... but it wasn't necessarily | |
747 | |
748 if (!m_model) return false; | |
749 | |
750 std::cerr << "TimeInstantLayer::clipboardAlignmentDiffers" << std::endl; | |
751 | |
752 for (Clipboard::PointList::const_iterator i = clip.getPoints().begin(); | |
753 i != clip.getPoints().end(); ++i) { | |
754 | |
755 // In principle, we want to know whether the aligned version | |
756 // of the reference frame in our model is the same as the | |
757 // source frame contained in the clipboard point. However, | |
758 // because of rounding during alignment, that won't | |
759 // necessarily be the case even if the clipboard point came | |
760 // from our model! What we need to check is whether, if we | |
761 // aligned the clipboard point's frame back to the reference | |
762 // using this model's alignment, we would obtain the same | |
763 // reference frame as that for the clipboard point. | |
764 | |
765 // What if the clipboard point has no reference frame? Then | |
766 // we have to treat it as having its own frame as the | |
767 // reference (i.e. having been copied from the reference | |
768 // model). | |
769 | |
770 long sourceFrame = i->getFrame(); | |
771 long referenceFrame = sourceFrame; | |
772 if (i->haveReferenceFrame()) { | |
773 referenceFrame = i->getReferenceFrame(); | |
774 } | |
775 long myMappedFrame = m_model->alignToReference(sourceFrame); | |
776 | |
777 std::cerr << "sourceFrame = " << sourceFrame << ", referenceFrame = " << referenceFrame << " (have = " << i->haveReferenceFrame() << "), myMappedFrame = " << myMappedFrame << std::endl; | |
778 | |
779 if (myMappedFrame != referenceFrame) return true; | |
780 } | |
781 | |
782 return false; | |
783 } | |
784 | |
785 bool | |
732 TimeInstantLayer::paste(const Clipboard &from, int frameOffset, bool) | 786 TimeInstantLayer::paste(const Clipboard &from, int frameOffset, bool) |
733 { | 787 { |
734 if (!m_model) return false; | 788 if (!m_model) return false; |
735 | 789 |
736 const Clipboard::PointList &points = from.getPoints(); | 790 const Clipboard::PointList &points = from.getPoints(); |
737 | |
738 SparseOneDimensionalModel::EditCommand *command = | |
739 new SparseOneDimensionalModel::EditCommand(m_model, tr("Paste")); | |
740 | 791 |
741 //!!! | 792 //!!! |
742 | 793 |
743 // Clipboard::haveReferenceFrames() will return true if any of the | 794 // Clipboard::haveReferenceFrames() will return true if any of the |
744 // items in the clipboard came from an aligned, non-reference model. | 795 // items in the clipboard came from an aligned, non-reference model. |
790 // doing that, would it be better to paste at 5s and 10s or at 10s | 841 // doing that, would it be better to paste at 5s and 10s or at 10s |
791 // and 20s? We probably don't ever want to do the former, do we? | 842 // and 20s? We probably don't ever want to do the former, do we? |
792 // We either want to be literal all the way through, or aligned | 843 // We either want to be literal all the way through, or aligned |
793 // all the way through. | 844 // all the way through. |
794 | 845 |
846 bool realign = false; | |
847 | |
848 if (clipboardAlignmentDiffers(from)) { | |
849 | |
850 std::cerr << "Offer alignment option..." << std::endl; | |
851 | |
852 QStringList options; | |
853 options << "Use times unchanged from the original layer"; | |
854 options << "Re-align times to match the same points in the reference layer"; | |
855 | |
856 bool ok = false; | |
857 | |
858 QString selected = ListInputDialog::getItem | |
859 (0, tr("Choose alignment"), | |
860 tr("The points you are pasting originated in a layer with different alignment from the current layer. Would you like to re-align them when pasting?"), | |
861 options, 0, &ok); | |
862 if (!ok) return false; | |
863 | |
864 if (selected == options[1]) realign = true; | |
865 } | |
866 | |
867 | |
868 SparseOneDimensionalModel::EditCommand *command = | |
869 new SparseOneDimensionalModel::EditCommand(m_model, tr("Paste")); | |
870 | |
795 for (Clipboard::PointList::const_iterator i = points.begin(); | 871 for (Clipboard::PointList::const_iterator i = points.begin(); |
796 i != points.end(); ++i) { | 872 i != points.end(); ++i) { |
797 | 873 |
798 if (!i->haveFrame()) continue; | 874 if (!i->haveFrame()) continue; |
799 size_t frame = 0; | 875 size_t frame = 0; |