]> Git trees. - libqmvoc.git/commitdiff
Trey to making the spectre work.
authorPino Toscano <pino@kde.org>
Tue, 12 Jul 2005 17:02:17 +0000 (17:02 +0000)
committerPino Toscano <pino@kde.org>
Tue, 12 Jul 2005 17:02:17 +0000 (17:02 +0000)
svn path=/trunk/KDE/kdeedu/kalzium/src/spectrum.cpp; revision=434029

kalzium/src/spectrum.cpp

index 047cd0b69c9b47f8541e762ec4875c358ee8e391..4720d399ddb4b23c61030e75703c466800261838 100644 (file)
@@ -19,6 +19,9 @@
  ***************************************************************************/
 #include "spectrum.h"
 
+#include <kglobal.h>
+#include <kstandarddirs.h>
+
 SpectrumWidget::SpectrumWidget( QWidget* parent, const char* name )
        : QWidget( parent,name )
 {
@@ -28,7 +31,10 @@ SpectrumWidget::SpectrumWidget( QWidget* parent, const char* name )
        m_realWidth = 360;
        m_realHeight = 200;
 
-       ref_image = QImage( "/home/carsten/cvs/trunk/kdeedu/kalzium/src/data/spectrum.png" );
+       QString spectrumpix = KGlobal::dirs()->findResourceDir("data", "kalzium/data/" );
+       spectrumpix += "kalzium/data/spektrum.png";
+
+       ref_image = QImage( spectrumpix );
 }
 
 SpectrumWidget::~SpectrumWidget(){}
@@ -56,7 +62,7 @@ void SpectrumWidget::drawLines( QPainter *p )
        //(255,231,49) is for 600 nm
        //(246,144,49) is for 650 nm
        
-       for(int h = 450; h < 750 ; ++h)
+       for(int h = 450; h < 760 ; ++h)
        {
                p->setPen(linecolor(h) );
                p->drawLine(h-450,0,h-450,m_realHeight );
@@ -104,12 +110,9 @@ QColor SpectrumWidget::linecolor( double spectrum )
 //The picture has 575 pixel
 //
 
-       int max = endValue;
-       int min = startValue;
-
        //Example: Freq is 600nm. 760-450 = 360.
        //760 - 600 = 160.   360/160 = 2.25
-       int proportion = ( max-min )/( max - spectrum );
+       int proportion = m_realWidth * ( spectrum - startValue ) / ( endValue - startValue );
 
        QRgb rgb = ref_image.pixel(proportion, 2 );