I'm gonna be irooon like a lioooon in zioooon.
From 4996e0117684484ed3f693a96d9200734aea8386 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tcanabr...@kde.org>
Date: Wed, 5 Feb 2014 14:25:28 -0200
Subject: [PATCH 1/5] Moved the divetooltipitem to it's own file.

This is needed so we can share the dive tooltip item with the
new and old profile at the same time. Next few commits will be
setting the functionality of the tooltip item on the new one.

Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org>
---
 qt-ui/profile/divetooltipitem.cpp | 209 ++++++++++++++++++++++++++++++++++++++
 qt-ui/profile/divetooltipitem.h   |  54 ++++++++++
 qt-ui/profilegraphics.cpp         | 199 +-----------------------------------
 qt-ui/profilegraphics.h           |  41 +-------
 subsurface.pro                    |   6 +-
 5 files changed, 269 insertions(+), 240 deletions(-)
 create mode 100644 qt-ui/profile/divetooltipitem.cpp
 create mode 100644 qt-ui/profile/divetooltipitem.h

diff --git a/qt-ui/profile/divetooltipitem.cpp b/qt-ui/profile/divetooltipitem.cpp
new file mode 100644
index 0000000..dbc6f1d
--- /dev/null
+++ b/qt-ui/profile/divetooltipitem.cpp
@@ -0,0 +1,209 @@
+#include "divetooltipitem.h"
+#include <QPropertyAnimation>
+#include <QGraphicsSceneMouseEvent>
+#include <QPen>
+#include <QBrush>
+#include <QGraphicsScene>
+#include <QSettings>
+#include <QGraphicsView>
+
+#define PORT_IN_PROGRESS 1
+#ifdef PORT_IN_PROGRESS
+#include "display.h"
+#endif
+
+void ToolTipItem::addToolTip(const QString& toolTip, const QIcon& icon)
+{
+	QGraphicsPixmapItem *iconItem = 0;
+	double yValue = title->boundingRect().height() + SPACING;
+	Q_FOREACH(ToolTip t, toolTips) {
+		yValue += t.second->boundingRect().height();
+	}
+	if (!icon.isNull()) {
+		iconItem = new QGraphicsPixmapItem(icon.pixmap(ICON_SMALL,ICON_SMALL), this);
+		iconItem->setPos(SPACING, yValue);
+	}
+
+	QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem(toolTip, this);
+	textItem->setPos(SPACING + ICON_SMALL + SPACING, yValue);
+	textItem->setBrush(QBrush(Qt::white));
+	textItem->setFlag(ItemIgnoresTransformations);
+	toolTips.push_back(qMakePair(iconItem, textItem));
+	expand();
+}
+
+void ToolTipItem::refresh(struct graphics_context *gc, QPointF pos)
+{
+	clear();
+	int time = (pos.x() * gc->maxtime) / gc->maxx;
+	char buffer[500];
+	get_plot_details(gc, time, buffer, 500);
+	addToolTip(QString(buffer));
+
+	QList<QGraphicsItem*> items = scene()->items(pos, Qt::IntersectsItemShape, Qt::DescendingOrder, transform());
+	Q_FOREACH(QGraphicsItem *item, items) {
+		if (!item->toolTip().isEmpty())
+			addToolTip(item->toolTip());
+	}
+}
+
+void ToolTipItem::clear()
+{
+	Q_FOREACH(ToolTip t, toolTips) {
+		delete t.first;
+		delete t.second;
+	}
+	toolTips.clear();
+}
+
+void ToolTipItem::setRect(const QRectF& r)
+{
+	// qDeleteAll(childItems());
+	delete background;
+
+	rectangle = r;
+	setBrush(QBrush(Qt::white));
+	setPen(QPen(Qt::black, 0.5));
+
+	// Creates a 2pixels border
+	QPainterPath border;
+	border.addRoundedRect(-4, -4,  rectangle.width() + 8, rectangle.height() + 10, 3, 3);
+	border.addRoundedRect(-1, -1,  rectangle.width() + 3, rectangle.height() + 4, 3, 3);
+	setPath(border);
+
+	QPainterPath bg;
+	bg.addRoundedRect(-1, -1, rectangle.width() + 3, rectangle.height() + 4, 3, 3);
+
+	QColor c = QColor(Qt::black);
+	c.setAlpha(155);
+
+	QGraphicsPathItem *b = new QGraphicsPathItem(bg, this);
+	b->setFlag(ItemStacksBehindParent);
+	b->setFlag(ItemIgnoresTransformations);
+	b->setBrush(c);
+	b->setPen(QPen(QBrush(Qt::transparent), 0));
+	b->setZValue(-10);
+	background = b;
+
+	updateTitlePosition();
+}
+
+void ToolTipItem::collapse()
+{
+	QPropertyAnimation *animation = new QPropertyAnimation(this, "rect");
+	animation->setDuration(100);
+	animation->setStartValue(nextRectangle);
+	animation->setEndValue(QRect(0, 0, ICON_SMALL, ICON_SMALL));
+	animation->start(QAbstractAnimation::DeleteWhenStopped);
+	clear();
+
+	status = COLLAPSED;
+}
+
+void ToolTipItem::expand()
+{
+	if (!title)
+		return;
+
+	double width = 0, height = title->boundingRect().height() + SPACING;
+	Q_FOREACH(ToolTip t, toolTips) {
+		if (t.second->boundingRect().width() > width)
+			width = t.second->boundingRect().width();
+		height += t.second->boundingRect().height();
+	}
+	/*       Left padding, Icon Size,   space, right padding */
+	width += SPACING       + ICON_SMALL + SPACING + SPACING;
+
+	if (width < title->boundingRect().width() + SPACING*2)
+		width = title->boundingRect().width() + SPACING*2;
+
+	if (height < ICON_SMALL)
+		height = ICON_SMALL;
+
+	nextRectangle.setWidth(width);
+	nextRectangle.setHeight(height);
+
+	QPropertyAnimation *animation = new QPropertyAnimation(this, "rect");
+	animation->setDuration(100);
+	animation->setStartValue(rectangle);
+	animation->setEndValue(nextRectangle);
+	animation->start(QAbstractAnimation::DeleteWhenStopped);
+
+	status = EXPANDED;
+}
+
+ToolTipItem::ToolTipItem(QGraphicsItem* parent): QGraphicsPathItem(parent), background(0)
+{
+	title = new QGraphicsSimpleTextItem(tr("Information"), this);
+	separator = new QGraphicsLineItem(this);
+	setFlags(ItemIgnoresTransformations | ItemIsMovable | ItemClipsChildrenToShape);
+	status = COLLAPSED;
+	updateTitlePosition();
+	setZValue(99);
+}
+
+ToolTipItem::~ToolTipItem()
+{
+	clear();
+}
+
+void ToolTipItem::updateTitlePosition()
+{
+	if (rectangle.width() < title->boundingRect().width() + SPACING*4) {
+		QRectF newRect = rectangle;
+		newRect.setWidth(title->boundingRect().width() + SPACING*4);
+		newRect.setHeight((newRect.height() && isExpanded()) ? newRect.height() : ICON_SMALL);
+		setRect(newRect);
+	}
+
+	title->setPos(boundingRect().width()/2  - title->boundingRect().width()/2 -1, 0);
+	title->setFlag(ItemIgnoresTransformations);
+	title->setPen(QPen(Qt::white, 1));
+	title->setBrush(Qt::white);
+
+	if (toolTips.size() > 0) {
+		double x1 = 3;
+		double y1 = title->pos().y() + SPACING/2 + title->boundingRect().height();
+		double x2 = boundingRect().width() - 10;
+		double y2 = y1;
+
+		separator->setLine(x1, y1, x2, y2);
+		separator->setFlag(ItemIgnoresTransformations);
+		separator->setPen(QPen(Qt::white));
+		separator->show();
+	} else {
+		separator->hide();
+	}
+}
+
+bool ToolTipItem::isExpanded() {
+	return status == EXPANDED;
+}
+
+void ToolTipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
+{
+	persistPos();
+	QGraphicsPathItem::mouseReleaseEvent(event);
+}
+
+void ToolTipItem::persistPos()
+{
+	QPoint currentPos = scene()->views().at(0)->mapFromScene(pos());
+	QSettings s;
+	s.beginGroup("ProfileMap");
+	s.setValue("tooltip_position", currentPos);
+	s.endGroup();
+}
+
+void ToolTipItem::readPos()
+{
+	QSettings s;
+	s.beginGroup("ProfileMap");
+	QPointF value = scene()->views().at(0)->mapToScene(
+		s.value("tooltip_position").toPoint()
+	);
+	if (!scene()->sceneRect().contains(value)) {
+		value = QPointF(0,0);
+	}
+	setPos(value);
+}
diff --git a/qt-ui/profile/divetooltipitem.h b/qt-ui/profile/divetooltipitem.h
new file mode 100644
index 0000000..9f7b836
--- /dev/null
+++ b/qt-ui/profile/divetooltipitem.h
@@ -0,0 +1,54 @@
+#ifndef DIVETOOLTIPITEM_H
+#define DIVETOOLTIPITEM_H
+
+#include <QGraphicsPathItem>
+#include <QVector>
+#include <QPair>
+#include <QRectF>
+#include <QIcon>
+
+class QGraphicsLineItem;
+class QGraphicsSimpleTextItem;
+class QGraphicsPixmapItem;
+struct graphics_context;
+
+/* To use a tooltip, simply ->setToolTip on the QGraphicsItem that you want
+ * or, if it's a "global" tooltip, set it on the mouseMoveEvent of the ProfileGraphicsView.
+ */
+class ToolTipItem :public QObject, public QGraphicsPathItem
+{
+	Q_OBJECT
+	void updateTitlePosition();
+	Q_PROPERTY(QRectF rect READ boundingRect WRITE setRect)
+
+public:
+	enum Status{COLLAPSED, EXPANDED};
+	enum {ICON_SMALL = 16, ICON_MEDIUM = 24, ICON_BIG = 32, SPACING=4};
+
+	explicit ToolTipItem(QGraphicsItem* parent = 0);
+	virtual ~ToolTipItem();
+
+	void collapse();
+	void expand();
+	void clear();
+	void addToolTip(const QString& toolTip, const QIcon& icon = QIcon());
+	void refresh(struct graphics_context* gc, QPointF pos);
+	bool isExpanded();
+	void persistPos();
+	void readPos();
+	void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
+public slots:
+	void setRect(const QRectF& rect);
+
+private:
+	typedef QPair<QGraphicsPixmapItem*, QGraphicsSimpleTextItem*> ToolTip;
+	QVector<ToolTip> toolTips;
+	QGraphicsPathItem *background;
+	QGraphicsLineItem *separator;
+	QGraphicsSimpleTextItem *title;
+	Status status;
+	QRectF rectangle;
+	QRectF nextRectangle;
+};
+
+#endif
\ No newline at end of file
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp
index 0bb78d7..d500b42 100644
--- a/qt-ui/profilegraphics.cpp
+++ b/qt-ui/profilegraphics.cpp
@@ -28,6 +28,7 @@
 #include "../helpers.h"
 #include "../planner.h"
 #include "../gettextfromc.h"
