From: Carsten Niehaus Date: Wed, 13 Jul 2005 15:28:25 +0000 (+0000) Subject: Add the spectrum-stuff in the dialog X-Git-Tag: v3.80.2~300^2~85 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=3ad00b2b37d55c961be86424dadf5167a886bf9d;p=libqmvoc.git Add the spectrum-stuff in the dialog svn path=/trunk/KDE/kdeedu/kalzium/src/spectrum.cpp; revision=434276 --- diff --git a/kalzium/src/spectrum.cpp b/kalzium/src/spectrum.cpp index d8d56b5..abb3669 100644 --- a/kalzium/src/spectrum.cpp +++ b/kalzium/src/spectrum.cpp @@ -19,6 +19,7 @@ ***************************************************************************/ #include "spectrum.h" +#include #include #include @@ -40,11 +41,6 @@ SpectrumWidget::SpectrumWidget( QWidget* parent, const char* name ) m_realWidth = 360; m_realHeight = 200; - QString spectrumpix = KGlobal::dirs()->findResourceDir("data", "kalzium/data/" ); - spectrumpix += "kalzium/data/spektrum.png"; - - ref_image = QImage( spectrumpix ); - m_stretch = 1; } @@ -54,8 +50,7 @@ void SpectrumWidget::paintEvent( QPaintEvent * /*e*/ ) { QPainter p; p.begin( this ); - p.fillRect( 0, 0, width(), height(), paletteBackgroundColor() ); - p.drawRect( 0,0, width(), height() ); + p.fillRect( 0, 0, width(), m_realHeight, Qt::black ); drawLines( &p ); } @@ -67,7 +62,6 @@ void SpectrumWidget::drawLines( QPainter *p ) //580 green //500 light blue //400 dark blue - int i = 0; for ( QValueList::Iterator it = m_spectra.begin(); @@ -81,28 +75,32 @@ void SpectrumWidget::drawLines( QPainter *p ) int temp = 0; // every second item will have a little offset if ( i%2 ) - temp = 55; + temp = 35; else temp = 0; p->setPen(linecolor( *it )); - p->drawLine( x,0,x, m_realHeight+10+temp ); + p->drawLine( x,0,x, m_realHeight ); + p->setPen( Qt::black ); + p->drawLine( x,m_realHeight,x, m_realHeight+10+temp ); p->save(); p->translate(x, m_realHeight+10+15+temp); p->rotate(-90); p->setPen( Qt::black ); - p->drawText(0, 0, QString::number( *it )); + QString text = QString::number( *it ); + p->drawText(0, 0, text); p->restore(); i++; } - for ( double va = 400; va <= 770 ; va += 3.1 ) - { - int x = xPos( va ); - p->setPen(linecolor( va )); - p->drawLine( x,0,x, m_realHeight+10 ); - } +//To test the widget uncomment this code. +//X for ( double va = startValue; va <= endValue ; va += 0.7 ) +//X { +//X int x = xPos( va ); +//X p->setPen(linecolor( va )); +//X p->drawLine( x,0,x, m_realHeight+10 ); +//X } } void SpectrumWidget::wavelengthToRGB( double wavelength, int& r, int& g, int& b ) @@ -118,7 +116,7 @@ void SpectrumWidget::wavelengthToRGB( double wavelength, int& r, int& g, int& b red = -( wavelength-440 ) / ( 440-380 ); green = 0.0; blue = 1.0; - kdDebug() << "RGB on wavelength " << wavelength << " (1): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl; +// kdDebug() << "RGB on wavelength " << wavelength << " (1): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl; } if ( wavelength_ > 440 && wavelength_ < 489 ) @@ -126,35 +124,35 @@ void SpectrumWidget::wavelengthToRGB( double wavelength, int& r, int& g, int& b red = 0.0; green = ( wavelength-440 ) / ( 490-440 ); blue = 1.0; - kdDebug() << "RGB on wavelength " << wavelength << " (2): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl; +// kdDebug() << "RGB on wavelength " << wavelength << " (2): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl; } if ( wavelength_ > 490 && wavelength_ < 509 ) { red = 0.0; green = 1.0; blue = -( wavelength-510 ) / ( 510-490 ); - kdDebug() << "RGB on wavelength " << wavelength << " (3): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl; +// kdDebug() << "RGB on wavelength " << wavelength << " (3): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl; } if ( wavelength_ > 510 && wavelength_ < 579 ) { red = ( wavelength-510 ) / ( 580-510 ); green = 1.0; blue = 0.0; - kdDebug() << "RGB on wavelength " << wavelength << " (4): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl; +// kdDebug() << "RGB on wavelength " << wavelength << " (4): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl; } if ( wavelength_ > 580 && wavelength_ < 644 ) { red = 1.0; green = -( wavelength-645 ) / ( 645-580 ); blue = 0.0; - kdDebug() << "RGB on wavelength " << wavelength << "(5): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl; +// kdDebug() << "RGB on wavelength " << wavelength << "(5): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl; } if ( wavelength_ > 645 && wavelength_ < 780 ) { red = 1.0; green = 0.0; blue = 0.0; - kdDebug() << "RGB on wavelength " << wavelength << " (6): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl; +// kdDebug() << "RGB on wavelength " << wavelength << " (6): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl; } if ( wavelength_ > 380 && wavelength_ < 419 ) factor = 0.3 + 0.7*( wavelength - 380 ) / ( 420 - 380 ); @@ -180,12 +178,6 @@ int SpectrumWidget::Adjust( double color, double factor ) 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; }