From 5c136abbb035f0672f7d7db8fa4a9b7eb6074b44 Mon Sep 17 00:00:00 2001
From: "Robert C. Helling" <helling@atdotde.de>
Date: Fri, 19 Sep 2014 08:48:19 +0200
Subject: [PATCH] Add tissue saturation plot to tooltip

This adds a graphical representation of tissue loadings at the current moment during the dive
to the tooltip box. The layout is inspired by the Sherwater Petrel.Add tissue saturation plot to tooltip

This adds a graphical representation of tissue loadings at the current moment during the dive
to the tooltip box. The layout is inspired by the Sherwater Petrel.Add tissue saturation plot to tooltip

This adds a graphical representation of tissue loadings at the current moment during the dive
to the tooltip box. The layout is inspired by the Sherwater Petrel.Add tissue saturation plot to tooltip

This adds a graphical representation of tissue loadings at the current moment during the dive
to the tooltip box. The layout is inspired by the Sherwater Petrel.Add tissue saturation plot to tooltip

This adds a graphical representation of tissue loadings at the current moment during the dive
to the tooltip box. The layout is inspired by the Sherwater Petrel.Add tissue saturation plot to tooltip

This adds a graphical representation of tissue loadings at the current moment during the dive
to the tooltip box. The layout is inspired by the Sherwater Petrel.Add tissue saturation plot to tooltip

This adds a graphical representation of tissue loadings at the current moment during the dive
to the tooltip box. The layout is inspired by the Sherwater Petrel.Add tissue saturation plot to tooltip

This adds a graphical representation of tissue loadings at the current moment during the dive
to the tooltip box. The layout is inspired by the Sherwater Petrel.
---
 profile.c                         |  3 ++-
 profile.h                         |  2 +-
 qt-ui/profile/divetooltipitem.cpp | 33 +++++++++++++++++++++++++++++----
 qt-ui/profile/divetooltipitem.h   |  2 +-
 qt-ui/profile/profilewidget2.cpp  |  4 ++--
 5 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/profile.c b/profile.c
index 6caeab0..3e55725 100644
--- a/profile.c
+++ b/profile.c
@@ -1053,7 +1053,7 @@ static void plot_string(struct plot_info *pi, struct plot_data *entry, struct me
 	strip_mb(b);
 }
 
-void get_plot_details_new(struct plot_info *pi, int time, struct membuffer *mb)
+struct plot_data *get_plot_details_new(struct plot_info *pi, int time, struct membuffer *mb)
 {
 	struct plot_data *entry = NULL;
 	int i;
@@ -1065,6 +1065,7 @@ void get_plot_details_new(struct plot_info *pi, int time, struct membuffer *mb)
 	}
 	if (entry)
 		plot_string(pi, entry, mb, pi->has_ndl);
+	return (entry);
 }
 
 /* Compare two plot_data entries and writes the results into a string */
diff --git a/profile.h b/profile.h
index 05fe135..ab5853d 100644
--- a/profile.h
+++ b/profile.h
@@ -71,7 +71,7 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
 struct plot_info *analyze_plot_info(struct plot_info *pi);
 void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plot_info *pi);
 void calculate_deco_information(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool print_mode);
