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
|
/***************************************************************************
* Copyright (C) 2005, 2006 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 *
* 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 <QWidget>
#include "spectrum.h"
#include "prefs.h"
/**
* @author Carsten Niehaus
*/
class SpectrumWidget : public QWidget
{
Q_OBJECT
public:
SpectrumWidget(QWidget *parent);
~SpectrumWidget() {}
void setSpectrum(Spectrum* spec);
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
*
* @param left the left border
* @param right the right border
*/
void setBorders(double left, double right);
/**
* 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(int t)
{
m_type = t;
}
/**
* @return the currently active type
* of the spectrum
*/
int spectrumType() const
{
return m_type;
}
/**
* @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 - m_startValue) * width() / (m_endValue - m_startValue));
}
/**
* based on the current position of the mouse-cursor the nearest
* peak is searched. If found, it will be emitted.
*
* @see peakSelected
*/
void findPeakFromMouseposition(double wavelength);
/**
* @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 m_startValue + ((m_endValue - m_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
* @return the wavelenth color
*/
QColor wavelengthToRGB(double wavelength);
/**
* set the maximum value to @p value
*/
void setRightBorder(int value)
{
if (value != m_endValue) {
m_endValue = value;
if (m_endValue < m_startValue) {
m_startValue = m_endValue - 1;
}
update();
}
}
/**
* set the minimum value to @p value
*/
void setLeftBorder(int value)
{
if (value != m_startValue) {
m_startValue = value;
if (m_startValue > m_endValue) {
m_endValue = m_startValue + 1;
}
update();
}
}
private:
QList<double> m_spectra;
int m_type;
Spectrum *m_spectrum;
QPixmap m_pixmap;
void paintBands(QPainter* p);
void drawZoomLine(QPainter* p);
/**
* Draw the scale
*/
void drawTickmarks(QPainter *p);
double m_startValue;
double m_endValue;
double m_gamma;
int m_intensityMax;
int m_realHeight;
/**
* this QPoint stores the information where
* the left mouse button has been pressed. This
* is used for the mouse zooming
*/
QPoint m_LMBPointPress;
QPoint m_LMBPointCurrent;
public slots:
///(re)create startconditions
void resetSpectrum();
/**
* activates the spectrum of the type @p spectrumtype
*/
void slotActivateSpectrum(int spectrumtype)
{
m_type = spectrumtype;
Prefs::setSpectrumType(spectrumtype);
Prefs::self()->save();
update();
}
signals:
/**
* the minimum and maximum displayed wavelength have
* changed so emit the new minimum and maximum
*/
void bordersChanged(int, int);
/**
* the user selected a peak
*/
void peakSelected(Spectrum::peak * peak);
private slots:
void slotZoomIn();
void slotZoomOut();
protected:
virtual void paintEvent(QPaintEvent *e);
virtual void keyPressEvent(QKeyEvent *e);
virtual void mouseMoveEvent(QMouseEvent *e);
virtual void mousePressEvent(QMouseEvent *e);
virtual void mouseReleaseEvent(QMouseEvent *e);
};
#endif // SPECTRUMWIDGET_H
|