comparison layer/ImageLayer.cpp @ 374:64e84e5efb76 spectrogram-cache-rejig

* Merge from trunk
author Chris Cannam
date Wed, 27 Feb 2008 11:59:42 +0000
parents 07aa52466142
children
comparison
equal deleted inserted replaced
332:6440e280122e 374:64e84e5efb76
28 #include <QPainter> 28 #include <QPainter>
29 #include <QMouseEvent> 29 #include <QMouseEvent>
30 #include <QInputDialog> 30 #include <QInputDialog>
31 #include <QMutexLocker> 31 #include <QMutexLocker>
32 #include <QTextStream> 32 #include <QTextStream>
33 #include <QMessageBox>
33 34
34 #include <iostream> 35 #include <iostream>
35 #include <cmath> 36 #include <cmath>
36 37
37 ImageLayer::ImageMap 38 ImageLayer::ImageMap
800 801
801 command->finish(); 802 command->finish();
802 } 803 }
803 804
804 void 805 void
805 ImageLayer::copy(Selection s, Clipboard &to) 806 ImageLayer::copy(View *v, Selection s, Clipboard &to)
806 { 807 {
807 if (!m_model) return; 808 if (!m_model) return;
808 809
809 ImageModel::PointList points = 810 ImageModel::PointList points =
810 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 811 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
811 812
812 for (ImageModel::PointList::iterator i = points.begin(); 813 for (ImageModel::PointList::iterator i = points.begin();
813 i != points.end(); ++i) { 814 i != points.end(); ++i) {
814 if (s.contains(i->frame)) { 815 if (s.contains(i->frame)) {
815 //!!! inadequate
816 Clipboard::Point point(i->frame, i->label); 816 Clipboard::Point point(i->frame, i->label);
817 point.setReferenceFrame(alignToReference(v, i->frame));
817 to.addPoint(point); 818 to.addPoint(point);
818 } 819 }
819 } 820 }
820 } 821 }
821 822
822 bool 823 bool
823 ImageLayer::paste(const Clipboard &from, int frameOffset, bool /* interactive */) 824 ImageLayer::paste(View *v, const Clipboard &from, int frameOffset, bool /* interactive */)
824 { 825 {
825 if (!m_model) return false; 826 if (!m_model) return false;
826 827
827 const Clipboard::PointList &points = from.getPoints(); 828 const Clipboard::PointList &points = from.getPoints();
829
830 bool realign = false;
831
832 if (clipboardHasDifferentAlignment(v, from)) {
833
834 QMessageBox::StandardButton button =
835 QMessageBox::question(v, tr("Re-align pasted items?"),
836 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?"),
837 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
838 QMessageBox::Yes);
839
840 if (button == QMessageBox::Cancel) {
841 return false;
842 }
843
844 if (button == QMessageBox::Yes) {
845 realign = true;
846 }
847 }
828 848
829 ImageModel::EditCommand *command = 849 ImageModel::EditCommand *command =
830 new ImageModel::EditCommand(m_model, tr("Paste")); 850 new ImageModel::EditCommand(m_model, tr("Paste"));
831 851
832 for (Clipboard::PointList::const_iterator i = points.begin(); 852 for (Clipboard::PointList::const_iterator i = points.begin();
833 i != points.end(); ++i) { 853 i != points.end(); ++i) {
834 854
835 if (!i->haveFrame()) continue; 855 if (!i->haveFrame()) continue;
856
836 size_t frame = 0; 857 size_t frame = 0;
837 if (frameOffset > 0 || -frameOffset < i->getFrame()) { 858
838 frame = i->getFrame() + frameOffset; 859 if (!realign) {
839 } 860
861 frame = i->getFrame();
862
863 } else {
864
865 if (i->haveReferenceFrame()) {
866 frame = i->getReferenceFrame();
867 frame = alignFromReference(v, frame);
868 } else {
869 frame = i->getFrame();
870 }
871 }
872
840 ImageModel::Point newPoint(frame); 873 ImageModel::Point newPoint(frame);
841 874
842 //!!! inadequate 875 //!!! inadequate
843 876
844 if (i->haveLabel()) { 877 if (i->haveLabel()) {
877 910
878 if (m_remoteFiles.find(img) != m_remoteFiles.end()) { 911 if (m_remoteFiles.find(img) != m_remoteFiles.end()) {
879 return; 912 return;
880 } 913 }
881 914
882 FileSource *rf = new FileSource(img, true); 915 FileSource *rf = new FileSource(img, FileSource::ProgressDialog);
883 if (rf->isOK()) { 916 if (rf->isOK()) {
884 std::cerr << "ok, adding it (local filename = " << rf->getLocalFilename().toStdString() << ")" << std::endl; 917 std::cerr << "ok, adding it (local filename = " << rf->getLocalFilename().toStdString() << ")" << std::endl;
885 m_remoteFiles[img] = rf; 918 m_remoteFiles[img] = rf;
886 connect(rf, SIGNAL(ready()), this, SLOT(remoteFileReady())); 919 connect(rf, SIGNAL(ready()), this, SLOT(remoteFileReady()));
887 } else { 920 } else {