comparison layer/TimeValueLayer.cpp @ 22:179bf7b5ddea

* Update some copyright notice dates * Add commands for basic editing operations in time-instants and time-value layers
author Chris Cannam
date Tue, 31 Jan 2006 15:57:25 +0000
parents 3a506d25d95a
children ca57f70b0e48
comparison
equal deleted inserted replaced
21:3a506d25d95a 22:179bf7b5ddea
26 TimeValueLayer::TimeValueLayer(View *w) : 26 TimeValueLayer::TimeValueLayer(View *w) :
27 Layer(w), 27 Layer(w),
28 m_model(0), 28 m_model(0),
29 m_editing(false), 29 m_editing(false),
30 m_editingPoint(0, 0.0, tr("New Point")), 30 m_editingPoint(0, 0.0, tr("New Point")),
31 m_editingCommand(0),
31 m_colour(Qt::black), 32 m_colour(Qt::black),
32 m_plotStyle(PlotConnectedPoints) 33 m_plotStyle(PlotConnectedPoints)
33 { 34 {
34 m_view->addLayer(this); 35 m_view->addLayer(this);
35 } 36 }
494 frame = frame / m_model->getResolution() * m_model->getResolution(); 495 frame = frame / m_model->getResolution() * m_model->getResolution();
495 496
496 float value = getValueForY(e->y()); 497 float value = getValueForY(e->y());
497 498
498 m_editingPoint = SparseTimeValueModel::Point(frame, value, tr("New Point")); 499 m_editingPoint = SparseTimeValueModel::Point(frame, value, tr("New Point"));
499 m_model->addPoint(m_editingPoint); 500
501 if (m_editingCommand) m_editingCommand->finish();
502 m_editingCommand = new SparseTimeValueModel::EditCommand(m_model,
503 tr("Draw Point"));
504 m_editingCommand->addPoint(m_editingPoint);
505
500 m_editing = true; 506 m_editing = true;
501 } 507 }
502 508
503 void 509 void
504 TimeValueLayer::drawDrag(QMouseEvent *e) 510 TimeValueLayer::drawDrag(QMouseEvent *e)
511 if (frame < 0) frame = 0; 517 if (frame < 0) frame = 0;
512 frame = frame / m_model->getResolution() * m_model->getResolution(); 518 frame = frame / m_model->getResolution() * m_model->getResolution();
513 519
514 float value = getValueForY(e->y()); 520 float value = getValueForY(e->y());
515 521
516 m_model->deletePoint(m_editingPoint); 522 m_editingCommand->deletePoint(m_editingPoint);
517 m_editingPoint.frame = frame; 523 m_editingPoint.frame = frame;
518 m_editingPoint.value = value; 524 m_editingPoint.value = value;
519 m_model->addPoint(m_editingPoint); 525 m_editingCommand->addPoint(m_editingPoint);
520 } 526 }
521 527
522 void 528 void
523 TimeValueLayer::drawEnd(QMouseEvent *e) 529 TimeValueLayer::drawEnd(QMouseEvent *e)
524 { 530 {
525 std::cerr << "TimeValueLayer::drawEnd(" << e->x() << "," << e->y() << ")" << std::endl; 531 std::cerr << "TimeValueLayer::drawEnd(" << e->x() << "," << e->y() << ")" << std::endl;
526 if (!m_model || !m_editing) return; 532 if (!m_model || !m_editing) return;
533 m_editingCommand->finish();
534 m_editingCommand = 0;
527 m_editing = false; 535 m_editing = false;
528 } 536 }
529 537
530 void 538 void
531 TimeValueLayer::editStart(QMouseEvent *e) 539 TimeValueLayer::editStart(QMouseEvent *e)
536 544
537 SparseTimeValueModel::PointList points = getLocalPoints(e->x()); 545 SparseTimeValueModel::PointList points = getLocalPoints(e->x());
538 if (points.empty()) return; 546 if (points.empty()) return;
539 547
540 m_editingPoint = *points.begin(); 548 m_editingPoint = *points.begin();
549
550 if (m_editingCommand) {
551 m_editingCommand->finish();
552 m_editingCommand = 0;
553 }
554
541 m_editing = true; 555 m_editing = true;
542 } 556 }
543 557
544 void 558 void
545 TimeValueLayer::editDrag(QMouseEvent *e) 559 TimeValueLayer::editDrag(QMouseEvent *e)
552 if (frame < 0) frame = 0; 566 if (frame < 0) frame = 0;
553 frame = frame / m_model->getResolution() * m_model->getResolution(); 567 frame = frame / m_model->getResolution() * m_model->getResolution();
554 568
555 float value = getValueForY(e->y()); 569 float value = getValueForY(e->y());
556 570
557 m_model->deletePoint(m_editingPoint); 571 if (!m_editingCommand) {
572 m_editingCommand = new SparseTimeValueModel::EditCommand(m_model,
573 tr("Drag Point"));
574 }
575
576 m_editingCommand->deletePoint(m_editingPoint);
558 m_editingPoint.frame = frame; 577 m_editingPoint.frame = frame;
559 m_editingPoint.value = value; 578 m_editingPoint.value = value;
560 m_model->addPoint(m_editingPoint); 579 m_editingCommand->addPoint(m_editingPoint);
561 } 580 }
562 581
563 void 582 void
564 TimeValueLayer::editEnd(QMouseEvent *e) 583 TimeValueLayer::editEnd(QMouseEvent *e)
565 { 584 {
566 std::cerr << "TimeValueLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl; 585 std::cerr << "TimeValueLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl;
567 if (!m_model || !m_editing) return; 586 if (!m_model || !m_editing) return;
587 if (m_editingCommand) m_editingCommand->finish();
588 m_editingCommand = 0;
568 m_editing = false; 589 m_editing = false;
569 } 590 }
570 591
571 QString 592 QString
572 TimeValueLayer::toXmlString(QString indent, QString extraAttributes) const 593 TimeValueLayer::toXmlString(QString indent, QString extraAttributes) const