-void get_plot_details_new(struct plot_info *pi, int time, struct membuffer *);
+struct plot_data *get_plot_details_new(struct plot_info *pi, int time, struct membuffer *);
 
 /*
  * When showing dive profiles, we scale things to the
diff --git a/qt-ui/profile/divetooltipitem.cpp b/qt-ui/profile/divetooltipitem.cpp
index 9ee44e4..97f687a 100644
--- a/qt-ui/profile/divetooltipitem.cpp
+++ b/qt-ui/profile/divetooltipitem.cpp
@@ -18,9 +18,9 @@
 #include "display.h"
 #endif
 
-void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon)
+void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QPixmap *pixmap)
 {
-	QGraphicsPixmapItem *iconItem = 0;
+	QGraphicsPixmapItem *iconItem = 0, *pixmapItem = 0;
 	double yValue = title->boundingRect().height() + SPACING;
 	Q_FOREACH (ToolTip t, toolTips) {
 		yValue += t.second->boundingRect().height();
@@ -28,6 +28,11 @@ void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon)
 	if (!icon.isNull()) {
 		iconItem = new QGraphicsPixmapItem(icon.pixmap(ICON_SMALL, ICON_SMALL), this);
 		iconItem->setPos(SPACING, yValue);
+	} else {
+		if (pixmap && !pixmap->isNull()) {
+			pixmapItem = new QGraphicsPixmapItem(*pixmap, this);
+			pixmapItem->setPos(SPACING, yValue);
+		}
 	}
 
 	QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem(toolTip, this);
@@ -217,6 +222,10 @@ void ToolTipItem::setTimeAxis(DiveCartesianAxis *axis)
 
 void ToolTipItem::refresh(const QPointF &pos)
 {
+	int i;
+	struct plot_data *entry;
+	static QPixmap *tissues = new QPixmap(16,60);
+	static QPainter *painter = new QPainter(tissues);
 	int time = timeAxis->valueAt(pos);
 	if (time == lastTime)
 		return;
@@ -225,8 +234,24 @@ void ToolTipItem::refresh(const QPointF &pos)
 	clear();
 	struct membuffer mb = { 0 };
 
-	get_plot_details_new(&pInfo, time, &mb);
-	addToolTip(QString::fromUtf8(mb.buffer, mb.len));
+	entry = get_plot_details_new(&pInfo, time, &mb);
+	tissues->fill();
+	painter->setPen(QColor(0, 0, 0, 0));
+	painter->setBrush(QColor(LIMENADE1));
+	painter->drawRect(0, 10 + (100 - AMB_PERCENTAGE) / 2, 16, AMB_PERCENTAGE / 2);
+	painter->setBrush(QColor(SPRINGWOOD1));
+	painter->drawRect(0, 10, 16, (100 - AMB_PERCENTAGE) / 2);
+	painter->setBrush(QColor("Red"));
+	painter->drawRect(0,0,16,10);
+	painter->setPen(QColor(0, 0, 0, 255));
+	painter->drawLine(0, 60 - entry->gfline / 2, 16, 60 - entry->gfline / 2);
+	painter->drawLine(0, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure / 2,
+			  16, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure /2);
+	painter->setPen(QColor(0, 0, 0, 127));
+	for (i=0; i<16; i++) {
+		painter->drawLine(i, 60, i, 60 - entry->percentages[i] / 2);
+	}
+	addToolTip(QString::fromUtf8(mb.buffer, mb.len),QIcon(), tissues);
 	free_buffer(&mb);
 
 	Q_FOREACH (QGraphicsItem *item, scene()->items(pos, Qt::IntersectsItemShape
diff --git a/qt-ui/profile/divetooltipitem.h b/qt-ui/profile/divetooltipitem.h
index c22287b..e0e6563 100644
--- a/qt-ui/profile/divetooltipitem.h
+++ b/qt-ui/profile/divetooltipitem.h
@@ -40,7 +40,7 @@ public:
 	void collapse();
 	void expand();
 	void clear();
-	void addToolTip(const QString &toolTip, const QIcon &icon = QIcon());
+	void addToolTip(const QString &toolTip, const QIcon &icon = QIcon(), const QPixmap *pixmap = NULL);
 	void refresh(const QPointF &pos);
 	bool isExpanded() const;
 	void persistPos();
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 16339c1..3838e91 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -360,9 +360,9 @@ void ProfileWidget2::setupItemSizes()
 	itemPos.heartBeat.expanded.setP2(QPointF(0, 15));
 
 	itemPos.percentage.pos.on.setX(3);
-	itemPos.percentage.pos.on.setY(85); // was 80
+	itemPos.percentage.pos.on.setY(85);
 	itemPos.percentage.expanded.setP1(QPointF(0, 0));
-	itemPos.percentage.expanded.setP2(QPointF(0, 15)); // was 20
+	itemPos.percentage.expanded.setP2(QPointF(0, 15));
 
 	itemPos.dcLabel.on.setX(3);
 	itemPos.dcLabel.on.setY(100);
-- 
1.8.5.2 (Apple Git-48)