+#include "profile/divetooltipitem.h"
 
 #include <libdivecomputer/parser.h>
 #include <libdivecomputer/version.h>
@@ -1448,204 +1449,6 @@ void ProfileGraphicsView::on_scaleAction()
 	zoomed_plot = !zoomed_plot;
 	refresh();
 }
-
-void ToolTipItem::addToolTip(const QString& toolTip, const QIcon& icon)
-{
-	QGraphicsPixmapItem *iconItem = 0;
-	double yValue = title->boundingRect().height() + SPACING;
-	Q_FOREACH(ToolTip t, toolTips) {
-		yValue += t.second->boundingRect().height();
-	}
-	if (!icon.isNull()) {
-		iconItem = new QGraphicsPixmapItem(icon.pixmap(ICON_SMALL,ICON_SMALL), this);
-		iconItem->setPos(SPACING, yValue);
-	}
-
-	QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem(toolTip, this);
-	textItem->setPos(SPACING + ICON_SMALL + SPACING, yValue);
-	textItem->setBrush(QBrush(Qt::white));
-	textItem->setFlag(ItemIgnoresTransformations);
-	toolTips.push_back(qMakePair(iconItem, textItem));
-	expand();
-}
-
-void ToolTipItem::refresh(struct graphics_context *gc, QPointF pos)
-{
-	clear();
-	int time = (pos.x() * gc->maxtime) / gc->maxx;
-	char buffer[500];
-	get_plot_details(gc, time, buffer, 500);
-	addToolTip(QString(buffer));
-
-	QList<QGraphicsItem*> items = scene()->items(pos, Qt::IntersectsItemShape, Qt::DescendingOrder, transform());
-	Q_FOREACH(QGraphicsItem *item, items) {
-		if (!item->toolTip().isEmpty())
-			addToolTip(item->toolTip());
-	}
-
-}
-
-void ToolTipItem::clear()
-{
-	Q_FOREACH(ToolTip t, toolTips) {
-		delete t.first;
-		delete t.second;
-	}
-	toolTips.clear();
-}
-
-void ToolTipItem::setRect(const QRectF& r)
-{
-	// qDeleteAll(childItems());
-	delete background;
-
-	rectangle = r;
-	setBrush(QBrush(Qt::white));
-	setPen(QPen(Qt::black, 0.5));
-
-	// Creates a 2pixels border
-	QPainterPath border;
-	border.addRoundedRect(-4, -4,  rectangle.width() + 8, rectangle.height() + 10, 3, 3);
-	border.addRoundedRect(-1, -1,  rectangle.width() + 3, rectangle.height() + 4, 3, 3);
-	setPath(border);
-
-	QPainterPath bg;
-	bg.addRoundedRect(-1, -1, rectangle.width() + 3, rectangle.height() + 4, 3, 3);
-
-	QColor c = QColor(Qt::black);
-	c.setAlpha(155);
-
-	QGraphicsPathItem *b = new QGraphicsPathItem(bg, this);
-	b->setFlag(ItemStacksBehindParent);
-	b->setFlags(ItemIgnoresTransformations);
-	b->setBrush(c);
-	b->setPen(QPen(QBrush(Qt::transparent), 0));
-	b->setZValue(-10);
-	background = b;
-
-	updateTitlePosition();
-}
-
-void ToolTipItem::collapse()
-{
-	QPropertyAnimation *animation = new QPropertyAnimation(this, "rect");
-	animation->setDuration(100);
-	animation->setStartValue(nextRectangle);
-	animation->setEndValue(QRect(0, 0, ICON_SMALL, ICON_SMALL));
-	animation->start(QAbstractAnimation::DeleteWhenStopped);
-	clear();
-
-	status = COLLAPSED;
-}
-
-void ToolTipItem::expand()
-{
-	if (!title)
-		return;
-
-	double width = 0, height = title->boundingRect().height() + SPACING;
-	Q_FOREACH(ToolTip t, toolTips) {
-		if (t.second->boundingRect().width() > width)
-			width = t.second->boundingRect().width();
-		height += t.second->boundingRect().height();
-	}
-	/*       Left padding, Icon Size,   space, right padding */
-	width += SPACING       + ICON_SMALL + SPACING + SPACING;
-
-	if (width < title->boundingRect().width() + SPACING*2)
-		width = title->boundingRect().width() + SPACING*2;
-
-	if (height < ICON_SMALL)
-		height = ICON_SMALL;
-
-	nextRectangle.setWidth(width);
-	nextRectangle.setHeight(height);
-
-	QPropertyAnimation *animation = new QPropertyAnimation(this, "rect");
-	animation->setDuration(100);
-	animation->setStartValue(rectangle);
-	animation->setEndValue(nextRectangle);
-	animation->start(QAbstractAnimation::DeleteWhenStopped);
-
-	status = EXPANDED;
-}
-
-ToolTipItem::ToolTipItem(QGraphicsItem* parent): QGraphicsPathItem(parent), background(0)
-{
-	title = new QGraphicsSimpleTextItem(tr("Information"), this);
-	separator = new QGraphicsLineItem(this);
-	setFlags(ItemIgnoresTransformations | ItemIsMovable | ItemClipsChildrenToShape);
-	status = COLLAPSED;
-	updateTitlePosition();
-	setZValue(99);
-}
-
-ToolTipItem::~ToolTipItem()
-{
-	clear();
-}
-
-void ToolTipItem::updateTitlePosition()
-{
-	if (rectangle.width() < title->boundingRect().width() + SPACING*4) {
-		QRectF newRect = rectangle;
-		newRect.setWidth(title->boundingRect().width() + SPACING*4);
-		newRect.setHeight((newRect.height() && isExpanded()) ? newRect.height() : ICON_SMALL);
-		setRect(newRect);
-	}
-
-	title->setPos(boundingRect().width()/2  - title->boundingRect().width()/2 -1, 0);
-	title->setFlag(ItemIgnoresTransformations);
-	title->setPen(QPen(Qt::white, 1));
-	title->setBrush(Qt::white);
-
-	if (toolTips.size() > 0) {
-		double x1 = 3;
-		double y1 = title->pos().y() + SPACING/2 + title->boundingRect().height();
-		double x2 = boundingRect().width() - 10;
-		double y2 = y1;
-
-		separator->setLine(x1, y1, x2, y2);
-		separator->setFlag(ItemIgnoresTransformations);
-		separator->setPen(QPen(Qt::white));
-		separator->show();
-	} else {
-		separator->hide();
-	}
-}
-
-bool ToolTipItem::isExpanded() {
-	return status == EXPANDED;
-}
-
-void ToolTipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
-{
-	persistPos();
-	QGraphicsPathItem::mouseReleaseEvent(event);
-}
-
-void ToolTipItem::persistPos()
-{
-	QPoint currentPos = scene()->views().at(0)->mapFromScene(pos());
-	QSettings s;
-	s.beginGroup("ProfileMap");
-	s.setValue("tooltip_position", currentPos);
-	s.endGroup();
-}
-
-void ToolTipItem::readPos()
-{
-	QSettings s;
-	s.beginGroup("ProfileMap");
-	QPointF value = scene()->views().at(0)->mapToScene(
-		s.value("tooltip_position").toPoint()
-	);
-	if (!scene()->sceneRect().contains(value)) {
-		value = QPointF(0,0);
-	}
-	setPos(value);
-}
-
 QColor EventItem::getColor(const color_indice_t i)
 {
 	return profile_color[i].at((isGrayscale) ? 1 : 0);
diff --git a/qt-ui/profilegraphics.h b/qt-ui/profilegraphics.h
index e2b8581..9080141 100644
--- a/qt-ui/profilegraphics.h
+++ b/qt-ui/profilegraphics.h
@@ -12,47 +12,8 @@
 
 struct graphics_context;
 struct plot_info;
-
-/* To use a tooltip, simply ->setToolTip on the QGraphicsItem that you want
- * or, if it's a "global" tooltip, set it on the mouseMoveEvent of the ProfileGraphicsView.
- */
-class ToolTipItem :public QObject, public QGraphicsPathItem
-{
-	Q_OBJECT
-	void updateTitlePosition();
-	Q_PROPERTY(QRectF rect READ boundingRect WRITE setRect)
-
-public:
-	enum Status{COLLAPSED, EXPANDED};
-	enum {ICON_SMALL = 16, ICON_MEDIUM = 24, ICON_BIG = 32, SPACING=4};
-
-	explicit ToolTipItem(QGraphicsItem* parent = 0);
-	virtual ~ToolTipItem();
-
-	void collapse();
-	void expand();
-	void clear();
-	void addToolTip(const QString& toolTip, const QIcon& icon = QIcon());
-	void refresh(struct graphics_context* gc, QPointF pos);
-	bool isExpanded();
-	void persistPos();
-	void readPos();
-	void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
-public slots:
-	void setRect(const QRectF& rect);
-
-private:
-	typedef QPair<QGraphicsPixmapItem*, QGraphicsSimpleTextItem*> ToolTip;
-	QVector<ToolTip> toolTips;
-	QGraphicsPathItem *background;
-	QGraphicsLineItem *separator;
-	QGraphicsSimpleTextItem *title;
-	Status status;
-	QRectF rectangle;
-	QRectF nextRectangle;
-};
-
 class RulerItem;
+class ToolTipItem;
 
 class RulerNodeItem : public QObject, public QGraphicsEllipseItem
 {
diff --git a/subsurface.pro b/subsurface.pro
index 32f925c..ea5dd34 100644
--- a/subsurface.pro
+++ b/subsurface.pro
@@ -73,7 +73,8 @@ HEADERS = \
 	qt-ui/profile/divecartesianaxis.h \
 	qt-ui/profile/diveplotdatamodel.h \
 	qt-ui/profile/diveprofileitem.h \
-	qt-ui/profile/diveeventitem.h
+	qt-ui/profile/diveeventitem.h \
+	qt-ui/profile/divetooltipitem.h
 
 SOURCES =  \
 	deco.c \
@@ -134,7 +135,8 @@ SOURCES =  \
 	qt-ui/profile/divecartesianaxis.cpp \
 	qt-ui/profile/diveplotdatamodel.cpp \
 	qt-ui/profile/diveprofileitem.cpp \
-	qt-ui/profile/diveeventitem.cpp
+	qt-ui/profile/diveeventitem.cpp \
+	qt-ui/profile/divetooltipitem.cpp
 
 linux*: SOURCES += linux.c
 mac: SOURCES += macos.c
-- 
1.8.5.3

From 040c101291fb3e5e5a9c9bc585f4b7bd5d627dd3 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tcanabr...@kde.org>
Date: Wed, 5 Feb 2014 14:34:45 -0200
Subject: [PATCH 2/5] Added the tooltip item on the new profile.

The functionality is not there yet - just the item hovering
the screen.

Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org>
---
 qt-ui/profile/profilewidget2.cpp | 32 +++++++++++---------------------
 qt-ui/profile/profilewidget2.h   |  2 ++
 2 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 0de1196..c0ca52d 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -8,6 +8,7 @@
 #include "profile.h"
 #include "diveeventitem.h"
 #include "divetextitem.h"
+#include "divetooltipitem.h"
 #include <QStateMachine>
 #include <QSignalTransition>
 #include <QPropertyAnimation>
@@ -28,6 +29,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
 	zoomLevel(0),
 	stateMachine(new QStateMachine(this)),
 	background (new DivePixmapItem()),
+	toolTipItem(new ToolTipItem()),
 	profileYAxis(new DepthAxis()),
 	gasYAxis(new PartialGasPressureAxis()),
 	temperatureAxis(new TemperatureAxis()),
@@ -53,6 +55,9 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
 	setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
 	setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
 	setMouseTracking(true);
+
+	scene()->addItem(toolTipItem);
+
 	// Creating the needed items.
 	// ORDER: {BACKGROUND, PROFILE_Y_AXIS, GAS_Y_AXIS, TIME_AXIS, DEPTH_CONTROLLER, TIME_CONTROLLER, COLUMNS};
 	profileYAxis->setOrientation(DiveCartesianAxis::TopToBottom);
@@ -481,14 +486,11 @@ void ProfileWidget2::fixBackgroundPos()
 
 void ProfileWidget2::wheelEvent(QWheelEvent* event)
 {
-// 	if (!toolTip)
-// 		return;
-
 	// doesn't seem to work for Qt 4.8.1
 	// setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
 
 	// Scale the view / do the zoom
-// 	QPoint toolTipPos = mapFromScene(toolTip->pos());
+	QPoint toolTipPos = mapFromScene(toolTipItem->pos());
 
 	double scaleFactor = 1.15;
 	if (event->delta() > 0 && zoomLevel < 20) {
@@ -501,13 +503,7 @@ void ProfileWidget2::wheelEvent(QWheelEvent* event)
 	}
 
 	scrollViewTo(event->pos());
-// 	toolTip->setPos(mapToScene(toolTipPos));
-// 	toolBarProxy->setPos(mapToScene(TOOLBAR_POS));
-// 	if (zoomLevel != 0) {
-// 		toolBarProxy->hide();
-// 	} else {
-// 		toolBarProxy->show();
-// 	}
+	toolTipItem->setPos(mapToScene(toolTipPos));
 }
 
 void ProfileWidget2::scrollViewTo(const QPoint& pos)
@@ -531,18 +527,12 @@ void ProfileWidget2::scrollViewTo(const QPoint& pos)
 
 void ProfileWidget2::mouseMoveEvent(QMouseEvent* event)
 {
-// 	if (!toolTip)
-// 		return;
-//
-// 	toolTip->refresh(&gc,  mapToScene(event->pos()));
-// 	QPoint toolTipPos = mapFromScene(toolTip->pos());
-
-
+	//toolTipItem->refresh(&gc,  mapToScene(event->pos()));
+	QPoint toolTipPos = mapFromScene(toolTipItem->pos());
 	if (zoomLevel == 0) {
 		QGraphicsView::mouseMoveEvent(event);
-	} else {/*
-		toolTip->setPos(mapToScene(toolTipPos));
-		toolBarProxy->setPos(mapToScene(TOOLBAR_POS));*/
+	} else {
+		toolTipItem->setPos(mapToScene(toolTipPos));
 		scrollViewTo(event->pos());
 	}
 }
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index a89cef7..2b0cf05 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -16,6 +16,7 @@
 #include "graphicsview-common.h"
 #include "divelineitem.h"
 
+class ToolTipItem;
 class MeanDepthLine;
 class DiveReportedCeiling;
 class DiveTextItem;
@@ -75,6 +76,7 @@ private:
 	QStateMachine *stateMachine;
 	int zoomLevel;
 	DivePixmapItem *background ;
+	ToolTipItem *toolTipItem;
 	// All those here should probably be merged into one structure,
 	// So it's esyer to replicate for more dives later.
 	// In the meantime, keep it here.
-- 
1.8.5.3

From 54d14afb554d0227b46755a754a2ae8ddef920e1 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tcanabr...@kde.org>
Date: Wed, 5 Feb 2014 14:53:57 -0200
Subject: [PATCH 3/5] Adapted the ToolTip to work on the new profile

With this patch the tooltip is ready to work on the new
profile, we just need to actually use it.

Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org>
---
 profile.c                         | 14 ++++++++++++++
 profile.h                         |  1 +
 qt-ui/profile/divetooltipitem.cpp | 29 ++++++++++++++++++++++++++++-
 qt-ui/profile/divetooltipitem.h   |  9 ++++++++-
 qt-ui/profile/profilewidget2.cpp  |  3 +++
 5 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/profile.c b/profile.c
index 6a20dce..f947b9d 100644
--- a/profile.c
+++ b/profile.c
@@ -1538,6 +1538,20 @@ void get_plot_details(struct graphics_context *gc, int time, char *buf, int bufs
 		plot_string(entry, buf, bufsize, pi->has_ndl);
 }
 
+void get_plot_details_new(struct plot_info *pi, int time, char *buf, int bufsize)
+{
+	struct plot_data *entry = NULL;
+	int i;
+
+	for (i = 0; i < pi->nr; i++) {
+		entry = pi->entry + i;
+		if (entry->sec >= time)
+			break;
+	}
+	if (entry)
+		plot_string(entry, buf, bufsize, pi->has_ndl);
+}
+
 /* Compare two plot_data entries and writes the results into a string */
 void compare_samples(struct plot_data *e1, struct plot_data *e2, char *buf, int bufsize, int sum)
 {
diff --git a/profile.h b/profile.h
index 7270eda..6a6936d 100644
--- a/profile.h
+++ b/profile.h
@@ -54,6 +54,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, char *buf, int bufsize);
 
 struct ev_select {
 	char *ev_name;
diff --git a/qt-ui/profile/divetooltipitem.cpp b/qt-ui/profile/divetooltipitem.cpp
index dbc6f1d..ffe22a8 100644
--- a/qt-ui/profile/divetooltipitem.cpp
+++ b/qt-ui/profile/divetooltipitem.cpp
@@ -1,4 +1,6 @@
 #include "divetooltipitem.h"
+#include "divecartesianaxis.h"
+#include "profile.h"
 #include <QPropertyAnimation>
 #include <QGraphicsSceneMouseEvent>
 #include <QPen>
@@ -176,7 +178,7 @@ void ToolTipItem::updateTitlePosition()
 	}
 }
 
-bool ToolTipItem::isExpanded() {
+bool ToolTipItem::isExpanded() const {
 	return status == EXPANDED;
 }
 
@@ -207,3 +209,28 @@ void ToolTipItem::readPos()
 	}
 	setPos(value);
 }
