comparison layer/TimeInstantLayer.cpp @ 1216:dc2af6616c83

Merge from branch 3.0-integration
author Chris Cannam
date Fri, 13 Jan 2017 10:29:50 +0000
parents ee01a4062747
children a34a2a25907c
comparison
equal deleted inserted replaced
1048:e8102ff5573b 1216:dc2af6616c83
18 #include "data/model/Model.h" 18 #include "data/model/Model.h"
19 #include "base/RealTime.h" 19 #include "base/RealTime.h"
20 #include "view/View.h" 20 #include "view/View.h"
21 #include "base/Profiler.h" 21 #include "base/Profiler.h"
22 #include "base/Clipboard.h" 22 #include "base/Clipboard.h"
23
23 #include "ColourDatabase.h" 24 #include "ColourDatabase.h"
25 #include "PaintAssistant.h"
24 26
25 #include "data/model/SparseOneDimensionalModel.h" 27 #include "data/model/SparseOneDimensionalModel.h"
26 28
27 #include "widgets/ItemEditDialog.h" 29 #include "widgets/ItemEditDialog.h"
28 #include "widgets/ListInputDialog.h" 30 #include "widgets/ListInputDialog.h"
145 m_plotStyle = style; 147 m_plotStyle = style;
146 emit layerParametersChanged(); 148 emit layerParametersChanged();
147 } 149 }
148 150
149 bool 151 bool
150 TimeInstantLayer::isLayerScrollable(const View *v) const 152 TimeInstantLayer::isLayerScrollable(const LayerGeometryProvider *v) const
151 { 153 {
152 QPoint discard; 154 QPoint discard;
153 return !v->shouldIlluminateLocalFeatures(this, discard); 155 return !v->shouldIlluminateLocalFeatures(this, discard);
154 } 156 }
155 157
156 SparseOneDimensionalModel::PointList 158 SparseOneDimensionalModel::PointList
157 TimeInstantLayer::getLocalPoints(View *v, int x) const 159 TimeInstantLayer::getLocalPoints(LayerGeometryProvider *v, int x) const
158 { 160 {
159 // Return a set of points that all have the same frame number, the 161 // Return a set of points that all have the same frame number, the
160 // nearest to the given x coordinate, and that are within a 162 // nearest to the given x coordinate, and that are within a
161 // certain fuzz distance of that x coordinate. 163 // certain fuzz distance of that x coordinate.
162 164
211 } 213 }
212 return ""; 214 return "";
213 } 215 }
214 216
215 QString 217 QString
216 TimeInstantLayer::getFeatureDescription(View *v, QPoint &pos) const 218 TimeInstantLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const
217 { 219 {
218 int x = pos.x(); 220 int x = pos.x();
219 221
220 if (!m_model || !m_model->getSampleRate()) return ""; 222 if (!m_model || !m_model->getSampleRate()) return "";
221 223
247 pos = QPoint(v->getXForFrame(useFrame), pos.y()); 249 pos = QPoint(v->getXForFrame(useFrame), pos.y());
248 return text; 250 return text;
249 } 251 }
250 252
251 bool 253 bool
252 TimeInstantLayer::snapToFeatureFrame(View *v, sv_frame_t &frame, 254 TimeInstantLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
253 int &resolution, 255 int &resolution,
254 SnapType snap) const 256 SnapType snap) const
255 { 257 {
256 if (!m_model) { 258 if (!m_model) {
257 return Layer::snapToFeatureFrame(v, frame, resolution, snap); 259 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
319 frame = snapped; 321 frame = snapped;
320 return found; 322 return found;
321 } 323 }
322 324
323 void 325 void
324 TimeInstantLayer::paint(View *v, QPainter &paint, QRect rect) const 326 TimeInstantLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
325 { 327 {
326 if (!m_model || !m_model->isOK()) return; 328 if (!m_model || !m_model->isOK()) return;
327 329
328 // Profiler profiler("TimeInstantLayer::paint", true); 330 // Profiler profiler("TimeInstantLayer::paint", true);
329 331
401 iw = 2; 403 iw = 2;
402 } 404 }
403 } 405 }
404 406
405 if (p.frame == illuminateFrame) { 407 if (p.frame == illuminateFrame) {
406 paint.setPen(getForegroundQColor(v)); 408 paint.setPen(getForegroundQColor(v->getView()));
407 } else { 409 } else {
408 paint.setPen(brushColour); 410 paint.setPen(brushColour);
409 } 411 }
410 412
411 if (m_plotStyle == PlotInstants) { 413 if (m_plotStyle == PlotInstants) {
412 if (iw > 1) { 414 if (iw > 1) {
413 paint.drawRect(x, 0, iw - 1, v->height() - 1); 415 paint.drawRect(x, 0, iw - 1, v->getPaintHeight() - 1);
414 } else { 416 } else {
415 paint.drawLine(x, 0, x, v->height() - 1); 417 paint.drawLine(x, 0, x, v->getPaintHeight() - 1);
416 } 418 }
417 } else { 419 } else {
418 420
419 if (odd) paint.setBrush(oddBrushColour); 421 if (odd) paint.setBrush(oddBrushColour);
420 else paint.setBrush(brushColour); 422 else paint.setBrush(brushColour);
429 } 431 }
430 432
431 if (nx >= x) { 433 if (nx >= x) {
432 434
433 if (illuminateFrame != p.frame && 435 if (illuminateFrame != p.frame &&
434 (nx < x + 5 || x >= v->width() - 1)) { 436 (nx < x + 5 || x >= v->getPaintWidth() - 1)) {
435 paint.setPen(Qt::NoPen); 437 paint.setPen(Qt::NoPen);
436 } 438 }
437 439
438 paint.drawRect(x, -1, nx - x, v->height() + 1); 440 paint.drawRect(x, -1, nx - x, v->getPaintHeight() + 1);
439 } 441 }
440 442
441 odd = !odd; 443 odd = !odd;
442 } 444 }
443 445
454 int nx = v->getXForFrame(j->frame); 456 int nx = v->getXForFrame(j->frame);
455 if (nx >= x && nx - x - iw - 3 <= lw) good = false; 457 if (nx >= x && nx - x - iw - 3 <= lw) good = false;
456 } 458 }
457 459
458 if (good) { 460 if (good) {
459 v->drawVisibleText(paint, x + iw + 2, textY, p.label, View::OutlinedText); 461 PaintAssistant::drawVisibleText(v, paint, x + iw + 2, textY, p.label, PaintAssistant::OutlinedText);
460 // paint.drawText(x + iw + 2, textY, p.label); 462 // paint.drawText(x + iw + 2, textY, p.label);
461 } 463 }
462 } 464 }
463 465
464 prevX = x; 466 prevX = x;
465 } 467 }
466 } 468 }
467 469
468 void 470 void
469 TimeInstantLayer::drawStart(View *v, QMouseEvent *e) 471 TimeInstantLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e)
470 { 472 {
471 #ifdef DEBUG_TIME_INSTANT_LAYER 473 #ifdef DEBUG_TIME_INSTANT_LAYER
472 cerr << "TimeInstantLayer::drawStart(" << e->x() << ")" << endl; 474 cerr << "TimeInstantLayer::drawStart(" << e->x() << ")" << endl;
473 #endif 475 #endif
474 476
487 489
488 m_editing = true; 490 m_editing = true;
489 } 491 }
490 492
491 void 493 void
492 TimeInstantLayer::drawDrag(View *v, QMouseEvent *e) 494 TimeInstantLayer::drawDrag(LayerGeometryProvider *v, QMouseEvent *e)
493 { 495 {
494 #ifdef DEBUG_TIME_INSTANT_LAYER 496 #ifdef DEBUG_TIME_INSTANT_LAYER
495 cerr << "TimeInstantLayer::drawDrag(" << e->x() << ")" << endl; 497 cerr << "TimeInstantLayer::drawDrag(" << e->x() << ")" << endl;
496 #endif 498 #endif
497 499
504 m_editingPoint.frame = frame; 506 m_editingPoint.frame = frame;
505 m_editingCommand->addPoint(m_editingPoint); 507 m_editingCommand->addPoint(m_editingPoint);
506 } 508 }
507 509
508 void 510 void
509 TimeInstantLayer::drawEnd(View *, QMouseEvent *) 511 TimeInstantLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *)
510 { 512 {
511 #ifdef DEBUG_TIME_INSTANT_LAYER 513 #ifdef DEBUG_TIME_INSTANT_LAYER
512 cerr << "TimeInstantLayer::drawEnd(" << e->x() << ")" << endl; 514 cerr << "TimeInstantLayer::drawEnd(" << e->x() << ")" << endl;
513 #endif 515 #endif
514 if (!m_model || !m_editing) return; 516 if (!m_model || !m_editing) return;
521 m_editingCommand = 0; 523 m_editingCommand = 0;
522 m_editing = false; 524 m_editing = false;
523 } 525 }
524 526
525 void 527 void
526 TimeInstantLayer::eraseStart(View *v, QMouseEvent *e) 528 TimeInstantLayer::eraseStart(LayerGeometryProvider *v, QMouseEvent *e)
527 { 529 {
528 if (!m_model) return; 530 if (!m_model) return;
529 531
530 SparseOneDimensionalModel::PointList points = getLocalPoints(v, e->x()); 532 SparseOneDimensionalModel::PointList points = getLocalPoints(v, e->x());
531 if (points.empty()) return; 533 if (points.empty()) return;
539 541
540 m_editing = true; 542 m_editing = true;
541 } 543 }
542 544
543 void 545 void
544 TimeInstantLayer::eraseDrag(View *, QMouseEvent *) 546 TimeInstantLayer::eraseDrag(LayerGeometryProvider *, QMouseEvent *)
545 { 547 {
546 } 548 }
547 549
548 void 550 void
549 TimeInstantLayer::eraseEnd(View *v, QMouseEvent *e) 551 TimeInstantLayer::eraseEnd(LayerGeometryProvider *v, QMouseEvent *e)
550 { 552 {
551 if (!m_model || !m_editing) return; 553 if (!m_model || !m_editing) return;
552 554
553 m_editing = false; 555 m_editing = false;
554 556
565 m_editingCommand = 0; 567 m_editingCommand = 0;
566 m_editing = false; 568 m_editing = false;
567 } 569 }
568 570
569 void 571 void
570 TimeInstantLayer::editStart(View *v, QMouseEvent *e) 572 TimeInstantLayer::editStart(LayerGeometryProvider *v, QMouseEvent *e)
571 { 573 {
572 #ifdef DEBUG_TIME_INSTANT_LAYER 574 #ifdef DEBUG_TIME_INSTANT_LAYER
573 cerr << "TimeInstantLayer::editStart(" << e->x() << ")" << endl; 575 cerr << "TimeInstantLayer::editStart(" << e->x() << ")" << endl;
574 #endif 576 #endif
575 577
587 589
588 m_editing = true; 590 m_editing = true;
589 } 591 }
590 592
591 void 593 void
592 TimeInstantLayer::editDrag(View *v, QMouseEvent *e) 594 TimeInstantLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e)
593 { 595 {
594 #ifdef DEBUG_TIME_INSTANT_LAYER 596 #ifdef DEBUG_TIME_INSTANT_LAYER
595 cerr << "TimeInstantLayer::editDrag(" << e->x() << ")" << endl; 597 cerr << "TimeInstantLayer::editDrag(" << e->x() << ")" << endl;
596 #endif 598 #endif
597 599
610 m_editingPoint.frame = frame; 612 m_editingPoint.frame = frame;
611 m_editingCommand->addPoint(m_editingPoint); 613 m_editingCommand->addPoint(m_editingPoint);
612 } 614 }
613 615
614 void 616 void
615 TimeInstantLayer::editEnd(View *, QMouseEvent *) 617 TimeInstantLayer::editEnd(LayerGeometryProvider *, QMouseEvent *)
616 { 618 {
617 #ifdef DEBUG_TIME_INSTANT_LAYER 619 #ifdef DEBUG_TIME_INSTANT_LAYER
618 cerr << "TimeInstantLayer::editEnd(" << e->x() << ")" << endl; 620 cerr << "TimeInstantLayer::editEnd(" << e->x() << ")" << endl;
619 #endif 621 #endif
620 if (!m_model || !m_editing) return; 622 if (!m_model || !m_editing) return;
629 m_editingCommand = 0; 631 m_editingCommand = 0;
630 m_editing = false; 632 m_editing = false;
631 } 633 }
632 634
633 bool 635 bool
634 TimeInstantLayer::editOpen(View *v, QMouseEvent *e) 636 TimeInstantLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e)
635 { 637 {
636 if (!m_model) return false; 638 if (!m_model) return false;
637 639
638 SparseOneDimensionalModel::PointList points = getLocalPoints(v, e->x()); 640 SparseOneDimensionalModel::PointList points = getLocalPoints(v, e->x());
639 if (points.empty()) return false; 641 if (points.empty()) return false;
745 747
746 finish(command); 748 finish(command);
747 } 749 }
748 750
749 void 751 void
750 TimeInstantLayer::copy(View *v, Selection s, Clipboard &to) 752 TimeInstantLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to)
751 { 753 {
752 if (!m_model) return; 754 if (!m_model) return;
753 755
754 SparseOneDimensionalModel::PointList points = 756 SparseOneDimensionalModel::PointList points =
755 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 757 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
763 } 765 }
764 } 766 }
765 } 767 }
766 768
767 bool 769 bool
768 TimeInstantLayer::paste(View *v, const Clipboard &from, sv_frame_t frameOffset, bool) 770 TimeInstantLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset, bool)
769 { 771 {
770 if (!m_model) return false; 772 if (!m_model) return false;
771 773
772 const Clipboard::PointList &points = from.getPoints(); 774 const Clipboard::PointList &points = from.getPoints();
773 775
774 bool realign = false; 776 bool realign = false;
775 777
776 if (clipboardHasDifferentAlignment(v, from)) { 778 if (clipboardHasDifferentAlignment(v, from)) {
777 779
778 QMessageBox::StandardButton button = 780 QMessageBox::StandardButton button =
779 QMessageBox::question(v, tr("Re-align pasted instants?"), 781 QMessageBox::question(v->getView(), tr("Re-align pasted instants?"),
780 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?"), 782 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?"),
781 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, 783 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
782 QMessageBox::Yes); 784 QMessageBox::Yes);
783 785
784 if (button == QMessageBox::Cancel) { 786 if (button == QMessageBox::Cancel) {