| 
									
										
										
										
											2013-05-04 16:12:43 -03:00
										 |  |  | #include "profilegraphics.h"
 | 
					
						
							| 
									
										
										
										
											2013-06-10 19:02:06 -03:00
										 |  |  | #include "mainwindow.h"
 | 
					
						
							|  |  |  | #include "divelistview.h"
 | 
					
						
							| 
									
										
										
										
											2013-05-04 16:12:43 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QGraphicsScene>
 | 
					
						
							|  |  |  | #include <QResizeEvent>
 | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | #include <QGraphicsLineItem>
 | 
					
						
							| 
									
										
										
										
											2013-07-04 23:55:27 +03:00
										 |  |  | #include <QScrollBar>
 | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | #include <QPen>
 | 
					
						
							|  |  |  | #include <QBrush>
 | 
					
						
							| 
									
										
										
										
											2013-05-04 16:12:43 -03:00
										 |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | #include <QLineF>
 | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | #include <QSettings>
 | 
					
						
							|  |  |  | #include <QIcon>
 | 
					
						
							|  |  |  | #include <QPropertyAnimation>
 | 
					
						
							| 
									
										
										
										
											2013-05-07 16:09:51 -07:00
										 |  |  | #include <QGraphicsSceneHoverEvent>
 | 
					
						
							| 
									
										
										
										
											2013-05-08 16:21:49 -03:00
										 |  |  | #include <QMouseEvent>
 | 
					
						
							| 
									
										
										
										
											2013-09-25 02:39:21 +02:00
										 |  |  | #include <QToolBar>
 | 
					
						
							| 
									
										
										
										
											2013-06-10 19:02:06 -03:00
										 |  |  | #include <qtextdocument.h>
 | 
					
						
							| 
									
										
										
										
											2013-11-19 23:37:45 -02:00
										 |  |  | #include <QMessageBox>
 | 
					
						
							| 
									
										
										
										
											2013-09-25 02:07:07 +02:00
										 |  |  | #include <limits>
 | 
					
						
							| 
									
										
										
										
											2013-05-04 16:12:43 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-04 16:41:49 -03:00
										 |  |  | #include "../color.h"
 | 
					
						
							| 
									
										
										
										
											2013-05-04 17:24:23 -03:00
										 |  |  | #include "../display.h"
 | 
					
						
							|  |  |  | #include "../dive.h"
 | 
					
						
							|  |  |  | #include "../profile.h"
 | 
					
						
							| 
									
										
										
										
											2013-06-10 13:35:27 -03:00
										 |  |  | #include "../device.h"
 | 
					
						
							| 
									
										
										
										
											2013-06-17 15:58:26 -07:00
										 |  |  | #include "../helpers.h"
 | 
					
						
							| 
									
										
										
										
											2013-11-19 20:35:15 -08:00
										 |  |  | #include "../planner.h"
 | 
					
						
							| 
									
										
										
										
											2013-12-01 17:55:09 -08:00
										 |  |  | #include "../gettextfromc.h"
 | 
					
						
							| 
									
										
										
										
											2013-05-04 16:41:49 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-06 19:42:39 -03:00
										 |  |  | #include <libdivecomputer/parser.h>
 | 
					
						
							|  |  |  | #include <libdivecomputer/version.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | static struct graphics_context last_gc; | 
					
						
							| 
									
										
										
										
											2013-07-02 13:58:03 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if PRINT_IMPLEMENTED
 | 
					
						
							| 
									
										
										
										
											2013-05-04 17:24:23 -03:00
										 |  |  | static double plot_scale = SCALE_SCREEN; | 
					
						
							| 
									
										
										
										
											2013-07-02 13:58:03 -07:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-05-04 17:24:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-06 15:35:17 -03:00
										 |  |  | struct text_render_options{ | 
					
						
							|  |  |  | 	double size; | 
					
						
							|  |  |  | 	color_indice_t color; | 
					
						
							|  |  |  | 	double hpos, vpos; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | extern struct ev_select *ev_namelist; | 
					
						
							|  |  |  | extern int evn_allocated; | 
					
						
							|  |  |  | extern int evn_used; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-26 16:04:21 -02:00
										 |  |  | #define TOOLBAR_POS \
 | 
					
						
							|  |  |  | QPoint(viewport()->geometry().width() - toolBarProxy->boundingRect().width(), \ | 
					
						
							|  |  |  | viewport()->geometry().height() - toolBarProxy->boundingRect().height() ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-25 02:39:21 +02:00
										 |  |  | ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent), toolTip(0) , dive(0), diveDC(0), rulerItem(0), toolBarProxy(0) | 
					
						
							| 
									
										
										
										
											2013-05-04 16:12:43 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-12 17:20:59 +03:00
										 |  |  | 	printMode = false; | 
					
						
							| 
									
										
										
										
											2013-07-13 17:02:06 +03:00
										 |  |  | 	isGrayscale = false; | 
					
						
							| 
									
										
										
										
											2013-09-25 02:07:07 +02:00
										 |  |  | 	rulerEnabled = false; | 
					
						
							| 
									
										
										
										
											2013-05-09 15:04:10 -03:00
										 |  |  | 	gc.printer = false; | 
					
						
							| 
									
										
										
										
											2013-07-02 10:13:06 -03:00
										 |  |  | 	fill_profile_color(); | 
					
						
							| 
									
										
										
										
											2013-05-04 16:12:43 -03:00
										 |  |  | 	setScene(new QGraphicsScene()); | 
					
						
							| 
									
										
										
										
											2013-07-02 10:13:06 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 07:22:23 -03:00
										 |  |  | 	scene()->installEventFilter(this); | 
					
						
							| 
									
										
										
										
											2013-05-05 13:51:02 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	setRenderHint(QPainter::Antialiasing); | 
					
						
							|  |  |  | 	setRenderHint(QPainter::HighQualityAntialiasing); | 
					
						
							|  |  |  | 	setRenderHint(QPainter::SmoothPixmapTransform); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-06 19:42:39 -03:00
										 |  |  | 	defaultPen.setJoinStyle(Qt::RoundJoin); | 
					
						
							|  |  |  | 	defaultPen.setCapStyle(Qt::RoundCap); | 
					
						
							|  |  |  | 	defaultPen.setWidth(2); | 
					
						
							| 
									
										
										
										
											2013-05-09 18:29:18 -03:00
										 |  |  | 	defaultPen.setCosmetic(true); | 
					
						
							| 
									
										
										
										
											2013-05-06 19:42:39 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-22 21:25:05 -07:00
										 |  |  | 	setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff); | 
					
						
							|  |  |  | 	setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff); | 
					
						
							| 
									
										
										
										
											2013-05-04 16:12:43 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-04 23:55:27 +03:00
										 |  |  | /* since we cannot use translate() directly on the scene we hack on
 | 
					
						
							|  |  |  |  * the scroll bars (hidden) functionality */ | 
					
						
							|  |  |  | void ProfileGraphicsView::scrollViewTo(const QPoint pos) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!zoomLevel) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	QScrollBar *vs = verticalScrollBar(); | 
					
						
							|  |  |  | 	QScrollBar *hs = horizontalScrollBar(); | 
					
						
							|  |  |  | 	const qreal yRat = pos.y() / sceneRect().height(); | 
					
						
							|  |  |  | 	const qreal xRat = pos.x() / sceneRect().width(); | 
					
						
							|  |  |  | 	const int vMax = vs->maximum(); | 
					
						
							|  |  |  | 	const int hMax = hs->maximum(); | 
					
						
							|  |  |  | 	const int vMin = vs->minimum(); | 
					
						
							|  |  |  | 	const int hMin = hs->minimum(); | 
					
						
							|  |  |  | 	/* QScrollBar receives crazy negative values for minimum */ | 
					
						
							|  |  |  | 	vs->setValue(yRat * (vMax - vMin) + vMin * 0.9); | 
					
						
							|  |  |  | 	hs->setValue(xRat * (hMax - hMin) + hMin * 0.9); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-09 19:59:55 -03:00
										 |  |  | void ProfileGraphicsView::wheelEvent(QWheelEvent* event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-10 15:52:06 -03:00
										 |  |  | 	if (!toolTip) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-04 23:55:27 +03:00
										 |  |  | 	// doesn't seem to work for Qt 4.8.1
 | 
					
						
							|  |  |  | 	// setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
 | 
					
						
							| 
									
										
										
										
											2013-05-09 19:59:55 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-22 21:25:05 -07:00
										 |  |  | 	// Scale the view / do the zoom
 | 
					
						
							| 
									
										
										
										
											2013-05-10 11:07:44 -03:00
										 |  |  | 	QPoint toolTipPos = mapFromScene(toolTip->pos()); | 
					
						
							| 
									
										
										
										
											2013-06-10 14:28:44 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-22 21:25:05 -07:00
										 |  |  | 	double scaleFactor = 1.15; | 
					
						
							| 
									
										
										
										
											2013-07-04 23:55:26 +03:00
										 |  |  | 	if (event->delta() > 0 && zoomLevel < 20) { | 
					
						
							| 
									
										
										
										
											2013-05-22 21:25:05 -07:00
										 |  |  | 		scale(scaleFactor, scaleFactor); | 
					
						
							| 
									
										
										
										
											2013-05-10 11:45:07 -03:00
										 |  |  | 		zoomLevel++; | 
					
						
							| 
									
										
										
										
											2013-07-04 23:55:25 +03:00
										 |  |  | 	} else if (event->delta() < 0 && zoomLevel > 0) { | 
					
						
							| 
									
										
										
										
											2013-05-22 21:25:05 -07:00
										 |  |  | 		// Zooming out
 | 
					
						
							|  |  |  | 		scale(1.0 / scaleFactor, 1.0 / scaleFactor); | 
					
						
							| 
									
										
										
										
											2013-05-10 11:45:07 -03:00
										 |  |  | 		zoomLevel--; | 
					
						
							| 
									
										
										
										
											2013-05-22 21:25:05 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-11-26 16:04:21 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-04 23:55:27 +03:00
										 |  |  | 	scrollViewTo(event->pos()); | 
					
						
							| 
									
										
										
										
											2013-11-26 16:04:21 -02:00
										 |  |  | 	toolTip->setPos(mapToScene(toolTipPos)); | 
					
						
							|  |  |  | 	toolBarProxy->setPos(mapToScene(TOOLBAR_POS)); | 
					
						
							|  |  |  | 	if(zoomLevel != 0){ | 
					
						
							|  |  |  | 		toolBarProxy->hide(); | 
					
						
							|  |  |  | 	}else{ | 
					
						
							|  |  |  | 		toolBarProxy->show(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-09 19:59:55 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-19 23:03:18 -02:00
										 |  |  | void ProfileGraphicsView::contextMenuEvent(QContextMenuEvent* event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(selected_dive == -1) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	QMenu m; | 
					
						
							| 
									
										
										
										
											2013-11-30 15:45:40 +02:00
										 |  |  | 	QMenu *gasChange = m.addMenu(tr("Add Gas Change")); | 
					
						
							| 
									
										
										
										
											2013-11-19 23:03:18 -02:00
										 |  |  | 	GasSelectionModel *model = GasSelectionModel::instance(); | 
					
						
							|  |  |  | 	model->repopulate(); | 
					
						
							|  |  |  | 	int rowCount = model->rowCount(); | 
					
						
							|  |  |  | 	for(int i = 0; i < rowCount; i++){ | 
					
						
							|  |  |  | 		QAction *action = new QAction(&m); | 
					
						
							|  |  |  | 		action->setText( model->data(model->index(i, 0),Qt::DisplayRole).toString()); | 
					
						
							|  |  |  | 		connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas())); | 
					
						
							|  |  |  | 		action->setData(event->globalPos()); | 
					
						
							|  |  |  | 		gasChange->addAction(action); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-11-30 15:45:40 +02:00
										 |  |  | 	QAction *action = m.addAction(tr("Add Bookmark"), this, SLOT(addBookmark())); | 
					
						
							| 
									
										
										
										
											2013-11-19 23:03:18 -02:00
										 |  |  | 	action->setData(event->globalPos()); | 
					
						
							|  |  |  | 	QList<QGraphicsItem*> itemsAtPos = scene()->items(mapToScene(mapFromGlobal(event->globalPos()))); | 
					
						
							|  |  |  | 	Q_FOREACH(QGraphicsItem *i, itemsAtPos){ | 
					
						
							|  |  |  | 		EventItem *item = dynamic_cast<EventItem*>(i); | 
					
						
							|  |  |  | 		if(!item) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		QAction *action = new QAction(&m); | 
					
						
							| 
									
										
										
										
											2013-11-30 15:45:40 +02:00
										 |  |  | 		action->setText(tr("Remove Event")); | 
					
						
							| 
									
										
										
										
											2013-11-19 23:37:45 -02:00
										 |  |  | 		action->setData(QVariant::fromValue<void*>(item)); // so we know what to remove.
 | 
					
						
							| 
									
										
										
										
											2013-11-19 23:03:18 -02:00
										 |  |  | 		connect(action, SIGNAL(triggered(bool)), this, SLOT(removeEvent())); | 
					
						
							|  |  |  | 		m.addAction(action); | 
					
						
							|  |  |  | 		action = new QAction(&m); | 
					
						
							| 
									
										
										
										
											2013-11-30 15:45:40 +02:00
										 |  |  | 		action->setText(tr("Hide similar events")); | 
					
						
							| 
									
										
										
										
											2013-11-19 23:59:56 -02:00
										 |  |  | 		action->setData(QVariant::fromValue<void*>(item)); | 
					
						
							| 
									
										
										
										
											2013-11-19 23:03:18 -02:00
										 |  |  | 		connect(action, SIGNAL(triggered(bool)), this, SLOT(hideEvents())); | 
					
						
							|  |  |  | 		m.addAction(action); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-12-18 21:55:53 +00:00
										 |  |  | 	bool some_hidden = false; | 
					
						
							|  |  |  | 	for (int i = 0; i < evn_used; i++) { | 
					
						
							|  |  |  | 		if (ev_namelist[i].plot_ev == false) { | 
					
						
							|  |  |  | 			some_hidden = true; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (some_hidden) { | 
					
						
							|  |  |  | 		action = m.addAction(tr("Unhde all events"), this, SLOT(unhideEvents())); | 
					
						
							|  |  |  | 		action->setData(event->globalPos()); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-11-19 23:03:18 -02:00
										 |  |  | 	m.exec(event->globalPos()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileGraphicsView::addBookmark() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QAction *action = qobject_cast<QAction*>(sender()); | 
					
						
							|  |  |  | 	QPoint globalPos = action->data().toPoint(); | 
					
						
							|  |  |  | 	QPoint viewPos = mapFromGlobal(globalPos); | 
					
						
							|  |  |  | 	QPointF scenePos = mapToScene(viewPos); | 
					
						
							| 
									
										
										
										
											2013-11-21 05:11:41 -08:00
										 |  |  | 	int seconds = scenePos.x() / gc.maxx * (gc.rightx - gc.leftx) + gc.leftx; | 
					
						
							|  |  |  | 	add_event(current_dc, seconds, SAMPLE_EVENT_BOOKMARK, 0, 0, "bookmark"); | 
					
						
							|  |  |  | 	mark_divelist_changed(TRUE); | 
					
						
							|  |  |  | 	plot(current_dive, TRUE); | 
					
						
							| 
									
										
										
										
											2013-11-19 23:03:18 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileGraphicsView::changeGas() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QAction *action = qobject_cast<QAction*>(sender()); | 
					
						
							|  |  |  | 	QPoint globalPos = action->data().toPoint(); | 
					
						
							|  |  |  | 	QPoint viewPos = mapFromGlobal(globalPos); | 
					
						
							|  |  |  | 	QPointF scenePos = mapToScene(viewPos); | 
					
						
							|  |  |  | 	QString gas = action->text(); | 
					
						
							| 
									
										
										
										
											2013-11-19 20:35:15 -08:00
										 |  |  | 	int o2, he; | 
					
						
							|  |  |  | 	validate_gas(gas.toUtf8().constData(), &o2, &he); | 
					
						
							|  |  |  | 	int seconds = scenePos.x() / gc.maxx * (gc.rightx - gc.leftx) + gc.leftx; | 
					
						
							|  |  |  | 	add_gas_switch_event(current_dive, current_dc, seconds, get_gasidx(current_dive, o2, he)); | 
					
						
							|  |  |  | 	mark_divelist_changed(TRUE); | 
					
						
							|  |  |  | 	plot(current_dive, TRUE); | 
					
						
							| 
									
										
										
										
											2013-11-19 23:03:18 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileGraphicsView::hideEvents() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QAction *action = qobject_cast<QAction*>(sender()); | 
					
						
							| 
									
										
										
										
											2013-11-19 23:59:56 -02:00
										 |  |  | 	EventItem *item = static_cast<EventItem*>(action->data().value<void*>()); | 
					
						
							|  |  |  | 	struct event *event = item->ev; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-21 04:23:10 -08:00
										 |  |  | 	if (QMessageBox::question(mainWindow(), TITLE_OR_TEXT( | 
					
						
							| 
									
										
										
										
											2013-11-19 23:59:56 -02:00
										 |  |  | 				  tr("Hide events"), | 
					
						
							| 
									
										
										
										
											2013-11-21 04:23:10 -08:00
										 |  |  | 				  tr("Hide all %1 events?").arg(event->name)), | 
					
						
							| 
									
										
										
										
											2013-11-19 23:59:56 -02:00
										 |  |  | 				  QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok){ | 
					
						
							|  |  |  | 		if (event->name) { | 
					
						
							|  |  |  | 			for (int i = 0; i < evn_used; i++) { | 
					
						
							|  |  |  | 				if (! strcmp(event->name, ev_namelist[i].ev_name)) { | 
					
						
							|  |  |  | 					ev_namelist[i].plot_ev = false; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		plot(current_dive, TRUE); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-11-19 23:03:18 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-18 21:55:53 +00:00
										 |  |  | void ProfileGraphicsView::unhideEvents() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	for (int i = 0; i < evn_used; i++) { | 
					
						
							|  |  |  | 		ev_namelist[i].plot_ev = true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	plot(current_dive, TRUE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-19 23:03:18 -02:00
										 |  |  | void ProfileGraphicsView::removeEvent() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QAction *action = qobject_cast<QAction*>(sender()); | 
					
						
							| 
									
										
										
										
											2013-11-19 23:37:45 -02:00
										 |  |  | 	EventItem *item = static_cast<EventItem*>(action->data().value<void*>()); | 
					
						
							|  |  |  | 	struct event *event = item->ev; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-21 04:23:10 -08:00
										 |  |  | 	if (QMessageBox::question(mainWindow(), TITLE_OR_TEXT( | 
					
						
							| 
									
										
										
										
											2013-11-19 23:37:45 -02:00
										 |  |  | 				  tr("Remove the selected event?"), | 
					
						
							|  |  |  | 				  tr("%1 @ %2:%3").arg(event->name) | 
					
						
							|  |  |  | 				  .arg(event->time.seconds / 60) | 
					
						
							| 
									
										
										
										
											2013-11-21 04:23:10 -08:00
										 |  |  | 				  .arg(event->time.seconds % 60, 2, 10, QChar('0'))), | 
					
						
							| 
									
										
										
										
											2013-11-19 23:37:45 -02:00
										 |  |  | 				  QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok){ | 
					
						
							|  |  |  | 		struct event **ep = ¤t_dc->events; | 
					
						
							|  |  |  | 		while (ep && *ep != event) | 
					
						
							|  |  |  | 			ep = &(*ep)->next; | 
					
						
							|  |  |  | 		if (ep) { | 
					
						
							|  |  |  | 			*ep = event->next; | 
					
						
							|  |  |  | 			free(event); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		mark_divelist_changed(TRUE); | 
					
						
							| 
									
										
										
										
											2013-11-19 23:59:56 -02:00
										 |  |  | 		plot(current_dive, TRUE); | 
					
						
							| 
									
										
										
										
											2013-11-19 23:37:45 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-11-19 23:03:18 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-19 23:37:45 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 16:21:49 -03:00
										 |  |  | void ProfileGraphicsView::mouseMoveEvent(QMouseEvent* event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-10 15:52:06 -03:00
										 |  |  | 	if (!toolTip) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-10 11:07:44 -03:00
										 |  |  | 	toolTip->refresh(&gc,  mapToScene(event->pos())); | 
					
						
							|  |  |  | 	QPoint toolTipPos = mapFromScene(toolTip->pos()); | 
					
						
							| 
									
										
										
										
											2013-07-04 23:55:27 +03:00
										 |  |  | 	scrollViewTo(event->pos()); | 
					
						
							| 
									
										
										
										
											2013-05-10 13:57:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-06 13:00:18 -03:00
										 |  |  | 	if (zoomLevel == 0) | 
					
						
							| 
									
										
										
										
											2013-05-10 11:45:07 -03:00
										 |  |  | 		QGraphicsView::mouseMoveEvent(event); | 
					
						
							| 
									
										
										
										
											2013-11-26 16:04:21 -02:00
										 |  |  | 	else{ | 
					
						
							|  |  |  | 		toolTip->setPos(mapToScene(toolTipPos)); | 
					
						
							|  |  |  | 		toolBarProxy->setPos(mapToScene(TOOLBAR_POS)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-08 16:21:49 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 07:22:23 -03:00
										 |  |  | bool ProfileGraphicsView::eventFilter(QObject* obj, QEvent* event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-07 22:49:57 -03:00
										 |  |  | 	if (event->type() == QEvent::Leave) { | 
					
						
							|  |  |  | 		if (toolTip && toolTip->isExpanded()) | 
					
						
							|  |  |  | 			toolTip->collapse(); | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-14 23:54:35 -02:00
										 |  |  | 	// This will "Eat" the default tooltip behavior if it is not on the toolBar.
 | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	if (event->type() == QEvent::GraphicsSceneHelp) { | 
					
						
							| 
									
										
										
										
											2013-11-16 22:25:26 -02:00
										 |  |  | 		if(toolBarProxy && !toolBarProxy->geometry().contains(mapToScene(mapFromGlobal(QCursor::pos())))){ | 
					
						
							| 
									
										
										
										
											2013-11-14 23:54:35 -02:00
										 |  |  | 			event->ignore(); | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-08 07:22:23 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return QGraphicsView::eventFilter(obj, event); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-02 13:58:03 -07:00
										 |  |  | #if PRINT_IMPLEMENTED
 | 
					
						
							| 
									
										
										
										
											2013-05-04 17:24:23 -03:00
										 |  |  | static void plot_set_scale(scale_mode_t scale) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	switch (scale) { | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 	case SC_SCREEN: | 
					
						
							|  |  |  | 		plot_scale = SCALE_SCREEN; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case SC_PRINT: | 
					
						
							|  |  |  | 		plot_scale = SCALE_PRINT; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-07-02 13:58:03 -07:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-05-04 17:24:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-10 14:18:33 -03:00
										 |  |  | void ProfileGraphicsView::showEvent(QShowEvent* event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-16 21:25:31 -03:00
										 |  |  | 	// Program just opened,
 | 
					
						
							|  |  |  | 	// but the dive was not ploted.
 | 
					
						
							|  |  |  | 	// force a replot by modifying the dive
 | 
					
						
							|  |  |  | 	// hold by the view, and issuing a plot.
 | 
					
						
							| 
									
										
										
										
											2013-06-12 14:28:44 -03:00
										 |  |  | 	if (dive && !scene()->items().count()) { | 
					
						
							| 
									
										
										
										
											2013-05-16 21:25:31 -03:00
										 |  |  | 		dive = 0; | 
					
						
							|  |  |  | 		plot(get_dive(selected_dive)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-11-26 16:04:21 -02:00
										 |  |  | 	if (toolBarProxy) | 
					
						
							|  |  |  | 		toolBarProxy->setPos(mapToScene(TOOLBAR_POS)); | 
					
						
							| 
									
										
										
										
											2013-05-10 14:18:33 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-16 16:00:33 -03:00
										 |  |  | void ProfileGraphicsView::clear() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	resetTransform(); | 
					
						
							|  |  |  | 	zoomLevel = 0; | 
					
						
							| 
									
										
										
										
											2013-09-25 02:07:07 +02:00
										 |  |  | 	if(toolTip) { | 
					
						
							| 
									
										
										
										
											2013-06-10 13:54:17 -03:00
										 |  |  | 		scene()->removeItem(toolTip); | 
					
						
							|  |  |  | 		toolTip->deleteLater(); | 
					
						
							|  |  |  | 		toolTip = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-09-25 02:39:21 +02:00
										 |  |  | 	if(toolBarProxy) { | 
					
						
							|  |  |  | 		scene()->removeItem(toolBarProxy); | 
					
						
							|  |  |  | 		toolBarProxy->deleteLater(); | 
					
						
							|  |  |  | 		toolBarProxy = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-09-25 02:07:07 +02:00
										 |  |  | 	if(rulerItem) { | 
					
						
							|  |  |  | 		remove_ruler(); | 
					
						
							|  |  |  | 		rulerItem->destNode()->deleteLater(); | 
					
						
							|  |  |  | 		rulerItem->sourceNode()->deleteLater(); | 
					
						
							|  |  |  | 		rulerItem->deleteLater(); | 
					
						
							|  |  |  | 		rulerItem=0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-06-10 13:54:17 -03:00
										 |  |  | 	scene()->clear(); | 
					
						
							| 
									
										
										
										
											2013-05-16 16:00:33 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-26 11:33:45 -07:00
										 |  |  | void ProfileGraphicsView::refresh() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-05 15:33:51 +03:00
										 |  |  | 	clear(); | 
					
						
							| 
									
										
										
										
											2013-05-26 11:33:45 -07:00
										 |  |  | 	plot(current_dive, TRUE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-13 17:02:06 +03:00
										 |  |  | void ProfileGraphicsView::setPrintMode(bool mode, bool grayscale) | 
					
						
							| 
									
										
										
										
											2013-07-12 17:20:59 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	printMode = mode; | 
					
						
							| 
									
										
										
										
											2013-07-13 17:02:06 +03:00
										 |  |  | 	isGrayscale = grayscale; | 
					
						
							| 
									
										
										
										
											2013-07-12 17:20:59 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | QColor ProfileGraphicsView::getColor(const color_indice_t i) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return profile_color[i].at((isGrayscale) ? 1 : 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-26 11:33:45 -07:00
										 |  |  | void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw) | 
					
						
							| 
									
										
										
										
											2013-05-04 16:12:43 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-09 00:15:46 -07:00
										 |  |  | 	struct divecomputer *dc = NULL; | 
					
						
							| 
									
										
										
										
											2013-05-22 20:31:27 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (d) | 
					
						
							|  |  |  | 		dc = select_dc(&d->dc); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-26 11:33:45 -07:00
										 |  |  | 	if (!forceRedraw && dive == d && (d && dc == diveDC)) | 
					
						
							| 
									
										
										
										
											2013-05-16 16:00:33 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-16 16:00:33 -03:00
										 |  |  | 	clear(); | 
					
						
							|  |  |  | 	dive = d; | 
					
						
							| 
									
										
										
										
											2013-05-22 20:31:27 -07:00
										 |  |  | 	diveDC = d ? dc : NULL; | 
					
						
							| 
									
										
										
										
											2013-05-10 11:45:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-25 02:07:07 +02:00
										 |  |  | 	if (!isVisible() || !dive || !mainWindow()) { | 
					
						
							| 
									
										
										
										
											2013-05-10 14:18:33 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 	setBackgroundBrush(getColor(BACKGROUND)); | 
					
						
							| 
									
										
										
										
											2013-05-10 14:18:33 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-10 19:02:06 -03:00
										 |  |  | 	// best place to put the focus stealer code.
 | 
					
						
							|  |  |  | 	setFocusProxy(mainWindow()->dive_list()); | 
					
						
							| 
									
										
										
										
											2013-05-09 19:59:55 -03:00
										 |  |  | 	scene()->setSceneRect(0,0, viewport()->width()-50, viewport()->height()-50); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | 	toolTip = new ToolTipItem(); | 
					
						
							| 
									
										
										
										
											2013-06-10 14:48:31 -03:00
										 |  |  | 	installEventFilter(toolTip); | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | 	scene()->addItem(toolTip); | 
					
						
							| 
									
										
										
										
											2013-07-12 17:20:59 +03:00
										 |  |  | 	if (printMode) | 
					
						
							|  |  |  | 		toolTip->setVisible(false); | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-04 17:24:23 -03:00
										 |  |  | 	// Fix this for printing / screen later.
 | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	// plot_set_scale(scale_mode_t);
 | 
					
						
							| 
									
										
										
										
											2013-05-04 17:24:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-09 00:15:46 -07:00
										 |  |  | 	if (!dc || !dc->samples) { | 
					
						
							| 
									
										
										
										
											2013-06-10 13:35:27 -03:00
										 |  |  | 		dc = fake_dc(dc); | 
					
						
							| 
									
										
										
										
											2013-05-04 17:24:23 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-17 15:58:26 -07:00
										 |  |  | 	QString nick = get_dc_nickname(dc->model, dc->deviceid); | 
					
						
							| 
									
										
										
										
											2013-06-10 17:33:46 -03:00
										 |  |  | 	if (nick.isEmpty()) | 
					
						
							|  |  |  | 		nick = QString(dc->model); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (nick.isEmpty()) | 
					
						
							|  |  |  | 		nick = tr("unknown divecomputer"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ( tr("unknown divecomputer") == nick){ | 
					
						
							|  |  |  | 		mode = PLAN; | 
					
						
							|  |  |  | 	}else{ | 
					
						
							|  |  |  | 		mode = DIVE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-04 17:24:23 -03:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Set up limits that are independent of | 
					
						
							|  |  |  | 	 * the dive computer | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	calculate_max_limits(dive, dc, &gc); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-10 10:30:24 -03:00
										 |  |  | 	QRectF profile_grid_area = scene()->sceneRect(); | 
					
						
							|  |  |  | 	gc.maxx = (profile_grid_area.width() - 2 * profile_grid_area.x()); | 
					
						
							|  |  |  | 	gc.maxy = (profile_grid_area.height() - 2 * profile_grid_area.y()); | 
					
						
							| 
									
										
										
										
											2013-05-04 17:24:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-13 19:52:30 +02:00
										 |  |  | 	/* This is per-dive-computer */ | 
					
						
							| 
									
										
										
										
											2013-12-04 00:12:01 +01:00
										 |  |  | 	gc.pi = *create_plot_info(dive, dc, &gc, printMode); | 
					
						
							| 
									
										
										
										
											2013-05-04 17:24:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 15:12:10 +03:00
										 |  |  | 	/* Bounding box */ | 
					
						
							|  |  |  | 	QPen pen = defaultPen; | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 	pen.setColor(getColor(TIME_GRID)); | 
					
						
							| 
									
										
										
										
											2013-06-28 15:12:10 +03:00
										 |  |  | 	QGraphicsRectItem *rect = new QGraphicsRectItem(profile_grid_area); | 
					
						
							|  |  |  | 	rect->setPen(pen); | 
					
						
							|  |  |  | 	scene()->addItem(rect); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-04 17:24:23 -03:00
										 |  |  | 	/* Depth profile */ | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	plot_depth_profile(); | 
					
						
							|  |  |  | 	plot_events(dc); | 
					
						
							| 
									
										
										
										
											2013-05-04 17:24:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-25 02:07:07 +02:00
										 |  |  | 	if (rulerEnabled && !printMode) | 
					
						
							|  |  |  | 		create_ruler(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 17:46:28 -03:00
										 |  |  | 	/* Temperature profile */ | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	plot_temperature_profile(); | 
					
						
							| 
									
										
										
										
											2013-05-04 17:24:23 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-09 00:24:03 -03:00
										 |  |  | 	/* Cylinder pressure plot */ | 
					
						
							| 
									
										
										
										
											2013-10-11 18:52:38 +02:00
										 |  |  | 	plot_cylinder_pressure(); | 
					
						
							| 
									
										
										
										
											2013-05-09 15:28:50 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-04 17:24:23 -03:00
										 |  |  | 	/* Text on top of all graphs.. */ | 
					
						
							| 
									
										
										
										
											2013-05-09 15:28:50 -03:00
										 |  |  | 	plot_temperature_text(); | 
					
						
							| 
									
										
										
										
											2013-05-09 15:37:43 -03:00
										 |  |  | 	plot_depth_text(); | 
					
						
							| 
									
										
										
										
											2013-05-09 15:42:38 -03:00
										 |  |  | 	plot_cylinder_pressure_text(); | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 	plot_deco_text(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-04 17:24:23 -03:00
										 |  |  | 	/* Put the dive computer name in the lower left corner */ | 
					
						
							| 
									
										
										
										
											2013-05-16 15:43:38 -03:00
										 |  |  | 	gc.leftx = 0; gc.rightx = 1.0; | 
					
						
							|  |  |  | 	gc.topy = 0; gc.bottomy = 1.0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-28 09:57:49 -07:00
										 |  |  | 	text_render_options_t computer = {DC_TEXT_SIZE, TIME_TEXT, LEFT, TOP}; | 
					
						
							| 
									
										
										
										
											2013-05-11 22:52:02 -07:00
										 |  |  | 	diveComputer = plot_text(&computer, QPointF(gc.leftx, gc.bottomy), nick); | 
					
						
							| 
									
										
										
										
											2013-05-10 13:57:36 -03:00
										 |  |  | 	// The Time ruler should be right after the DiveComputer:
 | 
					
						
							|  |  |  | 	timeMarkers->setPos(0, diveComputer->y()); | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-10 10:30:24 -03:00
										 |  |  | 	if (PP_GRAPHS_ENABLED) { | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 		plot_pp_gas_profile(); | 
					
						
							| 
									
										
										
										
											2013-05-09 17:30:16 -03:00
										 |  |  | 		plot_pp_text(); | 
					
						
							| 
									
										
										
										
											2013-05-10 10:30:24 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-09 18:02:52 -03:00
										 |  |  | 	plot_depth_scale(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2013-05-04 17:24:23 -03:00
										 |  |  | 	if (gc->printer) { | 
					
						
							|  |  |  | 		free(pi->entry); | 
					
						
							|  |  |  | 		last_pi_entry = pi->entry = NULL; | 
					
						
							|  |  |  | 		pi->nr = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-05-09 19:59:55 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-10 13:57:36 -03:00
										 |  |  | 	QRectF r = scene()->itemsBoundingRect(); | 
					
						
							|  |  |  | 	scene()->setSceneRect(r.x() - 15, r.y() -15, r.width() + 30, r.height() + 30); | 
					
						
							| 
									
										
										
										
											2013-05-22 21:25:05 -07:00
										 |  |  | 	if (zoomLevel == 0) { | 
					
						
							| 
									
										
										
										
											2013-05-10 13:57:36 -03:00
										 |  |  | 		fitInView(sceneRect()); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-06-10 14:28:44 -03:00
										 |  |  | 	toolTip->readPos(); | 
					
						
							| 
									
										
										
										
											2013-06-10 19:35:22 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(mode == PLAN){ | 
					
						
							|  |  |  | 		timeEditor = new GraphicsTextEditor(); | 
					
						
							|  |  |  | 		timeEditor->setPlainText( dive->duration.seconds ? QString::number(dive->duration.seconds/60) : tr("Set Duration: 10 minutes")); | 
					
						
							|  |  |  | 		timeEditor->setPos(profile_grid_area.width() - timeEditor->boundingRect().width(), timeMarkers->y()); | 
					
						
							|  |  |  | 		timeEditor->document(); | 
					
						
							|  |  |  | 		connect(timeEditor, SIGNAL(editingFinished(QString)), this, SLOT(edit_dive_time(QString))); | 
					
						
							|  |  |  | 		scene()->addItem(timeEditor); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-09-25 02:07:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-25 02:39:21 +02:00
										 |  |  | 	if (!printMode) | 
					
						
							| 
									
										
										
										
											2013-11-01 09:33:39 -04:00
										 |  |  | 		addControlItems(d); | 
					
						
							| 
									
										
										
										
											2013-09-25 02:39:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-25 02:07:07 +02:00
										 |  |  | 	if (rulerEnabled && !printMode) | 
					
						
							|  |  |  | 		add_ruler(); | 
					
						
							| 
									
										
										
										
											2013-05-04 16:12:43 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-09 18:02:52 -03:00
										 |  |  | void ProfileGraphicsView::plot_depth_scale() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i, maxdepth, marker; | 
					
						
							|  |  |  | 	static text_render_options_t tro = {DEPTH_TEXT_SIZE, SAMPLE_DEEP, RIGHT, MIDDLE}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Depth markers: every 30 ft or 10 m*/ | 
					
						
							|  |  |  | 	maxdepth = get_maxdepth(&gc.pi); | 
					
						
							|  |  |  | 	gc.topy = 0; gc.bottomy = maxdepth; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (prefs.units.length) { | 
					
						
							|  |  |  | 		case units::METERS: marker = 10000; break; | 
					
						
							|  |  |  | 		case units::FEET: marker = 9144; break;	/* 30 ft */ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* don't write depth labels all the way to the bottom as
 | 
					
						
							|  |  |  | 	 * there may be other graphs below the depth plot (like | 
					
						
							|  |  |  | 	 * partial pressure graphs) where this would look out | 
					
						
							|  |  |  | 	 * of place - so we only make sure that we print the next | 
					
						
							|  |  |  | 	 * marker below the actual maxdepth of the dive */ | 
					
						
							| 
									
										
										
										
											2013-05-10 13:57:36 -03:00
										 |  |  | 	depthMarkers = new QGraphicsRectItem(); | 
					
						
							| 
									
										
										
										
											2013-05-09 18:02:52 -03:00
										 |  |  | 	for (i = marker; i <= gc.pi.maxdepth + marker; i += marker) { | 
					
						
							|  |  |  | 		double d = get_depth_units(i, NULL, NULL); | 
					
						
							| 
									
										
										
										
											2013-05-10 13:57:36 -03:00
										 |  |  | 		plot_text(&tro, QPointF(-0.002, i), QString::number(d), depthMarkers); | 
					
						
							| 
									
										
										
										
											2013-05-09 18:02:52 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-10 13:57:36 -03:00
										 |  |  | 	scene()->addItem(depthMarkers); | 
					
						
							|  |  |  | 	depthMarkers->setPos(depthMarkers->pos().x() - 10, 0); | 
					
						
							| 
									
										
										
										
											2013-05-09 18:02:52 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-01 09:33:39 -04:00
										 |  |  | void ProfileGraphicsView::addControlItems(struct dive *d) | 
					
						
							| 
									
										
										
										
											2013-09-25 02:39:21 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	QAction *scaleAction = new QAction(QIcon(":scale"), tr("Scale"), this); | 
					
						
							|  |  |  | 	QAction *rulerAction = new QAction(QIcon(":ruler"), tr("Ruler"), this); | 
					
						
							|  |  |  | 	QToolBar *toolBar = new QToolBar("", 0); | 
					
						
							| 
									
										
										
										
											2013-11-27 10:06:30 -08:00
										 |  |  | 	rulerAction->setToolTip(tr("Measure properties of dive segments")); | 
					
						
							| 
									
										
										
										
											2013-11-14 23:54:35 -02:00
										 |  |  | 	scaleAction->setToolTip(tr("Scale your dive to screen size")); | 
					
						
							| 
									
										
										
										
											2013-09-25 02:39:21 +02:00
										 |  |  | 	toolBar->addAction(rulerAction); | 
					
						
							|  |  |  | 	toolBar->addAction(scaleAction); | 
					
						
							| 
									
										
										
										
											2013-11-01 09:33:39 -04:00
										 |  |  | 	toolBar->setOrientation(Qt::Vertical); | 
					
						
							| 
									
										
										
										
											2013-09-25 02:39:21 +02:00
										 |  |  | 	//make toolbar transparent
 | 
					
						
							| 
									
										
										
										
											2013-11-01 09:33:39 -04:00
										 |  |  | 	//toolBar->setStyleSheet(QString::fromUtf8 ("background-color: rgba(255,255,255,0);"));
 | 
					
						
							| 
									
										
										
										
											2013-09-25 02:39:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	connect(scaleAction, SIGNAL(triggered()), this, SLOT(on_scaleAction())); | 
					
						
							|  |  |  | 	connect(rulerAction, SIGNAL(triggered()), this, SLOT(on_rulerAction())); | 
					
						
							|  |  |  | 	//Put it into the lower right corner of the profile
 | 
					
						
							| 
									
										
										
										
											2013-11-01 09:33:39 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QString defaultDC(d->dc.model); | 
					
						
							| 
									
										
										
										
											2013-11-07 16:52:39 +09:00
										 |  |  | 	if (defaultDC == "manually added dive" || defaultDC == "planned dive") { | 
					
						
							| 
									
										
										
										
											2013-11-01 09:33:39 -04:00
										 |  |  | 		QAction *editAction = new QAction(QIcon(":edit"), tr("Edit"), this); | 
					
						
							|  |  |  | 		toolBar->addAction(editAction); | 
					
						
							|  |  |  | 		connect(editAction, SIGNAL(triggered()), mainWindow(), SLOT(editCurrentDive())); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	toolBarProxy = scene()->addWidget(toolBar); | 
					
						
							| 
									
										
										
										
											2013-11-26 16:04:21 -02:00
										 |  |  | 	toolBarProxy->setPos(mapToScene(TOOLBAR_POS)); | 
					
						
							|  |  |  | 	toolBarProxy->setFlag(QGraphicsItem::ItemIgnoresTransformations); | 
					
						
							| 
									
										
										
										
											2013-09-25 02:39:21 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-09 17:30:16 -03:00
										 |  |  | void ProfileGraphicsView::plot_pp_text() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	double pp, dpp, m; | 
					
						
							|  |  |  | 	int hpos; | 
					
						
							| 
									
										
										
										
											2013-12-04 13:27:34 -08:00
										 |  |  | 	static text_render_options_t tro = {PP_TEXT_SIZE, PP_LINES, LEFT, -0.75}; | 
					
						
							| 
									
										
										
										
											2013-09-25 02:47:47 +02:00
										 |  |  | 	QGraphicsRectItem *pressureMarkers = new QGraphicsRectItem(); | 
					
						
							| 
									
										
										
										
											2013-05-09 17:30:16 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	setup_pp_limits(&gc); | 
					
						
							|  |  |  | 	pp = floor(gc.pi.maxpp * 10.0) / 10.0 + 0.2; | 
					
						
							| 
									
										
										
										
											2013-12-04 13:27:34 -08:00
										 |  |  | 	dpp = pp > 4 ? 0.5 : 0.25; | 
					
						
							| 
									
										
										
										
											2013-05-09 17:30:16 -03:00
										 |  |  | 	hpos = gc.pi.entry[gc.pi.nr - 1].sec; | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 	QColor c = getColor(PP_LINES); | 
					
						
							| 
									
										
										
										
											2013-05-09 17:30:16 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-04 13:27:34 -08:00
										 |  |  | 	bool alt = true; | 
					
						
							| 
									
										
										
										
											2013-05-09 17:30:16 -03:00
										 |  |  | 	for (m = 0.0; m <= pp; m += dpp) { | 
					
						
							|  |  |  | 		QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(0, m), SCALEGC(hpos, m)); | 
					
						
							| 
									
										
										
										
											2013-05-09 18:29:18 -03:00
										 |  |  | 		QPen pen(defaultPen); | 
					
						
							|  |  |  | 		pen.setColor(c); | 
					
						
							| 
									
										
										
										
											2013-11-27 21:24:48 -02:00
										 |  |  | 		if ( QString::number(m).toDouble() != QString::number(m).toInt()){ | 
					
						
							|  |  |  | 			pen.setStyle(Qt::DashLine); | 
					
						
							|  |  |  | 			pen.setWidthF(1.2); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-09 18:29:18 -03:00
										 |  |  | 		item->setPen(pen); | 
					
						
							| 
									
										
										
										
											2013-05-09 17:30:16 -03:00
										 |  |  | 		scene()->addItem(item); | 
					
						
							| 
									
										
										
										
											2013-11-27 21:24:48 -02:00
										 |  |  | 		qreal textPos = hpos; | 
					
						
							|  |  |  | 		if (alt) | 
					
						
							| 
									
										
										
										
											2013-12-04 13:27:34 -08:00
										 |  |  | 			plot_text(&tro, QPointF(textPos, m), QString::number(m), pressureMarkers); | 
					
						
							| 
									
										
										
										
											2013-11-27 21:24:48 -02:00
										 |  |  | 		alt = !alt; | 
					
						
							| 
									
										
										
										
											2013-05-09 17:30:16 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-09-25 02:47:47 +02:00
										 |  |  | 	scene()->addItem(pressureMarkers); | 
					
						
							|  |  |  | 	pressureMarkers->setPos(pressureMarkers->pos().x() + 10, 0); | 
					
						
							| 
									
										
										
										
											2013-05-09 17:30:16 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-13 19:52:30 +02:00
										 |  |  | void ProfileGraphicsView::plot_add_line(int sec, double val, QColor c, QPointF &from) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QPointF to = QPointF(SCALEGC(sec, val)); | 
					
						
							|  |  |  | 	QGraphicsLineItem *item = new QGraphicsLineItem(from.x(), from.y(), to.x(), to.y()); | 
					
						
							|  |  |  | 	QPen pen(defaultPen); | 
					
						
							|  |  |  | 	pen.setColor(c); | 
					
						
							|  |  |  | 	item->setPen(pen); | 
					
						
							|  |  |  | 	scene()->addItem(item); | 
					
						
							|  |  |  | 	from = to; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | void ProfileGraphicsView::plot_pp_gas_profile() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	struct plot_data *entry; | 
					
						
							|  |  |  | 	struct plot_info *pi = &gc.pi; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	setup_pp_limits(&gc); | 
					
						
							|  |  |  | 	QColor c; | 
					
						
							|  |  |  | 	QPointF from, to; | 
					
						
							| 
									
										
										
										
											2013-12-04 23:12:07 -02:00
										 |  |  | 	QPointF legendPos = QPointF(scene()->sceneRect().width() * 0.4, scene()->sceneRect().height() - scene()->sceneRect().height()*0.02); | 
					
						
							| 
									
										
										
										
											2013-12-03 18:27:44 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-28 11:21:27 -07:00
										 |  |  | 	if (prefs.pp_graphs.pn2) { | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 		c = getColor(PN2); | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 		entry = pi->entry; | 
					
						
							|  |  |  | 		from = QPointF(SCALEGC(entry->sec, entry->pn2)); | 
					
						
							|  |  |  | 		for (i = 1; i < pi->nr; i++) { | 
					
						
							|  |  |  | 			entry++; | 
					
						
							| 
									
										
										
										
											2013-06-13 19:52:30 +02:00
										 |  |  | 			if (entry->pn2 < prefs.pp_graphs.pn2_threshold) | 
					
						
							|  |  |  | 				plot_add_line(entry->sec, entry->pn2, c, from); | 
					
						
							|  |  |  | 			else | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 				from = QPointF(SCALEGC(entry->sec, entry->pn2)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 		c = getColor(PN2_ALERT); | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 		entry = pi->entry; | 
					
						
							|  |  |  | 		from = QPointF(SCALEGC(entry->sec, entry->pn2)); | 
					
						
							|  |  |  | 		for (i = 1; i < pi->nr; i++) { | 
					
						
							|  |  |  | 			entry++; | 
					
						
							| 
									
										
										
										
											2013-06-13 19:52:30 +02:00
										 |  |  | 			if (entry->pn2 >= prefs.pp_graphs.pn2_threshold) | 
					
						
							|  |  |  | 				plot_add_line(entry->sec, entry->pn2, c, from); | 
					
						
							|  |  |  | 			else | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 				from = QPointF(SCALEGC(entry->sec, entry->pn2)); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-12-07 14:11:54 +02:00
										 |  |  | 		createPPLegend(trUtf8("pN" UTF8_SUBSCRIPT_2),getColor(PN2), legendPos); | 
					
						
							| 
									
										
										
										
											2013-05-28 11:21:27 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-28 11:21:27 -07:00
										 |  |  | 	if (prefs.pp_graphs.phe) { | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 		c = getColor(PHE); | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 		entry = pi->entry; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		from = QPointF(SCALEGC(entry->sec, entry->phe)); | 
					
						
							|  |  |  | 		for (i = 1; i < pi->nr; i++) { | 
					
						
							|  |  |  | 			entry++; | 
					
						
							| 
									
										
										
										
											2013-06-13 19:52:30 +02:00
										 |  |  | 			if (entry->phe < prefs.pp_graphs.phe_threshold) | 
					
						
							|  |  |  | 				plot_add_line(entry->sec, entry->phe, c, from); | 
					
						
							|  |  |  | 			else | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 				from = QPointF(SCALEGC(entry->sec, entry->phe)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 		c = getColor(PHE_ALERT); | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 		entry = pi->entry; | 
					
						
							|  |  |  | 		from = QPointF(SCALEGC(entry->sec, entry->phe)); | 
					
						
							|  |  |  | 		for (i = 1; i < pi->nr; i++) { | 
					
						
							|  |  |  | 			entry++; | 
					
						
							| 
									
										
										
										
											2013-06-13 19:52:30 +02:00
										 |  |  | 			if (entry->phe >= prefs.pp_graphs.phe_threshold) | 
					
						
							|  |  |  | 				plot_add_line(entry->sec, entry->phe, c, from); | 
					
						
							|  |  |  | 			else | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 				from = QPointF(SCALEGC(entry->sec, entry->phe)); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-12-07 14:11:54 +02:00
										 |  |  | 		createPPLegend(trUtf8("pHe"),getColor(PHE), legendPos); | 
					
						
							| 
									
										
										
										
											2013-05-28 11:21:27 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (prefs.pp_graphs.po2) { | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 		c = getColor(PO2); | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 		entry = pi->entry; | 
					
						
							|  |  |  | 		from = QPointF(SCALEGC(entry->sec, entry->po2)); | 
					
						
							|  |  |  | 		for (i = 1; i < pi->nr; i++) { | 
					
						
							|  |  |  | 			entry++; | 
					
						
							| 
									
										
										
										
											2013-06-13 19:52:30 +02:00
										 |  |  | 			if (entry->po2 < prefs.pp_graphs.po2_threshold) | 
					
						
							|  |  |  | 				plot_add_line(entry->sec, entry->po2, c, from); | 
					
						
							|  |  |  | 			else | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 				from = QPointF(SCALEGC(entry->sec, entry->po2)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 		c = getColor(PO2_ALERT); | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 		entry = pi->entry; | 
					
						
							|  |  |  | 		from = QPointF(SCALEGC(entry->sec, entry->po2)); | 
					
						
							|  |  |  | 		for (i = 1; i < pi->nr; i++) { | 
					
						
							|  |  |  | 			entry++; | 
					
						
							| 
									
										
										
										
											2013-06-13 19:52:30 +02:00
										 |  |  | 			if (entry->po2 >= prefs.pp_graphs.po2_threshold) | 
					
						
							|  |  |  | 				plot_add_line(entry->sec, entry->po2, c, from); | 
					
						
							|  |  |  | 			 else | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 				from = QPointF(SCALEGC(entry->sec, entry->po2)); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-12-07 14:11:54 +02:00
										 |  |  | 		createPPLegend(trUtf8("pO" UTF8_SUBSCRIPT_2),getColor(PO2), legendPos); | 
					
						
							| 
									
										
										
										
											2013-05-28 11:21:27 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-03 18:27:44 -02:00
										 |  |  | void ProfileGraphicsView::createPPLegend(QString title, const QColor& c, QPointF& legendPos) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-04 23:12:07 -02:00
										 |  |  | 	QGraphicsRectItem *rect = new QGraphicsRectItem(0, 0, scene()->sceneRect().width() * 0.01, scene()->sceneRect().width() * 0.01); | 
					
						
							| 
									
										
										
										
											2013-12-03 18:27:44 -02:00
										 |  |  | 	rect->setBrush(QBrush(c)); | 
					
						
							|  |  |  | 	rect->setPos(legendPos); | 
					
						
							| 
									
										
										
										
											2013-12-04 23:12:07 -02:00
										 |  |  | 	rect->setPen(QPen(QColor(Qt::transparent))); | 
					
						
							| 
									
										
										
										
											2013-12-03 18:27:44 -02:00
										 |  |  | 	QGraphicsSimpleTextItem *text = new QGraphicsSimpleTextItem(title); | 
					
						
							| 
									
										
										
										
											2013-12-04 23:12:07 -02:00
										 |  |  | 	text->setPos(legendPos.x() + rect->boundingRect().width() + 5, legendPos.y() ); | 
					
						
							| 
									
										
										
										
											2013-12-03 18:27:44 -02:00
										 |  |  | 	scene()->addItem(rect); | 
					
						
							|  |  |  | 	scene()->addItem(text); | 
					
						
							| 
									
										
										
										
											2013-12-04 23:12:07 -02:00
										 |  |  | 	legendPos.setX(text->pos().x() + text->boundingRect().width() + 20); | 
					
						
							|  |  |  | 	if(printMode){ | 
					
						
							|  |  |  | 		QFont f = text->font(); | 
					
						
							|  |  |  | 		f.setPointSizeF( f.pointSizeF() * 0.7); | 
					
						
							|  |  |  | 		text->setFont(f); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-12-03 18:27:44 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | void ProfileGraphicsView::plot_deco_text() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (prefs.profile_calc_ceiling) { | 
					
						
							|  |  |  | 		float x = gc.leftx + (gc.rightx - gc.leftx) / 2; | 
					
						
							|  |  |  | 		float y = gc.topy = 1.0; | 
					
						
							| 
									
										
										
										
											2013-05-31 13:47:34 +09:00
										 |  |  | 		static text_render_options_t tro = {PRESSURE_TEXT_SIZE, PRESSURE_TEXT, CENTER, BOTTOM}; | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 		gc.bottomy = 0.0; | 
					
						
							| 
									
										
										
										
											2013-05-28 11:21:27 -07:00
										 |  |  | 		plot_text(&tro, QPointF(x, y), QString("GF %1/%2").arg(prefs.gflow).arg(prefs.gfhigh)); | 
					
						
							| 
									
										
										
										
											2013-05-09 15:47:39 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-09 15:42:38 -03:00
										 |  |  | void ProfileGraphicsView::plot_cylinder_pressure_text() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	int mbar, cyl; | 
					
						
							|  |  |  | 	int seen_cyl[MAX_CYLINDERS] = { FALSE, }; | 
					
						
							|  |  |  | 	int last_pressure[MAX_CYLINDERS] = { 0, }; | 
					
						
							|  |  |  | 	int last_time[MAX_CYLINDERS] = { 0, }; | 
					
						
							|  |  |  | 	struct plot_data *entry; | 
					
						
							|  |  |  | 	struct plot_info *pi = &gc.pi; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!get_cylinder_pressure_range(&gc)) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cyl = -1; | 
					
						
							|  |  |  | 	for (i = 0; i < pi->nr; i++) { | 
					
						
							|  |  |  | 		entry = pi->entry + i; | 
					
						
							|  |  |  | 		mbar = GET_PRESSURE(entry); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!mbar) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		if (cyl != entry->cylinderindex) { | 
					
						
							|  |  |  | 			cyl = entry->cylinderindex; | 
					
						
							|  |  |  | 			if (!seen_cyl[cyl]) { | 
					
						
							|  |  |  | 				plot_pressure_value(mbar, entry->sec, LEFT, BOTTOM); | 
					
						
							| 
									
										
										
										
											2013-05-31 16:21:39 +10:00
										 |  |  | 				plot_gas_value(mbar, entry->sec, LEFT, TOP, | 
					
						
							| 
									
										
										
										
											2013-09-22 23:21:01 +02:00
										 |  |  | 						get_o2(&dive->cylinder[cyl].gasmix), | 
					
						
							|  |  |  | 						get_he(&dive->cylinder[cyl].gasmix)); | 
					
						
							| 
									
										
										
										
											2013-05-09 15:42:38 -03:00
										 |  |  | 				seen_cyl[cyl] = TRUE; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		last_pressure[cyl] = mbar; | 
					
						
							|  |  |  | 		last_time[cyl] = entry->sec; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) { | 
					
						
							|  |  |  | 		if (last_time[cyl]) { | 
					
						
							|  |  |  | 			plot_pressure_value(last_pressure[cyl], last_time[cyl], CENTER, TOP); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-10 08:56:56 -07:00
										 |  |  | void ProfileGraphicsView::plot_pressure_value(int mbar, int sec, double xalign, double yalign) | 
					
						
							| 
									
										
										
										
											2013-05-09 15:42:38 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	int pressure; | 
					
						
							|  |  |  | 	const char *unit; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pressure = get_pressure_units(mbar, &unit); | 
					
						
							|  |  |  | 	static text_render_options_t tro = {PRESSURE_TEXT_SIZE, PRESSURE_TEXT, xalign, yalign}; | 
					
						
							| 
									
										
										
										
											2013-05-10 13:03:16 -03:00
										 |  |  | 	plot_text(&tro, QPointF(sec, mbar), QString("%1 %2").arg(pressure).arg(unit)); | 
					
						
							| 
									
										
										
										
											2013-05-09 15:42:38 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-31 16:21:39 +10:00
										 |  |  | void ProfileGraphicsView::plot_gas_value(int mbar, int sec, double xalign, double yalign, int o2, int he) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QString gas; | 
					
						
							|  |  |  | 	if (is_air(o2, he)) | 
					
						
							|  |  |  | 		gas = tr("air"); | 
					
						
							|  |  |  | 	else if (he == 0) | 
					
						
							|  |  |  | 		gas = QString(tr("EAN%1")).arg((o2 + 5) / 10); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		gas = QString("%1/%2").arg((o2 + 5) / 10).arg((he + 5) / 10); | 
					
						
							|  |  |  | 	static text_render_options_t tro = {PRESSURE_TEXT_SIZE, PRESSURE_TEXT, xalign, yalign}; | 
					
						
							|  |  |  | 	plot_text(&tro, QPointF(sec, mbar), gas); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-09 15:37:43 -03:00
										 |  |  | void ProfileGraphicsView::plot_depth_text() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int maxtime, maxdepth; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Get plot scaling limits */ | 
					
						
							|  |  |  | 	maxtime = get_maxtime(&gc.pi); | 
					
						
							|  |  |  | 	maxdepth = get_maxdepth(&gc.pi); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gc.leftx = 0; gc.rightx = maxtime; | 
					
						
							|  |  |  | 	gc.topy = 0; gc.bottomy = maxdepth; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	plot_text_samples(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileGraphicsView::plot_text_samples() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static text_render_options_t deep = {14, SAMPLE_DEEP, CENTER, TOP}; | 
					
						
							|  |  |  | 	static text_render_options_t shallow = {14, SAMPLE_SHALLOW, CENTER, BOTTOM}; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	int last = -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct plot_info* pi = &gc.pi; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < pi->nr; i++) { | 
					
						
							|  |  |  | 		struct plot_data *entry = pi->entry + i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (entry->depth < 2000) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-10 21:07:49 -07:00
										 |  |  | 		if ((entry == entry->max[2]) && entry->depth / 100 != last) { | 
					
						
							| 
									
										
										
										
											2013-05-09 15:37:43 -03:00
										 |  |  | 			plot_depth_sample(entry, &deep); | 
					
						
							| 
									
										
										
										
											2013-05-10 21:07:49 -07:00
										 |  |  | 			last = entry->depth / 100; | 
					
						
							| 
									
										
										
										
											2013-05-09 15:37:43 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-10 21:07:49 -07:00
										 |  |  | 		if ((entry == entry->min[2]) && entry->depth / 100 != last) { | 
					
						
							| 
									
										
										
										
											2013-05-09 15:37:43 -03:00
										 |  |  | 			plot_depth_sample(entry, &shallow); | 
					
						
							| 
									
										
										
										
											2013-05-10 21:07:49 -07:00
										 |  |  | 			last = entry->depth / 100; | 
					
						
							| 
									
										
										
										
											2013-05-09 15:37:43 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (entry->depth != last) | 
					
						
							|  |  |  | 			last = -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileGraphicsView::plot_depth_sample(struct plot_data *entry,text_render_options_t *tro) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int sec = entry->sec, decimals; | 
					
						
							|  |  |  | 	double d; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	d = get_depth_units(entry->depth, &decimals, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-10 21:07:49 -07:00
										 |  |  | 	plot_text(tro, QPointF(sec, entry->depth), QString("%1").arg(d, 0, 'f', 1)); | 
					
						
							| 
									
										
										
										
											2013-05-09 15:37:43 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-09 15:28:50 -03:00
										 |  |  | void ProfileGraphicsView::plot_temperature_text() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	int last = -300, sec = 0; | 
					
						
							|  |  |  | 	int last_temperature = 0, last_printed_temp = 0; | 
					
						
							|  |  |  | 	plot_info *pi = &gc.pi; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!setup_temperature_limits(&gc)) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < pi->nr; i++) { | 
					
						
							|  |  |  | 		struct plot_data *entry = pi->entry+i; | 
					
						
							|  |  |  | 		int mkelvin = entry->temperature; | 
					
						
							|  |  |  | 		sec = entry->sec; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!mkelvin) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		last_temperature = mkelvin; | 
					
						
							|  |  |  | 		/* don't print a temperature
 | 
					
						
							|  |  |  | 		 * if it's been less than 5min and less than a 2K change OR | 
					
						
							|  |  |  | 		 * if it's been less than 2min OR if the change from the | 
					
						
							| 
									
										
										
										
											2013-05-14 09:28:30 +02:00
										 |  |  | 		 * last print is less than .4K (and therefore less than 1F) */ | 
					
						
							| 
									
										
										
										
											2013-05-09 15:28:50 -03:00
										 |  |  | 		if (((sec < last + 300) && (abs(mkelvin - last_printed_temp) < 2000)) || | 
					
						
							|  |  |  | 			(sec < last + 120) || | 
					
						
							|  |  |  | 			(abs(mkelvin - last_printed_temp) < 400)) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		last = sec; | 
					
						
							| 
									
										
										
										
											2013-05-11 22:56:53 -07:00
										 |  |  | 		if (mkelvin > 200000) | 
					
						
							|  |  |  | 			plot_single_temp_text(sec,mkelvin); | 
					
						
							| 
									
										
										
										
											2013-05-09 15:28:50 -03:00
										 |  |  | 		last_printed_temp = mkelvin; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	/* it would be nice to print the end temperature, if it's
 | 
					
						
							|  |  |  | 	 * different or if the last temperature print has been more | 
					
						
							|  |  |  | 	 * than a quarter of the dive back */ | 
					
						
							| 
									
										
										
										
											2013-05-11 22:56:53 -07:00
										 |  |  | 	if (last_temperature > 200000 && | 
					
						
							|  |  |  | 	    ((abs(last_temperature - last_printed_temp) > 500) || ((double)last / (double)sec < 0.75))) | 
					
						
							| 
									
										
										
										
											2013-05-09 15:28:50 -03:00
										 |  |  | 		plot_single_temp_text(sec, last_temperature); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileGraphicsView::plot_single_temp_text(int sec, int mkelvin) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	double deg; | 
					
						
							|  |  |  | 	const char *unit; | 
					
						
							|  |  |  | 	static text_render_options_t tro = {TEMP_TEXT_SIZE, TEMP_TEXT, LEFT, TOP}; | 
					
						
							|  |  |  | 	deg = get_temp_units(mkelvin, &unit); | 
					
						
							| 
									
										
										
										
											2013-05-10 21:07:49 -07:00
										 |  |  | 	plot_text(&tro, QPointF(sec, mkelvin), QString("%1%2").arg(deg, 0, 'f', 1).arg(unit)); //"%.2g%s"
 | 
					
						
							| 
									
										
										
										
											2013-05-09 15:28:50 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-11 18:52:38 +02:00
										 |  |  | void ProfileGraphicsView::plot_cylinder_pressure() | 
					
						
							| 
									
										
										
										
											2013-05-09 00:24:03 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2013-10-14 23:48:43 +02:00
										 |  |  | 	int last_index = -1; | 
					
						
							| 
									
										
										
										
											2013-05-09 00:24:03 -03:00
										 |  |  | 	int lift_pen = FALSE; | 
					
						
							|  |  |  | 	int first_plot = TRUE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!get_cylinder_pressure_range(&gc)) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QPointF from, to; | 
					
						
							|  |  |  | 	for (i = 0; i < gc.pi.nr; i++) { | 
					
						
							|  |  |  | 		int mbar; | 
					
						
							|  |  |  | 		struct plot_data *entry = gc.pi.entry + i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		mbar = GET_PRESSURE(entry); | 
					
						
							|  |  |  | 		if (entry->cylinderindex != last_index) { | 
					
						
							|  |  |  | 			lift_pen = TRUE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (!mbar) { | 
					
						
							|  |  |  | 			lift_pen = TRUE; | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-14 23:48:43 +02:00
										 |  |  | 		QColor c = get_sac_color(entry->sac, dive->sac); | 
					
						
							| 
									
										
										
										
											2013-05-09 00:24:03 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (lift_pen) { | 
					
						
							|  |  |  | 			if (!first_plot && entry->cylinderindex == last_index) { | 
					
						
							|  |  |  | 				/* if we have a previous event from the same tank,
 | 
					
						
							|  |  |  | 				 * draw at least a short line */ | 
					
						
							|  |  |  | 				int prev_pr; | 
					
						
							|  |  |  | 				prev_pr = GET_PRESSURE(entry - 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC((entry-1)->sec, prev_pr), SCALEGC(entry->sec, mbar)); | 
					
						
							| 
									
										
										
										
											2013-05-09 18:29:18 -03:00
										 |  |  | 				QPen pen(defaultPen); | 
					
						
							|  |  |  | 				pen.setColor(c); | 
					
						
							|  |  |  | 				item->setPen(pen); | 
					
						
							| 
									
										
										
										
											2013-05-09 00:24:03 -03:00
										 |  |  | 				scene()->addItem(item); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				first_plot = FALSE; | 
					
						
							|  |  |  | 				from = QPointF(SCALEGC(entry->sec, mbar)); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			lift_pen = FALSE; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			to = QPointF(SCALEGC(entry->sec, mbar)); | 
					
						
							|  |  |  | 			QGraphicsLineItem *item = new QGraphicsLineItem(from.x(), from.y(), to.x(), to.y()); | 
					
						
							| 
									
										
										
										
											2013-05-09 18:29:18 -03:00
										 |  |  | 			QPen pen(defaultPen); | 
					
						
							|  |  |  | 			pen.setColor(c); | 
					
						
							|  |  |  | 			item->setPen(pen); | 
					
						
							| 
									
										
										
										
											2013-05-09 00:24:03 -03:00
										 |  |  | 			scene()->addItem(item); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		from = QPointF(SCALEGC(entry->sec, mbar)); | 
					
						
							|  |  |  | 		last_index = entry->cylinderindex; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* set the color for the pressure plot according to temporary sac rate
 | 
					
						
							|  |  |  |  * as compared to avg_sac; the calculation simply maps the delta between | 
					
						
							|  |  |  |  * sac and avg_sac to indexes 0 .. (SAC_COLORS - 1) with everything | 
					
						
							|  |  |  |  * more than 6000 ml/min below avg_sac mapped to 0 */ | 
					
						
							|  |  |  | QColor ProfileGraphicsView::get_sac_color(int sac, int avg_sac) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int sac_index = 0; | 
					
						
							|  |  |  | 	int delta = sac - avg_sac + 7000; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!gc.printer) { | 
					
						
							|  |  |  | 		sac_index = delta / 2000; | 
					
						
							|  |  |  | 		if (sac_index < 0) | 
					
						
							|  |  |  | 			sac_index = 0; | 
					
						
							|  |  |  | 		if (sac_index > SAC_COLORS - 1) | 
					
						
							|  |  |  | 			sac_index = SAC_COLORS - 1; | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 		return getColor((color_indice_t)(SAC_COLORS_START_IDX + sac_index)); | 
					
						
							| 
									
										
										
										
											2013-05-09 00:24:03 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 	return getColor(SAC_DEFAULT); | 
					
						
							| 
									
										
										
										
											2013-05-09 00:24:03 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | void ProfileGraphicsView::plot_events(struct divecomputer *dc) | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct event *event = dc->events; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-26 16:04:21 -02:00
										 |  |  | //	if (gc->printer) {
 | 
					
						
							|  |  |  | //		return;
 | 
					
						
							|  |  |  | //	}
 | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while (event) { | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 		plot_one_event(event); | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | 		event = event->next; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | void ProfileGraphicsView::plot_one_event(struct event *ev) | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-03 22:44:04 +02:00
										 |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	struct plot_info *pi = &gc.pi; | 
					
						
							| 
									
										
										
										
											2013-12-11 00:53:35 +01:00
										 |  |  | 	struct plot_data *entry = NULL; | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-14 09:28:30 +02:00
										 |  |  | 	/* is plotting of this event disabled? */ | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | 	if (ev->name) { | 
					
						
							|  |  |  | 		for (i = 0; i < evn_used; i++) { | 
					
						
							|  |  |  | 			if (! strcmp(ev->name, ev_namelist[i].ev_name)) { | 
					
						
							|  |  |  | 				if (ev_namelist[i].plot_ev) | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 					return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ev->time.seconds < 30 && !strcmp(ev->name, "gaschange")) | 
					
						
							|  |  |  | 		/* a gas change in the first 30 seconds is the way of some dive computers
 | 
					
						
							|  |  |  | 		 * to tell us the gas that is used; let's not plot a marker for that */ | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < pi->nr; i++) { | 
					
						
							| 
									
										
										
										
											2013-10-03 22:44:04 +02:00
										 |  |  | 		entry = pi->entry + i; | 
					
						
							|  |  |  | 		if (ev->time.seconds < entry->sec) | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-11 00:53:35 +01:00
										 |  |  | 	/* If we didn't find the right event, don't dereference null */ | 
					
						
							|  |  |  | 	if (entry == NULL) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | 	/* draw a little triangular marker and attach tooltip */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	int x = SCALEXGC(ev->time.seconds); | 
					
						
							| 
									
										
										
										
											2013-10-03 22:44:04 +02:00
										 |  |  | 	int y = SCALEYGC(entry->depth); | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-19 23:37:45 -02:00
										 |  |  | 	EventItem *item = new EventItem(ev, 0, isGrayscale); | 
					
						
							| 
									
										
										
										
											2013-05-07 16:09:51 -07:00
										 |  |  | 	item->setPos(x, y); | 
					
						
							|  |  |  | 	scene()->addItem(item); | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-01 17:55:09 -08:00
										 |  |  | 	/* we display the event on screen - so translate (with the correct context for events) */ | 
					
						
							|  |  |  | 	QString name = gettextFromC::instance()->tr(ev->name); | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | 	if (ev->value) { | 
					
						
							| 
									
										
										
										
											2013-12-01 17:55:09 -08:00
										 |  |  | 		if (ev->name && strcmp(ev->name, "gaschange") == 0) { | 
					
						
							| 
									
										
										
										
											2013-10-03 22:44:04 +02:00
										 |  |  | 			int he = get_he(&dive->cylinder[entry->cylinderindex].gasmix); | 
					
						
							|  |  |  | 			int o2 = get_o2(&dive->cylinder[entry->cylinderindex].gasmix); | 
					
						
							| 
									
										
										
										
											2013-05-06 19:42:39 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 15:46:16 -07:00
										 |  |  | 			name += ": "; | 
					
						
							| 
									
										
										
										
											2013-11-22 00:09:26 +01:00
										 |  |  | 			if (he) | 
					
						
							|  |  |  | 				name += QString("%1/%2").arg((o2 + 5) / 10).arg((he + 5) / 10); | 
					
						
							|  |  |  | 			else if(is_air(o2, he)) | 
					
						
							|  |  |  | 				name += tr("air"); | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				name += QString(tr("EAN%1")).arg((o2 + 5) / 10); | 
					
						
							| 
									
										
										
										
											2013-05-06 19:42:39 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | 		} else if (ev->name && !strcmp(ev->name, "SP change")) { | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 			name += QString(":%1").arg((double) ev->value / 1000); | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			name += QString(":%1").arg(ev->value); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else if (ev->name && name == "SP change") { | 
					
						
							| 
									
										
										
										
											2013-11-20 00:10:52 +01:00
										 |  |  | 		name += "\n" + tr("Bailing out to OC"); | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2013-07-27 15:51:51 +02:00
										 |  |  | 		name += ev->flags == SAMPLE_FLAGS_BEGIN ? tr(" begin", "Starts with space!") : | 
					
						
							|  |  |  | 				ev->flags == SAMPLE_FLAGS_END ? tr(" end", "Starts with space!") : ""; | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 07:22:23 -03:00
										 |  |  | 	//item->setToolTipController(toolTip);
 | 
					
						
							|  |  |  | 	//item->addToolTip(name);
 | 
					
						
							|  |  |  | 	item->setToolTip(name); | 
					
						
							| 
									
										
										
										
											2013-05-06 18:58:18 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-25 02:07:07 +02:00
										 |  |  | void ProfileGraphicsView::create_ruler() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int x,y; | 
					
						
							|  |  |  | 	struct plot_info *pi = &gc.pi; | 
					
						
							|  |  |  | 	struct plot_data *data = pi->entry; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RulerNodeItem *first = new RulerNodeItem(0, gc); | 
					
						
							|  |  |  | 	RulerNodeItem *second = new RulerNodeItem(0, gc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	x = SCALEXGC(data->sec); | 
					
						
							|  |  |  | 	y = data->depth; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	first->setPos(x,y); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	data = pi->entry+(pi->nr-1); | 
					
						
							|  |  |  | 	x = SCALEXGC(data->sec); | 
					
						
							|  |  |  | 	y = data->depth; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	second->setPos(x,y); | 
					
						
							|  |  |  | 	//Make sure that both points already have their entries
 | 
					
						
							|  |  |  | 	first->recalculate(); | 
					
						
							|  |  |  | 	second->recalculate(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rulerItem = new RulerItem(0, first, second); | 
					
						
							|  |  |  | 	first->setRuler(rulerItem); | 
					
						
							|  |  |  | 	second->setRuler(rulerItem); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileGraphicsView::add_ruler() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (! scene()->items().contains(rulerItem)) { | 
					
						
							|  |  |  | 		scene()->addItem(rulerItem->sourceNode()); | 
					
						
							|  |  |  | 		scene()->addItem(rulerItem->destNode()); | 
					
						
							|  |  |  | 		scene()->addItem(rulerItem); | 
					
						
							|  |  |  | 		rulerItem->recalculate(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileGraphicsView::remove_ruler() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (rulerItem) { | 
					
						
							|  |  |  | 		if (scene()->items().contains(rulerItem)) | 
					
						
							|  |  |  | 			scene()->removeItem(rulerItem); | 
					
						
							|  |  |  | 		if (scene()->items().contains(rulerItem->sourceNode())) | 
					
						
							|  |  |  | 			scene()->removeItem(rulerItem->sourceNode()); | 
					
						
							|  |  |  | 		if (scene()->items().contains(rulerItem->destNode())) | 
					
						
							|  |  |  | 			scene()->removeItem(rulerItem->destNode()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | void ProfileGraphicsView::plot_depth_profile() | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i, incr; | 
					
						
							|  |  |  | 	int sec, depth; | 
					
						
							|  |  |  | 	struct plot_data *entry; | 
					
						
							|  |  |  | 	int maxtime, maxdepth, marker, maxline; | 
					
						
							|  |  |  | 	int increments[8] = { 10, 20, 30, 60, 5*60, 10*60, 15*60, 30*60 }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Get plot scaling limits */ | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	maxtime = get_maxtime(&gc.pi); | 
					
						
							|  |  |  | 	maxdepth = get_maxdepth(&gc.pi); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	gc.maxtime = maxtime; | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Time markers: at most every 10 seconds, but no more than 12 markers.
 | 
					
						
							|  |  |  | 	 * We start out with 10 seconds and increment up to 30 minutes, | 
					
						
							|  |  |  | 	 * depending on the dive time. | 
					
						
							|  |  |  | 	 * This allows for 6h dives - enough (I hope) for even the craziest | 
					
						
							|  |  |  | 	 * divers - but just in case, for those 8h depth-record-breaking dives, | 
					
						
							|  |  |  | 	 * we double the interval if this still doesn't get us to 12 or fewer | 
					
						
							|  |  |  | 	 * time markers */ | 
					
						
							|  |  |  | 	i = 0; | 
					
						
							| 
									
										
										
										
											2013-12-11 15:26:48 +02:00
										 |  |  | 	while (i < 7 && maxtime / increments[i] > 12) | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 		i++; | 
					
						
							|  |  |  | 	incr = increments[i]; | 
					
						
							|  |  |  | 	while (maxtime / incr > 12) | 
					
						
							|  |  |  | 		incr *= 2; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	gc.leftx = 0; gc.rightx = maxtime; | 
					
						
							|  |  |  | 	gc.topy = 0; gc.bottomy = 1.0; | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	last_gc = gc; | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 	QColor c = getColor(TIME_GRID); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 	for (i = incr; i < maxtime; i += incr) { | 
					
						
							| 
									
										
										
										
											2013-05-09 18:29:18 -03:00
										 |  |  | 		QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(i, 0), SCALEGC(i, 1)); | 
					
						
							|  |  |  | 		QPen pen(defaultPen); | 
					
						
							|  |  |  | 		pen.setColor(c); | 
					
						
							|  |  |  | 		item->setPen(pen); | 
					
						
							|  |  |  | 		scene()->addItem(item); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-10 13:57:36 -03:00
										 |  |  | 	timeMarkers = new QGraphicsRectItem(); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 	/* now the text on the time markers */ | 
					
						
							| 
									
										
										
										
											2013-05-28 09:57:49 -07:00
										 |  |  | 	struct text_render_options tro = {DEPTH_TEXT_SIZE, TIME_TEXT, CENTER, LINE_DOWN}; | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 	if (maxtime < 600) { | 
					
						
							|  |  |  | 		/* Be a bit more verbose with shorter dives */ | 
					
						
							|  |  |  | 		for (i = incr; i < maxtime; i += incr) | 
					
						
							| 
									
										
										
										
											2013-09-08 20:48:09 +02:00
										 |  |  | 			plot_text(&tro, QPointF(i, 0), QString("%1:%2").arg(i/60).arg(i%60, 2, 10, QChar('0')), timeMarkers); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		/* Only render the time on every second marker for normal dives */ | 
					
						
							|  |  |  | 		for (i = incr; i < maxtime; i += 2 * incr) | 
					
						
							| 
									
										
										
										
											2013-05-10 13:57:36 -03:00
										 |  |  | 			plot_text(&tro, QPointF(i, 0), QString("%1").arg(QString::number(i/60)), timeMarkers); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-10 13:57:36 -03:00
										 |  |  | 	timeMarkers->setPos(0,0); | 
					
						
							|  |  |  | 	scene()->addItem(timeMarkers); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Depth markers: every 30 ft or 10 m*/ | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	gc.leftx = 0; gc.rightx = 1.0; | 
					
						
							|  |  |  | 	gc.topy = 0; gc.bottomy = maxdepth; | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 	switch (prefs.units.length) { | 
					
						
							|  |  |  | 	case units::METERS: | 
					
						
							|  |  |  | 		marker = 10000; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case units::FEET: | 
					
						
							|  |  |  | 		marker = 9144; | 
					
						
							|  |  |  | 		break;	/* 30 ft */ | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-10-07 16:49:56 -07:00
										 |  |  | 	maxline = qMax(gc.pi.maxdepth + marker, maxdepth * 2 / 3); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 	c = getColor(DEPTH_GRID); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (i = marker; i < maxline; i += marker) { | 
					
						
							| 
									
										
										
										
											2013-05-09 18:29:18 -03:00
										 |  |  | 		QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(0, i), SCALEGC(1, i)); | 
					
						
							|  |  |  | 		QPen pen(defaultPen); | 
					
						
							|  |  |  | 		pen.setColor(c); | 
					
						
							|  |  |  | 		item->setPen(pen); | 
					
						
							|  |  |  | 		scene()->addItem(item); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	gc.leftx = 0; gc.rightx = maxtime; | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 	c = getColor(MEAN_DEPTH); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Show mean depth */ | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	if (! gc.printer) { | 
					
						
							| 
									
										
										
										
											2013-05-09 18:29:18 -03:00
										 |  |  | 		QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(0, gc.pi.meandepth), | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 								SCALEGC(gc.pi.entry[gc.pi.nr - 1].sec, gc.pi.meandepth)); | 
					
						
							| 
									
										
										
										
											2013-05-09 18:29:18 -03:00
										 |  |  | 		QPen pen(defaultPen); | 
					
						
							|  |  |  | 		pen.setColor(c); | 
					
						
							|  |  |  | 		item->setPen(pen); | 
					
						
							|  |  |  | 		scene()->addItem(item); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-04 19:36:40 -03:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * These are good for debugging text placement etc, | 
					
						
							|  |  |  | 	 * but not for actual display.. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (0) { | 
					
						
							|  |  |  | 		plot_smoothed_profile(gc, pi); | 
					
						
							|  |  |  | 		plot_minmax_profile(gc, pi); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-04 20:18:16 -03:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Do the depth profile for the neat fill */ | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	gc.topy = 0; gc.bottomy = maxdepth; | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	entry = gc.pi.entry; | 
					
						
							| 
									
										
										
										
											2013-05-04 20:18:16 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QPolygonF p; | 
					
						
							| 
									
										
										
										
											2013-05-05 13:42:33 -03:00
										 |  |  | 	QLinearGradient pat(0.0,0.0,0.0,scene()->height()); | 
					
						
							| 
									
										
										
										
											2013-05-05 09:50:11 -07:00
										 |  |  | 	QGraphicsPolygonItem *neatFill = NULL; | 
					
						
							| 
									
										
										
										
											2013-05-05 13:42:33 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	p.append(QPointF(SCALEGC(0, 0))); | 
					
						
							|  |  |  | 	for (i = 0; i < gc.pi.nr; i++, entry++) | 
					
						
							|  |  |  | 		p.append(QPointF(SCALEGC(entry->sec, entry->depth))); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Show any ceiling we may have encountered */ | 
					
						
							| 
									
										
										
										
											2013-05-29 15:32:31 +09:00
										 |  |  | 	if (prefs.profile_dc_ceiling) { | 
					
						
							|  |  |  | 		for (i = gc.pi.nr - 1; i >= 0; i--, entry--) { | 
					
						
							| 
									
										
										
										
											2013-10-14 21:20:53 +02:00
										 |  |  | 			if (!entry->in_deco) { | 
					
						
							|  |  |  | 				/* not in deco implies this is a safety stop, no ceiling */ | 
					
						
							| 
									
										
										
										
											2013-05-29 15:32:31 +09:00
										 |  |  | 				p.append(QPointF(SCALEGC(entry->sec, 0))); | 
					
						
							|  |  |  | 			} else if (entry->stopdepth < entry->depth) { | 
					
						
							|  |  |  | 				p.append(QPointF(SCALEGC(entry->sec, entry->stopdepth))); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				p.append(QPointF(SCALEGC(entry->sec, entry->depth))); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 	pat.setColorAt(1, getColor(DEPTH_BOTTOM)); | 
					
						
							|  |  |  | 	pat.setColorAt(0, getColor(DEPTH_TOP)); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 13:42:33 -03:00
										 |  |  | 	neatFill = new QGraphicsPolygonItem(); | 
					
						
							|  |  |  | 	neatFill->setPolygon(p); | 
					
						
							| 
									
										
										
										
											2013-05-04 20:18:16 -03:00
										 |  |  | 	neatFill->setBrush(QBrush(pat)); | 
					
						
							| 
									
										
										
										
											2013-05-09 18:29:18 -03:00
										 |  |  | 	neatFill->setPen(QPen(QBrush(Qt::transparent),0)); | 
					
						
							| 
									
										
										
										
											2013-05-04 20:18:16 -03:00
										 |  |  | 	scene()->addItem(neatFill); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 19:30:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 	/* if the user wants the deco ceiling more visible, do that here (this
 | 
					
						
							|  |  |  | 	 * basically draws over the background that we had allowed to shine | 
					
						
							|  |  |  | 	 * through so far) */ | 
					
						
							| 
									
										
										
										
											2013-05-29 15:32:31 +09:00
										 |  |  | 	if (prefs.profile_dc_ceiling && prefs.profile_red_ceiling) { | 
					
						
							| 
									
										
										
										
											2013-05-05 13:42:33 -03:00
										 |  |  | 		p.clear(); | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 		pat.setColorAt(0, getColor(CEILING_SHALLOW)); | 
					
						
							|  |  |  | 		pat.setColorAt(1, getColor(CEILING_DEEP)); | 
					
						
							| 
									
										
										
										
											2013-05-05 13:42:33 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 		entry = gc.pi.entry; | 
					
						
							|  |  |  | 		p.append(QPointF(SCALEGC(0, 0))); | 
					
						
							|  |  |  | 		for (i = 0; i < gc.pi.nr; i++, entry++) { | 
					
						
							| 
									
										
										
										
											2013-10-14 21:20:53 +02:00
										 |  |  | 			if (entry->in_deco && entry->stopdepth) { | 
					
						
							|  |  |  | 				if (entry->stopdepth < entry->depth) { | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 					p.append(QPointF(SCALEGC(entry->sec, entry->stopdepth))); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 					p.append(QPointF(SCALEGC(entry->sec, entry->depth))); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 				p.append(QPointF(SCALEGC(entry->sec, 0))); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-05 13:42:33 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		neatFill = new QGraphicsPolygonItem(); | 
					
						
							|  |  |  | 		neatFill->setBrush(QBrush(pat)); | 
					
						
							|  |  |  | 		neatFill->setPolygon(p); | 
					
						
							| 
									
										
										
										
											2013-05-09 18:29:18 -03:00
										 |  |  | 		neatFill->setPen(QPen(QBrush(Qt::NoBrush),0)); | 
					
						
							| 
									
										
										
										
											2013-05-05 13:42:33 -03:00
										 |  |  | 		scene()->addItem(neatFill); | 
					
						
							| 
									
										
										
										
											2013-05-29 15:32:31 +09:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-05 13:42:33 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 	/* finally, plot the calculated ceiling over all this */ | 
					
						
							| 
									
										
										
										
											2013-05-29 15:32:31 +09:00
										 |  |  | 	if (prefs.profile_calc_ceiling) { | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 		pat.setColorAt(0, getColor(CALC_CEILING_SHALLOW)); | 
					
						
							|  |  |  | 		pat.setColorAt(1, getColor(CALC_CEILING_DEEP)); | 
					
						
							| 
									
										
										
										
											2013-05-05 13:42:33 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 		entry = gc.pi.entry; | 
					
						
							| 
									
										
										
										
											2013-05-05 13:42:33 -03:00
										 |  |  | 		p.clear(); | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 		p.append(QPointF(SCALEGC(0, 0))); | 
					
						
							|  |  |  | 		for (i = 0; i < gc.pi.nr; i++, entry++) { | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 			if (entry->ceiling) | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 				p.append(QPointF(SCALEGC(entry->sec, entry->ceiling))); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 				p.append(QPointF(SCALEGC(entry->sec, 0))); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 		p.append(QPointF(SCALEGC((entry-1)->sec, 0))); | 
					
						
							| 
									
										
										
										
											2013-05-05 13:42:33 -03:00
										 |  |  | 		neatFill = new QGraphicsPolygonItem(); | 
					
						
							|  |  |  | 		neatFill->setPolygon(p); | 
					
						
							| 
									
										
										
										
											2013-05-09 18:29:18 -03:00
										 |  |  | 		neatFill->setPen(QPen(QBrush(Qt::NoBrush),0)); | 
					
						
							| 
									
										
										
										
											2013-05-05 19:30:54 -03:00
										 |  |  | 		neatFill->setBrush(pat); | 
					
						
							| 
									
										
										
										
											2013-05-05 13:42:33 -03:00
										 |  |  | 		scene()->addItem(neatFill); | 
					
						
							| 
									
										
										
										
											2013-05-29 15:32:31 +09:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-30 20:56:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* plot the calculated ceiling for all tissues */ | 
					
						
							| 
									
										
										
										
											2013-05-31 05:28:24 +09:00
										 |  |  | 	if (prefs.profile_calc_ceiling && prefs.calc_all_tissues){ | 
					
						
							| 
									
										
										
										
											2013-05-30 20:56:00 +02:00
										 |  |  | 		int k; | 
					
						
							|  |  |  | 		for (k=0; k<16; k++){ | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 			pat.setColorAt(0, getColor(CALC_CEILING_SHALLOW)); | 
					
						
							| 
									
										
										
										
											2013-05-31 05:28:24 +09:00
										 |  |  | 			pat.setColorAt(1, QColor(100, 100, 100, 50)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			entry = gc.pi.entry; | 
					
						
							|  |  |  | 			p.clear(); | 
					
						
							|  |  |  | 			p.append(QPointF(SCALEGC(0, 0))); | 
					
						
							|  |  |  | 			for (i = 0; i < gc.pi.nr; i++, entry++) { | 
					
						
							|  |  |  | 				if ((entry->ceilings)[k]) | 
					
						
							|  |  |  | 					p.append(QPointF(SCALEGC(entry->sec, (entry->ceilings)[k]))); | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 					p.append(QPointF(SCALEGC(entry->sec, 0))); | 
					
						
							| 
									
										
										
										
											2013-05-30 20:56:00 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-05-31 05:28:24 +09:00
										 |  |  | 			p.append(QPointF(SCALEGC((entry-1)->sec, 0))); | 
					
						
							|  |  |  | 			neatFill = new QGraphicsPolygonItem(); | 
					
						
							|  |  |  | 			neatFill->setPolygon(p); | 
					
						
							|  |  |  | 			neatFill->setBrush(pat); | 
					
						
							|  |  |  | 			scene()->addItem(neatFill); | 
					
						
							| 
									
										
										
										
											2013-05-30 20:56:00 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 	/* next show where we have been bad and crossed the dc's ceiling */ | 
					
						
							| 
									
										
										
										
											2013-05-29 15:32:31 +09:00
										 |  |  | 	if (prefs.profile_dc_ceiling) { | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 		pat.setColorAt(0, getColor(CEILING_SHALLOW)); | 
					
						
							|  |  |  | 		pat.setColorAt(1, getColor(CEILING_DEEP)); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-29 15:32:31 +09:00
										 |  |  | 		entry = gc.pi.entry; | 
					
						
							|  |  |  | 		p.clear(); | 
					
						
							|  |  |  | 		p.append(QPointF(SCALEGC(0, 0))); | 
					
						
							|  |  |  | 		for (i = 0; i < gc.pi.nr; i++, entry++) | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 			p.append(QPointF(SCALEGC(entry->sec, entry->depth))); | 
					
						
							| 
									
										
										
										
											2013-05-29 15:32:31 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-17 08:25:09 +02:00
										 |  |  | 		for (i-- , entry--; i >= 0; i--, entry--) { | 
					
						
							| 
									
										
										
										
											2013-10-14 21:20:53 +02:00
										 |  |  | 			if (entry->in_deco && entry->stopdepth > entry->depth) { | 
					
						
							| 
									
										
										
										
											2013-05-29 15:32:31 +09:00
										 |  |  | 				p.append(QPointF(SCALEGC(entry->sec, entry->stopdepth))); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				p.append(QPointF(SCALEGC(entry->sec, entry->depth))); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-05 13:42:33 -03:00
										 |  |  | 	neatFill = new QGraphicsPolygonItem(); | 
					
						
							|  |  |  | 	neatFill->setPolygon(p); | 
					
						
							| 
									
										
										
										
											2013-05-09 18:29:18 -03:00
										 |  |  | 	neatFill->setPen(QPen(QBrush(Qt::NoBrush),0)); | 
					
						
							| 
									
										
										
										
											2013-05-05 13:42:33 -03:00
										 |  |  | 	neatFill->setBrush(QBrush(pat)); | 
					
						
							|  |  |  | 	scene()->addItem(neatFill); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Now do it again for the velocity colors */ | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	entry = gc.pi.entry; | 
					
						
							|  |  |  | 	for (i = 1; i < gc.pi.nr; i++) { | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 		entry++; | 
					
						
							|  |  |  | 		sec = entry->sec; | 
					
						
							|  |  |  | 		/* we want to draw the segments in different colors
 | 
					
						
							|  |  |  | 		 * representing the vertical velocity, so we need to | 
					
						
							|  |  |  | 		 * chop this into short segments */ | 
					
						
							|  |  |  | 		depth = entry->depth; | 
					
						
							| 
									
										
										
										
											2013-05-09 18:29:18 -03:00
										 |  |  | 		QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(entry[-1].sec, entry[-1].depth), SCALEGC(sec, depth)); | 
					
						
							|  |  |  | 		QPen pen(defaultPen); | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 		pen.setColor(getColor((color_indice_t)(VELOCITY_COLORS_START_IDX + entry->velocity))); | 
					
						
							| 
									
										
										
										
											2013-05-09 18:29:18 -03:00
										 |  |  | 		item->setPen(pen); | 
					
						
							|  |  |  | 		scene()->addItem(item); | 
					
						
							| 
									
										
										
										
											2013-05-04 19:20:49 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-01 15:21:01 +03:00
										 |  |  | QGraphicsItemGroup *ProfileGraphicsView::plot_text(text_render_options_t *tro,const QPointF& pos, const QString& text, QGraphicsItem *parent) | 
					
						
							| 
									
										
										
										
											2013-05-06 15:35:17 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-01 15:21:01 +03:00
										 |  |  | 	QFont fnt(font()); | 
					
						
							|  |  |  | 	QFontMetrics fm(fnt); | 
					
						
							| 
									
										
										
										
											2013-05-06 15:35:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-03 17:50:39 +03:00
										 |  |  | 	if (printMode) | 
					
						
							| 
									
										
										
										
											2013-10-15 12:54:18 +03:00
										 |  |  | 		fnt.setPixelSize(tro->size); | 
					
						
							| 
									
										
										
										
											2013-10-03 17:50:39 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-01 15:21:01 +03:00
										 |  |  | 	QPointF point(SCALEGC(pos.x(), pos.y())); // This is neded because of the SCALE macro.
 | 
					
						
							| 
									
										
										
										
											2013-05-06 15:35:17 -03:00
										 |  |  | 	double dx = tro->hpos * (fm.width(text)); | 
					
						
							|  |  |  | 	double dy = tro->vpos * (fm.height()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-01 15:21:01 +03:00
										 |  |  | 	QGraphicsItemGroup *group = new QGraphicsItemGroup(parent); | 
					
						
							|  |  |  | 	QPainterPath textPath; | 
					
						
							|  |  |  | 	/* addText() uses bottom-left text baseline and the -3 offset is probably slightly off
 | 
					
						
							|  |  |  | 	 * for different font sizes. */ | 
					
						
							|  |  |  | 	textPath.addText(0, fm.height() - 3, fnt, text); | 
					
						
							|  |  |  | 	QPainterPathStroker stroker; | 
					
						
							|  |  |  | 	stroker.setWidth(3); | 
					
						
							|  |  |  | 	QGraphicsPathItem *strokedItem = new QGraphicsPathItem(stroker.createStroke(textPath), group); | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 	strokedItem->setBrush(QBrush(getColor(TEXT_BACKGROUND))); | 
					
						
							| 
									
										
										
										
											2013-07-01 15:21:01 +03:00
										 |  |  | 	strokedItem->setPen(Qt::NoPen); | 
					
						
							| 
									
										
										
										
											2013-05-06 15:35:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-01 15:21:01 +03:00
										 |  |  | 	QGraphicsPathItem *textItem = new QGraphicsPathItem(textPath, group); | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 	textItem->setBrush(QBrush(getColor(tro->color))); | 
					
						
							| 
									
										
										
										
											2013-07-01 15:21:01 +03:00
										 |  |  | 	textItem->setPen(Qt::NoPen); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	group->setPos(point.x() + dx, point.y() + dy); | 
					
						
							| 
									
										
										
										
											2013-07-12 17:20:59 +03:00
										 |  |  | 	if (!printMode) | 
					
						
							|  |  |  | 		group->setFlag(QGraphicsItem::ItemIgnoresTransformations); | 
					
						
							| 
									
										
										
										
											2013-05-10 13:57:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-22 21:25:05 -07:00
										 |  |  | 	if (!parent) | 
					
						
							| 
									
										
										
										
											2013-07-01 15:21:01 +03:00
										 |  |  | 		scene()->addItem(group); | 
					
						
							|  |  |  | 	return group; | 
					
						
							| 
									
										
										
										
											2013-05-06 15:35:17 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-04 16:12:43 -03:00
										 |  |  | void ProfileGraphicsView::resizeEvent(QResizeEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-25 02:07:07 +02:00
										 |  |  | 	refresh(); | 
					
						
							| 
									
										
										
										
											2013-05-04 16:12:43 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | void ProfileGraphicsView::plot_temperature_profile() | 
					
						
							| 
									
										
										
										
											2013-05-08 17:46:28 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	int last = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-09 15:28:50 -03:00
										 |  |  | 	if (!setup_temperature_limits(&gc)) | 
					
						
							| 
									
										
										
										
											2013-05-08 17:46:28 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QPointF from; | 
					
						
							|  |  |  | 	QPointF to; | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 	QColor color = getColor(TEMP_PLOT); | 
					
						
							| 
									
										
										
										
											2013-05-08 17:46:28 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	for (int i = 0; i < gc.pi.nr; i++) { | 
					
						
							|  |  |  | 		struct plot_data *entry = gc.pi.entry + i; | 
					
						
							| 
									
										
										
										
											2013-05-08 17:46:28 -03:00
										 |  |  | 		int mkelvin = entry->temperature; | 
					
						
							|  |  |  | 		int sec = entry->sec; | 
					
						
							|  |  |  | 		if (!mkelvin) { | 
					
						
							|  |  |  | 			if (!last) | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			mkelvin = last; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 		if (last) { | 
					
						
							|  |  |  | 			to = QPointF(SCALEGC(sec, mkelvin)); | 
					
						
							| 
									
										
										
										
											2013-05-08 17:46:28 -03:00
										 |  |  | 			QGraphicsLineItem *item = new QGraphicsLineItem(from.x(), from.y(), to.x(), to.y()); | 
					
						
							| 
									
										
										
										
											2013-05-09 18:29:18 -03:00
										 |  |  | 			QPen pen(defaultPen); | 
					
						
							|  |  |  | 			pen.setColor(color); | 
					
						
							|  |  |  | 			item->setPen(pen); | 
					
						
							| 
									
										
										
										
											2013-05-08 17:46:28 -03:00
										 |  |  | 			scene()->addItem(item); | 
					
						
							|  |  |  | 			from = to; | 
					
						
							| 
									
										
										
										
											2013-05-22 21:25:05 -07:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 			from = QPointF(SCALEGC(sec, mkelvin)); | 
					
						
							| 
									
										
										
										
											2013-05-08 17:46:28 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		last = mkelvin; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-10 19:35:22 -03:00
										 |  |  | void ProfileGraphicsView::edit_dive_time(const QString& time) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// this should set the full time of the dive.
 | 
					
						
							|  |  |  | 	refresh(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-25 02:39:21 +02:00
										 |  |  | void ProfileGraphicsView::on_rulerAction() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	rulerEnabled = !rulerEnabled; | 
					
						
							|  |  |  | 	refresh(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileGraphicsView::on_scaleAction() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	zoomed_plot = !zoomed_plot; | 
					
						
							|  |  |  | 	refresh(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | void ToolTipItem::addToolTip(const QString& toolTip, const QIcon& icon) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QGraphicsPixmapItem *iconItem = 0; | 
					
						
							| 
									
										
										
										
											2013-05-08 15:46:16 -07:00
										 |  |  | 	double yValue = title->boundingRect().height() + SPACING; | 
					
						
							|  |  |  | 	Q_FOREACH(ToolTip t, toolTips) { | 
					
						
							|  |  |  | 		yValue += t.second->boundingRect().height(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | 	if (!icon.isNull()) { | 
					
						
							|  |  |  | 		iconItem = new QGraphicsPixmapItem(icon.pixmap(ICON_SMALL,ICON_SMALL), this); | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 		iconItem->setPos(SPACING, yValue); | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem(toolTip, this); | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	textItem->setPos(SPACING + ICON_SMALL + SPACING, yValue); | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | 	textItem->setBrush(QBrush(Qt::white)); | 
					
						
							|  |  |  | 	textItem->setFlag(ItemIgnoresTransformations); | 
					
						
							| 
									
										
										
										
											2013-07-30 23:36:20 +02:00
										 |  |  | 	toolTips.push_back(qMakePair(iconItem, textItem)); | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | 	expand(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-10 11:07:44 -03:00
										 |  |  | void ToolTipItem::refresh(struct graphics_context *gc, QPointF pos) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	clear(); | 
					
						
							| 
									
										
										
										
											2013-08-08 12:30:56 +02:00
										 |  |  | 	int time = (pos.x() * gc->maxtime) / gc->maxx; | 
					
						
							| 
									
										
										
										
											2013-05-10 11:07:44 -03:00
										 |  |  | 	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()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | void ToolTipItem::clear() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Q_FOREACH(ToolTip t, toolTips) { | 
					
						
							|  |  |  | 		delete t.first; | 
					
						
							|  |  |  | 		delete t.second; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	toolTips.clear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ToolTipItem::setRect(const QRectF& r) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// qDeleteAll(childItems());
 | 
					
						
							| 
									
										
										
										
											2013-05-07 23:00:05 -03:00
										 |  |  | 	delete background; | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	rectangle = r; | 
					
						
							|  |  |  | 	setBrush(QBrush(Qt::white)); | 
					
						
							|  |  |  | 	setPen(QPen(Qt::black, 0.5)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 23:00:05 -03:00
										 |  |  | 	// Creates a 2pixels border
 | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | 	QPainterPath border; | 
					
						
							| 
									
										
										
										
											2013-05-07 23:00:05 -03:00
										 |  |  | 	border.addRoundedRect(-4, -4,  rectangle.width() + 8, rectangle.height() + 10, 3, 3); | 
					
						
							|  |  |  | 	border.addRoundedRect(-1, -1,  rectangle.width() + 3, rectangle.height() + 4, 3, 3); | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | 	setPath(border); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 23:00:05 -03:00
										 |  |  | 	QPainterPath bg; | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	bg.addRoundedRect(-1, -1, rectangle.width() + 3, rectangle.height() + 4, 3, 3); | 
					
						
							| 
									
										
										
										
											2013-05-07 23:00:05 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | 	QColor c = QColor(Qt::black); | 
					
						
							|  |  |  | 	c.setAlpha(155); | 
					
						
							| 
									
										
										
										
											2013-05-07 23:00:05 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QGraphicsPathItem *b = new QGraphicsPathItem(bg, this); | 
					
						
							|  |  |  | 	b->setFlag(ItemStacksBehindParent); | 
					
						
							|  |  |  | 	b->setFlags(ItemIgnoresTransformations); | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | 	b->setBrush(c); | 
					
						
							| 
									
										
										
										
											2013-05-07 23:00:05 -03:00
										 |  |  | 	b->setPen(QPen(QBrush(Qt::transparent), 0)); | 
					
						
							|  |  |  | 	b->setZValue(-10); | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | 	background = b; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 16:09:51 -07:00
										 |  |  | 	updateTitlePosition(); | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ToolTipItem::collapse() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QPropertyAnimation *animation = new QPropertyAnimation(this, "rect"); | 
					
						
							|  |  |  | 	animation->setDuration(100); | 
					
						
							| 
									
										
										
										
											2013-07-05 15:33:50 +03:00
										 |  |  | 	animation->setStartValue(nextRectangle); | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	animation->setEndValue(QRect(0, 0, ICON_SMALL, ICON_SMALL)); | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | 	animation->start(QAbstractAnimation::DeleteWhenStopped); | 
					
						
							| 
									
										
										
										
											2013-06-07 22:49:57 -03:00
										 |  |  | 	clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	status = COLLAPSED; | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ToolTipItem::expand() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-11 10:21:04 -03:00
										 |  |  | 	if (!title) | 
					
						
							| 
									
										
										
										
											2013-05-13 15:28:17 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 15:46:16 -07:00
										 |  |  | 	double width = 0, height = title->boundingRect().height() + SPACING; | 
					
						
							| 
									
										
										
										
											2013-05-07 16:09:51 -07:00
										 |  |  | 	Q_FOREACH(ToolTip t, toolTips) { | 
					
						
							|  |  |  | 		if (t.second->boundingRect().width() > width) | 
					
						
							|  |  |  | 			width = t.second->boundingRect().width(); | 
					
						
							| 
									
										
										
										
											2013-05-08 15:46:16 -07:00
										 |  |  | 		height += t.second->boundingRect().height(); | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-07 16:09:51 -07:00
										 |  |  | 	/*       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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-22 21:25:05 -07:00
										 |  |  | 	if (height < ICON_SMALL) | 
					
						
							| 
									
										
										
										
											2013-05-07 16:09:51 -07:00
										 |  |  | 		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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-07 22:49:57 -03:00
										 |  |  | 	status = EXPANDED; | 
					
						
							| 
									
										
										
										
											2013-05-07 15:44:54 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ToolTipItem::ToolTipItem(QGraphicsItem* parent): QGraphicsPathItem(parent), background(0) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-07 16:09:51 -07:00
										 |  |  | 	title = new QGraphicsSimpleTextItem(tr("Information"), this); | 
					
						
							|  |  |  | 	separator = new QGraphicsLineItem(this); | 
					
						
							| 
									
										
										
										
											2013-11-28 09:28:25 -02:00
										 |  |  | 	setFlags(ItemIgnoresTransformations | ItemIsMovable | ItemClipsChildrenToShape); | 
					
						
							| 
									
										
										
										
											2013-06-07 22:49:57 -03:00
										 |  |  | 	status = COLLAPSED; | 
					
						
							| 
									
										
										
										
											2013-05-07 16:09:51 -07:00
										 |  |  | 	updateTitlePosition(); | 
					
						
							|  |  |  | 	setZValue(99); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-10 13:54:17 -03:00
										 |  |  | ToolTipItem::~ToolTipItem() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	clear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 16:09:51 -07:00
										 |  |  | void ToolTipItem::updateTitlePosition() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	if (rectangle.width() < title->boundingRect().width() + SPACING*4) { | 
					
						
							| 
									
										
										
										
											2013-05-07 16:09:51 -07:00
										 |  |  | 		QRectF newRect = rectangle; | 
					
						
							|  |  |  | 		newRect.setWidth(title->boundingRect().width() + SPACING*4); | 
					
						
							| 
									
										
										
										
											2013-07-05 15:33:48 +03:00
										 |  |  | 		newRect.setHeight((newRect.height() && isExpanded()) ? newRect.height() : ICON_SMALL); | 
					
						
							| 
									
										
										
										
											2013-05-07 16:09:51 -07:00
										 |  |  | 		setRect(newRect); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 23:00:05 -03:00
										 |  |  | 	title->setPos(boundingRect().width()/2  - title->boundingRect().width()/2 -1, 0); | 
					
						
							| 
									
										
										
										
											2013-05-07 16:09:51 -07:00
										 |  |  | 	title->setFlag(ItemIgnoresTransformations); | 
					
						
							|  |  |  | 	title->setPen(QPen(Qt::white, 1)); | 
					
						
							|  |  |  | 	title->setBrush(Qt::white); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	if (toolTips.size() > 0) { | 
					
						
							| 
									
										
										
										
											2013-07-05 15:33:49 +03:00
										 |  |  | 		double x1 = 3; | 
					
						
							| 
									
										
										
										
											2013-05-07 16:09:51 -07:00
										 |  |  | 		double y1 = title->pos().y() + SPACING/2 + title->boundingRect().height(); | 
					
						
							| 
									
										
										
										
											2013-05-07 23:00:05 -03:00
										 |  |  | 		double x2 = boundingRect().width() - 10; | 
					
						
							| 
									
										
										
										
											2013-05-07 16:09:51 -07:00
										 |  |  | 		double y2 = y1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		separator->setLine(x1, y1, x2, y2); | 
					
						
							|  |  |  | 		separator->setFlag(ItemIgnoresTransformations); | 
					
						
							|  |  |  | 		separator->setPen(QPen(Qt::white)); | 
					
						
							| 
									
										
										
										
											2013-05-07 23:00:05 -03:00
										 |  |  | 		separator->show(); | 
					
						
							| 
									
										
										
										
											2013-05-08 14:56:06 -07:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2013-05-07 23:00:05 -03:00
										 |  |  | 		separator->hide(); | 
					
						
							| 
									
										
										
										
											2013-05-07 16:09:51 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-07 22:49:57 -03:00
										 |  |  | bool ToolTipItem::isExpanded() { | 
					
						
							|  |  |  | 	return status == EXPANDED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-10 14:28:44 -03:00
										 |  |  | void ToolTipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	persistPos(); | 
					
						
							| 
									
										
										
										
											2013-10-15 23:18:09 -03:00
										 |  |  | 	QGraphicsPathItem::mouseReleaseEvent(event); | 
					
						
							| 
									
										
										
										
											2013-06-10 14:28:44 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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() | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2013-11-26 13:53:00 -02:00
										 |  |  | 	if (!scene()->sceneRect().contains(value)){ | 
					
						
							|  |  |  | 		value = QPointF(0,0); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-06-10 14:28:44 -03:00
										 |  |  | 	setPos(value); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | QColor EventItem::getColor(const color_indice_t i) | 
					
						
							| 
									
										
										
										
											2013-05-07 16:09:51 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | 	return profile_color[i].at((isGrayscale) ? 1 : 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-04 23:53:53 -02:00
										 |  |  | EventItem::EventItem(struct event *ev, QGraphicsItem* parent, bool grayscale): QGraphicsPixmapItem(parent), ev(ev), isGrayscale(grayscale) | 
					
						
							| 
									
										
										
										
											2013-07-13 18:18:26 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-04 23:53:53 -02:00
										 |  |  | 	if(ev->name && strcmp(ev->name, "bookmark") == 0) { | 
					
						
							|  |  |  | 		setPixmap( QPixmap(QString(":flag")).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation)); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		setPixmap( QPixmap(QString(":warning")).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-07 16:09:51 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-06-10 19:02:06 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-25 02:07:07 +02:00
										 |  |  | RulerNodeItem::RulerNodeItem(QGraphicsItem *parent, graphics_context context) : QGraphicsEllipseItem(parent), gc(context), entry(NULL) , ruler(NULL) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	setRect(QRect(QPoint(-8,8),QPoint(8,-8))); | 
					
						
							|  |  |  | 	setBrush(QColor(0xff, 0, 0, 127)); | 
					
						
							|  |  |  | 	setPen(QColor("#FF0000")); | 
					
						
							|  |  |  | 	setFlag(QGraphicsItem::ItemIsMovable); | 
					
						
							|  |  |  | 	setFlag(ItemSendsGeometryChanges); | 
					
						
							|  |  |  | 	setFlag(ItemIgnoresTransformations); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RulerNodeItem::setRuler(RulerItem *r) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ruler = r; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RulerNodeItem::recalculate() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct plot_info *pi = &gc.pi; | 
					
						
							|  |  |  | 	struct plot_data *data = pi->entry+(pi->nr-1); | 
					
						
							|  |  |  | 	uint16_t count = 0; | 
					
						
							|  |  |  | 	if (x() < 0) { | 
					
						
							|  |  |  | 		setPos(0, y()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (x() > SCALEXGC(data->sec)) { | 
					
						
							|  |  |  | 		setPos(SCALEXGC(data->sec), y()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		data = pi->entry; | 
					
						
							|  |  |  | 		count=0; | 
					
						
							|  |  |  | 		while (SCALEXGC(data->sec) < x() && count < pi->nr) { | 
					
						
							|  |  |  | 			data = pi->entry+count; | 
					
						
							|  |  |  | 			count++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		setPos(SCALEGC(data->sec, data->depth)); | 
					
						
							|  |  |  | 		entry=data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QVariant RulerNodeItem::itemChange(GraphicsItemChange change, const QVariant &value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(change == ItemPositionHasChanged) { | 
					
						
							|  |  |  | 		recalculate(); | 
					
						
							|  |  |  | 		if(ruler != NULL) | 
					
						
							|  |  |  | 			ruler->recalculate(); | 
					
						
							|  |  |  | 		if (scene()) { | 
					
						
							|  |  |  | 			scene()->update(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return QGraphicsEllipseItem::itemChange(change, value); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RulerItem::RulerItem(QGraphicsItem *parent, RulerNodeItem *sourceNode, RulerNodeItem *destNode) : QGraphicsObject(parent), source(sourceNode), dest(destNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	recalculate(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RulerItem::recalculate() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char buffer[500]; | 
					
						
							|  |  |  | 	QPointF tmp; | 
					
						
							|  |  |  | 	QFont font; | 
					
						
							|  |  |  | 	QFontMetrics fm(font); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (source == NULL || dest == NULL) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	prepareGeometryChange(); | 
					
						
							|  |  |  | 	startPoint = mapFromItem(source, 0, 0); | 
					
						
							|  |  |  | 	endPoint = mapFromItem(dest, 0, 0); | 
					
						
							|  |  |  | 	if (startPoint.x() > endPoint.x()) { | 
					
						
							|  |  |  | 		tmp = endPoint; | 
					
						
							|  |  |  | 		endPoint = startPoint; | 
					
						
							|  |  |  | 		startPoint = tmp; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	QLineF line(startPoint, endPoint); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	compare_samples(source->entry, dest->entry, buffer, 500, 1); | 
					
						
							|  |  |  | 	text = QString(buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QRect r = fm.boundingRect(QRect(QPoint(10,-1*INT_MAX), QPoint(line.length()-10, 0)), Qt::TextWordWrap, text); | 
					
						
							|  |  |  | 	if (r.height() < 10) | 
					
						
							|  |  |  | 		height = 10; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		height = r.height(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QLineF line_n = line.normalVector(); | 
					
						
							|  |  |  | 	line_n.setLength(height); | 
					
						
							|  |  |  | 	if (scene()) { | 
					
						
							|  |  |  | 		/* Determine whether we draw down or upwards */ | 
					
						
							|  |  |  | 		if (scene()->sceneRect().contains(line_n.p2()) && | 
					
						
							|  |  |  | 				scene()->sceneRect().contains(endPoint+QPointF(line_n.dx(),line_n.dy()))) | 
					
						
							|  |  |  | 			paint_direction = -1; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			paint_direction = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RulerNodeItem *RulerItem::sourceNode() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return source; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RulerNodeItem *RulerItem::destNode() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return dest; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RulerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QLineF line(startPoint, endPoint); | 
					
						
							|  |  |  | 	QLineF line_n = line.normalVector(); | 
					
						
							|  |  |  | 	painter->setPen(QColor(Qt::black)); | 
					
						
							|  |  |  | 	painter->setBrush(Qt::NoBrush); | 
					
						
							|  |  |  | 	line_n.setLength(height); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (paint_direction == 1) | 
					
						
							|  |  |  | 		line_n.setAngle(line_n.angle()+180); | 
					
						
							|  |  |  | 	painter->drawLine(line); | 
					
						
							|  |  |  | 	painter->drawLine(line_n); | 
					
						
							|  |  |  | 	painter->drawLine(line_n.p1() + QPointF(line.dx(), line.dy()), line_n.p2() + QPointF(line.dx(), line.dy())); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//Draw Text
 | 
					
						
							|  |  |  | 	painter->save(); | 
					
						
							|  |  |  | 	painter->translate(startPoint.x(), startPoint.y()); | 
					
						
							|  |  |  | 	painter->rotate(line.angle()*-1); | 
					
						
							|  |  |  | 	if (paint_direction == 1) | 
					
						
							|  |  |  | 		painter->translate(0, height); | 
					
						
							|  |  |  | 	painter->setPen(Qt::black); | 
					
						
							|  |  |  | 	painter->drawText(QRectF(QPointF(10,-1*height), QPointF(line.length()-10, 0)), Qt::TextWordWrap, text); | 
					
						
							|  |  |  | 	painter->restore(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QRectF RulerItem::boundingRect() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return shape().controlPointRect(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QPainterPath RulerItem::shape() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QPainterPath path; | 
					
						
							|  |  |  | 	QLineF line(startPoint, endPoint); | 
					
						
							|  |  |  | 	QLineF line_n = line.normalVector(); | 
					
						
							|  |  |  | 	line_n.setLength(height); | 
					
						
							|  |  |  | 	if (paint_direction == 1) | 
					
						
							|  |  |  | 		line_n.setAngle(line_n.angle()+180); | 
					
						
							|  |  |  | 	path.moveTo(startPoint); | 
					
						
							|  |  |  | 	path.lineTo(line_n.p2()); | 
					
						
							|  |  |  | 	path.lineTo(line_n.p2() + QPointF(line.dx(), line.dy())); | 
					
						
							|  |  |  | 	path.lineTo(endPoint); | 
					
						
							|  |  |  | 	path.lineTo(startPoint); | 
					
						
							|  |  |  | 	return path; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-10 19:02:06 -03:00
										 |  |  | GraphicsTextEditor::GraphicsTextEditor(QGraphicsItem* parent): QGraphicsTextItem(parent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GraphicsTextEditor::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// Remove the proxy filter so we can focus here.
 | 
					
						
							|  |  |  | 	mainWindow()->graphics()->setFocusProxy(0); | 
					
						
							|  |  |  | 	setTextInteractionFlags(Qt::TextEditorInteraction | Qt::TextEditable); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GraphicsTextEditor::keyReleaseEvent(QKeyEvent* event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return){ | 
					
						
							|  |  |  | 		setTextInteractionFlags(Qt::NoTextInteraction); | 
					
						
							|  |  |  | 		emit editingFinished( toPlainText() ); | 
					
						
							|  |  |  | 		mainWindow()->graphics()->setFocusProxy(mainWindow()->dive_list()); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	emit textChanged( toPlainText() ); | 
					
						
							|  |  |  |     QGraphicsTextItem::keyReleaseEvent(event); | 
					
						
							|  |  |  | } |