#include <math.h>
-const double Gamma = 0.80;
-const int IntensityMax = 255;
-
SpectrumWidget::SpectrumWidget( QWidget* parent, const char* name )
: QWidget( parent,name )
{
m_realWidth = 360;
m_realHeight = 200;
- m_stretch = 1;
-
setType( EmissionSpectrum );
}
{
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 );
{
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 )
{
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;
}
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 ) ) );
#include <kpixmapeffect.h>
#include <kcombobox.h>
-#define MAXCOLOR = 750
-#define MINCOLOR = 450
-
+/**
+ * @author Carsten Niehaus
+ */
class SpectrumWidget : public QWidget
{
Q_OBJECT
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;
* @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
*/
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
int m_realWidth;
int m_realHeight;
- double m_stretch;
-
public slots:
/**
* set the the minimumvalue to @p value
update();
}
+ /**
+ * activates the spectrum of the type @p spectrumtype
+ */
void slotActivateSpectrum( int spectrumtype ){
m_type = ( SpectrumType )spectrumtype;
update();