+
+void ToolTipItem::setPlotInfo(const plot_info& plot)
+{
+	pInfo = plot;
+}
+
+void ToolTipItem::setTimeAxis(DiveCartesianAxis* axis)
+{
+	timeAxis = axis;
+}
+
+void ToolTipItem::refresh(const QPointF& pos)
+{
+	clear();
+	int time = timeAxis->posAtValue( pos.x() );
+	char buffer[500];
+	get_plot_details_new(&pInfo, time, buffer, 500);
+	addToolTip(QString(buffer));
+
+	QList<QGraphicsItem*> items = scene()->items(pos, Qt::IntersectsItemShape, Qt::DescendingOrder, transform());
+	Q_FOREACH(QGraphicsItem *item, items) {
+		if (!item->toolTip().isEmpty())
+			addToolTip(item->toolTip());
+	}
+}
diff --git a/qt-ui/profile/divetooltipitem.h b/qt-ui/profile/divetooltipitem.h
index 9f7b836..8e9573e 100644
--- a/qt-ui/profile/divetooltipitem.h
+++ b/qt-ui/profile/divetooltipitem.h
@@ -6,7 +6,9 @@
 #include <QPair>
 #include <QRectF>
 #include <QIcon>
+#include "display.h"
 
+class DiveCartesianAxis;
 class QGraphicsLineItem;
 class QGraphicsSimpleTextItem;
 class QGraphicsPixmapItem;
