comparison view/Pane.cpp @ 258:6732a5b8a2c4

* Add logic for picking up the vertical scale from an underlying layer if the top layer doesn't define one and the units match (closes #1721489)
author Chris Cannam
date Wed, 13 Jun 2007 12:41:19 +0000
parents 1ab41ee36952
children 2d891e02c5ce
comparison
equal deleted inserted replaced
257:1ab41ee36952 258:6732a5b8a2c4
381 381
382 if (e) { 382 if (e) {
383 paint.setClipRect(r); 383 paint.setClipRect(r);
384 } 384 }
385 385
386 const Model *waveformModel = 0; // just for reporting purposes
387
388 int fontHeight = paint.fontMetrics().height(); 386 int fontHeight = paint.fontMetrics().height();
389 int fontAscent = paint.fontMetrics().ascent(); 387 int fontAscent = paint.fontMetrics().ascent();
390 388
391 if (m_manager && 389 if (m_manager &&
392 !m_manager->isPlaying() && 390 !m_manager->isPlaying() &&
405 break; 403 break;
406 } 404 }
407 } 405 }
408 } 406 }
409 407
408 Layer *topLayer = 0;
409 const Model *waveformModel = 0; // just for reporting purposes
410 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) { 410 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
411 --vi; 411 --vi;
412 412 if (!topLayer) topLayer = *vi;
413 if (dynamic_cast<WaveformLayer *>(*vi)) { 413 if (dynamic_cast<WaveformLayer *>(*vi)) {
414 waveformModel = (*vi)->getModel(); 414 waveformModel = (*vi)->getModel();
415 } 415 break;
416 416 }
417 if (!m_manager || !m_manager->shouldShowVerticalScale()) { 417 }
418 m_scaleWidth = 0; 418
419 Layer *scaleLayer = 0;
420
421 if (m_manager && m_manager->shouldShowVerticalScale() && topLayer) {
422
423 float min, max;
424 bool log;
425 QString unit;
426
427 // If the top layer has no scale and reports no display
428 // extents, but does report a unit, then the scale should be
429 // drawn from any underlying layer with a scale and that unit.
430 // If the top layer has no scale and no value extents at all,
431 // then the scale should be drawn from any underlying layer
432 // with a scale regardless of unit.
433
434 int sw = topLayer->getVerticalScaleWidth(this, paint);
435
436 if (sw > 0) {
437 scaleLayer = topLayer;
438 m_scaleWidth = sw;
439
419 } else { 440 } else {
420 m_scaleWidth = (*vi)->getVerticalScaleWidth(this, paint); 441
421 } 442 bool hasDisplayExtents = topLayer->getDisplayExtents(min, max);
422 443 bool hasValueExtents = topLayer->getValueExtents(min, max, log, unit);
423 if (m_scaleWidth > 0 && r.left() < m_scaleWidth) { 444
445 if (!hasDisplayExtents) {
446
447 if (!hasValueExtents) {
448
449 for (LayerList::iterator vi = m_layers.end();
450 vi != m_layers.begin(); ) {
451
452 --vi;
453
454 if ((*vi) == topLayer) continue;
455
456 sw = (*vi)->getVerticalScaleWidth(this, paint);
457
458 if (sw > 0) {
459 scaleLayer = *vi;
460 m_scaleWidth = sw;
461 break;
462 }
463 }
464 } else if (unit != "") { // && hasValueExtents && !hasDisplayExtents
465
466 QString requireUnit = unit;
467
468 for (LayerList::iterator vi = m_layers.end();
469 vi != m_layers.begin(); ) {
470
471 --vi;
472
473 if ((*vi) == topLayer) continue;
474
475 if ((*vi)->getDisplayExtents(min, max)) {
476
477 // search no further than this: if the
478 // scale from this layer isn't suitable,
479 // we'll have to draw no scale (else we'd
480 // risk ending up with the wrong scale)
481
482 if ((*vi)->getValueExtents(min, max, log, unit) &&
483 unit == requireUnit) {
484
485 sw = (*vi)->getVerticalScaleWidth(this, paint);
486 if (sw > 0) {
487 scaleLayer = *vi;
488 m_scaleWidth = sw;
489 }
490 }
491 break;
492 }
493 }
494 }
495 }
496 }
497 }
498
499 if (!scaleLayer) m_scaleWidth = 0;
500
501 if (m_scaleWidth > 0 && r.left() < m_scaleWidth) {
424 502
425 // Profiler profiler("Pane::paintEvent - painting vertical scale", true); 503 // Profiler profiler("Pane::paintEvent - painting vertical scale", true);
426 504
427 // std::cerr << "Pane::paintEvent: calling paint.save() in vertical scale block" << std::endl; 505 // std::cerr << "Pane::paintEvent: calling paint.save() in vertical scale block" << std::endl;
506 paint.save();
507
508 paint.setPen(Qt::black);
509 paint.setBrush(Qt::white);
510 paint.drawRect(0, -1, m_scaleWidth, height()+1);
511
512 paint.setBrush(Qt::NoBrush);
513 scaleLayer->paintVerticalScale
514 (this, paint, QRect(0, 0, m_scaleWidth, height()));
515
516 paint.restore();
517 }
518
519 if (m_identifyFeatures && topLayer) {
520
521 QPoint pos = m_identifyPoint;
522 QString desc = topLayer->getFeatureDescription(this, pos);
523
524 if (desc != "") {
525
428 paint.save(); 526 paint.save();
429 527
430 paint.setPen(Qt::black); 528 int tabStop =
431 paint.setBrush(Qt::white); 529 paint.fontMetrics().width(tr("Some lengthy prefix:"));
432 paint.drawRect(0, -1, m_scaleWidth, height()+1);
433 530
434 paint.setBrush(Qt::NoBrush); 531 QRect boundingRect =
435 (*vi)->paintVerticalScale 532 paint.fontMetrics().boundingRect
436 (this, paint, QRect(0, 0, m_scaleWidth, height())); 533 (rect(),
534 Qt::AlignRight | Qt::AlignTop | Qt::TextExpandTabs,
535 desc, tabStop);
536
537 if (hasLightBackground()) {
538 paint.setPen(Qt::NoPen);
539 paint.setBrush(QColor(250, 250, 250, 200));
540 } else {
541 paint.setPen(Qt::NoPen);
542 paint.setBrush(QColor(50, 50, 50, 200));
543 }
544
545 int extra = paint.fontMetrics().descent();
546 paint.drawRect(width() - boundingRect.width() - 10 - extra,
547 10 - extra,
548 boundingRect.width() + 2 * extra,
549 boundingRect.height() + extra);
550
551 if (hasLightBackground()) {
552 paint.setPen(QColor(150, 20, 0));
553 } else {
554 paint.setPen(QColor(255, 150, 100));
555 }
556
557 QTextOption option;
558 option.setWrapMode(QTextOption::NoWrap);
559 option.setAlignment(Qt::AlignRight | Qt::AlignTop);
560 option.setTabStop(tabStop);
561 paint.drawText(QRectF(width() - boundingRect.width() - 10, 10,
562 boundingRect.width(),
563 boundingRect.height()),
564 desc,
565 option);
437 566
438 paint.restore(); 567 paint.restore();
439 } 568 }
440
441 if (m_identifyFeatures) {
442
443 QPoint pos = m_identifyPoint;
444 QString desc = (*vi)->getFeatureDescription(this, pos);
445
446 if (desc != "") {
447
448 paint.save();
449
450 int tabStop =
451 paint.fontMetrics().width(tr("Some lengthy prefix:"));
452
453 QRect boundingRect =
454 paint.fontMetrics().boundingRect
455 (rect(),
456 Qt::AlignRight | Qt::AlignTop | Qt::TextExpandTabs,
457 desc, tabStop);
458
459 if (hasLightBackground()) {
460 paint.setPen(Qt::NoPen);
461 paint.setBrush(QColor(250, 250, 250, 200));
462 } else {
463 paint.setPen(Qt::NoPen);
464 paint.setBrush(QColor(50, 50, 50, 200));
465 }
466
467 int extra = paint.fontMetrics().descent();
468 paint.drawRect(width() - boundingRect.width() - 10 - extra,
469 10 - extra,
470 boundingRect.width() + 2 * extra,
471 boundingRect.height() + extra);
472
473 if (hasLightBackground()) {
474 paint.setPen(QColor(150, 20, 0));
475 } else {
476 paint.setPen(QColor(255, 150, 100));
477 }
478
479 QTextOption option;
480 option.setWrapMode(QTextOption::NoWrap);
481 option.setAlignment(Qt::AlignRight | Qt::AlignTop);
482 option.setTabStop(tabStop);
483 paint.drawText(QRectF(width() - boundingRect.width() - 10, 10,
484 boundingRect.width(),
485 boundingRect.height()),
486 desc,
487 option);
488
489 paint.restore();
490 }
491 }
492
493 break;
494 } 569 }
495 570
496 int sampleRate = getModelsSampleRate(); 571 int sampleRate = getModelsSampleRate();
497 paint.setBrush(Qt::NoBrush); 572 paint.setBrush(Qt::NoBrush);
498 573
1373 setCentreFrame(m_centreFrame + move); 1448 setCentreFrame(m_centreFrame + move);
1374 } else if (offset <= available * 0.10) { 1449 } else if (offset <= available * 0.10) {
1375 int move = int(available * 0.10 - offset) + 1; 1450 int move = int(available * 0.10 - offset) + 1;
1376 if (move < 0) { 1451 if (move < 0) {
1377 setCentreFrame(m_centreFrame + (-move)); 1452 setCentreFrame(m_centreFrame + (-move));
1378 } else if (m_centreFrame > move) { 1453 } else if (m_centreFrame > size_t(move)) {
1379 setCentreFrame(m_centreFrame - move); 1454 setCentreFrame(m_centreFrame - move);
1380 } else { 1455 } else {
1381 setCentreFrame(0); 1456 setCentreFrame(0);
1382 } 1457 }
1383 } 1458 }