This might be the "right way" to fix the issue - mark our exported classes as
[kdeedu-porting.git] / kalzium / src / spectrumwidget.h
blobc3392ee30f0867450dba73645a3e36f59feef507
1 /***************************************************************************
2 * Copyright (C) 2005, 2006 by Carsten Niehaus *
3 * cniehaus@kde.org *
4 *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 ***************************************************************************/
21 #ifndef SPECTRUMWIDGET_H
22 #define SPECTRUMWIDGET_H
24 #include <QWidget>
26 #include "spectrum.h"
28 /**
29 * @author Carsten Niehaus
31 class SpectrumWidget : public QWidget
33 Q_OBJECT
35 public:
36 SpectrumWidget( QWidget *parent );
38 ~SpectrumWidget(){}
40 void setSpectrum( Spectrum* spec ){
41 m_spectrum = spec;
42 restart();
45 Spectrum* spectrum()const{
46 return m_spectrum;
49 /**
50 * This limits the width of the spectrum in terms of
51 * wavelength. For example you can set it to only
52 * show the area between 500 and 550 nm
54 * @param left the left border
55 * @param right the right border
57 void setBorders( double left, double right );
59 /**
60 * there are several possible types.
62 enum SpectrumType
64 EmissionSpectrum = 0,
65 AbsorptionSpectrum
68 /**
69 * sets the type of the spectrum to @p t
70 * @param t the type of the spectrum
72 void setType( SpectrumType t ){
73 m_type = t;
76 /**
77 * @return the currently active type
78 * of the spectrum
80 SpectrumType spectrumType() const{
81 return m_type;
84 /**
85 * @returns the color of a line
86 * @param spectrum the value of the spectrum
88 QColor linecolor( double spectrum );
90 double Gamma;
91 int IntensityMax;
93 /**
94 * @return the adjusted value of the @p color. The
95 * correction depends on @p factor which has been
96 * figured out emperically
98 int Adjust( double color, double factor );
101 * @return the postion in the widget of a band
102 * with the wavelength @p wavelength
104 * @param wavelength the wavelength for which the position is needed
106 inline int xPos( double wavelength ){
107 return ( int ) ( ( wavelength-startValue ) * width() / ( endValue - startValue ) );
111 * based on the current position of the mouse-cursor the nearest
112 * peak is searched. If found, it will be emitted.
114 * @see peakSelected
116 void findPeakFromMouseposition( double wavelength );
119 * @param xpos The ratio of the position relative to the width
120 * of the widget.
121 * @return the wavelength on position @p xpos
123 inline double Wavelength( double xpos ){
124 return startValue + ( ( endValue-startValue ) * xpos );
128 * This method changes the three values @p r, @p g and @p b to the
129 * correct values
130 * @param wavelength the wavelength for which the color is searched
131 * @param r red
132 * @param g green
133 * @param b blue
135 void wavelengthToRGB( double wavelength, int& r, int& g, int& b );
137 private:
138 ///(re)create startconditions
139 void restart();
141 QList<double> m_spectra;
143 SpectrumType m_type;
145 Spectrum *m_spectrum;
147 QPixmap m_pixmap;
149 bool m_showtooltip;
151 void paintBands( QPainter* p );
152 void drawZoomLine( QPainter* p );
155 * Draw the scale
157 void drawTickmarks( QPainter *p );
159 double startValue;
160 double endValue;
162 int m_realHeight;
165 * this QPoint stores the information where
166 * the left mouse button has been pressed. This
167 * is used for the mouse zooming
169 QPoint m_LMBPointPress;
171 QPoint m_LMBPointCurrent;
173 public slots:
175 * set the the maximum value to @p value
177 void setRightBorder( int value ){
178 endValue = value;
179 if ( endValue < startValue )
180 startValue = endValue-1;
181 update();
185 * set the the minimum value to @p value
187 void setLeftBorder( int value ){
188 startValue = value;
189 if ( startValue > endValue )
190 endValue = startValue+1;
191 update();
195 * activates the spectrum of the type @p spectrumtype
197 void slotActivateSpectrum( int spectrumtype ){
198 m_type = ( SpectrumType )spectrumtype;
199 update();
202 signals:
204 * the minimum and maximum displayed wavelength have
205 * changed so emit the new minimum and maximum
207 void bordersChanged( int, int );
210 * the user selected a peak
212 void peakSelected( Spectrum::peak * peak );
214 private slots:
215 void slotZoomIn();
216 void slotZoomOut();
218 protected:
219 virtual void paintEvent( QPaintEvent *e );
220 virtual void keyPressEvent(QKeyEvent *e);
221 virtual void mouseMoveEvent( QMouseEvent *e );
222 virtual void mousePressEvent( QMouseEvent *e );
223 virtual void mouseReleaseEvent( QMouseEvent *e );
226 #endif // SPECTRUMWIDGET_H