[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdeedu/kalzium/src
From: Carsten Niehaus <cniehaus () gmx ! de>
Date: 2005-07-12 14:34:19
Message-ID: 1121178859.750542.6183.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 434002 by cniehaus:
More work on the gradient
M +46 -8 spectrum.cpp
M +13 -5 spectrum.h
--- trunk/KDE/kdeedu/kalzium/src/spectrum.cpp #434001:434002
@@ -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 *
@@ -22,37 +22,75 @@
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 );
+ }
- QImage img = KImageEffect::gradient ( QSize( width(), height() ), Qt::blue, Qt::red,
- KImageEffect::HorizontalGradient );
- QPixmap pm( img );
+ int i = 0;
+ for ( QValueList<double>::Iterator it = m_spectra.begin();
+ it != m_spectra.end();
+ ++it )
+ {
+ if ( (*it) < startValue || ( *it ) > endValue )
+ continue;
- p->drawPixmap( width(), height(), pm );
+ 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 ));
+
+ i++;
+ }
}
+int SpectrumWidget::xPos( double value )
+{
+ double var = ( endValue-startValue );
+ double coeff = ( value - startValue )/var;
+
+ 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;
}
--- trunk/KDE/kdeedu/kalzium/src/spectrum.h #434001:434002
@@ -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 @@
*/
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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic