comparison layer/Colour3DPlotLayer.cpp @ 978:64c2b3a4435a 3.0-integration

Merge from branch osx-retina
author Chris Cannam
date Fri, 26 Jun 2015 14:10:40 +0100
parents bc23c2cfff65
children 7242fe160c19
comparison
equal deleted inserted replaced
977:f40ccbf228c2 978:64c2b3a4435a
528 { 528 {
529 return m_smooth; 529 return m_smooth;
530 } 530 }
531 531
532 void 532 void
533 Colour3DPlotLayer::setLayerDormant(const View *v, bool dormant) 533 Colour3DPlotLayer::setLayerDormant(const LayerGeometryProvider *v, bool dormant)
534 { 534 {
535 if (dormant) { 535 if (dormant) {
536 536
537 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 537 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
538 cerr << "Colour3DPlotLayer::setLayerDormant(" << dormant << ")" 538 cerr << "Colour3DPlotLayer::setLayerDormant(" << dormant << ")"
552 Layer::setLayerDormant(v, false); 552 Layer::setLayerDormant(v, false);
553 } 553 }
554 } 554 }
555 555
556 bool 556 bool
557 Colour3DPlotLayer::isLayerScrollable(const View *v) const 557 Colour3DPlotLayer::isLayerScrollable(const LayerGeometryProvider *v) const
558 { 558 {
559 if (m_normalizeVisibleArea) { 559 if (m_normalizeVisibleArea) {
560 return false; 560 return false;
561 } 561 }
562 if (shouldPaintDenseIn(v)) { 562 if (shouldPaintDenseIn(v)) {
611 emit layerParametersChanged(); 611 emit layerParametersChanged();
612 return true; 612 return true;
613 } 613 }
614 614
615 bool 615 bool
616 Colour3DPlotLayer::getYScaleValue(const View *, int, 616 Colour3DPlotLayer::getYScaleValue(const LayerGeometryProvider *, int,
617 double &, QString &) const 617 double &, QString &) const
618 { 618 {
619 return false;//!!! 619 return false;//!!!
620 } 620 }
621 621
667 return new LinearRangeMapper(0, m_model->getHeight(), 667 return new LinearRangeMapper(0, m_model->getHeight(),
668 0, m_model->getHeight(), ""); 668 0, m_model->getHeight(), "");
669 } 669 }
670 670
671 double 671 double
672 Colour3DPlotLayer::getYForBin(View *v, double bin) const 672 Colour3DPlotLayer::getYForBin(LayerGeometryProvider *v, double bin) const
673 { 673 {
674 double y = bin; 674 double y = bin;
675 if (!m_model) return y; 675 if (!m_model) return y;
676 double mn = 0, mx = m_model->getHeight(); 676 double mn = 0, mx = m_model->getHeight();
677 getDisplayExtents(mn, mx); 677 getDisplayExtents(mn, mx);
678 double h = v->height(); 678 double h = v->getPaintHeight();
679 if (m_binScale == LinearBinScale) { 679 if (m_binScale == LinearBinScale) {
680 y = h - (((bin - mn) * h) / (mx - mn)); 680 y = h - (((bin - mn) * h) / (mx - mn));
681 } else { 681 } else {
682 double logmin = mn + 1, logmax = mx + 1; 682 double logmin = mn + 1, logmax = mx + 1;
683 LogRange::mapRange(logmin, logmax); 683 LogRange::mapRange(logmin, logmax);
685 } 685 }
686 return y; 686 return y;
687 } 687 }
688 688
689 int 689 int
690 Colour3DPlotLayer::getIYForBin(View *v, int bin) const 690 Colour3DPlotLayer::getIYForBin(LayerGeometryProvider *v, int bin) const
691 { 691 {
692 return int(round(getYForBin(v, bin))); 692 return int(round(getYForBin(v, bin)));
693 } 693 }
694 694
695 double 695 double
696 Colour3DPlotLayer::getBinForY(View *v, double y) const 696 Colour3DPlotLayer::getBinForY(LayerGeometryProvider *v, double y) const
697 { 697 {
698 double bin = y; 698 double bin = y;
699 if (!m_model) return bin; 699 if (!m_model) return bin;
700 double mn = 0, mx = m_model->getHeight(); 700 double mn = 0, mx = m_model->getHeight();
701 getDisplayExtents(mn, mx); 701 getDisplayExtents(mn, mx);
702 double h = v->height(); 702 double h = v->getPaintHeight();
703 if (m_binScale == LinearBinScale) { 703 if (m_binScale == LinearBinScale) {
704 bin = mn + ((h - y) * (mx - mn)) / h; 704 bin = mn + ((h - y) * (mx - mn)) / h;
705 } else { 705 } else {
706 double logmin = mn + 1, logmax = mx + 1; 706 double logmin = mn + 1, logmax = mx + 1;
707 LogRange::mapRange(logmin, logmax); 707 LogRange::mapRange(logmin, logmax);
709 } 709 }
710 return bin; 710 return bin;
711 } 711 }
712 712
713 int 713 int
714 Colour3DPlotLayer::getIBinForY(View *v, int y) const 714 Colour3DPlotLayer::getIBinForY(LayerGeometryProvider *v, int y) const
715 { 715 {
716 return int(floor(getBinForY(v, y))); 716 return int(floor(getBinForY(v, y)));
717 } 717 }
718 718
719 QString 719 QString
720 Colour3DPlotLayer::getFeatureDescription(View *v, QPoint &pos) const 720 Colour3DPlotLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const
721 { 721 {
722 if (!m_model) return ""; 722 if (!m_model) return "";
723 723
724 int x = pos.x(); 724 int x = pos.x();
725 int y = pos.y(); 725 int y = pos.y();
746 symax = sh; 746 symax = sh;
747 } 747 }
748 if (symin < 0) symin = 0; 748 if (symin < 0) symin = 0;
749 if (symax > sh) symax = sh; 749 if (symax > sh) symax = sh;
750 750
751 // double binHeight = double(v->height()) / (symax - symin); 751 // double binHeight = double(v->getPaintHeight()) / (symax - symin);
752 // int sy = int((v->height() - y) / binHeight) + symin; 752 // int sy = int((v->getPaintHeight() - y) / binHeight) + symin;
753 753
754 int sy = getIBinForY(v, y); 754 int sy = getIBinForY(v, y);
755 755
756 if (sy < 0 || sy >= m_model->getHeight()) { 756 if (sy < 0 || sy >= m_model->getHeight()) {
757 return ""; 757 return "";
777 777
778 return text; 778 return text;
779 } 779 }
780 780
781 int 781 int
782 Colour3DPlotLayer::getColourScaleWidth(QPainter &) const 782 Colour3DPlotLayer::getColourScaleWidth(QPainter &p) const
783 { 783 {
784 int cw = 20; 784 // Font is rotated
785 int cw = p.fontMetrics().height();
785 return cw; 786 return cw;
786 } 787 }
787 788
788 int 789 int
789 Colour3DPlotLayer::getVerticalScaleWidth(View *, bool, QPainter &paint) const 790 Colour3DPlotLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const
790 { 791 {
791 if (!m_model) return 0; 792 if (!m_model) return 0;
792 793
793 QString sampleText = QString("[%1]").arg(m_model->getHeight()); 794 QString sampleText = QString("[%1]").arg(m_model->getHeight());
794 int tw = paint.fontMetrics().width(sampleText); 795 int tw = paint.fontMetrics().width(sampleText);
806 807
807 return tw + 13 + getColourScaleWidth(paint); 808 return tw + 13 + getColourScaleWidth(paint);
808 } 809 }
809 810
810 void 811 void
811 Colour3DPlotLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const 812 Colour3DPlotLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const
812 { 813 {
813 if (!m_model) return; 814 if (!m_model) return;
814 815
815 int h = rect.height(), w = rect.width(); 816 int h = rect.height(), w = rect.width();
816 817
866 QString maxstr = QString("%1").arg(max); 867 QString maxstr = QString("%1").arg(max);
867 868
868 paint.save(); 869 paint.save();
869 870
870 QFont font = paint.font(); 871 QFont font = paint.font();
871 font.setPixelSize(10); 872 font.setPixelSize(int(font.pixelSize() * 0.65));
872 paint.setFont(font); 873 paint.setFont(font);
873 874
874 int msw = paint.fontMetrics().width(maxstr); 875 int msw = paint.fontMetrics().width(maxstr);
875 876
876 QMatrix m; 877 QMatrix m;
904 905
905 paint.save(); 906 paint.save();
906 907
907 int py = h; 908 int py = h;
908 909
910 int defaultFontHeight = paint.fontMetrics().height();
911
909 for (int i = symin; i <= symax; ++i) { 912 for (int i = symin; i <= symax; ++i) {
910 913
911 int y0; 914 int y0;
912 915
913 y0 = getIYForBin(v, i); 916 y0 = getIYForBin(v, i);
914 int h = py - y0; 917 int h = py - y0;
915 918
916 if (i > symin) { 919 if (i > symin) {
917 if (paint.fontMetrics().height() >= h) { 920 if (paint.fontMetrics().height() >= h) {
918 if (h >= 8) { 921 if (h >= defaultFontHeight * 0.8) {
919 QFont tf = paint.font(); 922 QFont tf = paint.font();
920 tf.setPixelSize(h-2); 923 tf.setPixelSize(int(h * 0.8));
921 paint.setFont(tf); 924 paint.setFont(tf);
922 } else { 925 } else {
923 continue; 926 continue;
924 } 927 }
925 } 928 }
1281 1284
1282 delete[] peaks; 1285 delete[] peaks;
1283 } 1286 }
1284 1287
1285 bool 1288 bool
1286 Colour3DPlotLayer::shouldPaintDenseIn(const View *v) const 1289 Colour3DPlotLayer::shouldPaintDenseIn(const LayerGeometryProvider *v) const
1287 { 1290 {
1288 if (!m_model || !v || !(v->getViewManager())) { 1291 if (!m_model || !v || !(v->getViewManager())) {
1289 return false; 1292 return false;
1290 } 1293 }
1291 double srRatio = 1294 double srRatio =
1292 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate(); 1295 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate();
1293 if (m_opaque || 1296 if (m_opaque ||
1294 m_smooth || 1297 m_smooth ||
1295 m_model->getHeight() >= v->height() || 1298 m_model->getHeight() >= v->getPaintHeight() ||
1296 ((m_model->getResolution() * srRatio) / v->getZoomLevel()) < 2) { 1299 ((m_model->getResolution() * srRatio) / v->getZoomLevel()) < 2) {
1297 return true; 1300 return true;
1298 } 1301 }
1299 return false; 1302 return false;
1300 } 1303 }
1301 1304
1302 void 1305 void
1303 Colour3DPlotLayer::paint(View *v, QPainter &paint, QRect rect) const 1306 Colour3DPlotLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
1304 { 1307 {
1305 /* 1308 /*
1306 if (m_model) { 1309 if (m_model) {
1307 SVDEBUG << "Colour3DPlotLayer::paint: model says shouldUseLogValueScale = " << m_model->shouldUseLogValueScale() << endl; 1310 SVDEBUG << "Colour3DPlotLayer::paint: model says shouldUseLogValueScale = " << m_model->shouldUseLogValueScale() << endl;
1308 } 1311 }
1313 #endif 1316 #endif
1314 1317
1315 int completion = 0; 1318 int completion = 0;
1316 if (!m_model || !m_model->isOK() || !m_model->isReady(&completion)) { 1319 if (!m_model || !m_model->isOK() || !m_model->isReady(&completion)) {
1317 if (completion > 0) { 1320 if (completion > 0) {
1318 paint.fillRect(0, 10, v->width() * completion / 100, 1321 paint.fillRect(0, 10, v->getPaintWidth() * completion / 100,
1319 10, QColor(120, 120, 120)); 1322 10, QColor(120, 120, 120));
1320 } 1323 }
1321 return; 1324 return;
1322 } 1325 }
1323 1326
1324 if (m_normalizeVisibleArea && !m_normalizeColumns) rect = v->rect(); 1327 if (m_normalizeVisibleArea && !m_normalizeColumns) rect = v->getPaintRect();
1325 1328
1326 sv_frame_t modelStart = m_model->getStartFrame(); 1329 sv_frame_t modelStart = m_model->getStartFrame();
1327 sv_frame_t modelEnd = m_model->getEndFrame(); 1330 sv_frame_t modelEnd = m_model->getEndFrame();
1328 int modelResolution = m_model->getResolution(); 1331 int modelResolution = m_model->getResolution();
1329 1332
1337 // "small". This is "large"; see paintDense below for "small". 1340 // "small". This is "large"; see paintDense below for "small".
1338 1341
1339 int x0 = rect.left(); 1342 int x0 = rect.left();
1340 int x1 = rect.right() + 1; 1343 int x1 = rect.right() + 1;
1341 1344
1342 int h = v->height(); 1345 int h = v->getPaintHeight();
1343 1346
1344 double srRatio = 1347 double srRatio =
1345 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate(); 1348 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate();
1346 1349
1347 int sx0 = int((double(v->getFrameForX(x0)) / srRatio - double(modelStart)) 1350 int sx0 = int((double(v->getFrameForX(x0)) / srRatio - double(modelStart))
1459 } 1462 }
1460 } 1463 }
1461 } 1464 }
1462 1465
1463 void 1466 void
1464 Colour3DPlotLayer::paintDense(View *v, QPainter &paint, QRect rect) const 1467 Colour3DPlotLayer::paintDense(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
1465 { 1468 {
1466 Profiler profiler("Colour3DPlotLayer::paintDense", true); 1469 Profiler profiler("Colour3DPlotLayer::paintDense", true);
1467 if (!m_cache) return; 1470 if (!m_cache) return;
1468 1471
1469 double modelStart = double(m_model->getStartFrame()); 1472 double modelStart = double(m_model->getStartFrame());
1475 1478
1476 int x0 = rect.left(); 1479 int x0 = rect.left();
1477 int x1 = rect.right() + 1; 1480 int x1 = rect.right() + 1;
1478 1481
1479 const int w = x1 - x0; // const so it can be used as array size below 1482 const int w = x1 - x0; // const so it can be used as array size below
1480 int h = v->height(); // we always paint full height 1483 int h = v->getPaintHeight(); // we always paint full height
1481 int sh = m_model->getHeight(); 1484 int sh = m_model->getHeight();
1482 1485
1483 int symin = m_miny; 1486 int symin = m_miny;
1484 int symax = m_maxy; 1487 int symax = m_maxy;
1485 if (symax <= symin) { 1488 if (symax <= symin) {
1690 1693
1691 paint.drawImage(x0, 0, img); 1694 paint.drawImage(x0, 0, img);
1692 } 1695 }
1693 1696
1694 bool 1697 bool
1695 Colour3DPlotLayer::snapToFeatureFrame(View *v, sv_frame_t &frame, 1698 Colour3DPlotLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
1696 int &resolution, 1699 int &resolution,
1697 SnapType snap) const 1700 SnapType snap) const
1698 { 1701 {
1699 if (!m_model) { 1702 if (!m_model) {
1700 return Layer::snapToFeatureFrame(v, frame, resolution, snap); 1703 return Layer::snapToFeatureFrame(v, frame, resolution, snap);