comparison view/Pane.cpp @ 326:4f4f38a11cd2

* Factor out uses of "Sonic Visualiser" in "common" code to applicationName() * Add ability to show work title + artist in top-left of pane (thinking of Vect but may be useful in SV in future) * A few other generalisations useful for Vect
author Chris Cannam
date Fri, 09 Nov 2007 17:46:58 +0000
parents 984c1975f1ff
children 29fcf125f98b
comparison
equal deleted inserted replaced
324:1f67b110c1a3 326:4f4f38a11cd2
21 #include "base/Profiler.h" 21 #include "base/Profiler.h"
22 #include "ViewManager.h" 22 #include "ViewManager.h"
23 #include "base/CommandHistory.h" 23 #include "base/CommandHistory.h"
24 #include "base/TextAbbrev.h" 24 #include "base/TextAbbrev.h"
25 #include "layer/WaveformLayer.h" 25 #include "layer/WaveformLayer.h"
26
27 //!!! ugh
28 #include "data/model/WaveFileModel.h"
26 29
27 #include <QPaintEvent> 30 #include <QPaintEvent>
28 #include <QPainter> 31 #include <QPainter>
29 #include <QBitmap> 32 #include <QBitmap>
30 #include <QDragEnterEvent> 33 #include <QDragEnterEvent>
311 314
312 if (m_manager && m_manager->getToolMode() == ViewManager::MeasureMode) { 315 if (m_manager && m_manager->getToolMode() == ViewManager::MeasureMode) {
313 return false; 316 return false;
314 } 317 }
315 318
319 if (m_manager && !m_manager->shouldIlluminateLocalFeatures()) {
320 return false;
321 }
322
316 if (layer == getSelectedLayer() && 323 if (layer == getSelectedLayer() &&
317 !shouldIlluminateLocalSelection(discard, b0, b1)) { 324 !shouldIlluminateLocalSelection(discard, b0, b1)) {
318 325
319 pos = m_identifyPoint; 326 pos = m_identifyPoint;
320 return m_identifyFeatures; 327 return m_identifyFeatures;
408 415
409 Layer *topLayer = getTopLayer(); 416 Layer *topLayer = getTopLayer();
410 bool haveSomeTimeXAxis = false; 417 bool haveSomeTimeXAxis = false;
411 418
412 const Model *waveformModel = 0; // just for reporting purposes 419 const Model *waveformModel = 0; // just for reporting purposes
420 const Model *workModel = 0;
421
413 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) { 422 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
414 --vi; 423 --vi;
415 if (!haveSomeTimeXAxis && (*vi)->hasTimeXAxis()) { 424 if (!haveSomeTimeXAxis && (*vi)->hasTimeXAxis()) {
416 haveSomeTimeXAxis = true; 425 haveSomeTimeXAxis = true;
417 } 426 }
418 if (dynamic_cast<WaveformLayer *>(*vi)) { 427 if (dynamic_cast<WaveformLayer *>(*vi)) {
419 waveformModel = (*vi)->getModel(); 428 waveformModel = (*vi)->getModel();
420 } 429 workModel = waveformModel;
421 if (waveformModel && haveSomeTimeXAxis) break; 430 } else {
431 Model *m = (*vi)->getModel();
432 if (dynamic_cast<WaveFileModel *>(m)) {
433 workModel = m;
434 } else if (m && dynamic_cast<WaveFileModel *>(m->getSourceModel())) {
435 workModel = m->getSourceModel();
436 }
437 }
438
439 if (waveformModel && workModel && haveSomeTimeXAxis) break;
422 } 440 }
423 441
424 m_scaleWidth = 0; 442 m_scaleWidth = 0;
425 443
426 if (m_manager && m_manager->shouldShowVerticalScale() && topLayer) { 444 if (m_manager && m_manager->shouldShowVerticalScale() && topLayer) {
427 drawVerticalScale(r, topLayer, paint); 445 drawVerticalScale(r, topLayer, paint);
428 } 446 }
429 447
430 if (m_identifyFeatures && topLayer) { 448 if (m_identifyFeatures &&
449 m_manager && m_manager->shouldIlluminateLocalFeatures() &&
450 topLayer) {
431 drawFeatureDescription(topLayer, paint); 451 drawFeatureDescription(topLayer, paint);
432 } 452 }
433 453
434 int sampleRate = getModelsSampleRate(); 454 int sampleRate = getModelsSampleRate();
435 paint.setBrush(Qt::NoBrush); 455 paint.setBrush(Qt::NoBrush);
446 m_manager && 466 m_manager &&
447 m_manager->shouldShowDuration()) { 467 m_manager->shouldShowDuration()) {
448 drawDurationAndRate(r, waveformModel, sampleRate, paint); 468 drawDurationAndRate(r, waveformModel, sampleRate, paint);
449 } 469 }
450 470
451 if (waveformModel && 471 bool haveWorkTitle = false;
472
473 if (workModel &&
474 m_manager &&
475 m_manager->shouldShowWorkTitle()) {
476 drawWorkTitle(r, paint, workModel);
477 haveWorkTitle = true;
478 }
479
480 if (workModel &&
452 m_manager && 481 m_manager &&
453 m_manager->getAlignMode()) { 482 m_manager->getAlignMode()) {
454 drawAlignmentStatus(r, paint, waveformModel); 483 drawAlignmentStatus(r, paint, workModel, haveWorkTitle);
455 } 484 }
456 485
457 if (m_manager && 486 if (m_manager &&
458 m_manager->shouldShowLayerNames()) { 487 m_manager->shouldShowLayerNames()) {
459 drawLayerNames(r, paint); 488 drawLayerNames(r, paint);
715 drawVisibleText(paint, x, y, text, OutlinedText); 744 drawVisibleText(paint, x, y, text, OutlinedText);
716 } 745 }
717 } 746 }
718 747
719 void 748 void
720 Pane::drawAlignmentStatus(QRect r, QPainter &paint, const Model *model) 749 Pane::drawAlignmentStatus(QRect r, QPainter &paint, const Model *model,
750 bool down)
721 { 751 {
722 const Model *reference = model->getAlignmentReference(); 752 const Model *reference = model->getAlignmentReference();
723 /* 753 /*
724 if (!reference) { 754 if (!reference) {
725 std::cerr << "Pane[" << this << "]::drawAlignmentStatus: No reference" << std::endl; 755 std::cerr << "Pane[" << this << "]::drawAlignmentStatus: No reference" << std::endl;
745 } else { 775 } else {
746 text = tr("Aligned"); 776 text = tr("Aligned");
747 } 777 }
748 } 778 }
749 779
750 int w = paint.fontMetrics().width(text), h = paint.fontMetrics().height();
751 if (r.top() > h + 5 || r.left() > w + m_scaleWidth + 5) return;
752
753 paint.save(); 780 paint.save();
754 QFont font(paint.font()); 781 QFont font(paint.font());
755 font.setBold(true); 782 font.setBold(true);
756 paint.setFont(font); 783 paint.setFont(font);
757 if (completion < 100) paint.setPen(Qt::red); 784 if (completion < 100) paint.setBrush(Qt::red);
785
786 int y = 5;
787 if (down) y += paint.fontMetrics().height();
788 int w = paint.fontMetrics().width(text);
789 int h = paint.fontMetrics().height();
790 if (r.top() > h + y || r.left() > w + m_scaleWidth + 5) {
791 paint.restore();
792 return;
793 }
758 794
759 drawVisibleText(paint, m_scaleWidth + 5, 795 drawVisibleText(paint, m_scaleWidth + 5,
760 paint.fontMetrics().ascent() + 5, text, OutlinedText); 796 paint.fontMetrics().ascent() + y, text, OutlinedText);
761 797
762 paint.restore(); 798 paint.restore();
763 } 799 }
764 800
765 void 801 void
766 Pane::modelAlignmentCompletionChanged() 802 Pane::modelAlignmentCompletionChanged()
767 { 803 {
768 View::modelAlignmentCompletionChanged(); 804 View::modelAlignmentCompletionChanged();
769 update(QRect(0, 0, 300, 100)); 805 update(QRect(0, 0, 300, 100));
806 }
807
808 void
809 Pane::drawWorkTitle(QRect r, QPainter &paint, const Model *model)
810 {
811 QString title = model->getTitle();
812 QString maker = model->getMaker();
813 if (title == "") return;
814
815 QString text = title;
816 if (maker != "") {
817 text = tr("%1 - %2").arg(title).arg(maker);
818 }
819
820 paint.save();
821 QFont font(paint.font());
822 font.setItalic(true);
823 paint.setFont(font);
824
825 int y = 5;
826 int w = paint.fontMetrics().width(text);
827 int h = paint.fontMetrics().height();
828 if (r.top() > h + y || r.left() > w + m_scaleWidth + 5) {
829 paint.restore();
830 return;
831 }
832
833 drawVisibleText(paint, m_scaleWidth + 5,
834 paint.fontMetrics().ascent() + y, text, OutlinedText);
835
836 paint.restore();
770 } 837 }
771 838
772 void 839 void
773 Pane::drawLayerNames(QRect r, QPainter &paint) 840 Pane::drawLayerNames(QRect r, QPainter &paint)
774 { 841 {
1361 1428
1362 if (!m_manager->isPlaying()) { 1429 if (!m_manager->isPlaying()) {
1363 1430
1364 bool updating = false; 1431 bool updating = false;
1365 1432
1366 if (getSelectedLayer()) { 1433 if (getSelectedLayer() &&
1434 m_manager->shouldIlluminateLocalFeatures()) {
1367 1435
1368 bool previouslyIdentifying = m_identifyFeatures; 1436 bool previouslyIdentifying = m_identifyFeatures;
1369 m_identifyFeatures = true; 1437 m_identifyFeatures = true;
1370 1438
1371 if (m_identifyFeatures != previouslyIdentifying || 1439 if (m_identifyFeatures != previouslyIdentifying ||