]> Git trees. - libqmvoc.git/commitdiff
* add new icon, provided by Lee Olson
authorCarsten Niehaus <cniehaus@gmx.de>
Thu, 14 Jul 2005 10:44:14 +0000 (10:44 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Thu, 14 Jul 2005 10:44:14 +0000 (10:44 +0000)
* make more and more things work in the spectrum

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

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

index d040d3d329c8b158c1786795a52e5307575f7d51..deaf56ada01d5c5f0d73e11c0e7bc6d144dee557 100644 (file)
@@ -45,6 +45,8 @@ SpectrumWidget::SpectrumWidget( QWidget* parent, const char* name )
        m_realHeight = 200;
 
        m_stretch = 1;
+
+       setType( EmissionSpectrum );
 }
 
 SpectrumWidget::~SpectrumWidget(){}
@@ -54,20 +56,61 @@ void SpectrumWidget::paintEvent( QPaintEvent * /*e*/ )
        QPainter p;
        p.begin( this );
        p.fillRect( 0, 0, width(), m_realHeight, Qt::black ); 
-       drawLines(  &p );
+       
+       switch ( m_type )
+       {
+               case EmissionSpectrum:  
+                       drawEmmissionSpectrum(  &p );
+                       break;
+               case AbsorptionSpectrum:
+                       drawAbsorptionSpectrum( &p );
+                       break;
+       }
        drawTickmarks( &p );
 }
 
-void SpectrumWidget::drawLines( QPainter *p )
+void SpectrumWidget::drawAbsorptionSpectrum( QPainter *p )
 {
-       //the spectrum goes from about 780nm to about 400nm
-       //700 is a dark red 
-       //660 yellow
-       //580 green
-       //500 light blue
-       //400 dark blue
+       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++;
+       }
+}
+
+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 )
@@ -129,8 +172,6 @@ void SpectrumWidget::wavelengthToRGB( double wavelength, int& r, int& g, int& b
 
        int wavelength_ = floor( wavelength );
 
-//     kdDebug() << wavelength << " :: " << wavelength_ << endl;
-
        if ( wavelength_ > 380 && wavelength_ < 439 )
        {
                red = -( wavelength-440 ) / ( 440-380 );
@@ -192,8 +233,9 @@ int SpectrumWidget::Adjust( double color, double factor )
 
 int SpectrumWidget::xPos( double value )
 {
-       int proportion = width() * ( value - startValue ) / ( endValue - startValue );
-       return proportion;
+       return ( int ) width() * ( value - startValue ) / ( endValue - startValue );
+//X    int proportion = ( int ) width() * ( value - startValue ) / ( endValue - startValue );
+//X    return proportion;
 }
 
 int SpectrumWidget::Wavelength( double position )
@@ -228,11 +270,18 @@ SpectrumView::SpectrumView( QWidget *parent, const char* name )
        
        connect( m_spinbox_right, SIGNAL( valueChanged( int ) ), m_spectrum, SLOT( setRightBorder( int ) ) );
        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" );
+       connect( m_spectrumbox, SIGNAL( activated( int ) ), m_spectrum, SLOT( slotActivateSpectrum( int ) ) );
+       
        
        hbox->addWidget( new QLabel( i18n( "Minimumvalue" ), this ) );
        hbox->addWidget( m_spinbox_left );
        hbox->addWidget( new QLabel( i18n( "Maximumvalue" ), this ) );
        hbox->addWidget( m_spinbox_right );
+       hbox->addWidget( m_spectrumbox );
 
        spectrumLayout->addLayout( hbox );
 }
index c021b3d7edb7640b12117895fe9e33fb00bcad7b..715ca0a8d7e19c52c15459d434bd3457148a1062 100644 (file)
@@ -31,6 +31,7 @@
 #include <kimageeffect.h>
 #include <kdebug.h>
 #include <kpixmapeffect.h>
+#include <kcombobox.h>
 
 #define MAXCOLOR = 750
 #define MINCOLOR = 450
@@ -66,10 +67,29 @@ class SpectrumWidget : public QWidget
                 * 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;
+               }
        
        private:
                QValueList<double> m_spectra;
 
+               SpectrumType m_type;
+
                /**
                 * @return the adjusted value of the @p color. The
                 * correction depends on @p factor which has been
@@ -103,11 +123,19 @@ class SpectrumWidget : public QWidget
                /**
                 * draws the spectra-lines
                 */
-               void drawLines( QPainter *p );
+               void drawAbsorptionSpectrum( QPainter *p );
+               
+               /**
+                * draws the spectra-lines
+                */
+               void drawEmmissionSpectrum( QPainter *p );
 
+               /**
+                * Draw the scale
+                */
                void drawTickmarks( QPainter *p );
 
-               int xPos( double value );
+               inline int xPos( double value );
 
                /**
                 * @returns the color of a line
@@ -143,6 +171,11 @@ class SpectrumWidget : public QWidget
                                endValue = startValue+1;
                        update();
                }
+
+               void slotActivateSpectrum( int spectrumtype ){
+                       m_type = ( SpectrumType )spectrumtype;
+                       update();
+               }
        
        protected:
                virtual void paintEvent( QPaintEvent *e );
@@ -164,6 +197,8 @@ class SpectrumView : public QWidget
                SpectrumWidget *m_spectrum;
 
                QSpinBox *m_spinbox_left, *m_spinbox_right;
+
+               KComboBox *m_spectrumbox;
 };
 
 #endif // SPECTRUM_H