| 
									
										
										
										
											2014-01-14 14:30:13 -02:00
										 |  |  | #include "profilewidget2.h"
 | 
					
						
							| 
									
										
										
										
											2014-01-15 12:00:23 -02:00
										 |  |  | #include "diveplotdatamodel.h"
 | 
					
						
							|  |  |  | #include "divepixmapitem.h"
 | 
					
						
							|  |  |  | #include "diverectitem.h"
 | 
					
						
							|  |  |  | #include "divecartesianaxis.h"
 | 
					
						
							|  |  |  | #include "diveprofileitem.h"
 | 
					
						
							| 
									
										
										
										
											2014-01-15 12:23:40 -02:00
										 |  |  | #include "helpers.h"
 | 
					
						
							| 
									
										
										
										
											2014-01-15 13:34:55 -02:00
										 |  |  | #include "profile.h"
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:02:32 -02:00
										 |  |  | #include "diveeventitem.h"
 | 
					
						
							| 
									
										
										
										
											2014-01-21 10:48:26 -02:00
										 |  |  | #include "divetextitem.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-05 14:34:45 -02:00
										 |  |  | #include "divetooltipitem.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-07 16:34:42 -02:00
										 |  |  | #include "animationfunctions.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-17 19:15:40 -03:00
										 |  |  | #include "planner.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-26 11:42:55 -08:00
										 |  |  | #include "device.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-27 15:20:03 -03:00
										 |  |  | #include "ruleritem.h"
 | 
					
						
							| 
									
										
										
										
											2014-04-16 22:03:44 +02:00
										 |  |  | #include "dive.h"
 | 
					
						
							|  |  |  | #include "pref.h"
 | 
					
						
							| 
									
										
										
										
											2014-03-15 21:12:34 -07:00
										 |  |  | #include <libdivecomputer/parser.h>
 | 
					
						
							| 
									
										
										
										
											2014-01-15 12:34:42 -02:00
										 |  |  | #include <QSignalTransition>
 | 
					
						
							| 
									
										
										
										
											2014-01-15 13:01:29 -02:00
										 |  |  | #include <QPropertyAnimation>
 | 
					
						
							| 
									
										
										
										
											2014-01-15 13:04:01 -02:00
										 |  |  | #include <QMenu>
 | 
					
						
							|  |  |  | #include <QContextMenuEvent>
 | 
					
						
							| 
									
										
										
										
											2014-01-16 18:39:13 -02:00
										 |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2014-02-04 21:47:50 -02:00
										 |  |  | #include <QScrollBar>
 | 
					
						
							| 
									
										
										
										
											2014-03-10 17:59:02 +02:00
										 |  |  | #include <QtCore/qmath.h>
 | 
					
						
							| 
									
										
										
										
											2014-03-15 21:12:34 -07:00
										 |  |  | #include <QMessageBox>
 | 
					
						
							| 
									
										
										
										
											2014-04-03 21:16:15 +02:00
										 |  |  | #include <QInputDialog>
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:02:32 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-15 13:20:05 -02:00
										 |  |  | #ifndef QT_NO_DEBUG
 | 
					
						
							|  |  |  | #include <QTableView>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-01-16 12:28:33 +07:00
										 |  |  | #include "mainwindow.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-12 13:50:35 -02:00
										 |  |  | #include <preferences.h>
 | 
					
						
							| 
									
										
										
										
											2014-01-15 13:20:05 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 15:32:39 -02:00
										 |  |  | /* This is the global 'Item position' variable.
 | 
					
						
							|  |  |  |  * it should tell you where to position things up | 
					
						
							|  |  |  |  * on the canvas. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * please, please, please, use this instead of | 
					
						
							|  |  |  |  * hard coding the item on the scene with a random | 
					
						
							|  |  |  |  * value. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | static struct _ItemPos { | 
					
						
							|  |  |  | 	struct _Pos { | 
					
						
							| 
									
										
										
										
											2014-02-07 15:32:39 -02:00
										 |  |  | 		QPointF on; | 
					
						
							|  |  |  | 		QPointF off; | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	struct _Axis { | 
					
						
							|  |  |  | 		_Pos pos; | 
					
						
							|  |  |  | 		QLineF shrinked; | 
					
						
							|  |  |  | 		QLineF expanded; | 
					
						
							| 
									
										
										
										
											2014-02-07 15:32:39 -02:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 	_Pos background; | 
					
						
							| 
									
										
										
										
											2014-02-07 21:17:14 -02:00
										 |  |  | 	_Pos dcLabel; | 
					
						
							| 
									
										
										
										
											2014-02-07 15:32:39 -02:00
										 |  |  | 	_Axis depth; | 
					
						
							| 
									
										
										
										
											2014-02-11 10:55:07 -08:00
										 |  |  | 	_Axis partialPressure; | 
					
						
							| 
									
										
										
										
											2014-02-07 15:32:39 -02:00
										 |  |  | 	_Axis time; | 
					
						
							|  |  |  | 	_Axis cylinder; | 
					
						
							|  |  |  | 	_Axis temperature; | 
					
						
							| 
									
										
										
										
											2014-02-19 17:18:26 -08:00
										 |  |  | 	_Axis heartBeat; | 
					
						
							| 
									
										
										
										
											2014-02-07 15:32:39 -02:00
										 |  |  | } itemPos; | 
					
						
							| 
									
										
										
										
											2014-02-07 14:59:58 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent), | 
					
						
							| 
									
										
										
										
											2014-01-15 12:00:23 -02:00
										 |  |  | 	currentState(INVALID), | 
					
						
							| 
									
										
										
										
											2014-06-10 00:06:00 +03:00
										 |  |  | 	dataModel(new DivePlotDataModel(this)), | 
					
						
							| 
									
										
										
										
											2014-02-04 21:47:50 -02:00
										 |  |  | 	zoomLevel(0), | 
					
						
							| 
									
										
										
										
											2014-03-10 17:59:02 +02:00
										 |  |  | 	zoomFactor(1.15), | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	background(new DivePixmapItem()), | 
					
						
							| 
									
										
										
										
											2014-06-10 00:06:00 +03:00
										 |  |  | 	backgroundFile(":poster"), | 
					
						
							| 
									
										
										
										
											2014-02-05 14:34:45 -02:00
										 |  |  | 	toolTipItem(new ToolTipItem()), | 
					
						
							| 
									
										
										
										
											2014-03-10 13:43:43 +02:00
										 |  |  | 	isPlotZoomed(prefs.zoomed_plot), | 
					
						
							| 
									
										
										
										
											2014-01-15 12:00:23 -02:00
										 |  |  | 	profileYAxis(new DepthAxis()), | 
					
						
							| 
									
										
										
										
											2014-01-27 15:14:42 -02:00
										 |  |  | 	gasYAxis(new PartialGasPressureAxis()), | 
					
						
							| 
									
										
										
										
											2014-01-17 06:30:47 +07:00
										 |  |  | 	temperatureAxis(new TemperatureAxis()), | 
					
						
							| 
									
										
										
										
											2014-01-15 12:00:23 -02:00
										 |  |  | 	timeAxis(new TimeAxis()), | 
					
						
							| 
									
										
										
										
											2014-02-07 14:14:36 -02:00
										 |  |  | 	diveProfileItem(new DiveProfileItem()), | 
					
						
							|  |  |  | 	temperatureItem(new DiveTemperatureItem()), | 
					
						
							| 
									
										
										
										
											2014-02-09 19:11:17 +01:00
										 |  |  | 	cylinderPressureAxis(new DiveCartesianAxis()), | 
					
						
							| 
									
										
										
										
											2014-02-07 14:14:36 -02:00
										 |  |  | 	gasPressureItem(new DiveGasPressureItem()), | 
					
						
							| 
									
										
										
										
											2014-01-22 15:08:19 -02:00
										 |  |  | 	meanDepth(new MeanDepthLine()), | 
					
						
							| 
									
										
										
										
											2014-01-21 14:59:19 -02:00
										 |  |  | 	diveComputerText(new DiveTextItem()), | 
					
						
							| 
									
										
										
										
											2014-02-07 14:14:36 -02:00
										 |  |  | 	diveCeiling(new DiveCalculatedCeiling()), | 
					
						
							| 
									
										
										
										
											2014-02-07 14:59:58 -02:00
										 |  |  | 	reportedCeiling(new DiveReportedCeiling()), | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	pn2GasItem(new PartialPressureGasItem()), | 
					
						
							|  |  |  | 	pheGasItem(new PartialPressureGasItem()), | 
					
						
							|  |  |  | 	po2GasItem(new PartialPressureGasItem()), | 
					
						
							| 
									
										
										
										
											2014-02-19 17:18:26 -08:00
										 |  |  | 	heartBeatAxis(new DiveCartesianAxis()), | 
					
						
							| 
									
										
										
										
											2014-02-27 12:39:53 -03:00
										 |  |  | 	heartBeatItem(new DiveHeartrateItem()), | 
					
						
							| 
									
										
										
										
											2014-08-05 18:27:00 -03:00
										 |  |  | 	mouseFollowerVertical(new DiveLineItem()), | 
					
						
							| 
									
										
										
										
											2014-08-06 10:54:37 -07:00
										 |  |  | 	mouseFollowerHorizontal(new DiveLineItem()), | 
					
						
							| 
									
										
										
										
											2014-03-25 23:34:09 +02:00
										 |  |  | 	rulerItem(new RulerItem2()), | 
					
						
							|  |  |  | 	isGrayscale(false), | 
					
						
							| 
									
										
										
										
											2014-05-26 17:51:46 -03:00
										 |  |  | 	printMode(false), | 
					
						
							| 
									
										
										
										
											2014-06-30 19:08:16 -03:00
										 |  |  | 	shouldCalculateMaxTime(true), | 
					
						
							| 
									
										
										
										
											2014-07-09 13:09:52 -07:00
										 |  |  | 	shouldCalculateMaxDepth(true), | 
					
						
							|  |  |  | 	fontPrintScale(1.0) | 
					
						
							| 
									
										
										
										
											2014-01-14 14:30:13 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-09 19:11:17 +01:00
										 |  |  | 	memset(&plotInfo, 0, sizeof(plotInfo)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 14:59:58 -02:00
										 |  |  | 	setupSceneAndFlags(); | 
					
						
							|  |  |  | 	setupItemSizes(); | 
					
						
							|  |  |  | 	setupItemOnScene(); | 
					
						
							|  |  |  | 	addItemsToScene(); | 
					
						
							|  |  |  | 	scene()->installEventFilter(this); | 
					
						
							| 
									
										
										
										
											2014-02-12 13:50:35 -02:00
										 |  |  | 	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged())); | 
					
						
							| 
									
										
										
										
											2014-02-07 16:34:42 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-24 12:39:40 -03:00
										 |  |  | 	QAction *action = NULL; | 
					
						
							|  |  |  | #define ADD_ACTION(SHORTCUT, Slot)                                  \
 | 
					
						
							|  |  |  | 	action = new QAction(this);                                 \ | 
					
						
							|  |  |  | 	action->setShortcut(SHORTCUT);                              \ | 
					
						
							|  |  |  | 	action->setShortcutContext(Qt::WindowShortcut);             \ | 
					
						
							|  |  |  | 	addAction(action);                                          \ | 
					
						
							|  |  |  | 	connect(action, SIGNAL(triggered(bool)), this, SLOT(Slot)); \ | 
					
						
							|  |  |  | 	actionsForKeys[SHORTCUT] = action; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ADD_ACTION(Qt::Key_Escape, keyEscAction()); | 
					
						
							|  |  |  | 	ADD_ACTION(Qt::Key_Delete, keyDeleteAction()); | 
					
						
							|  |  |  | 	ADD_ACTION(Qt::Key_Up, keyUpAction()); | 
					
						
							|  |  |  | 	ADD_ACTION(Qt::Key_Down, keyDownAction()); | 
					
						
							|  |  |  | 	ADD_ACTION(Qt::Key_Left, keyLeftAction()); | 
					
						
							|  |  |  | 	ADD_ACTION(Qt::Key_Right, keyRightAction()); | 
					
						
							|  |  |  | #undef ADD_ACTION
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 14:59:58 -02:00
										 |  |  | #ifndef QT_NO_DEBUG
 | 
					
						
							|  |  |  | 	QTableView *diveDepthTableView = new QTableView(); | 
					
						
							|  |  |  | 	diveDepthTableView->setModel(dataModel); | 
					
						
							| 
									
										
										
										
											2014-03-07 12:42:13 -03:00
										 |  |  | 	diveDepthTableView->show(); | 
					
						
							| 
									
										
										
										
											2014-02-07 14:59:58 -02:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-15 12:23:40 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-19 14:39:34 +09:00
										 |  |  | #define SUBSURFACE_OBJ_DATA 1
 | 
					
						
							|  |  |  | #define SUBSURFACE_OBJ_DC_TEXT 0x42
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 14:59:58 -02:00
										 |  |  | void ProfileWidget2::addItemsToScene() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	scene()->addItem(background); | 
					
						
							|  |  |  | 	scene()->addItem(toolTipItem); | 
					
						
							|  |  |  | 	scene()->addItem(profileYAxis); | 
					
						
							|  |  |  | 	scene()->addItem(gasYAxis); | 
					
						
							|  |  |  | 	scene()->addItem(temperatureAxis); | 
					
						
							|  |  |  | 	scene()->addItem(timeAxis); | 
					
						
							|  |  |  | 	scene()->addItem(diveProfileItem); | 
					
						
							|  |  |  | 	scene()->addItem(cylinderPressureAxis); | 
					
						
							|  |  |  | 	scene()->addItem(temperatureItem); | 
					
						
							|  |  |  | 	scene()->addItem(gasPressureItem); | 
					
						
							|  |  |  | 	scene()->addItem(meanDepth); | 
					
						
							| 
									
										
										
										
											2014-05-19 14:39:34 +09:00
										 |  |  | 	// I cannot seem to figure out if an object that I find with itemAt() on the scene
 | 
					
						
							|  |  |  | 	// is the object I am looking for - my guess is there's a simple way in Qt to do that
 | 
					
						
							|  |  |  | 	// but nothing I tried worked.
 | 
					
						
							|  |  |  | 	// so instead this adds a special magic key/value pair to the object to mark it
 | 
					
						
							|  |  |  | 	diveComputerText->setData(SUBSURFACE_OBJ_DATA, SUBSURFACE_OBJ_DC_TEXT); | 
					
						
							| 
									
										
										
										
											2014-02-07 14:59:58 -02:00
										 |  |  | 	scene()->addItem(diveComputerText); | 
					
						
							|  |  |  | 	scene()->addItem(diveCeiling); | 
					
						
							|  |  |  | 	scene()->addItem(reportedCeiling); | 
					
						
							|  |  |  | 	scene()->addItem(pn2GasItem); | 
					
						
							|  |  |  | 	scene()->addItem(pheGasItem); | 
					
						
							|  |  |  | 	scene()->addItem(po2GasItem); | 
					
						
							| 
									
										
										
										
											2014-02-19 17:18:26 -08:00
										 |  |  | 	scene()->addItem(heartBeatAxis); | 
					
						
							|  |  |  | 	scene()->addItem(heartBeatItem); | 
					
						
							| 
									
										
										
										
											2014-02-27 15:20:03 -03:00
										 |  |  | 	scene()->addItem(rulerItem); | 
					
						
							|  |  |  | 	scene()->addItem(rulerItem->sourceNode()); | 
					
						
							|  |  |  | 	scene()->addItem(rulerItem->destNode()); | 
					
						
							| 
									
										
										
										
											2014-08-05 18:27:00 -03:00
										 |  |  | 	scene()->addItem(mouseFollowerHorizontal); | 
					
						
							|  |  |  | 	scene()->addItem(mouseFollowerVertical); | 
					
						
							| 
									
										
										
										
											2014-08-05 15:47:02 -07:00
										 |  |  | 	QPen pen(QColor(Qt::red).lighter()); | 
					
						
							|  |  |  | 	pen.setWidth(0); | 
					
						
							|  |  |  | 	mouseFollowerHorizontal->setPen(pen); | 
					
						
							|  |  |  | 	mouseFollowerVertical->setPen(pen); | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	Q_FOREACH (DiveCalculatedTissue *tissue, allTissues) { | 
					
						
							| 
									
										
										
										
											2014-02-07 14:59:58 -02:00
										 |  |  | 		scene()->addItem(tissue); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-15 12:23:40 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 14:59:58 -02:00
										 |  |  | void ProfileWidget2::setupItemOnScene() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-07 16:34:42 -02:00
										 |  |  | 	background->setZValue(9999); | 
					
						
							| 
									
										
										
										
											2014-03-12 00:09:54 +02:00
										 |  |  | 	toolTipItem->setZValue(9998); | 
					
						
							| 
									
										
										
										
											2014-02-07 14:59:58 -02:00
										 |  |  | 	toolTipItem->setTimeAxis(timeAxis); | 
					
						
							| 
									
										
										
										
											2014-03-12 00:09:54 +02:00
										 |  |  | 	rulerItem->setZValue(9997); | 
					
						
							| 
									
										
										
										
											2014-01-23 17:54:34 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 17:59:21 -02:00
										 |  |  | 	profileYAxis->setOrientation(DiveCartesianAxis::TopToBottom); | 
					
						
							|  |  |  | 	profileYAxis->setMinimum(0); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	profileYAxis->setTickInterval(M_OR_FT(10, 30)); | 
					
						
							| 
									
										
										
										
											2014-03-19 17:06:18 -03:00
										 |  |  | 	profileYAxis->setTickSize(0.5); | 
					
						
							| 
									
										
										
										
											2014-02-15 22:43:27 -02:00
										 |  |  | 	profileYAxis->setLineSize(96); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-16 14:16:39 -08:00
										 |  |  | 	timeAxis->setLineSize(92); | 
					
						
							| 
									
										
										
										
											2014-03-19 17:06:18 -03:00
										 |  |  | 	timeAxis->setTickSize(-0.5); | 
					
						
							| 
									
										
										
										
											2014-02-07 17:59:21 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-23 17:54:34 -02:00
										 |  |  | 	gasYAxis->setOrientation(DiveCartesianAxis::BottomToTop); | 
					
						
							|  |  |  | 	gasYAxis->setTickInterval(1); | 
					
						
							| 
									
										
										
										
											2014-02-07 19:42:47 -02:00
										 |  |  | 	gasYAxis->setTickSize(1); | 
					
						
							| 
									
										
										
										
											2014-01-27 15:14:42 -02:00
										 |  |  | 	gasYAxis->setMinimum(0); | 
					
						
							|  |  |  | 	gasYAxis->setModel(dataModel); | 
					
						
							| 
									
										
										
										
											2014-02-15 11:15:57 -08:00
										 |  |  | 	gasYAxis->setFontLabelScale(0.7); | 
					
						
							| 
									
										
										
										
											2014-02-15 22:43:27 -02:00
										 |  |  | 	gasYAxis->setLineSize(96); | 
					
						
							| 
									
										
										
										
											2014-01-16 18:39:13 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-19 17:18:26 -08:00
										 |  |  | 	heartBeatAxis->setOrientation(DiveCartesianAxis::BottomToTop); | 
					
						
							| 
									
										
										
										
											2014-04-07 22:15:21 +02:00
										 |  |  | 	heartBeatAxis->setTickSize(0.2); | 
					
						
							| 
									
										
										
										
											2014-02-19 17:18:26 -08:00
										 |  |  | 	heartBeatAxis->setTickInterval(10); | 
					
						
							|  |  |  | 	heartBeatAxis->setFontLabelScale(0.7); | 
					
						
							|  |  |  | 	heartBeatAxis->setLineSize(96); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 19:28:33 -02:00
										 |  |  | 	temperatureAxis->setOrientation(DiveCartesianAxis::BottomToTop); | 
					
						
							| 
									
										
										
										
											2014-01-16 18:39:13 -02:00
										 |  |  | 	temperatureAxis->setTickSize(2); | 
					
						
							|  |  |  | 	temperatureAxis->setTickInterval(300); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-17 15:34:15 -02:00
										 |  |  | 	cylinderPressureAxis->setOrientation(DiveCartesianAxis::BottomToTop); | 
					
						
							| 
									
										
										
										
											2014-01-17 14:28:59 -02:00
										 |  |  | 	cylinderPressureAxis->setTickSize(2); | 
					
						
							|  |  |  | 	cylinderPressureAxis->setTickInterval(30000); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	meanDepth->setLine(0, 0, 96, 0); | 
					
						
							| 
									
										
										
										
											2014-01-18 14:38:21 -08:00
										 |  |  | 	meanDepth->setX(3); | 
					
						
							|  |  |  | 	meanDepth->setPen(QPen(QBrush(Qt::red), 0, Qt::SolidLine)); | 
					
						
							| 
									
										
										
										
											2014-01-22 15:29:25 -02:00
										 |  |  | 	meanDepth->setZValue(1); | 
					
						
							| 
									
										
										
										
											2014-02-12 14:41:59 -02:00
										 |  |  | 	meanDepth->setAxis(profileYAxis); | 
					
						
							| 
									
										
										
										
											2014-01-15 12:23:40 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-16 14:16:39 -08:00
										 |  |  | 	diveComputerText->setAlignment(Qt::AlignRight | Qt::AlignTop); | 
					
						
							| 
									
										
										
										
											2014-03-25 23:34:10 +02:00
										 |  |  | 	diveComputerText->setBrush(getColor(TIME_TEXT, isGrayscale)); | 
					
						
							| 
									
										
										
										
											2014-01-21 10:48:26 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 16:42:00 -03:00
										 |  |  | 	rulerItem->setAxis(timeAxis, profileYAxis); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 14:14:36 -02:00
										 |  |  | 	setupItem(reportedCeiling, timeAxis, profileYAxis, dataModel, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1); | 
					
						
							|  |  |  | 	setupItem(diveCeiling, timeAxis, profileYAxis, dataModel, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	for (int i = 0; i < 16; i++) { | 
					
						
							| 
									
										
										
										
											2014-01-23 15:02:12 -02:00
										 |  |  | 		DiveCalculatedTissue *tissueItem = new DiveCalculatedTissue(); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		setupItem(tissueItem, timeAxis, profileYAxis, dataModel, DivePlotDataModel::TISSUE_1 + i, DivePlotDataModel::TIME, 1 + i); | 
					
						
							| 
									
										
										
										
											2014-01-23 15:02:12 -02:00
										 |  |  | 		allTissues.append(tissueItem); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-07 14:14:36 -02:00
										 |  |  | 	setupItem(gasPressureItem, timeAxis, cylinderPressureAxis, dataModel, DivePlotDataModel::TEMPERATURE, DivePlotDataModel::TIME, 1); | 
					
						
							|  |  |  | 	setupItem(temperatureItem, timeAxis, temperatureAxis, dataModel, DivePlotDataModel::TEMPERATURE, DivePlotDataModel::TIME, 1); | 
					
						
							| 
									
										
										
										
											2014-02-19 17:18:26 -08:00
										 |  |  | 	setupItem(heartBeatItem, timeAxis, heartBeatAxis, dataModel, DivePlotDataModel::HEARTBEAT, DivePlotDataModel::TIME, 1); | 
					
						
							| 
									
										
										
										
											2014-02-07 14:14:36 -02:00
										 |  |  | 	setupItem(diveProfileItem, timeAxis, profileYAxis, dataModel, DivePlotDataModel::DEPTH, DivePlotDataModel::TIME, 0); | 
					
						
							| 
									
										
										
										
											2014-01-23 16:03:19 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | #define CREATE_PP_GAS(ITEM, VERTICAL_COLUMN, COLOR, COLOR_ALERT, THRESHOULD_SETTINGS, VISIBILITY_SETTINGS)              \
 | 
					
						
							| 
									
										
										
										
											2014-02-07 14:14:36 -02:00
										 |  |  | 	setupItem(ITEM, timeAxis, gasYAxis, dataModel, DivePlotDataModel::VERTICAL_COLUMN, DivePlotDataModel::TIME, 0); \ | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	ITEM->setThreshouldSettingsKey(THRESHOULD_SETTINGS);                                                            \ | 
					
						
							|  |  |  | 	ITEM->setVisibilitySettingsKey(VISIBILITY_SETTINGS);                                                            \ | 
					
						
							| 
									
										
										
										
											2014-03-25 23:34:10 +02:00
										 |  |  | 	ITEM->setColors(getColor(COLOR, isGrayscale), getColor(COLOR_ALERT, isGrayscale));                              \ | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	ITEM->settingsChanged();                                                                                        \ | 
					
						
							| 
									
										
										
										
											2014-02-15 23:01:20 -02:00
										 |  |  | 	ITEM->setZValue(99); | 
					
						
							| 
									
										
										
										
											2014-01-27 15:14:42 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	CREATE_PP_GAS(pn2GasItem, PN2, PN2, PN2_ALERT, "pn2threshold", "pn2graph"); | 
					
						
							|  |  |  | 	CREATE_PP_GAS(pheGasItem, PHE, PHE, PHE_ALERT, "phethreshold", "phegraph"); | 
					
						
							|  |  |  | 	CREATE_PP_GAS(po2GasItem, PO2, PO2, PO2_ALERT, "po2threshold", "po2graph"); | 
					
						
							| 
									
										
										
										
											2014-01-27 15:14:42 -02:00
										 |  |  | #undef CREATE_PP_GAS
 | 
					
						
							| 
									
										
										
										
											2014-01-23 18:03:28 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-12 14:24:19 -02:00
										 |  |  | 	temperatureAxis->setTextVisible(false); | 
					
						
							| 
									
										
										
										
											2014-02-15 22:54:41 -02:00
										 |  |  | 	temperatureAxis->setLinesVisible(false); | 
					
						
							| 
									
										
										
										
											2014-02-12 14:24:19 -02:00
										 |  |  | 	cylinderPressureAxis->setTextVisible(false); | 
					
						
							| 
									
										
										
										
											2014-02-15 22:54:41 -02:00
										 |  |  | 	cylinderPressureAxis->setLinesVisible(false); | 
					
						
							|  |  |  | 	timeAxis->setLinesVisible(true); | 
					
						
							|  |  |  | 	profileYAxis->setLinesVisible(true); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	gasYAxis->setZValue(timeAxis->zValue() + 1); | 
					
						
							| 
									
										
										
										
											2014-02-19 17:18:26 -08:00
										 |  |  | 	heartBeatAxis->setTextVisible(true); | 
					
						
							|  |  |  | 	heartBeatAxis->setLinesVisible(true); | 
					
						
							| 
									
										
										
										
											2014-02-07 14:59:58 -02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-15 13:01:29 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-09 10:59:31 -03:00
										 |  |  | void ProfileWidget2::replot() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-04-03 12:52:05 -07:00
										 |  |  | 	dataModel->clear(); | 
					
						
							| 
									
										
										
										
											2014-07-09 11:19:08 -07:00
										 |  |  | 	plotDive(0, true); // simply plot the displayed_dive again
 | 
					
						
							| 
									
										
										
										
											2014-03-09 10:59:31 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 14:59:58 -02:00
										 |  |  | void ProfileWidget2::setupItemSizes() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-07 17:38:00 -02:00
										 |  |  | 	// Scene is *always* (double) 100 / 100.
 | 
					
						
							|  |  |  | 	// Background Config
 | 
					
						
							|  |  |  | 	/* Much probably a better math is needed here.
 | 
					
						
							|  |  |  | 	 * good thing is that we only need to change the | 
					
						
							|  |  |  | 	 * Axis and everything else is auto-adjusted.* | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 15:32:39 -02:00
										 |  |  | 	itemPos.background.on.setX(0); | 
					
						
							|  |  |  | 	itemPos.background.on.setY(0); | 
					
						
							|  |  |  | 	itemPos.background.off.setX(0); | 
					
						
							|  |  |  | 	itemPos.background.off.setY(110); | 
					
						
							| 
									
										
										
										
											2014-02-07 17:38:00 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//Depth Axis Config
 | 
					
						
							|  |  |  | 	itemPos.depth.pos.on.setX(3); | 
					
						
							|  |  |  | 	itemPos.depth.pos.on.setY(3); | 
					
						
							|  |  |  | 	itemPos.depth.pos.off.setX(-2); | 
					
						
							|  |  |  | 	itemPos.depth.pos.off.setY(3); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	itemPos.depth.expanded.setP1(QPointF(0, 0)); | 
					
						
							|  |  |  | 	itemPos.depth.expanded.setP2(QPointF(0, 86)); | 
					
						
							|  |  |  | 	itemPos.depth.shrinked.setP1(QPointF(0, 0)); | 
					
						
							|  |  |  | 	itemPos.depth.shrinked.setP2(QPointF(0, 60)); | 
					
						
							| 
									
										
										
										
											2014-02-07 17:38:00 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Time Axis Config
 | 
					
						
							|  |  |  | 	itemPos.time.pos.on.setX(3); | 
					
						
							| 
									
										
										
										
											2014-02-16 14:16:39 -08:00
										 |  |  | 	itemPos.time.pos.on.setY(95); | 
					
						
							| 
									
										
										
										
											2014-02-07 17:38:00 -02:00
										 |  |  | 	itemPos.time.pos.off.setX(3); | 
					
						
							|  |  |  | 	itemPos.time.pos.off.setY(110); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	itemPos.time.expanded.setP1(QPointF(0, 0)); | 
					
						
							|  |  |  | 	itemPos.time.expanded.setP2(QPointF(94, 0)); | 
					
						
							| 
									
										
										
										
											2014-02-07 19:42:47 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Partial Gas Axis Config
 | 
					
						
							| 
									
										
										
										
											2014-02-11 10:55:07 -08:00
										 |  |  | 	itemPos.partialPressure.pos.on.setX(97); | 
					
						
							| 
									
										
										
										
											2014-02-16 14:16:39 -08:00
										 |  |  | 	itemPos.partialPressure.pos.on.setY(65); | 
					
						
							| 
									
										
										
										
											2014-02-11 10:55:07 -08:00
										 |  |  | 	itemPos.partialPressure.pos.off.setX(110); | 
					
						
							| 
									
										
										
										
											2014-02-15 23:01:20 -02:00
										 |  |  | 	itemPos.partialPressure.pos.off.setY(63); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	itemPos.partialPressure.expanded.setP1(QPointF(0, 0)); | 
					
						
							|  |  |  | 	itemPos.partialPressure.expanded.setP2(QPointF(0, 30)); | 
					
						
							| 
									
										
										
										
											2014-02-07 19:42:47 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// cylinder axis config
 | 
					
						
							|  |  |  | 	itemPos.cylinder.pos.on.setX(3); | 
					
						
							|  |  |  | 	itemPos.cylinder.pos.on.setY(20); | 
					
						
							|  |  |  | 	itemPos.cylinder.pos.off.setX(-10); | 
					
						
							|  |  |  | 	itemPos.cylinder.pos.off.setY(20); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	itemPos.cylinder.expanded.setP1(QPointF(0, 15)); | 
					
						
							|  |  |  | 	itemPos.cylinder.expanded.setP2(QPointF(0, 50)); | 
					
						
							|  |  |  | 	itemPos.cylinder.shrinked.setP1(QPointF(0, 0)); | 
					
						
							|  |  |  | 	itemPos.cylinder.shrinked.setP2(QPointF(0, 20)); | 
					
						
							| 
									
										
										
										
											2014-02-07 21:17:14 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-16 14:16:39 -08:00
										 |  |  | 	// Temperature axis config
 | 
					
						
							| 
									
										
										
										
											2014-02-07 21:17:14 -02:00
										 |  |  | 	itemPos.temperature.pos.on.setX(3); | 
					
						
							|  |  |  | 	itemPos.temperature.pos.on.setY(40); | 
					
						
							|  |  |  | 	itemPos.temperature.pos.off.setX(-10); | 
					
						
							|  |  |  | 	itemPos.temperature.pos.off.setY(40); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	itemPos.temperature.expanded.setP1(QPointF(0, 30)); | 
					
						
							|  |  |  | 	itemPos.temperature.expanded.setP2(QPointF(0, 50)); | 
					
						
							|  |  |  | 	itemPos.temperature.shrinked.setP1(QPointF(0, 5)); | 
					
						
							|  |  |  | 	itemPos.temperature.shrinked.setP2(QPointF(0, 15)); | 
					
						
							| 
									
										
										
										
											2014-02-07 21:17:14 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-19 17:18:26 -08:00
										 |  |  | 	itemPos.heartBeat.pos.on.setX(3); | 
					
						
							|  |  |  | 	itemPos.heartBeat.pos.on.setY(60); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	itemPos.heartBeat.expanded.setP1(QPointF(0, 0)); | 
					
						
							|  |  |  | 	itemPos.heartBeat.expanded.setP2(QPointF(0, 20)); | 
					
						
							| 
									
										
										
										
											2014-02-19 17:18:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 21:17:14 -02:00
										 |  |  | 	itemPos.dcLabel.on.setX(3); | 
					
						
							| 
									
										
										
										
											2014-02-16 14:16:39 -08:00
										 |  |  | 	itemPos.dcLabel.on.setY(100); | 
					
						
							| 
									
										
										
										
											2014-02-07 21:17:14 -02:00
										 |  |  | 	itemPos.dcLabel.off.setX(-10); | 
					
						
							| 
									
										
										
										
											2014-02-16 14:16:39 -08:00
										 |  |  | 	itemPos.dcLabel.off.setY(100); | 
					
						
							| 
									
										
										
										
											2014-01-14 14:30:13 -02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-07 14:59:58 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-21 18:22:44 -03:00
										 |  |  | void ProfileWidget2::setupItem(AbstractProfilePolygonItem *item, DiveCartesianAxis *hAxis, | 
					
						
							|  |  |  | 	DiveCartesianAxis *vAxis, DivePlotDataModel *model, | 
					
						
							|  |  |  | 	int vData, int hData, int zValue) | 
					
						
							| 
									
										
										
										
											2014-02-07 14:14:36 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-07 14:59:58 -02:00
										 |  |  | 	item->setHorizontalAxis(hAxis); | 
					
						
							|  |  |  | 	item->setVerticalAxis(vAxis); | 
					
						
							|  |  |  | 	item->setModel(model); | 
					
						
							|  |  |  | 	item->setVerticalDataColumn(vData); | 
					
						
							|  |  |  | 	item->setHorizontalDataColumn(hData); | 
					
						
							|  |  |  | 	item->setZValue(zValue); | 
					
						
							| 
									
										
										
										
											2014-02-07 14:14:36 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 14:59:58 -02:00
										 |  |  | void ProfileWidget2::setupSceneAndFlags() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	setScene(new QGraphicsScene()); | 
					
						
							|  |  |  | 	scene()->setSceneRect(0, 0, 100, 100); | 
					
						
							|  |  |  | 	setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 
					
						
							|  |  |  | 	setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 
					
						
							|  |  |  | 	scene()->setItemIndexMethod(QGraphicsScene::NoIndex); | 
					
						
							|  |  |  | 	setOptimizationFlags(QGraphicsView::DontSavePainterState); | 
					
						
							|  |  |  | 	setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); | 
					
						
							|  |  |  | 	setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); | 
					
						
							|  |  |  | 	setMouseTracking(true); | 
					
						
							|  |  |  | 	background->setFlag(QGraphicsItem::ItemIgnoresTransformations); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-14 14:30:13 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Currently just one dive, but the plan is to enable All of the selected dives.
 | 
					
						
							| 
									
										
										
										
											2014-07-09 11:19:08 -07:00
										 |  |  | void ProfileWidget2::plotDive(struct dive *d, bool force) | 
					
						
							| 
									
										
										
										
											2014-01-14 14:30:13 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-03-11 18:54:28 -03:00
										 |  |  | 	static bool firstCall = true; | 
					
						
							| 
									
										
										
										
											2014-06-04 13:41:50 -07:00
										 |  |  | 	QTime measureDuration; // let's measure how long this takes us (maybe we'll turn of TTL calculation later
 | 
					
						
							|  |  |  | 	measureDuration.start(); | 
					
						
							| 
									
										
										
										
											2014-03-11 18:54:28 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-03 14:34:24 -07:00
										 |  |  | 	if (currentState != ADD && currentState != PLAN) { | 
					
						
							|  |  |  | 		if (!d) { | 
					
						
							|  |  |  | 			if (selected_dive == -1) | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			d = current_dive; // display the current dive
 | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-01-15 13:34:55 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-03 14:34:24 -07:00
										 |  |  | 		// No need to do this again if we are already showing the same dive
 | 
					
						
							|  |  |  | 		// computer of the same dive, so we check the unique id of the dive
 | 
					
						
							|  |  |  | 		// and the selected dive computer number against the ones we are
 | 
					
						
							|  |  |  | 		// showing (can't compare the dive pointers as those might change).
 | 
					
						
							| 
									
										
										
										
											2014-07-09 11:19:08 -07:00
										 |  |  | 		if (d->id == displayed_dive.id && dc_number == dataModel->dcShown() && !force) | 
					
						
							| 
									
										
										
										
											2014-07-03 14:34:24 -07:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2014-07-02 20:00:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-03 14:34:24 -07:00
										 |  |  | 		// this copies the dive and makes copies of all the relevant additional data
 | 
					
						
							|  |  |  | 		copy_dive(d, &displayed_dive); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-05-21 23:31:26 -03:00
										 |  |  | 		DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); | 
					
						
							|  |  |  | 		plannerModel->createTemporaryPlan(); | 
					
						
							|  |  |  | 		if (!plannerModel->getDiveplan().dp) { | 
					
						
							|  |  |  | 			plannerModel->deleteTemporaryPlan(); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-02 20:00:57 -07:00
										 |  |  | 	// special handling for the first time we display things
 | 
					
						
							| 
									
										
										
										
											2014-07-21 19:10:31 -03:00
										 |  |  | 	int animSpeedBackup = 0; | 
					
						
							| 
									
										
										
										
											2014-04-03 12:52:05 -07:00
										 |  |  | 	if (firstCall && MainWindow::instance()->filesFromCommandLine()) { | 
					
						
							| 
									
										
										
										
											2014-07-21 19:10:31 -03:00
										 |  |  | 		animSpeedBackup = prefs.animation_speed; | 
					
						
							|  |  |  | 		prefs.animation_speed = 0; | 
					
						
							| 
									
										
										
										
											2014-03-11 18:54:28 -03:00
										 |  |  | 		firstCall = false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-13 10:23:20 -07:00
										 |  |  | 	// restore default zoom level
 | 
					
						
							| 
									
										
										
										
											2014-03-10 17:59:02 +02:00
										 |  |  | 	if (zoomLevel) { | 
					
						
							|  |  |  | 		const qreal defScale = 1.0 / qPow(zoomFactor, (qreal)zoomLevel); | 
					
						
							|  |  |  | 		scale(defScale, defScale); | 
					
						
							|  |  |  | 		zoomLevel = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-25 23:34:12 +02:00
										 |  |  | 	// reset some item visibility on printMode changes
 | 
					
						
							| 
									
										
										
										
											2014-06-17 20:01:15 +02:00
										 |  |  | 	toolTipItem->setVisible(!printMode); | 
					
						
							| 
									
										
										
										
											2014-05-21 12:57:48 -03:00
										 |  |  | 	rulerItem->setVisible(prefs.rulergraph && !printMode); | 
					
						
							| 
									
										
										
										
											2014-03-25 23:34:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-12 21:26:12 -03:00
										 |  |  | 	if (currentState == EMPTY) | 
					
						
							|  |  |  | 		setProfileState(); | 
					
						
							| 
									
										
										
										
											2014-02-26 11:42:55 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// next get the dive computer structure - if there are no samples
 | 
					
						
							|  |  |  | 	// let's create a fake profile that's somewhat reasonable for the
 | 
					
						
							|  |  |  | 	// data that we have
 | 
					
						
							| 
									
										
										
										
											2014-07-02 20:00:57 -07:00
										 |  |  | 	struct divecomputer *currentdc = select_dc(&displayed_dive); | 
					
						
							| 
									
										
										
										
											2014-01-15 13:34:55 -02:00
										 |  |  | 	Q_ASSERT(currentdc); | 
					
						
							| 
									
										
										
										
											2014-02-26 11:42:55 -08:00
										 |  |  | 	if (!currentdc || !currentdc->samples) { | 
					
						
							|  |  |  | 		currentdc = fake_dc(currentdc); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-01-15 13:34:55 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* This struct holds all the data that's about to be plotted.
 | 
					
						
							|  |  |  | 	 * I'm not sure this is the best approach ( but since we are | 
					
						
							|  |  |  | 	 * interpolating some points of the Dive, maybe it is... ) | 
					
						
							|  |  |  | 	 * The  Calculation of the points should be done per graph, | 
					
						
							|  |  |  | 	 * so I'll *not* calculate everything if something is not being | 
					
						
							|  |  |  | 	 * shown. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2014-07-02 20:00:57 -07:00
										 |  |  | 	struct plot_info pInfo = calculate_max_limits_new(&displayed_dive, currentdc); | 
					
						
							|  |  |  | 	create_plot_info_new(&displayed_dive, currentdc, &pInfo); | 
					
						
							| 
									
										
										
										
											2014-05-26 17:51:46 -03:00
										 |  |  | 	if(shouldCalculateMaxTime) | 
					
						
							|  |  |  | 		maxtime = get_maxtime(&pInfo); | 
					
						
							| 
									
										
										
										
											2014-06-30 19:08:16 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Only update the max depth if it's bigger than the current ones
 | 
					
						
							|  |  |  | 	 * when we are dragging the handler to plan / add dive. | 
					
						
							|  |  |  | 	 * otherwhise, update normally. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	int newMaxDepth = get_maxdepth(&pInfo); | 
					
						
							|  |  |  | 	if(!shouldCalculateMaxDepth) { | 
					
						
							|  |  |  | 		if (maxdepth < newMaxDepth) { | 
					
						
							|  |  |  | 			maxdepth = newMaxDepth; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		maxdepth = newMaxDepth; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-01-15 13:34:55 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-02 20:00:57 -07:00
										 |  |  | 	dataModel->setDive(&displayed_dive, pInfo); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:53:57 -02:00
										 |  |  | 	toolTipItem->setPlotInfo(pInfo); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:02:32 -02:00
										 |  |  | 	// It seems that I'll have a lot of boilerplate setting the model / axis for
 | 
					
						
							|  |  |  | 	// each item, I'll mostly like to fix this in the future, but I'll keep at this for now.
 | 
					
						
							| 
									
										
										
										
											2014-01-18 14:33:12 -08:00
										 |  |  | 	profileYAxis->setMaximum(maxdepth); | 
					
						
							| 
									
										
										
										
											2014-01-15 13:34:55 -02:00
										 |  |  | 	profileYAxis->updateTicks(); | 
					
						
							| 
									
										
										
										
											2014-02-07 17:59:21 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 18:39:13 -02:00
										 |  |  | 	temperatureAxis->setMinimum(pInfo.mintemp); | 
					
						
							|  |  |  | 	temperatureAxis->setMaximum(pInfo.maxtemp); | 
					
						
							| 
									
										
										
										
											2014-02-19 17:18:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-21 19:32:46 -03:00
										 |  |  | 	if (pInfo.maxhr) { | 
					
						
							|  |  |  | 		heartBeatAxis->setMinimum(pInfo.minhr); | 
					
						
							|  |  |  | 		heartBeatAxis->setMaximum(pInfo.maxhr); | 
					
						
							|  |  |  | 		heartBeatAxis->updateTicks(HR_AXIS); // this shows the ticks
 | 
					
						
							| 
									
										
										
										
											2014-02-23 14:32:25 -08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-07-29 19:41:30 -03:00
										 |  |  | 	heartBeatAxis->setVisible(prefs.hrgraph && pInfo.maxhr); | 
					
						
							| 
									
										
										
										
											2014-07-21 19:32:46 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-15 18:03:58 -02:00
										 |  |  | 	timeAxis->setMaximum(maxtime); | 
					
						
							| 
									
										
										
										
											2014-01-27 17:09:08 -02:00
										 |  |  | 	int i, incr; | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	static int increments[8] = { 10, 20, 30, 60, 5 * 60, 10 * 60, 15 * 60, 30 * 60 }; | 
					
						
							| 
									
										
										
										
											2014-01-27 17:09:08 -02: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; | 
					
						
							|  |  |  | 	while (i < 7 && maxtime / increments[i] > 12) | 
					
						
							|  |  |  | 		i++; | 
					
						
							|  |  |  | 	incr = increments[i]; | 
					
						
							|  |  |  | 	while (maxtime / incr > 12) | 
					
						
							|  |  |  | 		incr *= 2; | 
					
						
							|  |  |  | 	timeAxis->setTickInterval(incr); | 
					
						
							| 
									
										
										
										
											2014-01-15 13:34:55 -02:00
										 |  |  | 	timeAxis->updateTicks(); | 
					
						
							| 
									
										
										
										
											2014-01-17 14:28:59 -02:00
										 |  |  | 	cylinderPressureAxis->setMinimum(pInfo.minpressure); | 
					
						
							|  |  |  | 	cylinderPressureAxis->setMaximum(pInfo.maxpressure); | 
					
						
							| 
									
										
										
										
											2014-03-07 12:08:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	rulerItem->setPlotInfo(pInfo); | 
					
						
							| 
									
										
										
										
											2014-07-21 18:23:02 -03:00
										 |  |  | 	meanDepth->setVisible(prefs.show_average_depth); | 
					
						
							| 
									
										
										
										
											2014-01-22 15:08:19 -02:00
										 |  |  | 	meanDepth->setMeanDepth(pInfo.meandepth); | 
					
						
							| 
									
										
										
										
											2014-08-04 07:36:07 -07:00
										 |  |  | 	meanDepth->setLine(0, 0, timeAxis->posAtValue(currentdc->duration.seconds), 0); | 
					
						
							| 
									
										
										
										
											2014-07-11 19:13:01 -03:00
										 |  |  | 	Animations::moveTo(meanDepth,3, profileYAxis->posAtValue(pInfo.meandepth)); | 
					
						
							| 
									
										
										
										
											2014-01-23 17:54:34 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-27 15:14:42 -02:00
										 |  |  | 	dataModel->emitDataChanged(); | 
					
						
							| 
									
										
										
										
											2014-01-23 16:12:18 -02:00
										 |  |  | 	// The event items are a bit special since we don't know how many events are going to
 | 
					
						
							|  |  |  | 	// exist on a dive, so I cant create cache items for that. that's why they are here
 | 
					
						
							|  |  |  | 	// while all other items are up there on the constructor.
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:02:32 -02:00
										 |  |  | 	qDeleteAll(eventItems); | 
					
						
							|  |  |  | 	eventItems.clear(); | 
					
						
							|  |  |  | 	struct event *event = currentdc->events; | 
					
						
							|  |  |  | 	while (event) { | 
					
						
							|  |  |  | 		DiveEventItem *item = new DiveEventItem(); | 
					
						
							|  |  |  | 		item->setHorizontalAxis(timeAxis); | 
					
						
							|  |  |  | 		item->setVerticalAxis(profileYAxis); | 
					
						
							|  |  |  | 		item->setModel(dataModel); | 
					
						
							|  |  |  | 		item->setEvent(event); | 
					
						
							| 
									
										
										
										
											2014-01-19 20:16:08 -02:00
										 |  |  | 		item->setZValue(2); | 
					
						
							| 
									
										
										
										
											2014-01-16 15:02:32 -02:00
										 |  |  | 		scene()->addItem(item); | 
					
						
							|  |  |  | 		eventItems.push_back(item); | 
					
						
							|  |  |  | 		event = event->next; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-17 08:14:58 -07:00
										 |  |  | 	// Only set visible the events that should be visible
 | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	Q_FOREACH (DiveEventItem *event, eventItems) { | 
					
						
							| 
									
										
										
										
											2014-03-16 15:10:03 -07:00
										 |  |  | 		event->setVisible(!event->shouldBeHidden()); | 
					
						
							| 
									
										
										
										
											2014-02-23 08:33:58 -08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-29 08:31:37 -07:00
										 |  |  | 	QString dcText = get_dc_nickname(currentdc->model, currentdc->deviceid); | 
					
						
							| 
									
										
										
										
											2014-05-19 14:29:43 +09:00
										 |  |  | 	int nr; | 
					
						
							| 
									
										
										
										
											2014-07-03 14:34:24 -07:00
										 |  |  | 	if ((nr = number_of_computers(&displayed_dive)) > 1) | 
					
						
							| 
									
										
										
										
											2014-05-19 14:29:43 +09:00
										 |  |  | 		dcText += tr(" (#%1 of %2)").arg(dc_number + 1).arg(nr); | 
					
						
							|  |  |  | 	diveComputerText->setText(dcText); | 
					
						
							| 
									
										
										
										
											2014-07-21 19:10:31 -03:00
										 |  |  | 	if (MainWindow::instance()->filesFromCommandLine() && animSpeedBackup != 0) { | 
					
						
							|  |  |  | 		prefs.animation_speed = animSpeedBackup; | 
					
						
							| 
									
										
										
										
											2014-03-11 18:54:28 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-21 23:31:26 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-25 17:49:26 -03:00
										 |  |  | 	if (currentState == ADD || currentState == PLAN) { // TODO: figure a way to move this from here.
 | 
					
						
							| 
									
										
										
										
											2014-05-21 23:31:26 -03:00
										 |  |  | 		repositionDiveHandlers(); | 
					
						
							|  |  |  | 		DivePlannerPointsModel *model = DivePlannerPointsModel::instance(); | 
					
						
							|  |  |  | 		model->deleteTemporaryPlan(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-07-21 18:54:28 -03:00
										 |  |  | 	plotPictures(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-04 13:41:50 -07:00
										 |  |  | 	// OK, how long did this take us? Anything above the second is way too long,
 | 
					
						
							|  |  |  | 	// so if we are calculation TTS / NDL then let's force that off.
 | 
					
						
							|  |  |  | 	if (measureDuration.elapsed() > 1000 && prefs.calcndltts) { | 
					
						
							|  |  |  | 		MainWindow::instance()->turnOffNdlTts(); | 
					
						
							|  |  |  | 		MainWindow::instance()->showError("Show NDL / TTS was disabled because of excessive processing time"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-01-14 14:30:13 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileWidget2::settingsChanged() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-05-05 15:58:25 -07:00
										 |  |  | 	// if we are showing calculated ceilings then we have to replot()
 | 
					
						
							|  |  |  | 	// because the GF could have changed; otherwise we try to avoid replot()
 | 
					
						
							|  |  |  | 	bool needReplot = prefs.calcceiling; | 
					
						
							| 
									
										
										
										
											2014-07-14 23:26:30 -05:00
										 |  |  | 	if (PP_GRAPHS_ENABLED || prefs.hrgraph) { | 
					
						
							| 
									
										
										
										
											2014-02-12 13:50:35 -02:00
										 |  |  | 		profileYAxis->animateChangeLine(itemPos.depth.shrinked); | 
					
						
							| 
									
										
										
										
											2014-02-12 14:08:01 -02:00
										 |  |  | 		temperatureAxis->animateChangeLine(itemPos.temperature.shrinked); | 
					
						
							| 
									
										
										
										
											2014-02-12 14:12:56 -02:00
										 |  |  | 		cylinderPressureAxis->animateChangeLine(itemPos.cylinder.shrinked); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-02-12 13:50:35 -02:00
										 |  |  | 		profileYAxis->animateChangeLine(itemPos.depth.expanded); | 
					
						
							| 
									
										
										
										
											2014-02-12 14:08:01 -02:00
										 |  |  | 		temperatureAxis->animateChangeLine(itemPos.temperature.expanded); | 
					
						
							| 
									
										
										
										
											2014-02-12 14:12:56 -02:00
										 |  |  | 		cylinderPressureAxis->animateChangeLine(itemPos.cylinder.expanded); | 
					
						
							| 
									
										
										
										
											2014-02-12 13:50:35 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-04-16 22:03:44 +02:00
										 |  |  | 	if (prefs.zoomed_plot != isPlotZoomed) { | 
					
						
							|  |  |  | 		isPlotZoomed = prefs.zoomed_plot; | 
					
						
							| 
									
										
										
										
											2014-05-05 15:58:25 -07:00
										 |  |  | 		needReplot = true; | 
					
						
							| 
									
										
										
										
											2014-02-27 12:39:53 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-05 15:58:25 -07:00
										 |  |  | 	if (needReplot) | 
					
						
							|  |  |  | 		replot(); | 
					
						
							| 
									
										
										
										
											2014-01-14 14:30:13 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void ProfileWidget2::resizeEvent(QResizeEvent *event) | 
					
						
							| 
									
										
										
										
											2014-01-14 14:30:13 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-10 20:45:08 -08:00
										 |  |  | 	QGraphicsView::resizeEvent(event); | 
					
						
							| 
									
										
										
										
											2014-01-15 12:55:33 -02:00
										 |  |  | 	fitInView(sceneRect(), Qt::IgnoreAspectRatio); | 
					
						
							| 
									
										
										
										
											2014-02-07 16:34:42 -02:00
										 |  |  | 	fixBackgroundPos(); | 
					
						
							| 
									
										
										
										
											2014-01-15 12:55:33 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-26 17:51:46 -03:00
										 |  |  | void ProfileWidget2::mousePressEvent(QMouseEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QGraphicsView::mousePressEvent(event); | 
					
						
							|  |  |  | 	if(currentState == PLAN) | 
					
						
							|  |  |  | 		shouldCalculateMaxTime = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-30 19:08:16 -03:00
										 |  |  | void ProfileWidget2::divePlannerHandlerClicked() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	shouldCalculateMaxDepth = false; | 
					
						
							|  |  |  | 	replot(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileWidget2::divePlannerHandlerReleased() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	shouldCalculateMaxDepth = true; | 
					
						
							|  |  |  | 	replot(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-26 17:51:46 -03:00
										 |  |  | void ProfileWidget2::mouseReleaseEvent(QMouseEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QGraphicsView::mouseReleaseEvent(event); | 
					
						
							|  |  |  | 	if(currentState == PLAN){ | 
					
						
							|  |  |  | 		shouldCalculateMaxTime = true; | 
					
						
							|  |  |  | 		replot(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-15 12:55:33 -02:00
										 |  |  | void ProfileWidget2::fixBackgroundPos() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-05-28 15:43:32 -03:00
										 |  |  | 	static QPixmap toBeScaled(backgroundFile); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	if (currentState != EMPTY) | 
					
						
							| 
									
										
										
										
											2014-02-07 19:42:47 -02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-03-10 17:59:01 +02:00
										 |  |  | 	QPixmap p = toBeScaled.scaledToHeight(viewport()->height() - 40, Qt::SmoothTransformation); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	int x = viewport()->width() / 2 - p.width() / 2; | 
					
						
							| 
									
										
										
										
											2014-03-10 17:59:01 +02:00
										 |  |  | 	int y = viewport()->height() / 2 - p.height() / 2; | 
					
						
							| 
									
										
										
										
											2014-02-07 15:32:39 -02:00
										 |  |  | 	background->setPixmap(p); | 
					
						
							|  |  |  | 	background->setX(mapToScene(x, 0).x()); | 
					
						
							| 
									
										
										
										
											2014-03-10 17:59:01 +02:00
										 |  |  | 	background->setY(mapToScene(y, 20).y()); | 
					
						
							| 
									
										
										
										
											2014-01-14 14:30:13 -02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-04 21:47:50 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void ProfileWidget2::wheelEvent(QWheelEvent *event) | 
					
						
							| 
									
										
										
										
											2014-02-04 21:47:50 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-03-10 17:59:01 +02:00
										 |  |  | 	if (currentState == EMPTY) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-02-05 14:34:45 -02:00
										 |  |  | 	QPoint toolTipPos = mapFromScene(toolTipItem->pos()); | 
					
						
							| 
									
										
										
										
											2014-08-06 13:51:54 +02:00
										 |  |  | 	if(event->buttons() == Qt::LeftButton) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-02-04 21:47:50 -02:00
										 |  |  | 	if (event->delta() > 0 && zoomLevel < 20) { | 
					
						
							| 
									
										
										
										
											2014-03-10 17:59:02 +02:00
										 |  |  | 		scale(zoomFactor, zoomFactor); | 
					
						
							| 
									
										
										
										
											2014-02-04 21:47:50 -02:00
										 |  |  | 		zoomLevel++; | 
					
						
							|  |  |  | 	} else if (event->delta() < 0 && zoomLevel > 0) { | 
					
						
							|  |  |  | 		// Zooming out
 | 
					
						
							| 
									
										
										
										
											2014-03-10 17:59:02 +02:00
										 |  |  | 		scale(1.0 / zoomFactor, 1.0 / zoomFactor); | 
					
						
							| 
									
										
										
										
											2014-02-04 21:47:50 -02:00
										 |  |  | 		zoomLevel--; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	scrollViewTo(event->pos()); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:34:45 -02:00
										 |  |  | 	toolTipItem->setPos(mapToScene(toolTipPos)); | 
					
						
							| 
									
										
										
										
											2014-02-04 21:47:50 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-21 15:52:24 -03:00
										 |  |  | void ProfileWidget2::mouseDoubleClickEvent(QMouseEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (currentState == PLAN || currentState == ADD) { | 
					
						
							|  |  |  | 		DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); | 
					
						
							|  |  |  | 		QPointF mappedPos = mapToScene(event->pos()); | 
					
						
							|  |  |  | 		if (isPointOutOfBoundaries(mappedPos)) | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int minutes = rint(timeAxis->valueAt(mappedPos) / 60); | 
					
						
							|  |  |  | 		int milimeters = rint(profileYAxis->valueAt(mappedPos) / M_OR_FT(1, 1)) * M_OR_FT(1, 1); | 
					
						
							| 
									
										
										
										
											2014-06-02 12:36:05 -07:00
										 |  |  | 		plannerModel->addStop(milimeters, minutes * 60, 0, 0, true); | 
					
						
							| 
									
										
										
										
											2014-05-21 15:52:24 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ProfileWidget2::isPointOutOfBoundaries(const QPointF &point) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	double xpos = timeAxis->valueAt(point); | 
					
						
							|  |  |  | 	double ypos = profileYAxis->valueAt(point); | 
					
						
							|  |  |  | 	return (xpos > timeAxis->maximum() || | 
					
						
							|  |  |  | 		xpos < timeAxis->minimum() || | 
					
						
							|  |  |  | 		ypos > profileYAxis->maximum() || | 
					
						
							|  |  |  | 		ypos < profileYAxis->minimum()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void ProfileWidget2::scrollViewTo(const QPoint &pos) | 
					
						
							| 
									
										
										
										
											2014-02-04 21:47:50 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	/* since we cannot use translate() directly on the scene we hack on
 | 
					
						
							| 
									
										
										
										
											2014-02-04 21:47:50 -02:00
										 |  |  |  * the scroll bars (hidden) functionality */ | 
					
						
							| 
									
										
										
										
											2014-03-10 17:59:01 +02:00
										 |  |  | 	if (!zoomLevel || currentState == EMPTY) | 
					
						
							| 
									
										
										
										
											2014-02-04 21:47:50 -02:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	QScrollBar *vs = verticalScrollBar(); | 
					
						
							|  |  |  | 	QScrollBar *hs = horizontalScrollBar(); | 
					
						
							| 
									
										
										
										
											2014-02-05 18:57:02 +02:00
										 |  |  | 	const qreal yRat = (qreal)pos.y() / viewport()->height(); | 
					
						
							|  |  |  | 	const qreal xRat = (qreal)pos.x() / viewport()->width(); | 
					
						
							|  |  |  | 	vs->setValue(yRat * vs->maximum()); | 
					
						
							|  |  |  | 	hs->setValue(xRat * hs->maximum()); | 
					
						
							| 
									
										
										
										
											2014-02-04 21:47:50 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void ProfileWidget2::mouseMoveEvent(QMouseEvent *event) | 
					
						
							| 
									
										
										
										
											2014-02-04 21:47:50 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-05 15:25:24 -02:00
										 |  |  | 	toolTipItem->refresh(mapToScene(event->pos())); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:34:45 -02:00
										 |  |  | 	QPoint toolTipPos = mapFromScene(toolTipItem->pos()); | 
					
						
							| 
									
										
										
										
											2014-02-04 21:47:50 -02:00
										 |  |  | 	if (zoomLevel == 0) { | 
					
						
							|  |  |  | 		QGraphicsView::mouseMoveEvent(event); | 
					
						
							| 
									
										
										
										
											2014-02-05 14:34:45 -02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-02-04 21:47:50 -02:00
										 |  |  | 		scrollViewTo(event->pos()); | 
					
						
							| 
									
										
										
										
											2014-02-07 21:38:06 -02:00
										 |  |  | 		toolTipItem->setPos(mapToScene(toolTipPos)); | 
					
						
							| 
									
										
										
										
											2014-02-04 21:47:50 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-08-05 18:27:00 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QPointF pos = mapToScene(event->pos()); | 
					
						
							|  |  |  | 	qreal vValue = profileYAxis->valueAt(pos); | 
					
						
							|  |  |  | 	qreal hValue = timeAxis->valueAt(pos); | 
					
						
							|  |  |  | 	if ( profileYAxis->maximum() >= vValue | 
					
						
							|  |  |  | 		&& profileYAxis->minimum() <= vValue){ | 
					
						
							|  |  |  | 		mouseFollowerHorizontal->setPos(timeAxis->pos().x(), pos.y()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if ( timeAxis->maximum() >= hValue | 
					
						
							|  |  |  | 		&& timeAxis->minimum() <= hValue){ | 
					
						
							|  |  |  | 		mouseFollowerVertical->setPos(pos.x(), profileYAxis->line().y1()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-04 21:47:50 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-05 16:15:59 -02:00
										 |  |  | bool ProfileWidget2::eventFilter(QObject *object, QEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	QGraphicsScene *s = qobject_cast<QGraphicsScene *>(object); | 
					
						
							|  |  |  | 	if (s && event->type() == QEvent::GraphicsSceneHelp) { | 
					
						
							| 
									
										
										
										
											2014-02-05 16:15:59 -02:00
										 |  |  | 		event->ignore(); | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return QGraphicsView::eventFilter(object, event); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-07 16:34:42 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void ProfileWidget2::setEmptyState() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// Then starting Empty State, move the background up.
 | 
					
						
							|  |  |  | 	if (currentState == EMPTY) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-21 21:23:19 -03:00
										 |  |  | 	disconnectTemporaryConnections(); | 
					
						
							| 
									
										
										
										
											2014-05-21 20:34:06 -03:00
										 |  |  | 	setBackgroundBrush(getColor(::BACKGROUND, isGrayscale)); | 
					
						
							| 
									
										
										
										
											2014-02-10 14:41:59 -02:00
										 |  |  | 	dataModel->clear(); | 
					
						
							| 
									
										
										
										
											2014-02-07 16:34:42 -02:00
										 |  |  | 	currentState = EMPTY; | 
					
						
							| 
									
										
										
										
											2014-03-11 18:30:58 +02:00
										 |  |  | 	MainWindow::instance()->setToolButtonsEnabled(false); | 
					
						
							| 
									
										
										
										
											2014-03-10 17:59:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 16:34:42 -02:00
										 |  |  | 	fixBackgroundPos(); | 
					
						
							| 
									
										
										
										
											2014-02-10 15:01:04 -02:00
										 |  |  | 	background->setVisible(true); | 
					
						
							| 
									
										
										
										
											2014-03-10 17:59:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	profileYAxis->setVisible(false); | 
					
						
							|  |  |  | 	gasYAxis->setVisible(false); | 
					
						
							|  |  |  | 	timeAxis->setVisible(false); | 
					
						
							|  |  |  | 	temperatureAxis->setVisible(false); | 
					
						
							|  |  |  | 	cylinderPressureAxis->setVisible(false); | 
					
						
							| 
									
										
										
										
											2014-02-07 16:34:42 -02:00
										 |  |  | 	toolTipItem->setVisible(false); | 
					
						
							|  |  |  | 	meanDepth->setVisible(false); | 
					
						
							|  |  |  | 	diveComputerText->setVisible(false); | 
					
						
							|  |  |  | 	diveCeiling->setVisible(false); | 
					
						
							|  |  |  | 	reportedCeiling->setVisible(false); | 
					
						
							| 
									
										
										
										
											2014-02-27 15:20:03 -03:00
										 |  |  | 	rulerItem->setVisible(false); | 
					
						
							| 
									
										
										
										
											2014-03-19 02:08:23 +08:00
										 |  |  | 	pn2GasItem->setVisible(false); | 
					
						
							|  |  |  | 	po2GasItem->setVisible(false); | 
					
						
							|  |  |  | 	pheGasItem->setVisible(false); | 
					
						
							| 
									
										
										
										
											2014-08-05 18:27:00 -03:00
										 |  |  | 	mouseFollowerHorizontal->setVisible(false); | 
					
						
							|  |  |  | 	mouseFollowerVertical->setVisible(false); | 
					
						
							| 
									
										
										
										
											2014-05-28 15:43:32 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	#define HIDE_ALL(TYPE, CONTAINER) \
 | 
					
						
							|  |  |  | 	Q_FOREACH (TYPE *item, CONTAINER) item->setVisible(false); | 
					
						
							|  |  |  | 	HIDE_ALL(DiveCalculatedTissue, allTissues); | 
					
						
							|  |  |  | 	HIDE_ALL(DiveEventItem, eventItems); | 
					
						
							|  |  |  | 	HIDE_ALL(DiveHandler, handles); | 
					
						
							|  |  |  | 	HIDE_ALL(QGraphicsSimpleTextItem, gases); | 
					
						
							|  |  |  | 	#undef HIDE_ALL
 | 
					
						
							| 
									
										
										
										
											2014-02-07 16:34:42 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileWidget2::setProfileState() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-07 16:54:12 -02:00
										 |  |  | 	// Then starting Empty State, move the background up.
 | 
					
						
							|  |  |  | 	if (currentState == PROFILE) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-02-07 16:34:42 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-21 21:23:19 -03:00
										 |  |  | 	disconnectTemporaryConnections(); | 
					
						
							| 
									
										
										
										
											2014-06-03 19:09:12 -03:00
										 |  |  | 	connect(DivePictureModel::instance(), SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(plotPictures())); | 
					
						
							| 
									
										
										
										
											2014-06-03 19:24:01 -03:00
										 |  |  | 	connect(DivePictureModel::instance(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),this, SLOT(plotPictures())); | 
					
						
							| 
									
										
										
										
											2014-06-03 19:09:12 -03:00
										 |  |  | 	connect(DivePictureModel::instance(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)),this, SLOT(plotPictures())); | 
					
						
							|  |  |  | 	/* show the same stuff that the profile shows. */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-24 12:39:40 -03:00
										 |  |  | 	//TODO: Move the DC handling to another method.
 | 
					
						
							|  |  |  | 	MainWindow::instance()->enableDcShortcuts(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 16:54:12 -02:00
										 |  |  | 	currentState = PROFILE; | 
					
						
							| 
									
										
										
										
											2014-03-11 18:30:58 +02:00
										 |  |  | 	MainWindow::instance()->setToolButtonsEnabled(true); | 
					
						
							| 
									
										
										
										
											2014-03-09 11:08:01 -03:00
										 |  |  | 	toolTipItem->readPos(); | 
					
						
							| 
									
										
										
										
											2014-03-25 23:34:10 +02:00
										 |  |  | 	setBackgroundBrush(getColor(::BACKGROUND, isGrayscale)); | 
					
						
							| 
									
										
										
										
											2014-02-07 17:38:00 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 19:42:47 -02:00
										 |  |  | 	background->setVisible(false); | 
					
						
							| 
									
										
										
										
											2014-02-07 16:54:12 -02:00
										 |  |  | 	toolTipItem->setVisible(true); | 
					
						
							| 
									
										
										
										
											2014-03-10 17:59:01 +02:00
										 |  |  | 	profileYAxis->setVisible(true); | 
					
						
							|  |  |  | 	gasYAxis->setVisible(true); | 
					
						
							|  |  |  | 	timeAxis->setVisible(true); | 
					
						
							|  |  |  | 	temperatureAxis->setVisible(true); | 
					
						
							|  |  |  | 	cylinderPressureAxis->setVisible(true); | 
					
						
							| 
									
										
										
										
											2014-02-07 17:38:00 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 19:42:47 -02:00
										 |  |  | 	profileYAxis->setPos(itemPos.depth.pos.on); | 
					
						
							| 
									
										
										
										
											2014-07-14 23:26:30 -05:00
										 |  |  | 	if (prefs.pp_graphs.phe || prefs.pp_graphs.po2 || prefs.pp_graphs.pn2 || prefs.hrgraph) { | 
					
						
							| 
									
										
										
										
											2014-02-07 19:42:47 -02:00
										 |  |  | 		profileYAxis->setLine(itemPos.depth.shrinked); | 
					
						
							| 
									
										
										
										
											2014-02-12 14:08:01 -02:00
										 |  |  | 		temperatureAxis->setLine(itemPos.temperature.shrinked); | 
					
						
							| 
									
										
										
										
											2014-02-12 14:12:56 -02:00
										 |  |  | 		cylinderPressureAxis->setLine(itemPos.cylinder.shrinked); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-02-07 19:42:47 -02:00
										 |  |  | 		profileYAxis->setLine(itemPos.depth.expanded); | 
					
						
							| 
									
										
										
										
											2014-02-12 14:08:01 -02:00
										 |  |  | 		temperatureAxis->setLine(itemPos.temperature.expanded); | 
					
						
							| 
									
										
										
										
											2014-02-12 14:12:56 -02:00
										 |  |  | 		cylinderPressureAxis->setLine(itemPos.cylinder.expanded); | 
					
						
							| 
									
										
										
										
											2014-02-07 19:42:47 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-04-16 22:03:44 +02:00
										 |  |  | 	pn2GasItem->setVisible(prefs.pp_graphs.pn2); | 
					
						
							|  |  |  | 	po2GasItem->setVisible(prefs.pp_graphs.po2); | 
					
						
							|  |  |  | 	pheGasItem->setVisible(prefs.pp_graphs.phe); | 
					
						
							| 
									
										
										
										
											2014-02-07 19:42:47 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-11 10:55:07 -08:00
										 |  |  | 	gasYAxis->setPos(itemPos.partialPressure.pos.on); | 
					
						
							|  |  |  | 	gasYAxis->setLine(itemPos.partialPressure.expanded); | 
					
						
							| 
									
										
										
										
											2014-02-07 17:38:00 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 19:42:47 -02:00
										 |  |  | 	timeAxis->setPos(itemPos.time.pos.on); | 
					
						
							| 
									
										
										
										
											2014-02-07 17:38:00 -02:00
										 |  |  | 	timeAxis->setLine(itemPos.time.expanded); | 
					
						
							| 
									
										
										
										
											2014-02-07 19:42:47 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	cylinderPressureAxis->setPos(itemPos.cylinder.pos.on); | 
					
						
							| 
									
										
										
										
											2014-02-07 21:17:14 -02:00
										 |  |  | 	temperatureAxis->setPos(itemPos.temperature.pos.on); | 
					
						
							| 
									
										
										
										
											2014-02-19 17:18:26 -08:00
										 |  |  | 	heartBeatAxis->setPos(itemPos.heartBeat.pos.on); | 
					
						
							| 
									
										
										
										
											2014-02-19 22:48:06 -03:00
										 |  |  | 	heartBeatAxis->setLine(itemPos.heartBeat.expanded); | 
					
						
							| 
									
										
										
										
											2014-04-16 22:03:44 +02:00
										 |  |  | 	heartBeatItem->setVisible(prefs.hrgraph); | 
					
						
							| 
									
										
										
										
											2014-02-07 21:17:14 -02:00
										 |  |  | 	meanDepth->setVisible(true); | 
					
						
							| 
									
										
										
										
											2014-02-07 21:28:59 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 21:17:14 -02:00
										 |  |  | 	diveComputerText->setVisible(true); | 
					
						
							| 
									
										
										
										
											2014-02-07 21:28:59 -02:00
										 |  |  | 	diveComputerText->setPos(itemPos.dcLabel.on); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-16 22:03:44 +02:00
										 |  |  | 	diveCeiling->setVisible(prefs.calcceiling); | 
					
						
							|  |  |  | 	reportedCeiling->setVisible(prefs.dcceiling); | 
					
						
							| 
									
										
										
										
											2014-02-07 21:28:59 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-16 22:03:44 +02:00
										 |  |  | 	if (prefs.calcalltissues) { | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 		Q_FOREACH (DiveCalculatedTissue *tissue, allTissues) { | 
					
						
							| 
									
										
										
										
											2014-02-07 21:28:59 -02:00
										 |  |  | 			tissue->setVisible(true); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-21 12:57:48 -03:00
										 |  |  | 	rulerItem->setVisible(prefs.rulergraph); | 
					
						
							| 
									
										
										
										
											2014-05-29 23:42:55 -03:00
										 |  |  | 	#define HIDE_ALL(TYPE, CONTAINER) \
 | 
					
						
							|  |  |  | 	Q_FOREACH (TYPE *item, CONTAINER) item->setVisible(false); | 
					
						
							|  |  |  | 	HIDE_ALL(DiveHandler, handles); | 
					
						
							|  |  |  | 	HIDE_ALL(QGraphicsSimpleTextItem, gases); | 
					
						
							|  |  |  | 	#undef HIDE_ALL
 | 
					
						
							| 
									
										
										
										
											2014-08-06 12:33:36 -07:00
										 |  |  | 	mouseFollowerHorizontal->setVisible(false); | 
					
						
							|  |  |  | 	mouseFollowerVertical->setVisible(false); | 
					
						
							| 
									
										
										
										
											2014-02-07 16:34:42 -02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-17 19:15:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-21 15:52:24 -03:00
										 |  |  | void ProfileWidget2::setAddState() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (currentState == ADD) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-21 23:31:26 -03:00
										 |  |  | 	setProfileState(); | 
					
						
							| 
									
										
										
										
											2014-08-06 12:33:36 -07:00
										 |  |  | 	mouseFollowerHorizontal->setVisible(true); | 
					
						
							|  |  |  | 	mouseFollowerVertical->setVisible(true); | 
					
						
							|  |  |  | 	mouseFollowerHorizontal->setLine(timeAxis->line()); | 
					
						
							|  |  |  | 	mouseFollowerVertical->setLine(QLineF(0, profileYAxis->pos().y(), 0, timeAxis->pos().y())); | 
					
						
							| 
									
										
										
										
											2014-05-21 21:23:19 -03:00
										 |  |  | 	disconnectTemporaryConnections(); | 
					
						
							| 
									
										
										
										
											2014-05-24 12:39:40 -03:00
										 |  |  | 	//TODO: Move this method to another place, shouldn't be on mainwindow.
 | 
					
						
							|  |  |  | 	MainWindow::instance()->disableDcShortcuts(); | 
					
						
							|  |  |  | 	actionsForKeys[Qt::Key_Left]->setShortcut(Qt::Key_Left); | 
					
						
							|  |  |  | 	actionsForKeys[Qt::Key_Right]->setShortcut(Qt::Key_Right); | 
					
						
							|  |  |  | 	actionsForKeys[Qt::Key_Up]->setShortcut(Qt::Key_Up); | 
					
						
							|  |  |  | 	actionsForKeys[Qt::Key_Down]->setShortcut(Qt::Key_Down); | 
					
						
							|  |  |  | 	actionsForKeys[Qt::Key_Escape]->setShortcut(Qt::Key_Escape); | 
					
						
							|  |  |  | 	actionsForKeys[Qt::Key_Delete]->setShortcut(Qt::Key_Delete); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-21 23:31:26 -03:00
										 |  |  | 	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); | 
					
						
							|  |  |  | 	connect(plannerModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(replot())); | 
					
						
							|  |  |  | 	connect(plannerModel, SIGNAL(cylinderModelEdited()), this, SLOT(replot())); | 
					
						
							|  |  |  | 	connect(plannerModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), | 
					
						
							|  |  |  | 		this, SLOT(pointInserted(const QModelIndex &, int, int))); | 
					
						
							|  |  |  | 	connect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), | 
					
						
							|  |  |  | 		this, SLOT(pointsRemoved(const QModelIndex &, int, int))); | 
					
						
							| 
									
										
										
										
											2014-05-21 15:52:24 -03:00
										 |  |  | 	/* show the same stuff that the profile shows. */ | 
					
						
							|  |  |  | 	currentState = ADD; /* enable the add state. */ | 
					
						
							| 
									
										
										
										
											2014-05-27 21:55:29 +02:00
										 |  |  | 	diveCeiling->setVisible(true); | 
					
						
							| 
									
										
										
										
											2014-06-30 18:46:51 -03:00
										 |  |  | 	setBackgroundBrush(QColor("#A7DCFF")); | 
					
						
							| 
									
										
										
										
											2014-05-21 15:52:24 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileWidget2::setPlanState() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (currentState == PLAN) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-05-25 15:12:00 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-21 23:31:26 -03:00
										 |  |  | 	setProfileState(); | 
					
						
							| 
									
										
										
										
											2014-08-06 12:33:36 -07:00
										 |  |  | 	mouseFollowerHorizontal->setVisible(true); | 
					
						
							|  |  |  | 	mouseFollowerVertical->setVisible(true); | 
					
						
							|  |  |  | 	mouseFollowerHorizontal->setLine(timeAxis->line()); | 
					
						
							|  |  |  | 	mouseFollowerVertical->setLine(QLineF(0, profileYAxis->pos().y(), 0, timeAxis->pos().y())); | 
					
						
							| 
									
										
										
										
											2014-05-21 21:23:19 -03:00
										 |  |  | 	disconnectTemporaryConnections(); | 
					
						
							| 
									
										
										
										
											2014-05-25 15:12:00 -03:00
										 |  |  | 	//TODO: Move this method to another place, shouldn't be on mainwindow.
 | 
					
						
							|  |  |  | 	MainWindow::instance()->disableDcShortcuts(); | 
					
						
							|  |  |  | 	actionsForKeys[Qt::Key_Left]->setShortcut(Qt::Key_Left); | 
					
						
							|  |  |  | 	actionsForKeys[Qt::Key_Right]->setShortcut(Qt::Key_Right); | 
					
						
							|  |  |  | 	actionsForKeys[Qt::Key_Up]->setShortcut(Qt::Key_Up); | 
					
						
							|  |  |  | 	actionsForKeys[Qt::Key_Down]->setShortcut(Qt::Key_Down); | 
					
						
							|  |  |  | 	actionsForKeys[Qt::Key_Escape]->setShortcut(Qt::Key_Escape); | 
					
						
							|  |  |  | 	actionsForKeys[Qt::Key_Delete]->setShortcut(Qt::Key_Delete); | 
					
						
							| 
									
										
										
										
											2014-05-25 14:16:43 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); | 
					
						
							|  |  |  | 	connect(plannerModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(replot())); | 
					
						
							|  |  |  | 	connect(plannerModel, SIGNAL(cylinderModelEdited()), this, SLOT(replot())); | 
					
						
							|  |  |  | 	connect(plannerModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), | 
					
						
							|  |  |  | 		this, SLOT(pointInserted(const QModelIndex &, int, int))); | 
					
						
							|  |  |  | 	connect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), | 
					
						
							|  |  |  | 		this, SLOT(pointsRemoved(const QModelIndex &, int, int))); | 
					
						
							| 
									
										
										
										
											2014-05-25 15:12:00 -03:00
										 |  |  | 	/* show the same stuff that the profile shows. */ | 
					
						
							| 
									
										
										
										
											2014-05-21 15:52:24 -03:00
										 |  |  | 	currentState = PLAN; /* enable the add state. */ | 
					
						
							| 
									
										
										
										
											2014-05-27 21:55:29 +02:00
										 |  |  | 	diveCeiling->setVisible(true); | 
					
						
							| 
									
										
										
										
											2014-06-30 18:46:51 -03:00
										 |  |  | 	setBackgroundBrush(QColor("#D7E3EF")); | 
					
						
							| 
									
										
										
										
											2014-05-21 15:52:24 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-17 19:15:40 -03:00
										 |  |  | extern struct ev_select *ev_namelist; | 
					
						
							|  |  |  | extern int evn_allocated; | 
					
						
							|  |  |  | extern int evn_used; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-26 15:17:34 -07:00
										 |  |  | bool ProfileWidget2::isPlanner() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return currentState == PLAN; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-31 14:54:36 -07:00
										 |  |  | bool ProfileWidget2::isAddOrPlanner() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return currentState == PLAN || currentState == ADD; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) | 
					
						
							| 
									
										
										
										
											2014-02-17 19:15:40 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-05-25 00:33:39 -03:00
										 |  |  | 	if (currentState == ADD || currentState == PLAN) { | 
					
						
							|  |  |  | 		QGraphicsView::contextMenuEvent(event); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-19 14:39:34 +09:00
										 |  |  | 	QMenu m; | 
					
						
							|  |  |  | 	bool isDCName = false; | 
					
						
							| 
									
										
										
										
											2014-02-17 19:15:40 -03:00
										 |  |  | 	if (selected_dive == -1) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-05-19 14:39:34 +09:00
										 |  |  | 	// figure out if we are ontop of the dive computer name in the profile
 | 
					
						
							|  |  |  | 	QGraphicsItem *sceneItem = itemAt(mapFromGlobal(event->globalPos())); | 
					
						
							|  |  |  | 	if (sceneItem) { | 
					
						
							|  |  |  | 		QGraphicsItem *parentItem = sceneItem; | 
					
						
							|  |  |  | 		while (parentItem) { | 
					
						
							|  |  |  | 			if (parentItem->data(SUBSURFACE_OBJ_DATA) == SUBSURFACE_OBJ_DC_TEXT) { | 
					
						
							|  |  |  | 				isDCName = true; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			parentItem = parentItem->parentItem(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (isDCName) { | 
					
						
							| 
									
										
										
										
											2014-06-11 13:56:33 -07:00
										 |  |  | 			if (dc_number == 0 && count_divecomputers() == 1) | 
					
						
							|  |  |  | 				// nothing to do, can't delete or reorder
 | 
					
						
							| 
									
										
										
										
											2014-05-19 14:39:34 +09:00
										 |  |  | 				return; | 
					
						
							|  |  |  | 			// create menu to show when right clicking on dive computer name
 | 
					
						
							| 
									
										
										
										
											2014-06-11 13:56:33 -07:00
										 |  |  | 			if (dc_number > 0) | 
					
						
							|  |  |  | 				m.addAction(tr("Make first divecomputer"), this, SLOT(makeFirstDC())); | 
					
						
							|  |  |  | 			if (count_divecomputers() > 1) | 
					
						
							|  |  |  | 				m.addAction(tr("Delete this divecomputer"), this, SLOT(deleteCurrentDC())); | 
					
						
							| 
									
										
										
										
											2014-05-19 14:39:34 +09:00
										 |  |  | 			m.exec(event->globalPos()); | 
					
						
							|  |  |  | 			// don't show the regular profile context menu
 | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// create the profile context menu
 | 
					
						
							| 
									
										
										
										
											2014-07-11 18:39:05 +01:00
										 |  |  | 	QMenu *gasChange = m.addMenu(tr("Add gas change")); | 
					
						
							| 
									
										
										
										
											2014-02-17 19:15:40 -03:00
										 |  |  | 	GasSelectionModel *model = GasSelectionModel::instance(); | 
					
						
							|  |  |  | 	model->repopulate(); | 
					
						
							|  |  |  | 	int rowCount = model->rowCount(); | 
					
						
							|  |  |  | 	for (int i = 0; i < rowCount; i++) { | 
					
						
							|  |  |  | 		QAction *action = new QAction(&m); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		action->setText(model->data(model->index(i, 0), Qt::DisplayRole).toString()); | 
					
						
							| 
									
										
										
										
											2014-02-17 19:15:40 -03:00
										 |  |  | 		connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas())); | 
					
						
							|  |  |  | 		action->setData(event->globalPos()); | 
					
						
							|  |  |  | 		gasChange->addAction(action); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-07-11 18:39:05 +01:00
										 |  |  | 	QAction *action = m.addAction(tr("Add bookmark"), this, SLOT(addBookmark())); | 
					
						
							| 
									
										
										
										
											2014-02-17 19:15:40 -03:00
										 |  |  | 	action->setData(event->globalPos()); | 
					
						
							| 
									
										
										
										
											2014-03-15 21:12:34 -07:00
										 |  |  | 	if (DiveEventItem *item = dynamic_cast<DiveEventItem *>(sceneItem)) { | 
					
						
							| 
									
										
										
										
											2014-02-17 19:15:40 -03:00
										 |  |  | 		action = new QAction(&m); | 
					
						
							| 
									
										
										
										
											2014-07-11 18:39:05 +01:00
										 |  |  | 		action->setText(tr("Remove event")); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		action->setData(QVariant::fromValue<void *>(item)); // so we know what to remove.
 | 
					
						
							| 
									
										
										
										
											2014-02-17 19:15:40 -03:00
										 |  |  | 		connect(action, SIGNAL(triggered(bool)), this, SLOT(removeEvent())); | 
					
						
							|  |  |  | 		m.addAction(action); | 
					
						
							|  |  |  | 		action = new QAction(&m); | 
					
						
							|  |  |  | 		action->setText(tr("Hide similar events")); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		action->setData(QVariant::fromValue<void *>(item)); | 
					
						
							| 
									
										
										
										
											2014-02-17 19:15:40 -03:00
										 |  |  | 		connect(action, SIGNAL(triggered(bool)), this, SLOT(hideEvents())); | 
					
						
							|  |  |  | 		m.addAction(action); | 
					
						
							| 
									
										
										
										
											2014-04-03 12:52:05 -07:00
										 |  |  | 		if (item->getEvent()->type == SAMPLE_EVENT_BOOKMARK) { | 
					
						
							| 
									
										
										
										
											2014-04-03 21:16:15 +02:00
										 |  |  | 			action = new QAction(&m); | 
					
						
							|  |  |  | 			action->setText(tr("Edit name")); | 
					
						
							|  |  |  | 			action->setData(QVariant::fromValue<void *>(item)); | 
					
						
							|  |  |  | 			connect(action, SIGNAL(triggered(bool)), this, SLOT(editName())); | 
					
						
							|  |  |  | 			m.addAction(action); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-17 19:15:40 -03: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("Unhide all events"), this, SLOT(unhideEvents())); | 
					
						
							|  |  |  | 		action->setData(event->globalPos()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	m.exec(event->globalPos()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-11 13:56:33 -07:00
										 |  |  | void ProfileWidget2::deleteCurrentDC() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	delete_current_divecomputer(); | 
					
						
							|  |  |  | 	mark_divelist_changed(true); | 
					
						
							|  |  |  | 	// we need to force it since it's likely the same dive and same dc_number - but that's a different dive computer now
 | 
					
						
							| 
									
										
										
										
											2014-07-09 11:19:08 -07:00
										 |  |  | 	MainWindow::instance()->graphics()->plotDive(0, true); | 
					
						
							| 
									
										
										
										
											2014-06-11 13:56:33 -07:00
										 |  |  | 	MainWindow::instance()->refreshDisplay(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-19 14:39:34 +09:00
										 |  |  | void ProfileWidget2::makeFirstDC() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	make_first_dc(); | 
					
						
							|  |  |  | 	mark_divelist_changed(true); | 
					
						
							|  |  |  | 	// this is now the first DC, so we need to redraw the profile and refresh the dive list
 | 
					
						
							|  |  |  | 	// (and no, it's not just enough to rewrite the text - the first DC is special so values in the
 | 
					
						
							|  |  |  | 	// dive list may change).
 | 
					
						
							|  |  |  | 	// As a side benefit, this returns focus to the dive list.
 | 
					
						
							|  |  |  | 	dc_number = 0; | 
					
						
							|  |  |  | 	MainWindow::instance()->refreshDisplay(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-15 21:12:34 -07:00
										 |  |  | void ProfileWidget2::hideEvents() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QAction *action = qobject_cast<QAction *>(sender()); | 
					
						
							|  |  |  | 	DiveEventItem *item = static_cast<DiveEventItem *>(action->data().value<void *>()); | 
					
						
							|  |  |  | 	struct event *event = item->getEvent(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (QMessageBox::question(MainWindow::instance(), | 
					
						
							|  |  |  | 				  TITLE_OR_TEXT(tr("Hide events"), tr("Hide all %1 events?").arg(event->name)), | 
					
						
							|  |  |  | 				  QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) { | 
					
						
							|  |  |  | 		if (event->name) { | 
					
						
							|  |  |  | 			for (int i = 0; i < evn_used; i++) { | 
					
						
							| 
									
										
										
										
											2014-05-14 21:45:39 -03:00
										 |  |  | 				if (same_string(event->name, ev_namelist[i].ev_name)) { | 
					
						
							| 
									
										
										
										
											2014-03-15 21:12:34 -07:00
										 |  |  | 					ev_namelist[i].plot_ev = false; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-05-14 21:45:39 -03:00
										 |  |  | 			Q_FOREACH (DiveEventItem *evItem, eventItems) { | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 				if (same_string(evItem->getEvent()->name, event->name)) | 
					
						
							| 
									
										
										
										
											2014-05-14 21:45:39 -03:00
										 |  |  | 					evItem->hide(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			item->hide(); | 
					
						
							| 
									
										
										
										
											2014-03-15 21:12:34 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileWidget2::unhideEvents() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	for (int i = 0; i < evn_used; i++) { | 
					
						
							|  |  |  | 		ev_namelist[i].plot_ev = true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-14 21:51:45 -03:00
										 |  |  | 	Q_FOREACH (DiveEventItem *item, eventItems) | 
					
						
							|  |  |  | 		item->show(); | 
					
						
							| 
									
										
										
										
											2014-03-15 21:12:34 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileWidget2::removeEvent() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QAction *action = qobject_cast<QAction *>(sender()); | 
					
						
							|  |  |  | 	DiveEventItem *item = static_cast<DiveEventItem *>(action->data().value<void *>()); | 
					
						
							|  |  |  | 	struct event *event = item->getEvent(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (QMessageBox::question(MainWindow::instance(), TITLE_OR_TEXT( | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 								  tr("Remove the selected event?"), | 
					
						
							|  |  |  | 								  tr("%1 @ %2:%3").arg(event->name).arg(event->time.seconds / 60).arg(event->time.seconds % 60, 2, 10, QChar('0'))), | 
					
						
							| 
									
										
										
										
											2014-03-15 21:12:34 -07:00
										 |  |  | 				  QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) { | 
					
						
							| 
									
										
										
										
											2014-05-21 12:06:02 -03:00
										 |  |  | 		remove_event(event); | 
					
						
							| 
									
										
										
										
											2014-03-15 21:12:34 -07:00
										 |  |  | 		mark_divelist_changed(true); | 
					
						
							|  |  |  | 		replot(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileWidget2::addBookmark() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QAction *action = qobject_cast<QAction *>(sender()); | 
					
						
							|  |  |  | 	QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint())); | 
					
						
							|  |  |  | 	add_event(current_dc, timeAxis->valueAt(scenePos), SAMPLE_EVENT_BOOKMARK, 0, 0, "bookmark"); | 
					
						
							| 
									
										
										
										
											2014-07-12 08:37:05 +03:00
										 |  |  | 	mark_divelist_changed(true); | 
					
						
							| 
									
										
										
										
											2014-03-15 21:12:34 -07:00
										 |  |  | 	replot(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-17 19:15:40 -03:00
										 |  |  | void ProfileWidget2::changeGas() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	QAction *action = qobject_cast<QAction *>(sender()); | 
					
						
							| 
									
										
										
										
											2014-02-17 19:15:40 -03:00
										 |  |  | 	QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint())); | 
					
						
							|  |  |  | 	QString gas = action->text(); | 
					
						
							|  |  |  | 	// backup the things on the dataModel, since we will clear that out.
 | 
					
						
							| 
									
										
										
										
											2014-06-01 14:17:06 -07:00
										 |  |  | 	struct gasmix gasmix; | 
					
						
							| 
									
										
										
										
											2014-02-17 19:15:40 -03:00
										 |  |  | 	int seconds = timeAxis->valueAt(scenePos); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-01 14:17:06 -07:00
										 |  |  | 	validate_gas(gas.toUtf8().constData(), &gasmix); | 
					
						
							| 
									
										
										
										
											2014-07-12 13:12:23 +03:00
										 |  |  | 	add_gas_switch_event(&displayed_dive, current_dc, seconds, get_gasidx(&displayed_dive, &gasmix)); | 
					
						
							| 
									
										
										
										
											2014-02-17 19:15:40 -03:00
										 |  |  | 	// this means we potentially have a new tank that is being used and needs to be shown
 | 
					
						
							| 
									
										
										
										
											2014-07-03 14:34:24 -07:00
										 |  |  | 	fixup_dive(&displayed_dive); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// FIXME - this no longer gets written to the dive list - so we need to enableEdition() here
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-02 12:58:41 -07:00
										 |  |  | 	MainWindow::instance()->information()->updateDiveInfo(); | 
					
						
							| 
									
										
										
										
											2014-02-17 19:15:40 -03:00
										 |  |  | 	mark_divelist_changed(true); | 
					
						
							| 
									
										
										
										
											2014-03-09 10:59:31 -03:00
										 |  |  | 	replot(); | 
					
						
							| 
									
										
										
										
											2014-02-19 17:18:26 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-03-25 23:34:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-09 13:09:52 -07:00
										 |  |  | bool ProfileWidget2::getPrintMode() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return printMode; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-25 23:34:09 +02:00
										 |  |  | void ProfileWidget2::setPrintMode(bool mode, bool grayscale) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	printMode = mode; | 
					
						
							|  |  |  | 	isGrayscale = mode ? grayscale : false; | 
					
						
							| 
									
										
										
										
											2014-08-05 18:27:00 -03:00
										 |  |  | 	mouseFollowerHorizontal->setVisible( !mode ); | 
					
						
							|  |  |  | 	mouseFollowerVertical->setVisible( !mode ); | 
					
						
							| 
									
										
										
										
											2014-03-25 23:34:09 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-04-03 21:16:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-09 13:09:52 -07:00
										 |  |  | void ProfileWidget2::setFontPrintScale(double scale) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	fontPrintScale = scale; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | double ProfileWidget2::getFontPrintScale() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (printMode) | 
					
						
							|  |  |  | 		return fontPrintScale; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return 1.0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-03 21:16:15 +02:00
										 |  |  | void ProfileWidget2::editName() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QAction *action = qobject_cast<QAction *>(sender()); | 
					
						
							|  |  |  | 	DiveEventItem *item = static_cast<DiveEventItem *>(action->data().value<void *>()); | 
					
						
							|  |  |  | 	struct event *event = item->getEvent(); | 
					
						
							|  |  |  | 	bool ok; | 
					
						
							|  |  |  | 	QString newName = QInputDialog::getText(MainWindow::instance(), tr("Edit name of bookmark"), | 
					
						
							|  |  |  | 						tr("Custom name:"), QLineEdit::Normal, | 
					
						
							|  |  |  | 						event->name, &ok); | 
					
						
							| 
									
										
										
										
											2014-04-03 12:52:05 -07:00
										 |  |  | 	if (ok && !newName.isEmpty()) { | 
					
						
							|  |  |  | 		if (newName.length() > 22) { //longer names will display as garbage.
 | 
					
						
							| 
									
										
										
										
											2014-04-03 21:16:15 +02:00
										 |  |  | 			QMessageBox lengthWarning; | 
					
						
							| 
									
										
										
										
											2014-07-28 18:12:51 +04:00
										 |  |  | 			lengthWarning.setText(tr("Name is too long!")); | 
					
						
							| 
									
										
										
										
											2014-04-03 21:16:15 +02:00
										 |  |  | 			lengthWarning.exec(); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-07-12 12:48:27 -07:00
										 |  |  | 		// order is important! first update the current dive (by matching the unchanged event),
 | 
					
						
							|  |  |  | 		// then update the displayed dive (as event is part of the events on displayed dive
 | 
					
						
							|  |  |  | 		// and will be freed as part of changing the name!
 | 
					
						
							|  |  |  | 		update_event_name(current_dive, event, newName.toUtf8().data()); | 
					
						
							|  |  |  | 		update_event_name(&displayed_dive, event, newName.toUtf8().data()); | 
					
						
							|  |  |  | 		mark_divelist_changed(true); | 
					
						
							|  |  |  | 		replot(); | 
					
						
							| 
									
										
										
										
											2014-04-03 21:16:15 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-05-21 21:18:10 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-21 21:23:19 -03:00
										 |  |  | void ProfileWidget2::disconnectTemporaryConnections() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); | 
					
						
							|  |  |  | 	disconnect(plannerModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(replot())); | 
					
						
							|  |  |  | 	disconnect(plannerModel, SIGNAL(cylinderModelEdited()), this, SLOT(replot())); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	disconnect(plannerModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 		   this, SLOT(pointInserted(const QModelIndex &, int, int))); | 
					
						
							| 
									
										
										
										
											2014-05-21 21:23:19 -03:00
										 |  |  | 	disconnect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 		   this, SLOT(pointsRemoved(const QModelIndex &, int, int))); | 
					
						
							| 
									
										
										
										
											2014-05-24 12:39:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-03 15:28:06 -07:00
										 |  |  | 	Q_FOREACH (QAction *action, actionsForKeys.values()) { | 
					
						
							| 
									
										
										
										
											2014-05-24 12:39:40 -03:00
										 |  |  | 		action->setShortcut(QKeySequence()); | 
					
						
							| 
									
										
										
										
											2014-06-03 15:28:06 -07:00
										 |  |  | 		action->setShortcutContext(Qt::WidgetShortcut); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-21 21:23:19 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-21 21:18:10 -03:00
										 |  |  | void ProfileWidget2::pointInserted(const QModelIndex &parent, int start, int end) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	DiveHandler *item = new DiveHandler(); | 
					
						
							|  |  |  | 	scene()->addItem(item); | 
					
						
							|  |  |  | 	handles << item; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-23 20:51:30 -03:00
										 |  |  | 	connect(item, SIGNAL(moved()), this, SLOT(recreatePlannedDive())); | 
					
						
							| 
									
										
										
										
											2014-06-30 19:08:16 -03:00
										 |  |  | 	connect(item, SIGNAL(clicked()), this, SLOT(divePlannerHandlerClicked())); | 
					
						
							|  |  |  | 	connect(item, SIGNAL(released()), this, SLOT(divePlannerHandlerReleased())); | 
					
						
							| 
									
										
										
										
											2014-05-21 21:18:10 -03:00
										 |  |  | 	QGraphicsSimpleTextItem *gasChooseBtn = new QGraphicsSimpleTextItem(); | 
					
						
							|  |  |  | 	scene()->addItem(gasChooseBtn); | 
					
						
							|  |  |  | 	gasChooseBtn->setZValue(10); | 
					
						
							|  |  |  | 	gasChooseBtn->setFlag(QGraphicsItem::ItemIgnoresTransformations); | 
					
						
							|  |  |  | 	gases << gasChooseBtn; | 
					
						
							|  |  |  | 	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); | 
					
						
							|  |  |  | 	if (plannerModel->recalcQ()) | 
					
						
							|  |  |  | 		replot(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileWidget2::pointsRemoved(const QModelIndex &, int start, int end) | 
					
						
							|  |  |  | { // start and end are inclusive.
 | 
					
						
							|  |  |  | 	int num = (end - start) + 1; | 
					
						
							|  |  |  | 	for (int i = num; i != 0; i--) { | 
					
						
							|  |  |  | 		delete handles.back(); | 
					
						
							|  |  |  | 		handles.pop_back(); | 
					
						
							|  |  |  | 		delete gases.back(); | 
					
						
							|  |  |  | 		gases.pop_back(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	scene()->clearSelection(); | 
					
						
							|  |  |  | 	replot(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-05-21 23:31:26 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void ProfileWidget2::repositionDiveHandlers() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); | 
					
						
							|  |  |  | 	// Re-position the user generated dive handlers
 | 
					
						
							|  |  |  | 	int last = 0; | 
					
						
							|  |  |  | 	for (int i = 0; i < plannerModel->rowCount(); i++) { | 
					
						
							|  |  |  | 		struct divedatapoint datapoint = plannerModel->at(i); | 
					
						
							|  |  |  | 		if (datapoint.time == 0) // those are the magic entries for tanks
 | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		DiveHandler *h = handles.at(i); | 
					
						
							| 
									
										
										
										
											2014-05-29 23:47:03 -03:00
										 |  |  | 		h->setVisible(datapoint.entered); | 
					
						
							| 
									
										
										
										
											2014-05-21 23:31:26 -03:00
										 |  |  | 		h->setPos(timeAxis->posAtValue(datapoint.time), profileYAxis->posAtValue(datapoint.depth)); | 
					
						
							|  |  |  | 		QPointF p1 = (last == i) ? QPointF(timeAxis->posAtValue(0), profileYAxis->posAtValue(0)) : handles[last]->pos(); | 
					
						
							|  |  |  | 		QPointF p2 = handles[i]->pos(); | 
					
						
							|  |  |  | 		QLineF line(p1, p2); | 
					
						
							|  |  |  | 		QPointF pos = line.pointAt(0.5); | 
					
						
							|  |  |  | 		gases[i]->setPos(pos); | 
					
						
							| 
									
										
										
										
											2014-05-29 23:47:03 -03:00
										 |  |  | 		gases[i]->setVisible(datapoint.entered); | 
					
						
							| 
									
										
										
										
											2014-05-21 23:31:26 -03:00
										 |  |  | 		gases[i]->setText(dpGasToStr(plannerModel->at(i))); | 
					
						
							|  |  |  | 		last = i; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-05-23 20:51:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-23 22:22:02 -03:00
										 |  |  | int ProfileWidget2::fixHandlerIndex(DiveHandler *activeHandler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int index = handles.indexOf(activeHandler); | 
					
						
							|  |  |  | 	if (index > 0 && index < handles.count() - 1) { | 
					
						
							|  |  |  | 		DiveHandler *before = handles[index - 1]; | 
					
						
							|  |  |  | 		if (before->pos().x() > activeHandler->pos().x()) { | 
					
						
							| 
									
										
										
										
											2014-05-24 12:39:40 -03:00
										 |  |  | 			handles.swap(index, index - 1); | 
					
						
							| 
									
										
										
										
											2014-05-23 22:22:02 -03:00
										 |  |  | 			return index - 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		DiveHandler *after = handles[index + 1]; | 
					
						
							|  |  |  | 		if (after->pos().x() < activeHandler->pos().x()) { | 
					
						
							| 
									
										
										
										
											2014-05-24 12:39:40 -03:00
										 |  |  | 			handles.swap(index, index + 1); | 
					
						
							| 
									
										
										
										
											2014-05-23 22:22:02 -03:00
										 |  |  | 			return index + 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return index; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-23 20:51:30 -03:00
										 |  |  | void ProfileWidget2::recreatePlannedDive() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-05-24 12:39:40 -03:00
										 |  |  | 	DiveHandler *activeHandler = qobject_cast<DiveHandler *>(sender()); | 
					
						
							| 
									
										
										
										
											2014-05-23 20:51:30 -03:00
										 |  |  | 	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); | 
					
						
							| 
									
										
										
										
											2014-05-23 22:22:02 -03:00
										 |  |  | 	int index = fixHandlerIndex(activeHandler); | 
					
						
							| 
									
										
										
										
											2014-05-23 20:51:30 -03:00
										 |  |  | 	int mintime = 0, maxtime = (timeAxis->maximum() + 10) * 60; | 
					
						
							|  |  |  | 	if (index > 0) | 
					
						
							|  |  |  | 		mintime = plannerModel->at(index - 1).time; | 
					
						
							|  |  |  | 	if (index < plannerModel->size() - 1) | 
					
						
							|  |  |  | 		maxtime = plannerModel->at(index + 1).time; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int minutes = rint(timeAxis->valueAt(activeHandler->pos()) / 60); | 
					
						
							|  |  |  | 	if (minutes * 60 <= mintime || minutes * 60 >= maxtime) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	divedatapoint data = plannerModel->at(index); | 
					
						
							| 
									
										
										
										
											2014-05-24 12:39:40 -03:00
										 |  |  | 	data.depth = rint(profileYAxis->valueAt(activeHandler->pos()) / M_OR_FT(1, 1)) * M_OR_FT(1, 1); | 
					
						
							| 
									
										
										
										
											2014-05-23 20:51:30 -03:00
										 |  |  | 	data.time = rint(timeAxis->valueAt(activeHandler->pos())); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	plannerModel->editStop(index, data); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-05-24 12:39:40 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void ProfileWidget2::keyDownAction() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (currentState != ADD && currentState != PLAN) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); | 
					
						
							|  |  |  | 	Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) { | 
					
						
							|  |  |  | 		if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) { | 
					
						
							|  |  |  | 			int row = handles.indexOf(handler); | 
					
						
							|  |  |  | 			divedatapoint dp = plannerModel->at(row); | 
					
						
							|  |  |  | 			if (dp.depth >= profileYAxis->maximum()) | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			dp.depth += M_OR_FT(1, 5); | 
					
						
							|  |  |  | 			plannerModel->editStop(row, dp); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileWidget2::keyUpAction() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (currentState != ADD && currentState != PLAN) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); | 
					
						
							|  |  |  | 	Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) { | 
					
						
							|  |  |  | 		if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) { | 
					
						
							|  |  |  | 			int row = handles.indexOf(handler); | 
					
						
							|  |  |  | 			divedatapoint dp = plannerModel->at(row); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (dp.depth <= 0) | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			dp.depth -= M_OR_FT(1, 5); | 
					
						
							|  |  |  | 			plannerModel->editStop(row, dp); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileWidget2::keyLeftAction() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (currentState != ADD && currentState != PLAN) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); | 
					
						
							|  |  |  | 	Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) { | 
					
						
							|  |  |  | 		if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) { | 
					
						
							|  |  |  | 			int row = handles.indexOf(handler); | 
					
						
							|  |  |  | 			divedatapoint dp = plannerModel->at(row); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (dp.time / 60 <= 0) | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// don't overlap positions.
 | 
					
						
							|  |  |  | 			// maybe this is a good place for a 'goto'?
 | 
					
						
							|  |  |  | 			double xpos = timeAxis->posAtValue((dp.time - 60) / 60); | 
					
						
							|  |  |  | 			bool nextStep = false; | 
					
						
							|  |  |  | 			Q_FOREACH (DiveHandler *h, handles) { | 
					
						
							|  |  |  | 				if (IS_FP_SAME(h->pos().x(), xpos)) { | 
					
						
							|  |  |  | 					nextStep = true; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (nextStep) | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			dp.time -= 60; | 
					
						
							|  |  |  | 			plannerModel->editStop(row, dp); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileWidget2::keyRightAction() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (currentState != ADD && currentState != PLAN) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); | 
					
						
							|  |  |  | 	Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) { | 
					
						
							|  |  |  | 		if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) { | 
					
						
							|  |  |  | 			int row = handles.indexOf(handler); | 
					
						
							|  |  |  | 			divedatapoint dp = plannerModel->at(row); | 
					
						
							|  |  |  | 			if (dp.time / 60 >= timeAxis->maximum()) | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// don't overlap positions.
 | 
					
						
							|  |  |  | 			// maybe this is a good place for a 'goto'?
 | 
					
						
							|  |  |  | 			double xpos = timeAxis->posAtValue((dp.time + 60) / 60); | 
					
						
							|  |  |  | 			bool nextStep = false; | 
					
						
							|  |  |  | 			Q_FOREACH (DiveHandler *h, handles) { | 
					
						
							|  |  |  | 				if (IS_FP_SAME(h->pos().x(), xpos)) { | 
					
						
							|  |  |  | 					nextStep = true; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (nextStep) | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			dp.time += 60; | 
					
						
							|  |  |  | 			plannerModel->editStop(row, dp); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileWidget2::keyDeleteAction() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (currentState != ADD && currentState != PLAN) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); | 
					
						
							|  |  |  | 	int selCount = scene()->selectedItems().count(); | 
					
						
							|  |  |  | 	if (selCount) { | 
					
						
							|  |  |  | 		QVector<int> selectedIndexes; | 
					
						
							|  |  |  | 		Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) { | 
					
						
							|  |  |  | 			if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) { | 
					
						
							|  |  |  | 				selectedIndexes.push_back(handles.indexOf(handler)); | 
					
						
							| 
									
										
										
										
											2014-07-30 09:31:22 -07:00
										 |  |  | 				handler->hide(); | 
					
						
							| 
									
										
										
										
											2014-05-24 12:39:40 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		plannerModel->removeSelectedPoints(selectedIndexes); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ProfileWidget2::keyEscAction() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (currentState != ADD && currentState != PLAN) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (scene()->selectedItems().count()) { | 
					
						
							|  |  |  | 		scene()->clearSelection(); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); | 
					
						
							|  |  |  | 	if (plannerModel->isPlanner()) | 
					
						
							|  |  |  | 		plannerModel->cancelPlan(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-03 19:24:01 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void ProfileWidget2::plotPictures() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-07-29 23:03:32 -03:00
										 |  |  | 	Q_FOREACH(DivePictureItem *item, pictures){ | 
					
						
							| 
									
										
										
										
											2014-08-05 11:42:19 -07:00
										 |  |  | 		item->hide(); | 
					
						
							| 
									
										
										
										
											2014-07-29 23:03:32 -03:00
										 |  |  | 		item->deleteLater(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-07-21 18:54:28 -03:00
										 |  |  | 	pictures.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-02 13:58:06 -07:00
										 |  |  | 	if (printMode) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-08 12:36:27 -07:00
										 |  |  | 	double x, y, lastX = -1.0, lastY = -1.0; | 
					
						
							| 
									
										
										
										
											2014-06-03 19:24:01 -03:00
										 |  |  | 	DivePictureModel *m = DivePictureModel::instance(); | 
					
						
							| 
									
										
										
										
											2014-06-03 19:42:47 -03:00
										 |  |  | 	for (int i = 0; i < m->rowCount(); i++) { | 
					
						
							| 
									
										
										
										
											2014-08-05 12:37:14 -07:00
										 |  |  | 		int offsetSeconds = m->index(i,1).data(Qt::UserRole).value<int>(); | 
					
						
							| 
									
										
										
										
											2014-06-03 19:42:47 -03:00
										 |  |  | 		// it's a correct picture, but doesn't have a timestamp: only show on the widget near the
 | 
					
						
							|  |  |  | 		// information area.
 | 
					
						
							| 
									
										
										
										
											2014-08-05 12:37:14 -07:00
										 |  |  | 		if (!offsetSeconds) | 
					
						
							| 
									
										
										
										
											2014-06-03 19:42:47 -03:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2014-07-29 22:13:14 -03:00
										 |  |  | 		DivePictureItem *item = new DivePictureItem(); | 
					
						
							| 
									
										
										
										
											2014-06-03 19:24:01 -03:00
										 |  |  | 		item->setPixmap(m->index(i,0).data(Qt::DecorationRole).value<QPixmap>()); | 
					
						
							| 
									
										
										
										
											2014-07-29 23:03:32 -03:00
										 |  |  | 		item->setFileUrl(m->index(i,1).data().toString()); | 
					
						
							| 
									
										
										
										
											2014-06-08 11:56:35 -07:00
										 |  |  | 		// let's put the picture at the correct time, but at a fixed "depth" on the profile
 | 
					
						
							|  |  |  | 		// not sure this is ideal, but it seems to look right.
 | 
					
						
							| 
									
										
										
										
											2014-08-05 12:37:14 -07:00
										 |  |  | 		x = timeAxis->posAtValue(offsetSeconds); | 
					
						
							| 
									
										
										
										
											2014-06-08 12:36:27 -07:00
										 |  |  | 		if (i == 0) | 
					
						
							|  |  |  | 			y = 10; | 
					
						
							| 
									
										
										
										
											2014-06-27 18:00:42 -03:00
										 |  |  | 		else if (fabs(x - lastX) < 4) | 
					
						
							|  |  |  | 			y = lastY + 3; | 
					
						
							| 
									
										
										
										
											2014-06-08 12:36:27 -07:00
										 |  |  | 		lastX = x; | 
					
						
							|  |  |  | 		lastY = y; | 
					
						
							| 
									
										
										
										
											2014-06-08 11:56:35 -07:00
										 |  |  | 		item->setPos(x, y); | 
					
						
							| 
									
										
										
										
											2014-06-03 19:24:01 -03:00
										 |  |  | 		scene()->addItem(item); | 
					
						
							|  |  |  | 		pictures.push_back(item); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |