1 /***************************************************************************
2 * Copyright (C) 2005, 2006 by Carsten Niehaus *
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. *
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. *
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
29 * @author Carsten Niehaus
31 class SpectrumWidget
: public QWidget
36 SpectrumWidget( QWidget
*parent
);
40 void setSpectrum( Spectrum
* spec
){
45 Spectrum
* spectrum()const{
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
);
60 * there are several possible types.
69 * sets the type of the spectrum to @p t
70 * @param t the type of the spectrum
72 void setType( SpectrumType t
){
77 * @return the currently active type
80 SpectrumType
spectrumType() const{
85 * @returns the color of a line
86 * @param spectrum the value of the spectrum
88 QColor
linecolor( double spectrum
);
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.
116 void findPeakFromMouseposition( double wavelength
);
119 * @param xpos The ratio of the position relative to the width
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
130 * @param wavelength the wavelength for which the color is searched
135 void wavelengthToRGB( double wavelength
, int& r
, int& g
, int& b
);
138 ///(re)create startconditions
141 QList
<double> m_spectra
;
145 Spectrum
*m_spectrum
;
151 void paintBands( QPainter
* p
);
152 void drawZoomLine( QPainter
* p
);
157 void drawTickmarks( QPainter
*p
);
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
;
175 * set the the maximum value to @p value
177 void setRightBorder( int value
){
179 if ( endValue
< startValue
)
180 startValue
= endValue
-1;
185 * set the the minimum value to @p value
187 void setLeftBorder( int value
){
189 if ( startValue
> endValue
)
190 endValue
= startValue
+1;
195 * activates the spectrum of the type @p spectrumtype
197 void slotActivateSpectrum( int spectrumtype
){
198 m_type
= ( SpectrumType
)spectrumtype
;
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
);
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