* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "spectrum.h"
+#include "spectrumwidget.h"
#include <qlayout.h>
#include <qlabel.h>
void Spectrum::paintBands( QPainter* p, double startValue, double endValue, bool emissionSpectrum )
{
- kdDebug() << "Spectrum::paintBands" << endl;
+ kdDebug() << "Spectrum::paintBands()" << endl;
if ( !emissionSpectrum )
{
it != m_bandlist.end();
++it )
{
- kdDebug() << "band gemalt" << endl;
+ kdDebug() << "band painted" << endl;
if ( ( *it ).wavelength < startValue || ( *it ).wavelength > endValue )
continue;
i++;
}
- kdDebug() << "fertig" << endl;
-}
-
-SpectrumWidget::SpectrumWidget( QWidget* parent, const char* name )
- : QWidget( parent,name )
-{
- kdDebug() << "SpectrumWidget::SpectrumWidget()" << endl;
-
- m_realWidth = 360;
- m_realHeight = 200;
-
- setType( EmissionSpectrum );
-}
-
-SpectrumWidget::~SpectrumWidget(){}
-
-void SpectrumWidget::paintEvent( QPaintEvent * /*e*/ )
-{
- if ( !m_spectrum ) return;
- QPainter p;
- p.begin( this );
- p.fillRect( 0, 0, width(), m_realHeight, Qt::black );
-
- m_spectrum->setWidth ( width() );
-
- switch ( m_type )
- {
- case EmissionSpectrum:
- drawEmmissionSpectrum( &p );
- break;
- case AbsorptionSpectrum:
- drawAbsorptionSpectrum( &p );
- break;
- }
- drawTickmarks( &p );
-}
-
-void SpectrumWidget::drawAbsorptionSpectrum( QPainter *p )
-{
- kdDebug() << "SpectrumWidget::drawAbsorptionSpectrum()" << endl;
-
- m_spectrum->paintBands ( p, startValue, endValue, false );
-}
-
-void SpectrumWidget::drawEmmissionSpectrum( QPainter *p )
-{
- kdDebug() << "SpectrumWidget::drawEmmissionSpectrum()" << endl;
-
- 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 {
-//X int x = xPos( va );
-//X p->setPen(linecolor( va ));
-//X p->drawLine( x,0,x, m_realHeight+10 );
-//X }
+ kdDebug() << "leaving Spectrum::paintBands()" << endl;
}
QColor Spectrum::linecolor( double spectrum )
return c;
}
-void SpectrumWidget::drawTickmarks( QPainter* p )
-{
- kdDebug() << "tickmarks" << endl;
- const int space = 13;
-
-/* for ( int i = 0; i < width() ; i+=10 )
- {
- p->drawLine( i,m_realHeight,i, m_realHeight+5 );
- }
- for ( int i = 50; i < width() ; i+=50 )
- {
- double pos = ( double )i/width();
-
- 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 );
- p->drawText( i-space, m_realHeight+12, 2*space, 15, Qt::AlignCenter, QString::number( wave ) );
- }
-*/
- int start = (int)startValue % 10;
- double dist = width()/(endValue-startValue) * 10; //distance between the tickles in px
-
- int count = ( int )startValue - start + 10;
- start *= width()/(endValue-startValue);
-
- for ( int i = start; i < width(); i += dist )
- {
- if(count%50 == 0 )
- {
- //int wave = ( int )Wavelength( count );
-
- p->drawLine( i, m_realHeight, i, m_realHeight+10 );
- p->fillRect( i-space, m_realHeight+12, 2*space, 15, Qt::white );
- p->drawText( i-space, m_realHeight+12, 2*space, 15, Qt::AlignCenter, QString::number( count ) );
- }
- else
- {
- p->drawLine( i, m_realHeight, i, m_realHeight+5 );
- }
- count += 10;
- }
-}
void Spectrum::wavelengthToRGB( double wavelength, int& r, int& g, int& b )
{
#include "element.h"
+class SpectrumWidget;
+
/**
* @author Carsten Niehaus
*
int m_width;
};
-/**
- * @author Carsten Niehaus
- */
-class SpectrumWidget : public QWidget
-{
- Q_OBJECT
-
- public:
- SpectrumWidget( QWidget *parent, const char* name = 0 );
- ~SpectrumWidget();
-
- void setSpectrum( Spectrum* spec ){
- m_spectrum = spec;
- }
-
- /**
- * This limits the width of the spectrum in terms of
- * wavelength. For example you can set it to only
- * show the area between 500 and 550 nm
- *
- * @param left the left border
- * @param right the right border
- */
- void setBorders( double left, double right ){
- startValue = ( int )left;
- endValue = ( int )right;
- }
-
- /**
- * find the nearest band. The returnvalue is the number
- * of pixel the next band is away
- */
- int findNearestBand( QValueList<double>::iterator it );
-
- /**
- * there are several possible types.
- */
- enum SpectrumType
- {
- EmissionSpectrum = 0,
- AbsorptionSpectrum
- };
-
- /**
- * sets the type of the spectrum to @p t
- * @param t the type of the spectrum
- */
- 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;
-
- SpectrumType m_type;
-
- Spectrum *m_spectrum;
-
- /**
- * draws the spectra-lines
- */
- void drawAbsorptionSpectrum( QPainter *p );
-
- /**
- * draws the spectra-lines
- */
- void drawEmmissionSpectrum( QPainter *p );
-
- /**
- * Draw the scale
- */
- void drawTickmarks( QPainter *p );
-
- double startValue;
- double endValue;
-
- int m_realHeight;
- int m_realWidth;
-
- public slots:
- /**
- * set the the maximumvalue to @p value
- */
- void setRightBorder( int value ){
- endValue = value;
- if ( endValue < startValue )
- startValue = endValue-1;
- update();
- }
-
- /**
- * set the the minimumvalue to @p value
- */
- void setLeftBorder( int value ){
- startValue = value;
- if ( startValue > endValue )
- endValue = startValue+1;
- update();
- }
-
- /**
- * activates the spectrum of the type @p spectrumtype
- */
- void slotActivateSpectrum( int spectrumtype ){
- m_type = ( SpectrumType )spectrumtype;
- update();
- }
-
- protected:
- virtual void paintEvent( QPaintEvent *e );
-};
-
class SpectrumView : public QWidget
{
Q_OBJECT