1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00
GPXSee/src/palette.cpp

47 lines
721 B
C++
Raw Normal View History

2016-02-28 09:32:54 +01:00
#include "palette.h"
2015-10-05 01:43:48 +02:00
2016-12-06 01:48:26 +01:00
Palette::Palette(const QColor &color, qreal shift)
{
_h = 0; _s = 0; _v = 0; _a = 1.0;
setColor(color);
setShift(shift);
2015-11-25 23:58:46 +01:00
2016-12-06 01:48:26 +01:00
_state = _h;
}
2015-10-05 01:43:48 +02:00
2016-12-06 01:48:26 +01:00
void Palette::setColor(const QColor &color)
2015-10-05 01:43:48 +02:00
{
2016-12-06 01:48:26 +01:00
if (color.isValid())
color.getHsvF(&_h, &_s, &_v, &_a);
2015-10-05 01:43:48 +02:00
}
2016-12-06 01:48:26 +01:00
void Palette::setShift(qreal shift)
2015-10-05 01:43:48 +02:00
{
2016-12-06 01:48:26 +01:00
if (shift >= 0 && shift <= 1.0)
_shift = shift;
2015-10-05 01:43:48 +02:00
}
2016-12-06 01:48:26 +01:00
QColor Palette::nextColor()
2015-10-05 01:43:48 +02:00
{
2016-12-06 01:48:26 +01:00
QColor ret = QColor::fromHsvF(_state, _s, _v, _a);
_state += _shift;
_state -= (int) _state;
2015-10-05 01:43:48 +02:00
2016-12-06 01:48:26 +01:00
return ret;
2015-10-05 01:43:48 +02:00
}
2016-02-28 09:32:54 +01:00
void Palette::reset()
2015-10-05 01:43:48 +02:00
{
2016-12-06 01:48:26 +01:00
_state = _h;
2015-10-05 01:43:48 +02:00
}
2016-12-06 21:02:44 +01:00
QDebug operator<<(QDebug dbg, const Palette &palette)
{
dbg.nospace() << "Palette(" << palette.color() << ", " << palette.shift()
<< ")";
return dbg.maybeSpace();
}