comparison layer/TimeInstantLayer.cpp @ 373:0895517bb2d1 1.2-stable

* merge from trunk (1.2 ended up being tracked from trunk, but we may want this branch for fixes later)
author Chris Cannam
date Wed, 27 Feb 2008 10:32:45 +0000
parents 2f83b6e3b8ca
children
comparison
equal deleted inserted replaced
337:813170c57b13 373:0895517bb2d1
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>
33 #include <QMessageBox>
32 34
33 #include <iostream> 35 #include <iostream>
34 #include <cmath> 36 #include <cmath>
35 37
36 TimeInstantLayer::TimeInstantLayer() : 38 TimeInstantLayer::TimeInstantLayer() :
709 711
710 command->finish(); 712 command->finish();
711 } 713 }
712 714
713 void 715 void
714 TimeInstantLayer::copy(Selection s, Clipboard &to) 716 TimeInstantLayer::copy(View *v, Selection s, Clipboard &to)
715 { 717 {
716 if (!m_model) return; 718 if (!m_model) return;
717 719
718 SparseOneDimensionalModel::PointList points = 720 SparseOneDimensionalModel::PointList points =
719 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 721 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
720 722
721 for (SparseOneDimensionalModel::PointList::iterator i = points.begin(); 723 for (SparseOneDimensionalModel::PointList::iterator i = points.begin();
722 i != points.end(); ++i) { 724 i != points.end(); ++i) {
723 if (s.contains(i->frame)) { 725 if (s.contains(i->frame)) {
724 Clipboard::Point point(i->frame, i->label); 726 Clipboard::Point point(i->frame, i->label);
725 point.setReferenceFrame(m_model->alignToReference(i->frame)); 727 point.setReferenceFrame(alignToReference(v, i->frame));
726 to.addPoint(point); 728 to.addPoint(point);
727 } 729 }
728 } 730 }
729 } 731 }
730 732
731 bool 733 bool
732 TimeInstantLayer::paste(const Clipboard &from, int frameOffset, bool) 734 TimeInstantLayer::paste(View *v, const Clipboard &from, int frameOffset, bool)
733 { 735 {
734 if (!m_model) return false; 736 if (!m_model) return false;
735 737
736 const Clipboard::PointList &points = from.getPoints(); 738 const Clipboard::PointList &points = from.getPoints();
739
740 bool realign = false;
741
742 if (clipboardHasDifferentAlignment(v, from)) {
743
744 QMessageBox::StandardButton button =
745 QMessageBox::question(v, tr("Re-align pasted instants?"),
746 tr("The instants you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"),
747 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
748 QMessageBox::Yes);
749
750 if (button == QMessageBox::Cancel) {
751 return false;
752 }
753
754 if (button == QMessageBox::Yes) {
755 realign = true;
756 }
757 }
737 758
738 SparseOneDimensionalModel::EditCommand *command = 759 SparseOneDimensionalModel::EditCommand *command =
739 new SparseOneDimensionalModel::EditCommand(m_model, tr("Paste")); 760 new SparseOneDimensionalModel::EditCommand(m_model, tr("Paste"));
740
741 //!!!
742
743 // Clipboard::haveReferenceFrames() will return true if any of the
744 // items in the clipboard came from an aligned, non-reference model.
745
746 // We need to know whether these points came from our model or not
747 // -- if they did, we don't want to align them.
748
749 // If they didn't come from our model, and if reference frames are
750 // available, then we want to offer to align them. If reference
751 // frames are unavailable but they came from the reference model,
752 // we want to offer to align them too.
753 761
754 for (Clipboard::PointList::const_iterator i = points.begin(); 762 for (Clipboard::PointList::const_iterator i = points.begin();
755 i != points.end(); ++i) { 763 i != points.end(); ++i) {
756 764
757 if (!i->haveFrame()) continue; 765 if (!i->haveFrame()) continue;
766
758 size_t frame = 0; 767 size_t frame = 0;
759 if (frameOffset > 0 || -frameOffset < i->getFrame()) { 768
760 frame = i->getFrame() + frameOffset; 769 if (!realign) {
770
771 frame = i->getFrame();
772
773 } else {
774
775 if (i->haveReferenceFrame()) {
776 frame = i->getReferenceFrame();
777 frame = alignFromReference(v, frame);
778 } else {
779 frame = i->getFrame();
780 }
761 } 781 }
782
783 if (frameOffset > 0) frame += frameOffset;
784 else if (frameOffset < 0) {
785 if (frame > -frameOffset) frame += frameOffset;
786 else frame = 0;
787 }
788
762 SparseOneDimensionalModel::Point newPoint(frame); 789 SparseOneDimensionalModel::Point newPoint(frame);
763 if (i->haveLabel()) { 790 if (i->haveLabel()) {
764 newPoint.label = i->getLabel(); 791 newPoint.label = i->getLabel();
765 } else if (i->haveValue()) { 792 } else if (i->haveValue()) {
766 newPoint.label = QString("%1").arg(i->getValue()); 793 newPoint.label = QString("%1").arg(i->getValue());