]> Git trees. - libqmvoc.git/commitdiff
* the spectrum-file grew to big. Now the class SpectrumWidget
authorCarsten Niehaus <cniehaus@gmx.de>
Mon, 18 Jul 2005 09:56:46 +0000 (09:56 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Mon, 18 Jul 2005 09:56:46 +0000 (09:56 +0000)
  is located in spectrumwidget.{cpp,h}
* Also removed german kdDebug-calls

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

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

index fa8cc5a342f7b945af53086242dffe41afc90724..e178c72f2deb08e517bed13f6c0719654464a371 100644 (file)
@@ -18,6 +18,7 @@
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 #include "spectrum.h"
+#include "spectrumwidget.h"
 
 #include <qlayout.h>
 #include <qlabel.h>
@@ -57,7 +58,7 @@ double Spectrum::maxBand()
 
 void Spectrum::paintBands( QPainter* p, double startValue, double endValue, bool emissionSpectrum )
 {
-       kdDebug() << "Spectrum::paintBands" << endl;
+       kdDebug() << "Spectrum::paintBands()" << endl;
        
        if ( !emissionSpectrum )
        {
@@ -77,7 +78,7 @@ void Spectrum::paintBands( QPainter* p, double startValue, double endValue, bool
                        it != m_bandlist.end();
                        ++it )
        {
-               kdDebug() << "band gemalt" << endl;
+               kdDebug() << "band painted" << endl;
                if ( ( *it ).wavelength < startValue || ( *it ).wavelength > endValue )
                        continue;
 
@@ -109,63 +110,7 @@ void Spectrum::paintBands( QPainter* p, double startValue, double endValue, bool
 
                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 )
@@ -177,49 +122,6 @@ 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 )
 {
index 49750cb8c27938e2f8438648eea88d97df8c5da5..9c3f6829ef0aedc16d091e442b0eb7e3baea70e8 100644 (file)
@@ -34,6 +34,8 @@
 
 #include "element.h"
 
+class SpectrumWidget;
+
 /**
  * @author Carsten Niehaus
  *
@@ -151,126 +153,6 @@ class Spectrum
                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