1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
/***************************************************************************
* Copyright (C) 2005 by Carsten Niehaus *
* [email protected] *
*
* *
* 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 *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef SPECTRUMWIDGET_H
#define SPECTRUMWIDGET_H
#include <tqwidget.h>
#include <tqpixmap.h>
#include "spectrum.h"
/**
* @author Carsten Niehaus
*
*/
class SpectrumWidget : public QWidget
{
Q_OBJECT
public:
SpectrumWidget( TQWidget *parent, const char* name = 0 );
~SpectrumWidget(){}
void setSpectrum( Spectrum* spec ){
m_spectrum = spec;
update();
}
Spectrum* spectrum()const{
return m_spectrum;
}
/**
* This limits the width of the spectrum in terms of
* wavelength. For example you can set it to only
* show the area between 500 and 550 nm. Invalid values
* will be set back to the default start- and stopvalues
*
* @param left the left border
* @param right the right border
*/
void setBorders( double left, double right ){
//check for invalid values
if ( startValue < 0.0 )
startValue = 0.0;
if ( endValue > 800.0 )
endValue = 800.0;
startValue = left;
endValue = right;
update();
}
/**
* find the nearest band. The returned value is the number
* of pixel the next band is away
*/
int findNearestBand( TQValueList<double>::iterator it );
/**
* there are several possible types.
*/
enum SpectrumType
{
EmissionSpectrum = 0,
AbsorptionSpectrum
};
/**
* sets the type of the spectrum to @p t
* @param t the type of the spectrum
*/
void setType( SpectrumType t ){
m_type = t;
}
/**
* @return the currently active type
* of the spectrum
*/
SpectrumType spectrumType() const{
return m_type;
}
/**
* @returns the color of a line
* @param spectrum the value of the spectrum
*/
TQColor linecolor( double spectrum );
double Gamma;
int IntensityMax;
/**
* @return the adjusted value of the @p color. The
* correction depends on @p factor which has been
* figured out emperically
*/
int Adjust( double color, double factor );
/**
* @return the postion in the widget of a band
* with the wavelength @p wavelength
*
* @param wavelength the wavelength for which the position is needed
*/
inline int xPos( double wavelength ){
return ( int ) ( ( wavelength-startValue ) * width() / ( endValue - startValue ) );
}
void PrepareTooltip( double wavelength );
void showTooltip( Spectrum::band band );
/**
* @param xpos The ratio of the position relative to the width
* of the widget.
* @return the wavelength on position @p xpos
*/
inline double Wavelength( double xpos ){
return startValue + ( ( endValue-startValue ) * xpos );
}
/**
* This method changes the three values @p r, @p g and @p b to the
* correct values
* @param wavelength the wavelength for which the color is searched
* @param r red
* @param g green
* @param b blue
*/
void wavelengthToRGB( double wavelength, int& r, int& g, int& b );
TQPixmap pixmap();
private:
TQValueList<double> m_spectra;
SpectrumType m_type;
Spectrum *m_spectrum;
TQPixmap m_pixmap;
bool m_showtooltip;
Spectrum::band m_band;
void paintBands( TQPainter* p );
void drawZoomLine( TQPainter* p );
void drawTooltip( TQPainter *p );
/**
* Draw the scale
*/
void drawTickmarks( TQPainter *p );
double startValue;
double endValue;
int m_realHeight;
/**
* this TQPoint stores the information where
* the left mouse button has been pressed. This
* is used for the mouse zooming
*/
TQPoint m_LMBPointPress;
TQPoint m_LMBPointCurrent;
public slots:
/**
* set the the maximum value to @p value
*/
void setRightBorder( int value ){
endValue = value;
if ( endValue < startValue )
startValue = endValue-1;
update();
}
/**
* set the the minimum value to @p value
*/
void setLeftBorder( int value ){
startValue = value;
if ( startValue > endValue )
endValue = startValue+1;
update();
}
/**
* activates the spectrum of the type @p spectrumtype
*/
void slotActivateSpectrum( int spectrumtype ){
m_type = ( SpectrumType )spectrumtype;
update();
}
private slots:
void slotZoomIn();
void slotZoomOut();
protected:
virtual void paintEvent( TQPaintEvent *e );
virtual void keyPressEvent(TQKeyEvent *e);
virtual void mouseMoveEvent( TQMouseEvent *e );
virtual void mousePressEvent( TQMouseEvent *e );
virtual void mouseReleaseEvent( TQMouseEvent *e );
};
#endif // SPECTRUMWIDGET_H
|