@@ -33,10 +35,13 @@ public:
 	void clear();
 	void addToolTip(const QString& toolTip, const QIcon& icon = QIcon());
 	void refresh(struct graphics_context* gc, QPointF pos);
-	bool isExpanded();
+	void refresh(const QPointF& pos);
+	bool isExpanded() const;
 	void persistPos();
 	void readPos();
 	void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
+	void setTimeAxis(DiveCartesianAxis *axis);
+	void setPlotInfo(const plot_info& plot);
 public slots:
 	void setRect(const QRectF& rect);
 
@@ -49,6 +54,8 @@ private:
 	Status status;
 	QRectF rectangle;
 	QRectF nextRectangle;
+	DiveCartesianAxis *timeAxis;
+	plot_info pInfo;
 };
 
 #endif
\ No newline at end of file
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index c0ca52d..c069fb0 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -56,6 +56,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
 	setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
 	setMouseTracking(true);
 
+	toolTipItem->setTimeAxis(timeAxis);
 	scene()->addItem(toolTipItem);
 
 	// Creating the needed items.
@@ -387,6 +388,8 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
 	int maxdepth = get_maxdepth(&pInfo);
 
 	dataModel->setDive(current_dive, pInfo);
+	toolTipItem->setPlotInfo(pInfo);
+
 	// It seems that I'll have a lot of boilerplate setting the model / axis for
 	// each item, I'll mostly like to fix this in the future, but I'll keep at this for now.
 	profileYAxis->setMaximum(maxdepth);
