comparison layer/TextLayer.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
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() :
446 m_editingCommand = 0; 447 m_editingCommand = 0;
447 m_editing = false; 448 m_editing = false;
448 } 449 }
449 450
450 void 451 void
452 TextLayer::eraseStart(View *v, QMouseEvent *e)
453 {
454 if (!m_model) return;
455
456 TextModel::PointList points = getLocalPoints(v, e->x(), e->y());
457 if (points.empty()) return;
458
459 m_editingPoint = *points.begin();
460
461 if (m_editingCommand) {
462 m_editingCommand->finish();
463 m_editingCommand = 0;
464 }
465
466 m_editing = true;
467 }
468
469 void
470 TextLayer::eraseDrag(View *v, QMouseEvent *e)
471 {
472 }
473
474 void
475 TextLayer::eraseEnd(View *v, QMouseEvent *e)
476 {
477 if (!m_model || !m_editing) return;
478
479 m_editing = false;
480
481 TextModel::PointList points = getLocalPoints(v, e->x(), e->y());
482 if (points.empty()) return;
483 if (points.begin()->frame != m_editingPoint.frame ||
484 points.begin()->height != m_editingPoint.height) return;
485
486 m_editingCommand = new TextModel::EditCommand
487 (m_model, tr("Erase Point"));
488
489 m_editingCommand->deletePoint(m_editingPoint);
490
491 m_editingCommand->finish();
492 m_editingCommand = 0;
493 m_editing = false;
494 }
495
496 void
451 TextLayer::editStart(View *v, QMouseEvent *e) 497 TextLayer::editStart(View *v, QMouseEvent *e)
452 { 498 {
453 // std::cerr << "TextLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; 499 // std::cerr << "TextLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl;
454 500
455 if (!m_model) return; 501 if (!m_model) return;
624 670
625 command->finish(); 671 command->finish();
626 } 672 }
627 673
628 void 674 void
629 TextLayer::copy(Selection s, Clipboard &to) 675 TextLayer::copy(View *v, Selection s, Clipboard &to)
630 { 676 {
631 if (!m_model) return; 677 if (!m_model) return;
632 678
633 TextModel::PointList points = 679 TextModel::PointList points =
634 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 680 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
635 681
636 for (TextModel::PointList::iterator i = points.begin(); 682 for (TextModel::PointList::iterator i = points.begin();
637 i != points.end(); ++i) { 683 i != points.end(); ++i) {
638 if (s.contains(i->frame)) { 684 if (s.contains(i->frame)) {
639 Clipboard::Point point(i->frame, i->height, i->label); 685 Clipboard::Point point(i->frame, i->height, i->label);
686 point.setReferenceFrame(alignToReference(v, i->frame));
640 to.addPoint(point); 687 to.addPoint(point);
641 } 688 }
642 } 689 }
643 } 690 }
644 691
645 bool 692 bool
646 TextLayer::paste(const Clipboard &from, int frameOffset, bool /* interactive */) 693 TextLayer::paste(View *v, const Clipboard &from, int frameOffset, bool /* interactive */)
647 { 694 {
648 if (!m_model) return false; 695 if (!m_model) return false;
649 696
650 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 }
651 717
652 TextModel::EditCommand *command = 718 TextModel::EditCommand *command =
653 new TextModel::EditCommand(m_model, tr("Paste")); 719 new TextModel::EditCommand(m_model, tr("Paste"));
654 720
655 float valueMin = 0.0, valueMax = 1.0; 721 float valueMin = 0.0, valueMax = 1.0;
665 for (Clipboard::PointList::const_iterator i = points.begin(); 731 for (Clipboard::PointList::const_iterator i = points.begin();
666 i != points.end(); ++i) { 732 i != points.end(); ++i) {
667 733
668 if (!i->haveFrame()) continue; 734 if (!i->haveFrame()) continue;
669 size_t frame = 0; 735 size_t frame = 0;
670 if (frameOffset > 0 || -frameOffset < i->getFrame()) { 736
671 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 }
672 } 749 }
750
673 TextModel::Point newPoint(frame); 751 TextModel::Point newPoint(frame);
674 752
675 if (i->haveValue()) { 753 if (i->haveValue()) {
676 newPoint.height = (i->getValue() - valueMin) / (valueMax - valueMin); 754 newPoint.height = (i->getValue() - valueMin) / (valueMax - valueMin);
677 } else { 755 } else {