From ba0cdb8f1fee3b9315ae90646dabe62e9ae63e31 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Tue, 12 Jul 2005 18:23:17 +0000 Subject: [PATCH] More work on the spectrum widget, that now should work well (even if "a bit" of flickering still remains...) svn path=/trunk/KDE/kdeedu/kalzium/src/spectrum.h; revision=434040 --- kalzium/src/spectrum.cpp | 17 +++++++++++++++-- kalzium/src/spectrum.h | 4 +++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/kalzium/src/spectrum.cpp b/kalzium/src/spectrum.cpp index 4720d39..60f5d8c 100644 --- a/kalzium/src/spectrum.cpp +++ b/kalzium/src/spectrum.cpp @@ -26,7 +26,7 @@ SpectrumWidget::SpectrumWidget( QWidget* parent, const char* name ) : QWidget( parent,name ) { startValue = 450; - endValue = 760; + endValue = 700; m_realWidth = 360; m_realHeight = 200; @@ -35,6 +35,8 @@ SpectrumWidget::SpectrumWidget( QWidget* parent, const char* name ) spectrumpix += "kalzium/data/spektrum.png"; ref_image = QImage( spectrumpix ); + + m_stretch = 1; } SpectrumWidget::~SpectrumWidget(){} @@ -45,6 +47,11 @@ void SpectrumWidget::paintEvent( QPaintEvent * /*e*/ ) p.begin( this ); p.fillRect( 0, 0, width(), height(), paletteBackgroundColor() ); p.drawRect( 0,0, width(), height() ); + QImage i = ref_image; + QPixmap px; + px.convertFromImage( i.smoothScale( width(), height() ) ); + m_stretch = ( width() * 1.0 ) / ref_image.width(); + bitBlt( this, 0, 0, &px ); drawLines( &p ); } @@ -62,6 +69,7 @@ void SpectrumWidget::drawLines( QPainter *p ) //(255,231,49) is for 600 nm //(246,144,49) is for 650 nm +/* for(int h = 450; h < 760 ; ++h) { p->setPen(linecolor(h) ); @@ -69,6 +77,7 @@ void SpectrumWidget::drawLines( QPainter *p ) } p->setPen(Qt::black); +*/ int i = 0; for ( QValueList::Iterator it = m_spectra.begin(); @@ -99,10 +108,14 @@ void SpectrumWidget::drawLines( QPainter *p ) int SpectrumWidget::xPos( double value ) { +/* double var = ( endValue-startValue ); double coeff = ( value - startValue )/var; return coeff * m_realWidth; +*/ + int proportion = width() * ( value - startValue ) / ( endValue - startValue ); + return proportion; } QColor SpectrumWidget::linecolor( double spectrum ) @@ -112,7 +125,7 @@ QColor SpectrumWidget::linecolor( double spectrum ) //Example: Freq is 600nm. 760-450 = 360. //760 - 600 = 160. 360/160 = 2.25 - int proportion = m_realWidth * ( spectrum - startValue ) / ( endValue - startValue ); + int proportion = m_stretch * ( spectrum - startValue ) / ( endValue - startValue ); QRgb rgb = ref_image.pixel(proportion, 2 ); diff --git a/kalzium/src/spectrum.h b/kalzium/src/spectrum.h index 4bf2871..b22ee52 100644 --- a/kalzium/src/spectrum.h +++ b/kalzium/src/spectrum.h @@ -66,10 +66,12 @@ class SpectrumWidget : public QWidget double startValue; double endValue; - + int m_realWidth; int m_realHeight; + double m_stretch; + protected: virtual void paintEvent( QPaintEvent *e ); }; -- 2.47.3