summaryrefslogtreecommitdiffstats
path: root/profile-widget
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2016-09-13 10:59:47 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-09-17 13:42:46 -0700
commit1b57b6cc174409bb6e2cede77a804254cbeb5fb6 (patch)
treee00c25edf8cbcf93797de46aeede18cb252e01f1 /profile-widget
parent1cae1255d7ea882f062fd857b2097aed859d0401 (diff)
downloadsubsurface-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')
-rw-r--r--profile-widget/diveprofileitem.cpp37
-rw-r--r--profile-widget/diveprofileitem.h2
2 files changed, 24 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]);
}
diff --git a/profile-widget/diveprofileitem.h b/profile-widget/diveprofileitem.h
index 05c7eb7d6..6e6b47b3a 100644
--- a/profile-widget/diveprofileitem.h
+++ b/profile-widget/diveprofileitem.h
@@ -133,6 +133,8 @@ public:
private:
QString visibilityKey;
int tissueIndex;
+ QColor ColorScale(double value);
+
};
class DiveAmbPressureItem : public AbstractProfilePolygonItem {