]> Git trees. - libqmvoc.git/commitdiff
* remove some no longer needed stuff
authorCarsten Niehaus <cniehaus@gmx.de>
Thu, 14 Jul 2005 11:20:08 +0000 (11:20 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Thu, 14 Jul 2005 11:20:08 +0000 (11:20 +0000)
* make two methods inline
* add API-docs
* fix rounding-errors

svn path=/trunk/KDE/kdeedu/kalzium/src/spectrum.h; revision=434496

kalzium/src/spectrum.cpp
kalzium/src/spectrum.h

index deaf56ada01d5c5f0d73e11c0e7bc6d144dee557..16ac48350da4ca466ecf6ae31e91bfb8b79fd372 100644 (file)
@@ -28,9 +28,6 @@
 
 #include <math.h>
 
-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 ) ) );
        
        
index 715ca0a8d7e19c52c15459d434bd3457148a1062..389a5a29227cf4c85c7d94fbdd97b5fc2fbab91d 100644 (file)
@@ -33,9 +33,9 @@
 #include <kpixmapeffect.h>
 #include <kcombobox.h>
 
-#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<double> 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();