]> Git trees. - libqmvoc.git/commitdiff
More work on the gradient
authorCarsten Niehaus <cniehaus@gmx.de>
Tue, 12 Jul 2005 14:34:18 +0000 (14:34 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Tue, 12 Jul 2005 14:34:18 +0000 (14:34 +0000)
svn path=/trunk/KDE/kdeedu/kalzium/src/spectrum.h; revision=434002

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

index 346d567cca050e8054e67cf6448bfecc0ce7885a..6765176df37f2c035ea4cda13d9e4a629c931ee9 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2003-2005 by Carsten Niehaus                            *
+ *   Copyright (C) 2005 by Carsten Niehaus                                 *
  *   cniehaus@kde.org                                                      *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
 SpectrumWidget::SpectrumWidget( QWidget* parent, const char* name )
        : QWidget( parent,name )
 {
+       startValue = 450;
+       endValue = 800;
+
+       m_realWidth = 360;
+       m_realHeight = 200;
 }
 
 SpectrumWidget::~SpectrumWidget(){}
 
-void SpectrumWidget::paintEvent( QPaintEvent *e )
+void SpectrumWidget::paintEvent( QPaintEvent * /*e*/ )
 {
        QPainter p;
        p.begin( this );
        p.fillRect( 0, 0, width(), height(), paletteBackgroundColor() ); 
+       p.drawRect( 0,0, width(), height() );
        drawLines(  &p );
 }
 
 void SpectrumWidget::drawLines( QPainter *p )
 {
        //the spectrum goes from about 780nm to about 400nm
-       //750 is a dark red 
+       //700 is a dark red 
        //660 yellow
        //580 green
        //500 light blue
        //400 dark blue
+       
+       for(int h = 0; h < 300 ; ++h)
+       {
+               p->setPen(linecolor( h+450 ));
+               int xvalue = m_realWidth/360;
+               p->drawLine(xvalue*h,0,xvalue*h,m_realHeight );
+       }
+
+       int i = 0;
+       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 = 15;
+               else
+                       temp = 0;
+               
+               p->drawLine( x,0,x, m_realHeight+10+temp );
+               p->drawText( x,m_realHeight+10+15+temp, QString::number( *it ));
 
-       QImage img = KImageEffect::gradient ( QSize( width(), height() ), Qt::blue, Qt::red, 
-                                                                                 KImageEffect::HorizontalGradient );
-       QPixmap pm( img );
+               i++;
+       }
+}
+
+int SpectrumWidget::xPos( double value )
+{
+       double var = ( endValue-startValue );
+       double coeff = ( value - startValue )/var;
 
-       p->drawPixmap( width(), height(), pm );
+       return coeff * m_realWidth;
 }
 
 QColor SpectrumWidget::linecolor( double spectrum )
 {
-       QColor c( 128,128,128 );
+//     int Hcolor = 
+       QColor c( ( int )spectrum-450,255,255, QColor::Hsv );
        return c;
 }
 
index 6331ee5fed36af6e550bd116c9c82b42d9a8dd5b..6d1343f99ac495d89637a1213a9969c3e74c1d1c 100644 (file)
@@ -1,6 +1,9 @@
+#ifndef SPECTRUM_H
+#define SPECTRUM_H
 /***************************************************************************
- *   Copyright (C) 2003-2005 by Carsten Niehaus                            *
+ *   Copyright (C) 2005 by Carsten Niehaus                                 *
  *   cniehaus@kde.org                                                      *
+ *   
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
@@ -17,9 +20,6 @@
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
-#ifndef SPECTRUMWIDGET_H_
-#define SPECTRUMWIDGET_H_
-
 #include <qwidget.h>
 #include <qcolor.h>
 #include <qpainter.h>
@@ -52,14 +52,22 @@ class SpectrumWidget : public QWidget
                 */
                void drawLines( QPainter *p );
 
+               int xPos( double value );
+
                /**
                 * @returns the color of a line
                 * @param spectrum the value of the spectrum
                 */
                QColor linecolor( double spectrum );
+       
+               double startValue;
+               double endValue;
+       
+               int m_realWidth;
+               int m_realHeight;
 
        protected:
                virtual void paintEvent( QPaintEvent *e );
 };
+#endif // SPECTRUM_H
 
-#endif
\ No newline at end of file