Changeset View
Changeset View
Standalone View
Standalone View
src/spectrumwidget.cpp
Show First 20 Lines • Show All 146 Lines • ▼ Show 20 Line(s) | |||||
147 | QColor SpectrumWidget::wavelengthToRGB(double wavelength) | 147 | QColor SpectrumWidget::wavelengthToRGB(double wavelength) | ||
148 | { | 148 | { | ||
149 | double blue = 0.0, green = 0.0, red = 0.0, factor = 0.0; | 149 | double blue = 0.0, green = 0.0, red = 0.0, factor = 0.0; | ||
150 | 150 | | |||
151 | // wavelengthTo RGB function works with nanometers. | 151 | // wavelengthTo RGB function works with nanometers. | ||
152 | wavelength = KUnitConversion::Value(wavelength,KUnitConversion::UnitId(Prefs::spectrumWavelengthUnit())) | 152 | wavelength = KUnitConversion::Value(wavelength,KUnitConversion::UnitId(Prefs::spectrumWavelengthUnit())) | ||
153 | .convertTo(KUnitConversion::Nanometer).number(); | 153 | .convertTo(KUnitConversion::Nanometer).number(); | ||
154 | 154 | | |||
155 | int wavelength_ = (int)floor(wavelength); | 155 | int wavelength_ = static_cast<int>(floor(wavelength)); | ||
156 | 156 | | |||
157 | if (wavelength_ < 380 || wavelength_ > 780) { | 157 | if (wavelength_ < 380 || wavelength_ > 780) { | ||
158 | return QColor(Qt::white); | 158 | return QColor(Qt::white); | ||
159 | } else if (wavelength_ >= 380 && wavelength_ < 440) { | 159 | } else if (wavelength_ >= 380 && wavelength_ < 440) { | ||
160 | red = -(wavelength - 440) / (440 - 380); | 160 | red = -(wavelength - 440) / (440 - 380); | ||
161 | green = 0.0; | 161 | green = 0.0; | ||
162 | blue = 1.0; | 162 | blue = 1.0; | ||
163 | } else if (wavelength_ >= 440 && wavelength_ < 490) { | 163 | } else if (wavelength_ >= 440 && wavelength_ < 490) { | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | |||||
211 | { | 211 | { | ||
212 | //the size of the text on the tickmarks | 212 | //the size of the text on the tickmarks | ||
213 | const int space = 20; | 213 | const int space = 20; | ||
214 | 214 | | |||
215 | //the distance between the tickmarks in pixel | 215 | //the distance between the tickmarks in pixel | ||
216 | const int d = 10; | 216 | const int d = 10; | ||
217 | 217 | | |||
218 | //the total number of tickmarks to draw (small and long) | 218 | //the total number of tickmarks to draw (small and long) | ||
219 | const int numberOfTickmarks = (int)floor((double)(width() / d)); | 219 | const int numberOfTickmarks = static_cast<int>(floor(width() / d)); | ||
pino: floor() does not have a "int" variant, so forcing the type of its argument to double helps the… | |||||
220 | 220 | | |||
221 | double pos = 0.0; | 221 | double pos = 0.0; | ||
222 | 222 | | |||
223 | for (int i = 0; i < numberOfTickmarks; ++i) { | 223 | for (int i = 0; i < numberOfTickmarks; ++i) { | ||
224 | if (i % 5 == 0) { | 224 | if (i % 5 == 0) { | ||
225 | //long tickmarks plus text | 225 | //long tickmarks plus text | ||
226 | p->drawLine(i * d, m_realHeight, i * d, m_realHeight + 10); | 226 | p->drawLine(i * d, m_realHeight, i * d, m_realHeight + 10); | ||
227 | if (i % 10 == 0 && | 227 | if (i % 10 == 0 && | ||
228 | i * d > space && | 228 | i * d > space && | ||
229 | i * d < width() - space) { | 229 | i * d < width() - space) { | ||
230 | pos = (double)(i * d) / width(); | 230 | pos = static_cast<double>((i * d) / width()); | ||
231 | p->fillRect(i * d - space, m_realHeight + 12, 2 * space, 15, Qt::white); | 231 | p->fillRect(i * d - space, m_realHeight + 12, 2 * space, 15, Qt::white); | ||
232 | p->drawText(i * d - space, m_realHeight + 12, 2 * space, 15, Qt::AlignCenter, | 232 | p->drawText(i * d - space, m_realHeight + 12, 2 * space, 15, Qt::AlignCenter, | ||
233 | QString::number(KalziumUtils::strippedValue(Wavelength(pos)))); | 233 | QString::number(KalziumUtils::strippedValue(Wavelength(pos)))); | ||
234 | } | 234 | } | ||
235 | } else { //small tickmarks | 235 | } else { //small tickmarks | ||
236 | p->drawLine(i * d, m_realHeight, i * d, m_realHeight + 5); | 236 | p->drawLine(i * d, m_realHeight, i * d, m_realHeight + 5); | ||
237 | } | 237 | } | ||
238 | } | 238 | } | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | |||||
310 | { | 310 | { | ||
311 | if (e->button() == Qt::LeftButton) { | 311 | if (e->button() == Qt::LeftButton) { | ||
312 | m_LMBPointPress = e->pos(); | 312 | m_LMBPointPress = e->pos(); | ||
313 | } | 313 | } | ||
314 | if (e->button() == Qt::RightButton) { | 314 | if (e->button() == Qt::RightButton) { | ||
315 | resetSpectrum(); | 315 | resetSpectrum(); | ||
316 | } | 316 | } | ||
317 | 317 | | |||
318 | findPeakFromMouseposition(Wavelength((double)e->pos().x() / width())); | 318 | findPeakFromMouseposition(Wavelength(static_cast<double>(e->pos().x() / width()))); | ||
319 | } | 319 | } | ||
320 | 320 | | |||
321 | void SpectrumWidget::findPeakFromMouseposition(double wavelength) | 321 | void SpectrumWidget::findPeakFromMouseposition(double wavelength) | ||
322 | { | 322 | { | ||
323 | qDebug() << "SpectrumWidget::findPeakFromMouseposition()"; | 323 | qDebug() << "SpectrumWidget::findPeakFromMouseposition()"; | ||
324 | Spectrum::peak *peak = nullptr; | 324 | Spectrum::peak *peak = nullptr; | ||
325 | 325 | | |||
326 | //find the difference in percent (1.0 is 100%, 0.1 is 10%) | 326 | //find the difference in percent (1.0 is 100%, 0.1 is 10%) | ||
Show All 26 Lines | |||||
353 | if (foundWavelength) { | 353 | if (foundWavelength) { | ||
354 | emit peakSelected(peak); | 354 | emit peakSelected(peak); | ||
355 | } | 355 | } | ||
356 | } | 356 | } | ||
357 | 357 | | |||
358 | void SpectrumWidget::mouseReleaseEvent(QMouseEvent *e) | 358 | void SpectrumWidget::mouseReleaseEvent(QMouseEvent *e) | ||
359 | { | 359 | { | ||
360 | if (e->button() == Qt::LeftButton) { | 360 | if (e->button() == Qt::LeftButton) { | ||
361 | int left = (int)Wavelength((double)m_LMBPointPress.x() / width()); | 361 | int left = static_cast<int>(Wavelength(static_cast<double>(m_LMBPointPress.x()) / width())); | ||
362 | int right = (int)Wavelength((double)e->pos().x() / width()); | 362 | int right = static_cast<int>(Wavelength(static_cast<double>(e->pos().x()) / width())); | ||
363 | 363 | | |||
364 | if (left == right) { | 364 | if (left == right) { | ||
365 | return; | 365 | return; | ||
366 | } | 366 | } | ||
367 | 367 | | |||
368 | if (left > right) { | 368 | if (left > right) { | ||
369 | setBorders(right, left); | 369 | setBorders(right, left); | ||
370 | } else { | 370 | } else { | ||
Show All 25 Lines |
floor() does not have a "int" variant, so forcing the type of its argument to double helps the compiler to choose the right variant