| 
									
										
										
										
											2017-04-27 20:26:36 +02:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							| 
									
										
										
										
											2016-04-04 22:02:03 -07:00
										 |  |  | #include "profile-widget/divetooltipitem.h"
 | 
					
						
							|  |  |  | #include "profile-widget/divecartesianaxis.h"
 | 
					
						
							|  |  |  | #include "core/dive.h"
 | 
					
						
							|  |  |  | #include "core/profile.h"
 | 
					
						
							|  |  |  | #include "core/membuffer.h"
 | 
					
						
							|  |  |  | #include "core/metrics.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | #include <QPropertyAnimation>
 | 
					
						
							|  |  |  | #include <QSettings>
 | 
					
						
							|  |  |  | #include <QGraphicsView>
 | 
					
						
							| 
									
										
										
										
											2015-01-16 16:17:26 -02:00
										 |  |  | #include <QStyleOptionGraphicsItem>
 | 
					
						
							| 
									
										
										
										
											2017-01-07 03:01:14 +01:00
										 |  |  | #include "core/qthelper.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-14 13:02:18 -02:00
										 |  |  | void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QPixmap& pixmap) | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-10-15 15:30:52 +02:00
										 |  |  | 	const IconMetrics& iconMetrics = defaultIconMetrics(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-14 17:11:41 -02:00
										 |  |  | 	QGraphicsPixmapItem *iconItem = 0; | 
					
						
							| 
									
										
										
										
											2014-10-15 15:30:47 +02:00
										 |  |  | 	double yValue = title->boundingRect().height() + iconMetrics.spacing; | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	Q_FOREACH (ToolTip t, toolTips) { | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 		yValue += t.second->boundingRect().height(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-01-14 17:11:41 -02:00
										 |  |  | 	if (entryToolTip.second) { | 
					
						
							|  |  |  | 		yValue += entryToolTip.second->boundingRect().height(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	iconItem = new QGraphicsPixmapItem(this); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 	if (!icon.isNull()) { | 
					
						
							| 
									
										
										
										
											2015-01-14 17:11:41 -02:00
										 |  |  | 		iconItem->setPixmap(icon.pixmap(iconMetrics.sz_small, iconMetrics.sz_small)); | 
					
						
							|  |  |  | 	} else if (!pixmap.isNull()) { | 
					
						
							|  |  |  | 		iconItem->setPixmap(pixmap); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-11-08 15:41:42 +02:00
										 |  |  | 	const int sp2 = iconMetrics.spacing * 2; | 
					
						
							|  |  |  | 	iconItem->setPos(sp2, yValue); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem(toolTip, this); | 
					
						
							| 
									
										
										
										
											2015-11-08 15:41:42 +02:00
										 |  |  | 	textItem->setPos(sp2 + iconMetrics.sz_small + sp2, yValue); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 	textItem->setBrush(QBrush(Qt::white)); | 
					
						
							|  |  |  | 	textItem->setFlag(ItemIgnoresTransformations); | 
					
						
							|  |  |  | 	toolTips.push_back(qMakePair(iconItem, textItem)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ToolTipItem::clear() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	Q_FOREACH (ToolTip t, toolTips) { | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 		delete t.first; | 
					
						
							|  |  |  | 		delete t.second; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	toolTips.clear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void ToolTipItem::setRect(const QRectF &r) | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-16 16:01:54 -02:00
										 |  |  | 	if( r == rect() ) { | 
					
						
							| 
									
										
										
										
											2015-01-14 22:36:00 -02:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-16 16:01:54 -02:00
										 |  |  | 	QGraphicsRectItem::setRect(r); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 	updateTitlePosition(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ToolTipItem::collapse() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-10-15 15:30:52 +02:00
										 |  |  | 	int dim = defaultIconMetrics().sz_small; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-16 16:39:14 -02:00
										 |  |  | 	if (prefs.animation_speed) { | 
					
						
							|  |  |  | 		QPropertyAnimation *animation = new QPropertyAnimation(this, "rect"); | 
					
						
							|  |  |  | 		animation->setDuration(100); | 
					
						
							|  |  |  | 		animation->setStartValue(nextRectangle); | 
					
						
							|  |  |  | 		animation->setEndValue(QRect(0, 0, dim, dim)); | 
					
						
							|  |  |  | 		animation->start(QAbstractAnimation::DeleteWhenStopped); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		setRect(nextRectangle); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 	clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	status = COLLAPSED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ToolTipItem::expand() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!title) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-15 15:30:52 +02:00
										 |  |  | 	const IconMetrics& iconMetrics = defaultIconMetrics(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-15 15:30:47 +02:00
										 |  |  | 	double width = 0, height = title->boundingRect().height() + iconMetrics.spacing; | 
					
						
							| 
									
										
										
										
											2015-01-14 17:11:41 -02:00
										 |  |  | 	Q_FOREACH (const ToolTip& t, toolTips) { | 
					
						
							| 
									
										
										
										
											2015-01-16 16:29:07 -02:00
										 |  |  | 		QRectF sRect = t.second->boundingRect(); | 
					
						
							|  |  |  | 		if (sRect.width() > width) | 
					
						
							|  |  |  | 			width = sRect.width(); | 
					
						
							|  |  |  | 		height += sRect.height(); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-01-14 17:11:41 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (entryToolTip.first) { | 
					
						
							| 
									
										
										
										
											2015-01-16 16:29:07 -02:00
										 |  |  | 		QRectF sRect = entryToolTip.second->boundingRect(); | 
					
						
							|  |  |  | 		if (sRect.width() > width) | 
					
						
							|  |  |  | 			width = sRect.width(); | 
					
						
							|  |  |  | 		height += sRect.height(); | 
					
						
							| 
									
										
										
										
											2015-01-14 17:11:41 -02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-08 15:41:42 +02:00
										 |  |  | 	const int sp2 = iconMetrics.spacing * 2; | 
					
						
							|  |  |  | 	// pixmap left padding, icon, pixmap right padding, right padding */
 | 
					
						
							|  |  |  | 	width += sp2 + iconMetrics.sz_small + sp2 + sp2 * 2; | 
					
						
							|  |  |  | 	// bottom padding
 | 
					
						
							|  |  |  | 	height += sp2; | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-08 15:41:42 +02:00
										 |  |  | 	// clip the tooltip width
 | 
					
						
							|  |  |  | 	if (width < title->boundingRect().width() + sp2) | 
					
						
							|  |  |  | 		width = title->boundingRect().width() + sp2; | 
					
						
							|  |  |  | 	// clip the height
 | 
					
						
							|  |  |  | 	if (entryToolTip.first) { | 
					
						
							| 
									
										
										
										
											2017-03-23 08:13:49 +07:00
										 |  |  | 		const int minH = lrint(entryToolTip.first->y() + entryToolTip.first->pixmap().height() + sp2); | 
					
						
							| 
									
										
										
										
											2015-11-08 15:41:42 +02:00
										 |  |  | 		if (height < minH) | 
					
						
							|  |  |  | 			height = minH; | 
					
						
							|  |  |  | 	} else if (height < iconMetrics.sz_small) { | 
					
						
							| 
									
										
										
										
											2014-10-15 15:30:52 +02:00
										 |  |  | 		height = iconMetrics.sz_small; | 
					
						
							| 
									
										
										
										
											2015-11-08 15:41:42 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	nextRectangle.setWidth(width); | 
					
						
							|  |  |  | 	nextRectangle.setHeight(height); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-16 16:01:54 -02:00
										 |  |  | 	if (nextRectangle != rect()) { | 
					
						
							| 
									
										
										
										
											2015-01-16 16:39:14 -02:00
										 |  |  | 		if (prefs.animation_speed) { | 
					
						
							|  |  |  | 			QPropertyAnimation *animation = new QPropertyAnimation(this, "rect", this); | 
					
						
							|  |  |  | 			animation->setDuration(prefs.animation_speed); | 
					
						
							|  |  |  | 			animation->setStartValue(rect()); | 
					
						
							|  |  |  | 			animation->setEndValue(nextRectangle); | 
					
						
							|  |  |  | 			animation->start(QAbstractAnimation::DeleteWhenStopped); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			setRect(nextRectangle); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-01-14 22:30:14 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	status = EXPANDED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-16 16:01:54 -02:00
										 |  |  | ToolTipItem::ToolTipItem(QGraphicsItem *parent) : QGraphicsRectItem(parent), | 
					
						
							| 
									
										
										
										
											2014-02-09 19:04:59 +01:00
										 |  |  | 	title(new QGraphicsSimpleTextItem(tr("Information"), this)), | 
					
						
							|  |  |  | 	status(COLLAPSED), | 
					
						
							| 
									
										
										
										
											2014-02-19 16:06:16 -08:00
										 |  |  | 	timeAxis(0), | 
					
						
							|  |  |  | 	lastTime(-1) | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-09 19:04:59 +01:00
										 |  |  | 	memset(&pInfo, 0, sizeof(pInfo)); | 
					
						
							| 
									
										
										
										
											2015-01-14 17:11:41 -02:00
										 |  |  | 	entryToolTip.first = NULL; | 
					
						
							|  |  |  | 	entryToolTip.second = NULL; | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 	setFlags(ItemIgnoresTransformations | ItemIsMovable | ItemClipsChildrenToShape); | 
					
						
							| 
									
										
										
										
											2015-01-14 22:50:08 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QColor c = QColor(Qt::black); | 
					
						
							|  |  |  | 	c.setAlpha(155); | 
					
						
							| 
									
										
										
										
											2015-01-16 16:06:14 -02:00
										 |  |  | 	setBrush(c); | 
					
						
							| 
									
										
										
										
											2015-01-14 22:50:08 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 	setZValue(99); | 
					
						
							| 
									
										
										
										
											2015-01-14 17:11:41 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	addToolTip(QString(), QIcon(), QPixmap(16,60)); | 
					
						
							|  |  |  | 	entryToolTip = toolTips.first(); | 
					
						
							|  |  |  | 	toolTips.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	title->setFlag(ItemIgnoresTransformations); | 
					
						
							|  |  |  | 	title->setPen(QPen(Qt::white, 1)); | 
					
						
							|  |  |  | 	title->setBrush(Qt::white); | 
					
						
							| 
									
										
										
										
											2015-01-14 22:50:08 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-16 16:19:28 -02:00
										 |  |  | 	setPen(QPen(Qt::white, 2)); | 
					
						
							| 
									
										
										
										
											2015-01-16 16:45:13 -02:00
										 |  |  | 	refreshTime.start(); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ToolTipItem::~ToolTipItem() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	clear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ToolTipItem::updateTitlePosition() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-10-15 15:30:52 +02:00
										 |  |  | 	const IconMetrics& iconMetrics = defaultIconMetrics(); | 
					
						
							| 
									
										
										
										
											2015-01-16 16:01:54 -02:00
										 |  |  | 	if (rect().width() < title->boundingRect().width() + iconMetrics.spacing * 4) { | 
					
						
							|  |  |  | 		QRectF newRect = rect(); | 
					
						
							| 
									
										
										
										
											2014-10-15 15:30:47 +02:00
										 |  |  | 		newRect.setWidth(title->boundingRect().width() + iconMetrics.spacing * 4); | 
					
						
							| 
									
										
										
										
											2014-10-15 15:30:52 +02:00
										 |  |  | 		newRect.setHeight((newRect.height() && isExpanded()) ? newRect.height() : iconMetrics.sz_small); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 		setRect(newRect); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-16 16:29:07 -02:00
										 |  |  | 	title->setPos(rect().width() / 2 - title->boundingRect().width() / 2 - 1, 0); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | bool ToolTipItem::isExpanded() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 	return status == EXPANDED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void ToolTipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | { | 
					
						
							|  |  |  | 	persistPos(); | 
					
						
							| 
									
										
										
										
											2015-01-16 16:01:54 -02:00
										 |  |  | 	QGraphicsRectItem::mouseReleaseEvent(event); | 
					
						
							| 
									
										
										
										
											2014-05-23 21:06:30 -03:00
										 |  |  | 	Q_FOREACH (QGraphicsItem *item, oldSelection) { | 
					
						
							|  |  |  | 		item->setSelected(true); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-16 16:17:26 -02:00
										 |  |  | void ToolTipItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Q_UNUSED(widget); | 
					
						
							|  |  |  | 	painter->save(); | 
					
						
							|  |  |  | 	painter->setClipRect(option->rect); | 
					
						
							|  |  |  | 	painter->setPen(pen()); | 
					
						
							|  |  |  | 	painter->setBrush(brush()); | 
					
						
							| 
									
										
										
										
											2015-11-08 15:41:42 +02:00
										 |  |  | 	painter->drawRoundedRect(rect(), 8, 8, Qt::AbsoluteSize); | 
					
						
							| 
									
										
										
										
											2015-01-16 16:17:26 -02:00
										 |  |  | 	painter->restore(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | void ToolTipItem::persistPos() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QSettings s; | 
					
						
							|  |  |  | 	s.beginGroup("ProfileMap"); | 
					
						
							| 
									
										
										
										
											2014-03-13 10:23:20 -07:00
										 |  |  | 	s.setValue("tooltip_position", pos()); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 	s.endGroup(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ToolTipItem::readPos() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QSettings s; | 
					
						
							|  |  |  | 	s.beginGroup("ProfileMap"); | 
					
						
							| 
									
										
										
										
											2014-03-13 10:23:20 -07:00
										 |  |  | 	QPointF value = s.value("tooltip_position").toPoint(); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 	if (!scene()->sceneRect().contains(value)) { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		value = QPointF(0, 0); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:25:28 -02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	setPos(value); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-05 14:53:57 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void ToolTipItem::setPlotInfo(const plot_info &plot) | 
					
						
							| 
									
										
										
										
											2014-02-05 14:53:57 -02:00
										 |  |  | { | 
					
						
							|  |  |  | 	pInfo = plot; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void ToolTipItem::setTimeAxis(DiveCartesianAxis *axis) | 
					
						
							| 
									
										
										
										
											2014-02-05 14:53:57 -02:00
										 |  |  | { | 
					
						
							|  |  |  | 	timeAxis = axis; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void ToolTipItem::refresh(const QPointF &pos) | 
					
						
							| 
									
										
										
										
											2014-02-05 14:53:57 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-09-19 08:48:19 +02:00
										 |  |  | 	struct plot_data *entry; | 
					
						
							| 
									
										
										
										
											2015-01-14 13:02:18 -02:00
										 |  |  | 	static QPixmap tissues(16,60); | 
					
						
							|  |  |  | 	static QPainter painter(&tissues); | 
					
						
							| 
									
										
										
										
											2016-03-09 15:15:53 -03:00
										 |  |  | 	static struct membuffer mb = {}; | 
					
						
							| 
									
										
										
										
											2015-01-14 22:18:20 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-16 16:45:13 -02:00
										 |  |  | 	if(refreshTime.elapsed() < 40) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	refreshTime.start(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-23 08:13:49 +07:00
										 |  |  | 	int time = lrint(timeAxis->valueAt(pos)); | 
					
						
							| 
									
										
										
										
											2014-02-19 16:06:16 -08:00
										 |  |  | 	if (time == lastTime) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	lastTime = time; | 
					
						
							|  |  |  | 	clear(); | 
					
						
							| 
									
										
										
										
											2014-01-18 16:21:13 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-14 22:18:20 -02:00
										 |  |  | 	mb.len = 0; | 
					
						
							| 
									
										
										
										
											2014-09-19 08:48:19 +02:00
										 |  |  | 	entry = get_plot_details_new(&pInfo, time, &mb); | 
					
						
							| 
									
										
										
										
											2016-10-01 17:38:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	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(Qt::red)); | 
					
						
							|  |  |  | 	painter.drawRect(0,0,16,10); | 
					
						
							| 
									
										
										
										
											2014-09-20 13:41:36 -03:00
										 |  |  | 	if (entry) { | 
					
						
							| 
									
										
										
										
											2016-11-01 17:00:06 +01:00
										 |  |  | 		ProfileWidget2 *view = qobject_cast<ProfileWidget2*>(scene()->views().first()); | 
					
						
							|  |  |  | 		Q_ASSERT(view); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-14 13:02:18 -02:00
										 |  |  | 		painter.setPen(QColor(0, 0, 0, 255)); | 
					
						
							| 
									
										
										
										
											2017-01-07 03:01:14 +01:00
										 |  |  | 		if (decoMode() == BUEHLMANN) | 
					
						
							| 
									
										
										
										
											2017-03-23 08:13:49 +07:00
										 |  |  | 			painter.drawLine(0, lrint(60 - entry->gfline / 2), 16, lrint(60 - entry->gfline / 2)); | 
					
						
							|  |  |  | 		painter.drawLine(0, lrint(60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure / 2), | 
					
						
							|  |  |  | 				16, lrint(60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure /2)); | 
					
						
							| 
									
										
										
										
											2015-01-14 13:02:18 -02:00
										 |  |  | 		painter.setPen(QColor(0, 0, 0, 127)); | 
					
						
							| 
									
										
										
										
											2015-01-14 17:11:41 -02:00
										 |  |  | 		for (int i=0; i<16; i++) { | 
					
						
							| 
									
										
										
										
											2015-01-14 13:02:18 -02:00
										 |  |  | 			painter.drawLine(i, 60, i, 60 - entry->percentages[i] / 2); | 
					
						
							| 
									
										
										
										
											2014-09-20 13:41:36 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-01-14 17:11:41 -02:00
										 |  |  | 		entryToolTip.second->setText(QString::fromUtf8(mb.buffer, mb.len)); | 
					
						
							| 
									
										
										
										
											2014-09-19 08:48:19 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-10-01 17:38:12 +02:00
										 |  |  | 	entryToolTip.first->setPixmap(tissues); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:53:57 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-14 12:52:23 -02:00
										 |  |  | 	Q_FOREACH (QGraphicsItem *item, scene()->items(pos, Qt::IntersectsItemBoundingRect | 
					
						
							| 
									
										
										
										
											2014-07-15 14:43:20 -03:00
										 |  |  | 		,Qt::DescendingOrder, scene()->views().first()->transform())) { | 
					
						
							| 
									
										
										
										
											2014-02-05 14:53:57 -02:00
										 |  |  | 		if (!item->toolTip().isEmpty()) | 
					
						
							|  |  |  | 			addToolTip(item->toolTip()); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-01-14 17:11:41 -02:00
										 |  |  | 	expand(); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:53:57 -02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-05-23 21:06:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void ToolTipItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	oldSelection = scene()->selectedItems(); | 
					
						
							|  |  |  | 	scene()->clearSelection(); | 
					
						
							|  |  |  | 	QGraphicsItem::mousePressEvent(event); | 
					
						
							|  |  |  | } |