return value;
}
+void Spectrum::paintBands( QPainter* p, double startValue, double endValue, bool emissionSpectrum )
+{
+ kdDebug() << "Spectrum::paintBands" << endl;
+
+ if ( !emissionSpectrum )
+ {
+ for ( double va = startValue; va <= endValue ; va += 0.1 )
+ {
+ int x = xPos( va, startValue, endValue );
+ p->setPen( linecolor( va ) );
+ p->drawLine( x,0,x, m_realHeight+10 );
+ }
+
+ p->setPen( Qt::black );
+ }
+
+ int i = 0;
+
+ for ( QValueList<band>::Iterator it = m_bandlist.begin();
+ it != m_bandlist.end();
+ ++it )
+ {
+ if ( ( *it ).wavelength < startValue || ( *it ).wavelength > endValue )
+ continue;
+
+ int x = xPos( ( *it ).wavelength, startValue, endValue );
+
+ int temp = 0; // every second item will have a little offset
+
+ if ( i%2 )
+ temp = 35;
+ else
+ temp = 0;
+
+ if ( emissionSpectrum )
+ {
+ p->setPen( linecolor( ( *it ).wavelength ) );
+
+ p->drawLine( x,0,x, m_realHeight );
+
+ p->setPen( Qt::black );
+ p->drawLine( x,m_realHeight,x, m_realHeight+10+temp );
+ }
+ else
+ {
+ p->drawLine( x,0,x, m_realHeight+10+temp );
+ }
+
+ QString text = QString::number( ( *it ).wavelength );
+ p->drawText(0, 0, text);
+
+ i++;
+ }
+}
+
SpectrumWidget::SpectrumWidget( QWidget* parent, const char* name )
: QWidget( parent,name )
{
- //For the colorcalculation
- Gamma = 0.8;
- IntensityMax = 255,
-
+ kdDebug() << "SpectrumWidget::SpectrumWidget()" << endl;
+
m_realWidth = 360;
- m_realHeight = 200;
+ m_realHeight = 200;
setType( EmissionSpectrum );
}
QPainter p;
p.begin( this );
p.fillRect( 0, 0, width(), m_realHeight, Qt::black );
+
+ m_spectrum->setWidth ( width() );
switch ( m_type )
{
{
kdDebug() << "SpectrumWidget::drawAbsorptionSpectrum()" << endl;
- int i = 0;
-
- for ( double va = startValue; va <= endValue ; va += 0.1 )
- {
- int x = xPos( va );
- p->setPen(linecolor( va ));
- p->drawLine( x,0,x, m_realHeight+10 );
- }
-
- for ( QValueList<double>::Iterator it = m_spectra.begin();
- it != m_spectra.end();
- ++it )
- {
- if ( (*it) < startValue || ( *it ) > endValue )
- continue;
-
- int x = xPos( *it );
-
- int temp = 0; // every second item will have a little offset
- if ( i%2 )
- temp = 35;
- else
- temp = 0;
-
- p->setPen( Qt::black );
- p->drawLine( x,0,x, m_realHeight+10+temp );
- QString text = QString::number( *it );
- p->drawText(0, 0, text);
-
- i++;
- }
+ m_spectrum->paintBands ( p, startValue, endValue, false );
}
void SpectrumWidget::drawEmmissionSpectrum( QPainter *p )
{
kdDebug() << "SpectrumWidget::drawEmmissionSpectrum()" << endl;
- int i = 0;
-
- for ( QValueList<double>::Iterator it = m_spectra.begin();
- it != m_spectra.end();
- ++it )
- {
- if ( (*it) < startValue || ( *it ) > endValue )
- continue;
- int x = xPos( *it );
-
- int temp = 0; // every second item will have a little offset
- if ( i%2 )
- temp = 35;
- else
- temp = 0;
-
- p->setPen(linecolor( *it ));
- p->drawLine( x,0,x, m_realHeight );
- //p->drawRect( x,0,x+width()/(endValue-startValue),m_realHeight );
- p->setPen( Qt::black );
- p->drawLine( x,m_realHeight,x, m_realHeight+10+temp );
- p->setPen( Qt::black );
- QString text = QString::number( *it );
- p->drawText(0, 0, text);
-
- i++;
- }
+ m_spectrum->paintBands ( p, startValue, endValue, true );
//To test the widget uncomment this code.
//X for ( double va = startValue; va <= endValue ; va += 0.7 )
//X }
}
+QColor Spectrum::linecolor( double spectrum )
+{
+ int r,g,b;
+ wavelengthToRGB( spectrum, r,g,b );
+
+ QColor c( r,g,b );
+ return c;
+}
+
void SpectrumWidget::drawTickmarks( QPainter* p )
{
const int space = 13;
}
}
-void SpectrumWidget::wavelengthToRGB( double wavelength, int& r, int& g, int& b )
+void Spectrum::wavelengthToRGB( double wavelength, int& r, int& g, int& b )
{
double blue = 0.0, green = 0.0, red = 0.0, factor = 0.0;
b = Adjust( blue, factor );
}
-int SpectrumWidget::Adjust( double color, double factor )
+int Spectrum::Adjust( double color, double factor )
{
if ( color == 0.0 )
return 0;
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;
-}
-
SpectrumView::SpectrumView( Spectrum *spec, QWidget *parent, const char* name )
: QWidget( parent, name )
{
+ kdDebug()<<"SpectrumView::SpectrumView()" << endl;
+
m_spectrum = spec;
QVBoxLayout *spectrumLayout = new QVBoxLayout( this );
{
public:
Spectrum(){
+ kdDebug() <<"Spectrum::Spectrum" << endl;
+
m_min = minBand();
m_max = maxBand();
+
+ //For the colorcalculation
+ Gamma = 0.8;
+ IntensityMax = 255,
+
+ m_realWidth = 360;
+ m_realHeight = 200;
};
~Spectrum(){};
return m_max;
}
+ void setWidth( int width ){
+ m_width = width;
+ }
+
+ void paintBands( QPainter* p, double startValue, double endValue, bool emissionSpectrum );
+
+ /**
+ * @returns the color of a line
+ * @param spectrum the value of the spectrum
+ */
+ QColor linecolor( double spectrum );
+
+
private:
/**
* @return the smallest wavelength
*/
double maxBand();
+ /**
+ * @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, double startValue, double endValue ){
+ return ( int ) ( m_width * ( wavelength - startValue ) / ( endValue - startValue ) );
+ }
+
+ /**
+ * This method changes the three values @p r @p g and @p b to the
+ * correct values
+ * param wavelength the wavelength for which the color is searched
+ * param r red
+ * param g green
+ * param b blue
+ */
+ void wavelengthToRGB( double wavelength, int& r, int& g, int& b );
+
+ double Gamma;
+ int IntensityMax;
+
+ int m_realWidth;
+ int m_realHeight;
+
+ /**
+ * @return the adjusted value of the @p color. The
+ * correction depends on @p factor which has been
+ * figured out emperically
+ */
+ int Adjust( double color, double factor );
+
QValueList<band> m_bandlist;
double m_max, m_min;
+
+ int m_width;
};
/**
SpectrumType m_type;
- /**
- * @return the adjusted value of the @p color. The
- * correction depends on @p factor which has been
- * figured out emperically
- */
- int Adjust( double color, double factor );
-
Spectrum *m_spectrum;
- /**
- * @param the position on a 0 to 1-scale in the widget. 0.5 mean
- * that you want the wavelength in the middle of the widget,
- * 0.25 mean at one quarter of the width of the widget
- *
- * @param position the position on a 0 to 1 scale.
- * @return the Wavelength on @p 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
- * correct values
- * param wavelength the wavelength for which the color is searched
- * param r red
- * param g green
- * param b blue
- */
- void wavelengthToRGB( double wavelength, int& r, int& g, int& b );
-
- double Gamma;
- int IntensityMax;
-
/**
* draws the spectra-lines
*/
*/
void drawTickmarks( QPainter *p );
- /**
- * @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() * ( wavelength - startValue ) / ( endValue - startValue ) );
- }
-
- /**
- * @returns the color of a line
- * @param spectrum the value of the spectrum
- */
- QColor linecolor( double spectrum );
-
double startValue;
double endValue;
- int m_realWidth;
int m_realHeight;
+ int m_realWidth;
public slots:
/**