From: Carsten Niehaus Date: Mon, 18 Jul 2005 09:56:46 +0000 (+0000) Subject: * the spectrum-file grew to big. Now the class SpectrumWidget X-Git-Tag: v3.80.2~300^2~53 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=b017b245ee2e0efbbb1ae97a5d6034b1508d884e;p=libqmvoc.git * the spectrum-file grew to big. Now the class SpectrumWidget is located in spectrumwidget.{cpp,h} * Also removed german kdDebug-calls svn path=/trunk/KDE/kdeedu/kalzium/src/spectrum.h; revision=435811 --- diff --git a/kalzium/src/spectrum.cpp b/kalzium/src/spectrum.cpp index fa8cc5a..e178c72 100644 --- a/kalzium/src/spectrum.cpp +++ b/kalzium/src/spectrum.cpp @@ -18,6 +18,7 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "spectrum.h" +#include "spectrumwidget.h" #include #include @@ -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 ) { diff --git a/kalzium/src/spectrum.h b/kalzium/src/spectrum.h index 49750cb..9c3f682 100644 --- a/kalzium/src/spectrum.h +++ b/kalzium/src/spectrum.h @@ -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::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 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