From: Carsten Niehaus Date: Thu, 14 Jul 2005 11:20:08 +0000 (+0000) Subject: * remove some no longer needed stuff X-Git-Tag: v3.80.2~300^2~77 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=195560c7161515eba606a304f214d625c8d222f2;p=libqmvoc.git * remove some no longer needed stuff * make two methods inline * add API-docs * fix rounding-errors svn path=/trunk/KDE/kdeedu/kalzium/src/spectrum.h; revision=434496 --- diff --git a/kalzium/src/spectrum.cpp b/kalzium/src/spectrum.cpp index deaf56a..16ac483 100644 --- a/kalzium/src/spectrum.cpp +++ b/kalzium/src/spectrum.cpp @@ -28,9 +28,6 @@ #include -const double Gamma = 0.80; -const int IntensityMax = 255; - SpectrumWidget::SpectrumWidget( QWidget* parent, const char* name ) : QWidget( parent,name ) { @@ -44,8 +41,6 @@ SpectrumWidget::SpectrumWidget( QWidget* parent, const char* name ) m_realWidth = 360; m_realHeight = 200; - m_stretch = 1; - setType( EmissionSpectrum ); } @@ -158,7 +153,7 @@ void SpectrumWidget::drawTickmarks( QPainter* p ) { double pos = ( double )i/width(); - int wave = Wavelength( pos ); + int wave = ( int )Wavelength( pos ); p->drawLine( i,m_realHeight,i, m_realHeight+10 ); p->fillRect( i-space, m_realHeight+12, 2*space, 15, Qt::white ); @@ -170,7 +165,7 @@ void SpectrumWidget::wavelengthToRGB( double wavelength, int& r, int& g, int& b { double blue = 0.0, green = 0.0, red = 0.0, factor = 0.0; - int wavelength_ = floor( wavelength ); + int wavelength_ = ( int ) floor( wavelength ); if ( wavelength_ > 380 && wavelength_ < 439 ) { @@ -228,29 +223,14 @@ int SpectrumWidget::Adjust( double color, double factor ) if ( color == 0.0 ) return 0; else - return round( IntensityMax * pow( color*factor, Gamma ) ); -} - -int SpectrumWidget::xPos( double value ) -{ - return ( int ) width() * ( value - startValue ) / ( endValue - startValue ); -//X int proportion = ( int ) width() * ( value - startValue ) / ( endValue - startValue ); -//X return proportion; -} - -int SpectrumWidget::Wavelength( double position ) -{ - double range = endValue-startValue; - int result = ( int ) ( startValue + ( range * position ) ); - - return result; + return ( int )( round( IntensityMax * pow( color*factor, Gamma ) ) ); } QColor SpectrumWidget::linecolor( double spectrum ) { int r,g,b; wavelengthToRGB( spectrum, r,g,b ); - + QColor c( r,g,b ); return c; } @@ -272,8 +252,8 @@ SpectrumView::SpectrumView( QWidget *parent, const char* name ) connect( m_spinbox_left, SIGNAL( valueChanged( int ) ), m_spectrum, SLOT( setLeftBorder( int ) ) ); m_spectrumbox = new KComboBox( this, "combobox" ); - m_spectrumbox->insertItem( "EmissionSpectrum" ); - m_spectrumbox->insertItem( "AbsorptionSpectrum" ); + m_spectrumbox->insertItem( "Emission Spectrum" ); + m_spectrumbox->insertItem( "Absorption Spectrum" ); connect( m_spectrumbox, SIGNAL( activated( int ) ), m_spectrum, SLOT( slotActivateSpectrum( int ) ) ); diff --git a/kalzium/src/spectrum.h b/kalzium/src/spectrum.h index 715ca0a..389a5a2 100644 --- a/kalzium/src/spectrum.h +++ b/kalzium/src/spectrum.h @@ -33,9 +33,9 @@ #include #include -#define MAXCOLOR = 750 -#define MINCOLOR = 450 - +/** + * @author Carsten Niehaus + */ class SpectrumWidget : public QWidget { Q_OBJECT @@ -84,6 +84,14 @@ class SpectrumWidget : public QWidget void setType( SpectrumType t ){ m_type = t; } + + /** + * @return the currently active type + * of the spectrum + */ + SpectrumType spectrumType() const{ + return m_type; + } private: QValueList m_spectra; @@ -105,7 +113,9 @@ class SpectrumWidget : public QWidget * @param position the position on a 0 to 1 scale. * @return the Wavelength on @p position */ - int Wavelength( double position ); + inline double Wavelength( double position ){ + return startValue + ( ( endValue-startValue ) * position ); + } /** * This method changes the three values @p r @p g and @p b to the @@ -135,7 +145,15 @@ class SpectrumWidget : public QWidget */ void drawTickmarks( QPainter *p ); - inline int xPos( double value ); + /** + * @return the postion in the widget of a band + * with the wavelength @p wavelength + * + * @param wavelength the wavelength for which the position is needed + */ + inline int xPos( double wavelength ){ + return ( int ) ( width() * ( value - startValue ) / ( endValue - startValue ) ); + } /** * @returns the color of a line @@ -149,8 +167,6 @@ class SpectrumWidget : public QWidget int m_realWidth; int m_realHeight; - double m_stretch; - public slots: /** * set the the minimumvalue to @p value @@ -172,6 +188,9 @@ class SpectrumWidget : public QWidget update(); } + /** + * activates the spectrum of the type @p spectrumtype + */ void slotActivateSpectrum( int spectrumtype ){ m_type = ( SpectrumType )spectrumtype; update();