-- 
1.8.5.3

From cd8d51845a00d33002ead7e32bb6becd3afba663 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tcanabr...@kde.org>
Date: Wed, 5 Feb 2014 15:25:24 -0200
Subject: [PATCH 4/5] Make the Tooltip Item work on the new profile.

Just make the tooltip item work on the new profile.

Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org>
---
 qt-ui/profile/divetooltipitem.cpp | 4 +++-
 qt-ui/profile/profilewidget2.cpp  | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/qt-ui/profile/divetooltipitem.cpp b/qt-ui/profile/divetooltipitem.cpp
index ffe22a8..ca355b7 100644
--- a/qt-ui/profile/divetooltipitem.cpp
+++ b/qt-ui/profile/divetooltipitem.cpp
@@ -8,6 +8,7 @@
 #include <QGraphicsScene>
 #include <QSettings>
 #include <QGraphicsView>
+#include <QDebug>
 
 #define PORT_IN_PROGRESS 1
 #ifdef PORT_IN_PROGRESS
@@ -223,7 +224,8 @@ void ToolTipItem::setTimeAxis(DiveCartesianAxis* axis)
 void ToolTipItem::refresh(const QPointF& pos)
 {
 	clear();
-	int time = timeAxis->posAtValue( pos.x() );
+	int time = timeAxis->valueAt( pos );
+	qDebug() << "time" << time;
 	char buffer[500];
 	get_plot_details_new(&pInfo, time, buffer, 500);
 	addToolTip(QString(buffer));
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index c069fb0..3f215ee 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -530,7 +530,7 @@ void ProfileWidget2::scrollViewTo(const QPoint& pos)
 
 void ProfileWidget2::mouseMoveEvent(QMouseEvent* event)
 {
-	//toolTipItem->refresh(&gc,  mapToScene(event->pos()));
+	toolTipItem->refresh(mapToScene(event->pos()));
 	QPoint toolTipPos = mapFromScene(toolTipItem->pos());
 	if (zoomLevel == 0) {
 		QGraphicsView::mouseMoveEvent(event);
-- 
1.8.5.3

From 7af8cae7bb489db0be90dd1390c62073c52897b3 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tcanabr...@kde.org>
Date: Wed, 5 Feb 2014 15:45:23 -0200
Subject: [PATCH 5/5] Big improvement in speed ( callgrind )

This patch makes use of a cache variable instead of
creating / acessing a new one via operator[], because
for some reason QGraphicsPolygonItem doesn't returns
a reference for polygon and a copy is always made.

Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org>
---
 qt-ui/profile/diveprofileitem.cpp | 3 ++-
 qt-ui/profile/divetooltipitem.cpp | 1 -
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp
index e7cf7cf..9aa2048 100644
--- a/qt-ui/profile/diveprofileitem.cpp
+++ b/qt-ui/profile/diveprofileitem.cpp
@@ -113,12 +113,13 @@ void DiveProfileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
 	QPen pen;
 	pen.setCosmetic(true);
 	pen.setWidth(2);
+	QPolygonF poly = polygon();
 	// This paints the colors of the velocities.
 	for (int i = 1, count = dataModel->rowCount(); i < count; i++) {
 		QModelIndex colorIndex = dataModel->index(i, DivePlotDataModel::COLOR);
 		pen.setBrush(QBrush(colorIndex.data(Qt::BackgroundRole).value<QColor>()));
 		painter->setPen(pen);
-		painter->drawLine(polygon()[i-1],polygon()[i]);
+		painter->drawLine(poly[i-1],poly[i]);
 	}
 }
 
diff --git a/qt-ui/profile/divetooltipitem.cpp b/qt-ui/profile/divetooltipitem.cpp
index ca355b7..26d19ec 100644
--- a/qt-ui/profile/divetooltipitem.cpp
+++ b/qt-ui/profile/divetooltipitem.cpp
@@ -225,7 +225,6 @@ void ToolTipItem::refresh(const QPointF& pos)
 {
 	clear();
 	int time = timeAxis->valueAt( pos );
-	qDebug() << "time" << time;
 	char buffer[500];
 	get_plot_details_new(&pInfo, time, buffer, 500);
 	addToolTip(QString(buffer));
-- 
1.8.5.3

_______________________________________________
subsurface mailing list
subsurface@hohndel.org
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to