]> Git trees. - libqmvoc.git/commitdiff
Woha :-) The Tickmarks are working.
authorCarsten Niehaus <cniehaus@gmx.de>
Thu, 14 Jul 2005 09:26:06 +0000 (09:26 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Thu, 14 Jul 2005 09:26:06 +0000 (09:26 +0000)
svn path=/trunk/KDE/kdeedu/kalzium/src/spectrum.h; revision=434475

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

index b241df771628a1e7a42ef5a9e3b8ace17c4e6362..d040d3d329c8b158c1786795a52e5307575f7d51 100644 (file)
@@ -55,6 +55,7 @@ void SpectrumWidget::paintEvent( QPaintEvent * /*e*/ )
        p.begin( this );
        p.fillRect( 0, 0, width(), m_realHeight, Qt::black ); 
        drawLines(  &p );
+       drawTickmarks( &p );
 }
 
 void SpectrumWidget::drawLines( QPainter *p )
@@ -86,13 +87,9 @@ void SpectrumWidget::drawLines( QPainter *p )
                p->drawLine( x,0,x, m_realHeight );
                p->setPen( Qt::black );
                p->drawLine( x,m_realHeight,x, m_realHeight+10+temp );
-               p->save();
-               p->translate(x, m_realHeight+10+15+temp);
-               p->rotate(-90);
                p->setPen( Qt::black );
                QString text = QString::number( *it );
                p->drawText(0, 0, text);
-               p->restore();
 
                i++;
        }
@@ -106,20 +103,39 @@ void SpectrumWidget::drawLines( QPainter *p )
 //X    }
 }
 
+void SpectrumWidget::drawTickmarks( QPainter* p )
+{
+       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 = 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 ) );
+       }
+}
+
 void SpectrumWidget::wavelengthToRGB( double wavelength, int& r, int& g, int& b )
 {
        double blue = 0.0, green = 0.0, red = 0.0, factor = 0.0;
 
        int wavelength_ = floor( wavelength );
 
-       kdDebug() << wavelength << " :: " << wavelength_ << endl;
+//     kdDebug() << wavelength << " :: " << wavelength_ << endl;
 
        if ( wavelength_ > 380 && wavelength_ < 439 )
        {
                red = -( wavelength-440 ) / ( 440-380 );
                green = 0.0;
                blue = 1.0;
-//             kdDebug() << "RGB on wavelength " << wavelength << " (1): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl;
        
        }
        if ( wavelength_ > 440 && wavelength_ < 489 )
@@ -127,35 +143,30 @@ void SpectrumWidget::wavelengthToRGB( double wavelength, int& r, int& g, int& b
                red = 0.0;
                green = ( wavelength-440 ) / ( 490-440 );
                blue = 1.0;
-//             kdDebug() << "RGB on wavelength " << wavelength << " (2): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl;
        }
        if ( wavelength_ > 490 && wavelength_ < 509 )
        {
                red = 0.0;
                green = 1.0;
                blue = -( wavelength-510 ) / ( 510-490 );
-//             kdDebug() << "RGB on wavelength " << wavelength << " (3): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl;
        }
        if ( wavelength_ > 510 && wavelength_ < 579 )
        {
                red = ( wavelength-510 ) / ( 580-510 );
                green = 1.0;
                blue = 0.0;
-//             kdDebug() << "RGB on wavelength " << wavelength << " (4): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl;
        }
        if ( wavelength_ > 580 && wavelength_ < 644 )
        {
                red = 1.0;
                green = -( wavelength-645 ) / ( 645-580 );
                blue = 0.0;
-//             kdDebug() << "RGB on wavelength " << wavelength << "(5): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl;
        }
        if ( wavelength_ > 645 && wavelength_ < 780 )
        {
                red = 1.0;
                green = 0.0;
                blue = 0.0;
-//             kdDebug() << "RGB on wavelength " << wavelength << " (6): " << red << " :: " << green << " :: " << blue << " Factor: " << factor << endl;
        }
        if ( wavelength_ > 380 && wavelength_ < 419 )
                factor = 0.3 + 0.7*( wavelength - 380 ) / ( 420 - 380 );
@@ -185,6 +196,14 @@ int SpectrumWidget::xPos( double value )
        return proportion;
 }
 
+int SpectrumWidget::Wavelength( double position )
+{
+       double range = endValue-startValue;
+       int result = ( int ) ( startValue + ( range *  position ) );
+       
+       return result;
+}
+
 QColor SpectrumWidget::linecolor( double spectrum )
 {
        int r,g,b;
index 504b955a108137df8ceb75f37d63c8e9b3536b0d..c021b3d7edb7640b12117895fe9e33fb00bcad7b 100644 (file)
@@ -45,6 +45,7 @@ class SpectrumWidget : public QWidget
 
                void setSpectra( QValueList<double> l ){
                        m_spectra = l;
+                       update();
                }
 
                /**
@@ -59,6 +60,12 @@ class SpectrumWidget : public QWidget
                        startValue = left;
                        endValue = right;
                }
+               
+               /**
+                * find the nearest band. The returnvalue is the number
+                * of pixel the next band is away
+                */
+               int findNearestBand( QValueList<double>::iterator it );
        
        private:
                QValueList<double> m_spectra;
@@ -70,6 +77,16 @@ class SpectrumWidget : public QWidget
                 */
                int Adjust( double color, double factor );
 
+               /**
+                * @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
+                */
+               int Wavelength( double position );
+
                /**
                 * This method changes the three values @p r @p g and @p b to the 
                 * correct values
@@ -88,6 +105,8 @@ class SpectrumWidget : public QWidget
                 */
                void drawLines( QPainter *p );
 
+               void drawTickmarks( QPainter *p );
+
                int xPos( double value );
 
                /**
@@ -138,6 +157,7 @@ class SpectrumView : public QWidget
 
                void setSpectra( QValueList<double> l ){
                        m_spectrum->setSpectra( l );
+                       update();
                }
 
        private: