diff options
author | Robert C. Helling <helling@atdotde.de> | 2016-09-13 10:59:47 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-09-17 13:42:46 -0700 |
commit | 1b57b6cc174409bb6e2cede77a804254cbeb5fb6 (patch) | |
tree | e00c25edf8cbcf93797de46aeede18cb252e01f1 /profile-widget/diveprofileitem.cpp | |
parent | 1cae1255d7ea882f062fd857b2097aed859d0401 (diff) | |
download | subsurface-1b57b6cc174409bb6e2cede77a804254cbeb5fb6.tar.gz |
Separate method for heatmap color scaling
I separated out the color scaling and slightly simplified the expressions.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'profile-widget/diveprofileitem.cpp')
-rw-r--r-- | profile-widget/diveprofileitem.cpp | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index 62df3b7a2..0856111cf 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -384,6 +384,27 @@ void DivePercentageItem::modelDataChanged(const QModelIndex &topLeft, const QMod texts.last()->setAlignment(Qt::AlignLeft | Qt::AlignBottom); } +QColor DivePercentageItem::ColorScale(double value) +{ + QColor color; + double scaledValue = value / (AMB_PERCENTAGE * N2_IN_AIR) * 1000.0; + + if (scaledValue < 0.8) // grade from cyan to blue to purple + color.setHsvF(0.5 + 0.25 * scaledValue / 0.8, 1.0, 1.0); + else if (scaledValue < 1.0) // grade from magenta to black + color.setHsvF(0.75, 1.0, (1.0 - scaledValue) / 0.2); + else if (value < 55) // grade from black to green + color.setHsvF(0.333, 1.0, (value - AMB_PERCENTAGE * N2_IN_AIR / 1000.0) / (55.0 - AMB_PERCENTAGE * N2_IN_AIR / 1000.0)); + else if (value < 100) // grade from green to yellow to red + color.setHsvF(0.333 * (100.0 - value) / 45.0, 1.0, 1.0); + else if (value < 120) // M value exceeded - grade from red to white + color.setHsvF(0.0, 1 - (value - 100.0) / 20.0, 1.0); + else // white + color.setHsvF(0.0, 0.0, 1.0); + return color; + +} + void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); @@ -392,7 +413,6 @@ void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem if (polygon().isEmpty()) return; painter->save(); - QColor color; QPen mypen; mypen.setCosmetic(false); mypen.setWidth(5); @@ -400,20 +420,7 @@ void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem for (int i = 0, modelDataCount = dataModel->rowCount(); i < modelDataCount; i++) { if (i < poly.count()) { double value = dataModel->index(i, vDataColumn).data().toDouble(); - if (value < 0.8 * AMB_PERCENTAGE * N2_IN_AIR / 1000.0) // grade from cyan to blue to purple - color.setHsvF(0.5 + 0.25 * value / (0.8 * AMB_PERCENTAGE * N2_IN_AIR / 1000.0), 1.0, 1.0); - else if (value < AMB_PERCENTAGE * N2_IN_AIR / 1000.0) // grade from magenta to black - color.setHsvF(0.75, 1.0, (AMB_PERCENTAGE * N2_IN_AIR / 1000.0 - value) / (0.2 * AMB_PERCENTAGE * N2_IN_AIR / 1000.0)); - else if (value < 55) // grade from black to green - color.setHsvF(0.333, 1.0, (value - AMB_PERCENTAGE * N2_IN_AIR / 1000.0) / (55.0 - AMB_PERCENTAGE * N2_IN_AIR / 1000.0)); - else if (value < 100) // grade from green to yellow to red - color.setHsvF(0.333 * (100.0 - value) / 45.0, 1.0, 1.0); - else if (value < 120) // M value exceeded - grade from red to white - color.setHsvF(0.0, 1 - (value - 100.0) / 20.0, 1.0); - else // white - color.setHsvF(0.0, 0.0, 1.0); - - mypen.setBrush(QBrush(color)); + mypen.setBrush(QBrush(ColorScale(value))); painter->setPen(mypen); painter->drawPoint(poly[i]); } |