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

* Merge from trunk
author Chris Cannam
date Wed, 27 Feb 2008 11:59:42 +0000
parents 984c1975f1ff
children
comparison
equal deleted inserted replaced
332:6440e280122e 374:64e84e5efb76
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() :
491 m_editingCommand = 0; 493 m_editingCommand = 0;
492 m_editing = false; 494 m_editing = false;
493 } 495 }
494 496
495 void 497 void
498 TimeInstantLayer::eraseStart(View *v, QMouseEvent *e)
499 {
500 if (!m_model) return;
501
502 SparseOneDimensionalModel::PointList points = getLocalPoints(v, e->x());
503 if (points.empty()) return;
504
505 m_editingPoint = *points.begin();
506
507 if (m_editingCommand) {
508 m_editingCommand->finish();
509 m_editingCommand = 0;
510 }
511
512 m_editing = true;
513 }
514
515 void
516 TimeInstantLayer::eraseDrag(View *v, QMouseEvent *e)
517 {
518 }
519
520 void
521 TimeInstantLayer::eraseEnd(View *v, QMouseEvent *e)
522 {
523 if (!m_model || !m_editing) return;
524
525 m_editing = false;
526
527 SparseOneDimensionalModel::PointList points = getLocalPoints(v, e->x());
528 if (points.empty()) return;
529 if (points.begin()->frame != m_editingPoint.frame) return;
530
531 m_editingCommand = new SparseOneDimensionalModel::EditCommand
532 (m_model, tr("Erase Point"));
533
534 m_editingCommand->deletePoint(m_editingPoint);
535
536 m_editingCommand->finish();
537 m_editingCommand = 0;
538 m_editing = false;
539 }
540
541 void
496 TimeInstantLayer::editStart(View *v, QMouseEvent *e) 542 TimeInstantLayer::editStart(View *v, QMouseEvent *e)
497 { 543 {
498 std::cerr << "TimeInstantLayer::editStart(" << e->x() << ")" << std::endl; 544 std::cerr << "TimeInstantLayer::editStart(" << e->x() << ")" << std::endl;
499 545
500 if (!m_model) return; 546 if (!m_model) return;
665 711
666 command->finish(); 712 command->finish();
667 } 713 }
668 714
669 void 715 void
670 TimeInstantLayer::copy(Selection s, Clipboard &to) 716 TimeInstantLayer::copy(View *v, Selection s, Clipboard &to)
671 { 717 {
672 if (!m_model) return; 718 if (!m_model) return;
673 719
674 SparseOneDimensionalModel::PointList points = 720 SparseOneDimensionalModel::PointList points =
675 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 721 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
676 722
677 for (SparseOneDimensionalModel::PointList::iterator i = points.begin(); 723 for (SparseOneDimensionalModel::PointList::iterator i = points.begin();
678 i != points.end(); ++i) { 724 i != points.end(); ++i) {
679 if (s.contains(i->frame)) { 725 if (s.contains(i->frame)) {
680 Clipboard::Point point(i->frame, i->label); 726 Clipboard::Point point(i->frame, i->label);
727 point.setReferenceFrame(alignToReference(v, i->frame));
681 to.addPoint(point); 728 to.addPoint(point);
682 } 729 }
683 } 730 }
684 } 731 }
685 732
686 bool 733 bool
687 TimeInstantLayer::paste(const Clipboard &from, int frameOffset, bool) 734 TimeInstantLayer::paste(View *v, const Clipboard &from, int frameOffset, bool)
688 { 735 {
689 if (!m_model) return false; 736 if (!m_model) return false;
690 737
691 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 }
692 758
693 SparseOneDimensionalModel::EditCommand *command = 759 SparseOneDimensionalModel::EditCommand *command =
694 new SparseOneDimensionalModel::EditCommand(m_model, tr("Paste")); 760 new SparseOneDimensionalModel::EditCommand(m_model, tr("Paste"));
695 761
696 for (Clipboard::PointList::const_iterator i = points.begin(); 762 for (Clipboard::PointList::const_iterator i = points.begin();
697 i != points.end(); ++i) { 763 i != points.end(); ++i) {
698 764
699 if (!i->haveFrame()) continue; 765 if (!i->haveFrame()) continue;
766
700 size_t frame = 0; 767 size_t frame = 0;
701 if (frameOffset > 0 || -frameOffset < i->getFrame()) { 768
702 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 }
703 } 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
704 SparseOneDimensionalModel::Point newPoint(frame); 789 SparseOneDimensionalModel::Point newPoint(frame);
705 if (i->haveLabel()) { 790 if (i->haveLabel()) {
706 newPoint.label = i->getLabel(); 791 newPoint.label = i->getLabel();
707 } else if (i->haveValue()) { 792 } else if (i->haveValue()) {
708 newPoint.label = QString("%1").arg(i->getValue()); 793 newPoint.label = QString("%1").arg(i->getValue());