comparison widgets/Pane.cpp @ 44:ad214997dddb

* Refactor Layer classes so as no longer to store a single View pointer; instead they need to be able to draw themselves on any View on demand. Layers with caches (e.g. spectrogram) will need to be further refactored so as to maintain a per-View cache * Begin refactoring MainWindow by pulling out the document stuff (set of layers, models etc) into a Document class. Not yet in use. This revision is fairly unstable.
author Chris Cannam
date Thu, 02 Mar 2006 16:58:49 +0000
parents 78515b1e29eb
children 97b0643bd799
comparison
equal deleted inserted replaced
43:78515b1e29eb 44:ad214997dddb
37 setObjectName("Pane"); 37 setObjectName("Pane");
38 setMouseTracking(true); 38 setMouseTracking(true);
39 } 39 }
40 40
41 bool 41 bool
42 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos) 42 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos) const
43 { 43 {
44 QPoint discard; 44 QPoint discard;
45 bool b0, b1; 45 bool b0, b1;
46 46
47 if (layer == getSelectedLayer() && 47 if (layer == getSelectedLayer() &&
55 } 55 }
56 56
57 bool 57 bool
58 Pane::shouldIlluminateLocalSelection(QPoint &pos, 58 Pane::shouldIlluminateLocalSelection(QPoint &pos,
59 bool &closeToLeft, 59 bool &closeToLeft,
60 bool &closeToRight) 60 bool &closeToRight) const
61 { 61 {
62 if (m_identifyFeatures && 62 if (m_identifyFeatures &&
63 m_manager && 63 m_manager &&
64 m_manager->getToolMode() == ViewManager::EditMode && 64 m_manager->getToolMode() == ViewManager::EditMode &&
65 !m_manager->getSelections().empty() && 65 !m_manager->getSelections().empty() &&
139 139
140 if (dynamic_cast<WaveformLayer *>(*vi)) { 140 if (dynamic_cast<WaveformLayer *>(*vi)) {
141 waveformModel = (*vi)->getModel(); 141 waveformModel = (*vi)->getModel();
142 } 142 }
143 143
144 int sw = (*vi)->getVerticalScaleWidth(paint); 144 int sw = (*vi)->getVerticalScaleWidth(this, paint);
145 145
146 if (sw > 0 && r.left() < sw) { 146 if (sw > 0 && r.left() < sw) {
147 147
148 // Profiler profiler("Pane::paintEvent - painting vertical scale", true); 148 // Profiler profiler("Pane::paintEvent - painting vertical scale", true);
149 149
153 paint.setPen(Qt::black); 153 paint.setPen(Qt::black);
154 paint.setBrush(Qt::white); 154 paint.setBrush(Qt::white);
155 paint.drawRect(0, 0, sw, height()); 155 paint.drawRect(0, 0, sw, height());
156 156
157 paint.setBrush(Qt::NoBrush); 157 paint.setBrush(Qt::NoBrush);
158 (*vi)->paintVerticalScale(paint, QRect(0, 0, sw, height())); 158 (*vi)->paintVerticalScale(this, paint, QRect(0, 0, sw, height()));
159 159
160 paint.restore(); 160 paint.restore();
161 } 161 }
162 162
163 if (m_identifyFeatures) { 163 if (m_identifyFeatures) {
164 164
165 QPoint pos = m_identifyPoint; 165 QPoint pos = m_identifyPoint;
166 QString desc = (*vi)->getFeatureDescription(pos); 166 QString desc = (*vi)->getFeatureDescription(this, pos);
167 167
168 if (desc != "") { 168 if (desc != "") {
169 169
170 paint.save(); 170 paint.save();
171 171
362 362
363 paint.end(); 363 paint.end();
364 } 364 }
365 365
366 Selection 366 Selection
367 Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge) 367 Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge) const
368 { 368 {
369 closeToLeftEdge = closeToRightEdge = false; 369 closeToLeftEdge = closeToRightEdge = false;
370 370
371 if (!m_manager) return Selection(); 371 if (!m_manager) return Selection();
372 372
444 size_t resolution = 1; 444 size_t resolution = 1;
445 int snapFrame = mouseFrame; 445 int snapFrame = mouseFrame;
446 446
447 Layer *layer = getSelectedLayer(); 447 Layer *layer = getSelectedLayer();
448 if (layer) { 448 if (layer) {
449 layer->snapToFeatureFrame(snapFrame, resolution, Layer::SnapLeft); 449 layer->snapToFeatureFrame(this, snapFrame,
450 resolution, Layer::SnapLeft);
450 } 451 }
451 452
452 if (snapFrame < 0) snapFrame = 0; 453 if (snapFrame < 0) snapFrame = 0;
453 m_selectionStartFrame = snapFrame; 454 m_selectionStartFrame = snapFrame;
454 if (m_manager) { 455 if (m_manager) {
464 465
465 } else if (mode == ViewManager::DrawMode) { 466 } else if (mode == ViewManager::DrawMode) {
466 467
467 Layer *layer = getSelectedLayer(); 468 Layer *layer = getSelectedLayer();
468 if (layer && layer->isLayerEditable()) { 469 if (layer && layer->isLayerEditable()) {
469 layer->drawStart(e); 470 layer->drawStart(this, e);
470 } 471 }
471 472
472 } else if (mode == ViewManager::EditMode) { 473 } else if (mode == ViewManager::EditMode) {
473 474
474 if (!editSelectionStart(e)) { 475 if (!editSelectionStart(e)) {
475 Layer *layer = getSelectedLayer(); 476 Layer *layer = getSelectedLayer();
476 if (layer && layer->isLayerEditable()) { 477 if (layer && layer->isLayerEditable()) {
477 layer->editStart(e); 478 layer->editStart(this, e);
478 } 479 }
479 } 480 }
480 } 481 }
481 482
482 emit paneInteractedWith(); 483 emit paneInteractedWith();
555 556
556 } else if (mode == ViewManager::DrawMode) { 557 } else if (mode == ViewManager::DrawMode) {
557 558
558 Layer *layer = getSelectedLayer(); 559 Layer *layer = getSelectedLayer();
559 if (layer && layer->isLayerEditable()) { 560 if (layer && layer->isLayerEditable()) {
560 layer->drawEnd(e); 561 layer->drawEnd(this, e);
561 update(); 562 update();
562 } 563 }
563 564
564 } else if (mode == ViewManager::EditMode) { 565 } else if (mode == ViewManager::EditMode) {
565 566
566 if (!editSelectionEnd(e)) { 567 if (!editSelectionEnd(e)) {
567 Layer *layer = getSelectedLayer(); 568 Layer *layer = getSelectedLayer();
568 if (layer && layer->isLayerEditable()) { 569 if (layer && layer->isLayerEditable()) {
569 layer->editEnd(e); 570 layer->editEnd(this, e);
570 update(); 571 update();
571 } 572 }
572 } 573 }
573 } 574 }
574 575
650 int snapFrameLeft = mouseFrame; 651 int snapFrameLeft = mouseFrame;
651 int snapFrameRight = mouseFrame; 652 int snapFrameRight = mouseFrame;
652 653
653 Layer *layer = getSelectedLayer(); 654 Layer *layer = getSelectedLayer();
654 if (layer) { 655 if (layer) {
655 layer->snapToFeatureFrame(snapFrameLeft, resolution, Layer::SnapLeft); 656 layer->snapToFeatureFrame(this, snapFrameLeft,
656 layer->snapToFeatureFrame(snapFrameRight, resolution, Layer::SnapRight); 657 resolution, Layer::SnapLeft);
658 layer->snapToFeatureFrame(this, snapFrameRight,
659 resolution, Layer::SnapRight);
657 } 660 }
658 661
659 // std::cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << std::endl; 662 // std::cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << std::endl;
660 663
661 if (snapFrameLeft < 0) snapFrameLeft = 0; 664 if (snapFrameLeft < 0) snapFrameLeft = 0;
704 707
705 } else if (mode == ViewManager::DrawMode) { 708 } else if (mode == ViewManager::DrawMode) {
706 709
707 Layer *layer = getSelectedLayer(); 710 Layer *layer = getSelectedLayer();
708 if (layer && layer->isLayerEditable()) { 711 if (layer && layer->isLayerEditable()) {
709 layer->drawDrag(e); 712 layer->drawDrag(this, e);
710 } 713 }
711 714
712 } else if (mode == ViewManager::EditMode) { 715 } else if (mode == ViewManager::EditMode) {
713 716
714 if (!editSelectionDrag(e)) { 717 if (!editSelectionDrag(e)) {
715 Layer *layer = getSelectedLayer(); 718 Layer *layer = getSelectedLayer();
716 if (layer && layer->isLayerEditable()) { 719 if (layer && layer->isLayerEditable()) {
717 layer->editDrag(e); 720 layer->editDrag(this, e);
718 } 721 }
719 } 722 }
720 } 723 }
721 } 724 }
722 725
735 738
736 if (mode == ViewManager::EditMode) { 739 if (mode == ViewManager::EditMode) {
737 740
738 Layer *layer = getSelectedLayer(); 741 Layer *layer = getSelectedLayer();
739 if (layer && layer->isLayerEditable()) { 742 if (layer && layer->isLayerEditable()) {
740 layer->editOpen(e); 743 layer->editOpen(this, e);
741 } 744 }
742 } 745 }
743 } 746 }
744 747
745 void 748 void