comparison layer/TextLayer.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
25 25
26 #include <QPainter> 26 #include <QPainter>
27 #include <QMouseEvent> 27 #include <QMouseEvent>
28 #include <QInputDialog> 28 #include <QInputDialog>
29 #include <QTextStream> 29 #include <QTextStream>
30 #include <QMessageBox>
30 31
31 #include <iostream> 32 #include <iostream>
32 #include <cmath> 33 #include <cmath>
33 34
34 TextLayer::TextLayer() : 35 TextLayer::TextLayer() :
669 670
670 command->finish(); 671 command->finish();
671 } 672 }
672 673
673 void 674 void
674 TextLayer::copy(Selection s, Clipboard &to) 675 TextLayer::copy(View *v, Selection s, Clipboard &to)
675 { 676 {
676 if (!m_model) return; 677 if (!m_model) return;
677 678
678 TextModel::PointList points = 679 TextModel::PointList points =
679 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 680 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
680 681
681 for (TextModel::PointList::iterator i = points.begin(); 682 for (TextModel::PointList::iterator i = points.begin();
682 i != points.end(); ++i) { 683 i != points.end(); ++i) {
683 if (s.contains(i->frame)) { 684 if (s.contains(i->frame)) {
684 Clipboard::Point point(i->frame, i->height, i->label); 685 Clipboard::Point point(i->frame, i->height, i->label);
685 point.setReferenceFrame(m_model->alignToReference(i->frame)); 686 point.setReferenceFrame(alignToReference(v, i->frame));
686 to.addPoint(point); 687 to.addPoint(point);
687 } 688 }
688 } 689 }
689 } 690 }
690 691
691 bool 692 bool
692 TextLayer::paste(const Clipboard &from, int frameOffset, bool /* interactive */) 693 TextLayer::paste(View *v, const Clipboard &from, int frameOffset, bool /* interactive */)
693 { 694 {
694 if (!m_model) return false; 695 if (!m_model) return false;
695 696
696 const Clipboard::PointList &points = from.getPoints(); 697 const Clipboard::PointList &points = from.getPoints();
698
699 bool realign = false;
700
701 if (clipboardHasDifferentAlignment(v, from)) {
702
703 QMessageBox::StandardButton button =
704 QMessageBox::question(v, tr("Re-align pasted items?"),
705 tr("The items 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?"),
706 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
707 QMessageBox::Yes);
708
709 if (button == QMessageBox::Cancel) {
710 return false;
711 }
712
713 if (button == QMessageBox::Yes) {
714 realign = true;
715 }
716 }
697 717
698 TextModel::EditCommand *command = 718 TextModel::EditCommand *command =
699 new TextModel::EditCommand(m_model, tr("Paste")); 719 new TextModel::EditCommand(m_model, tr("Paste"));
700 720
701 float valueMin = 0.0, valueMax = 1.0; 721 float valueMin = 0.0, valueMax = 1.0;
711 for (Clipboard::PointList::const_iterator i = points.begin(); 731 for (Clipboard::PointList::const_iterator i = points.begin();
712 i != points.end(); ++i) { 732 i != points.end(); ++i) {
713 733
714 if (!i->haveFrame()) continue; 734 if (!i->haveFrame()) continue;
715 size_t frame = 0; 735 size_t frame = 0;
716 if (frameOffset > 0 || -frameOffset < i->getFrame()) { 736
717 frame = i->getFrame() + frameOffset; 737 if (!realign) {
738
739 frame = i->getFrame();
740
741 } else {
742
743 if (i->haveReferenceFrame()) {
744 frame = i->getReferenceFrame();
745 frame = alignFromReference(v, frame);
746 } else {
747 frame = i->getFrame();
748 }
718 } 749 }
750
719 TextModel::Point newPoint(frame); 751 TextModel::Point newPoint(frame);
720 752
721 if (i->haveValue()) { 753 if (i->haveValue()) {
722 newPoint.height = (i->getValue() - valueMin) / (valueMax - valueMin); 754 newPoint.height = (i->getValue() - valueMin) / (valueMax - valueMin);
723 } else { 755 } else {