comparison view/Pane.cpp @ 227:6dab3ac2fe73

* Add scale to image
author Chris Cannam
date Mon, 12 Mar 2007 16:02:56 +0000
parents 9465b5375235
children 387f2f6fc333
comparison
equal deleted inserted replaced
226:2ccd02015530 227:6dab3ac2fe73
407 if (dynamic_cast<WaveformLayer *>(*vi)) { 407 if (dynamic_cast<WaveformLayer *>(*vi)) {
408 waveformModel = (*vi)->getModel(); 408 waveformModel = (*vi)->getModel();
409 } 409 }
410 410
411 if (!m_manager || !m_manager->shouldShowVerticalScale()) { 411 if (!m_manager || !m_manager->shouldShowVerticalScale()) {
412 break; 412 m_scaleWidth = 0;
413 } 413 } else {
414 414 m_scaleWidth = (*vi)->getVerticalScaleWidth(this, paint);
415 m_scaleWidth = (*vi)->getVerticalScaleWidth(this, paint); 415 }
416 416
417 if (m_scaleWidth > 0 && r.left() < m_scaleWidth) { 417 if (m_scaleWidth > 0 && r.left() < m_scaleWidth) {
418 418
419 // Profiler profiler("Pane::paintEvent - painting vertical scale", true); 419 // Profiler profiler("Pane::paintEvent - painting vertical scale", true);
420 420
698 } 698 }
699 paint.restore(); 699 paint.restore();
700 } 700 }
701 701
702 paint.end(); 702 paint.end();
703 }
704
705 bool
706 Pane::render(QPainter &paint, QRect rect)
707 {
708 if (!View::render(paint, QRect(rect.x() + m_scaleWidth, rect.y(),
709 rect.width() - m_scaleWidth, rect.height()))) {
710 return false;
711 }
712
713 if (m_scaleWidth > 0) {
714
715 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
716 --vi;
717
718 paint.save();
719
720 paint.setPen(Qt::black);
721 paint.setBrush(Qt::white);
722 paint.drawRect(0, -1, m_scaleWidth, height()+1);
723
724 paint.setBrush(Qt::NoBrush);
725 (*vi)->paintVerticalScale
726 (this, paint, QRect(0, 0, m_scaleWidth, height()));
727
728 paint.restore();
729 break;
730 }
731 }
732
733 return true;
734 }
735
736 QImage *
737 Pane::toNewImage()
738 {
739 size_t f0 = getModelsStartFrame();
740 size_t f1 = getModelsEndFrame();
741
742 size_t x0 = f0 / getZoomLevel();
743 size_t x1 = f1 / getZoomLevel();
744
745 QImage *image = new QImage(x1 - x0 + m_scaleWidth,
746 height(), QImage::Format_RGB32);
747
748 int formerScaleWidth = m_scaleWidth;
749
750 if (m_manager && m_manager->shouldShowVerticalScale()) {
751 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
752 --vi;
753 QPainter paint(image);
754 m_scaleWidth = (*vi)->getVerticalScaleWidth(this, paint);
755 break;
756 }
757 } else {
758 m_scaleWidth = 0;
759 }
760
761 if (m_scaleWidth != formerScaleWidth) {
762 delete image;
763 image = new QImage(x1 - x0 + m_scaleWidth,
764 height(), QImage::Format_RGB32);
765 }
766
767 QPainter *paint = new QPainter(image);
768 if (!render(*paint, image->rect())) {
769 delete paint;
770 delete image;
771 return 0;
772 } else {
773 delete paint;
774 return image;
775 }
703 } 776 }
704 777
705 size_t 778 size_t
706 Pane::getFirstVisibleFrame() const 779 Pane::getFirstVisibleFrame() const
707 { 780 {