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
30
* @author Carsten Niehaus
32
class SpectrumWidget : public QWidget
37
SpectrumWidget( QWidget *parent );
41
void setSpectrum( Spectrum* spec );
43
Spectrum* spectrum()const {
48
* This limits the width of the spectrum in terms of
49
* wavelength. For example you can set it to only
50
* show the area between 500 and 550 nm
52
* @param left the left border
53
* @param right the right border
55
void setBorders( double left, double right );
58
* there are several possible types.
67
* sets the type of the spectrum to @p t
68
* @param t the type of the spectrum
70
void setType( int t ) {
75
* @return the currently active type
78
int spectrumType() const {
83
* @return the adjusted value of the @p color. The
84
* correction depends on @p factor which has been
85
* figured out emperically
87
int Adjust( double color, double factor );
90
* @return the postion in the widget of a band
91
* with the wavelength @p wavelength
93
* @param wavelength the wavelength for which the position is needed
95
inline int xPos( double wavelength ) {
96
return ( int ) ( ( wavelength-m_startValue ) * width() / ( m_endValue - m_startValue ) );
100
* based on the current position of the mouse-cursor the nearest
101
* peak is searched. If found, it will be emitted.
105
void findPeakFromMouseposition( double wavelength );
108
* @param xpos The ratio of the position relative to the width
110
* @return the wavelength on position @p xpos
112
inline double Wavelength( double xpos ) {
113
return m_startValue + ( ( m_endValue-m_startValue ) * xpos );
117
* This method changes the three values @p r, @p g and @p b to the
119
* @param wavelength the wavelength for which the color is searched
120
* @return the wavelenth color
122
QColor wavelengthToRGB( double wavelength );
125
QList<double> m_spectra;
129
Spectrum *m_spectrum;
133
void paintBands( QPainter* p );
134
void drawZoomLine( QPainter* p );
139
void drawTickmarks( QPainter *p );
150
* this QPoint stores the information where
151
* the left mouse button has been pressed. This
152
* is used for the mouse zooming
154
QPoint m_LMBPointPress;
156
QPoint m_LMBPointCurrent;
159
///(re)create startconditions
160
void resetSpectrum();
163
* set the maximum value to @p value
165
void setRightBorder( int value ) {
166
if (value != m_endValue) {
168
if ( m_endValue < m_startValue ) {
169
m_startValue = m_endValue-1;
176
* set the minimum value to @p value
178
void setLeftBorder( int value ) {
179
if (value != m_startValue) {
180
m_startValue = value;
181
if ( m_startValue > m_endValue ) {
182
m_endValue = m_startValue+1;
189
* activates the spectrum of the type @p spectrumtype
191
void slotActivateSpectrum( int spectrumtype ) {
192
m_type = spectrumtype;
193
Prefs::setSpectrumType( spectrumtype );
194
Prefs::self()->writeConfig();
200
* the minimum and maximum displayed wavelength have
201
* changed so emit the new minimum and maximum
203
void bordersChanged( int, int );
206
* the user selected a peak
208
void peakSelected( Spectrum::peak * peak );
215
virtual void paintEvent( QPaintEvent *e );
216
virtual void keyPressEvent(QKeyEvent *e);
217
virtual void mouseMoveEvent( QMouseEvent *e );
218
virtual void mousePressEvent( QMouseEvent *e );
219
virtual void mouseReleaseEvent( QMouseEvent *e );
222
#endif // SPECTRUMWIDGET_H