| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | #include "divecartesianaxis.h"
 | 
					
						
							|  |  |  | #include "divelineitem.h"
 | 
					
						
							|  |  |  | #include "divetextitem.h"
 | 
					
						
							|  |  |  | #include "helpers.h"
 | 
					
						
							| 
									
										
										
										
											2014-01-22 17:10:18 -02:00
										 |  |  | #include "preferences.h"
 | 
					
						
							| 
									
										
										
										
											2014-01-27 15:14:42 -02:00
										 |  |  | #include "diveplotdatamodel.h"
 | 
					
						
							|  |  |  | #include "animationfunctions.h"
 | 
					
						
							| 
									
										
										
										
											2014-07-09 13:09:52 -07:00
										 |  |  | #include "mainwindow.h"
 | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | #include <QPen>
 | 
					
						
							|  |  |  | #include <QGraphicsScene>
 | 
					
						
							|  |  |  | #include <QDebug>
 | 
					
						
							|  |  |  | #include <QGraphicsView>
 | 
					
						
							|  |  |  | #include <QStyleOption>
 | 
					
						
							| 
									
										
										
										
											2014-01-22 17:10:18 -02:00
										 |  |  | #include <QSettings>
 | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | static QPen gridPen() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-01-19 20:14:48 -02:00
										 |  |  | 	QPen pen; | 
					
						
							|  |  |  | 	pen.setColor(getColor(TIME_GRID)); | 
					
						
							|  |  |  | 	pen.setWidth(2); | 
					
						
							|  |  |  | 	pen.setCosmetic(true); | 
					
						
							|  |  |  | 	return pen; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-07 14:59:58 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-07 17:59:21 -02:00
										 |  |  | double DiveCartesianAxis::tickInterval() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return interval; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | double DiveCartesianAxis::tickSize() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return tick_size; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-15 11:15:57 -08:00
										 |  |  | void DiveCartesianAxis::setFontLabelScale(qreal scale) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	labelScale = scale; | 
					
						
							| 
									
										
										
										
											2014-05-26 18:01:38 -03:00
										 |  |  | 	changed = true; | 
					
						
							| 
									
										
										
										
											2014-02-15 11:15:57 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | void DiveCartesianAxis::setMaximum(double maximum) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-10 20:43:21 -08:00
										 |  |  | 	if (IS_FP_SAME(max, maximum)) | 
					
						
							| 
									
										
										
										
											2014-02-04 19:21:57 -02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | 	max = maximum; | 
					
						
							| 
									
										
										
										
											2014-05-26 18:01:38 -03:00
										 |  |  | 	changed = true; | 
					
						
							| 
									
										
										
										
											2014-01-27 15:14:42 -02:00
										 |  |  | 	emit maxChanged(); | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DiveCartesianAxis::setMinimum(double minimum) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-10 20:43:21 -08:00
										 |  |  | 	if (IS_FP_SAME(min, minimum)) | 
					
						
							| 
									
										
										
										
											2014-02-04 19:21:57 -02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | 	min = minimum; | 
					
						
							| 
									
										
										
										
											2014-05-26 18:01:38 -03:00
										 |  |  | 	changed = true; | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void DiveCartesianAxis::setTextColor(const QColor &color) | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | { | 
					
						
							|  |  |  | 	textColor = color; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 18:37:40 +01:00
										 |  |  | DiveCartesianAxis::DiveCartesianAxis() : QObject(), | 
					
						
							|  |  |  | 	QGraphicsLineItem(), | 
					
						
							|  |  |  | 	unitSystem(0), | 
					
						
							|  |  |  | 	orientation(LeftToRight), | 
					
						
							|  |  |  | 	min(0), | 
					
						
							|  |  |  | 	max(0), | 
					
						
							|  |  |  | 	interval(1), | 
					
						
							| 
									
										
										
										
											2014-02-12 14:24:19 -02:00
										 |  |  | 	tick_size(0), | 
					
						
							| 
									
										
										
										
											2014-02-15 21:55:31 -02:00
										 |  |  | 	textVisibility(true), | 
					
						
							| 
									
										
										
										
											2014-02-17 14:39:03 -08:00
										 |  |  | 	lineVisibility(true), | 
					
						
							| 
									
										
										
										
											2014-03-10 13:43:43 +02:00
										 |  |  | 	labelScale(1.0), | 
					
						
							| 
									
										
										
										
											2014-05-26 18:01:38 -03:00
										 |  |  | 	line_size(1), | 
					
						
							|  |  |  | 	changed(true) | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-01-19 20:14:48 -02:00
										 |  |  | 	setPen(gridPen()); | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | DiveCartesianAxis::~DiveCartesianAxis() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-15 21:55:31 -02:00
										 |  |  | void DiveCartesianAxis::setLineSize(qreal lineSize) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	line_size = lineSize; | 
					
						
							| 
									
										
										
										
											2014-05-26 18:01:38 -03:00
										 |  |  | 	changed = true; | 
					
						
							| 
									
										
										
										
											2014-02-15 21:55:31 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 19:28:33 -02:00
										 |  |  | void DiveCartesianAxis::setOrientation(Orientation o) | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | { | 
					
						
							|  |  |  | 	orientation = o; | 
					
						
							| 
									
										
										
										
											2014-05-26 18:01:38 -03:00
										 |  |  | 	changed = true; | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-19 20:14:48 -02:00
										 |  |  | QColor DiveCartesianAxis::colorForValue(double value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return QColor(Qt::black); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-12 14:24:19 -02:00
										 |  |  | void DiveCartesianAxis::setTextVisible(bool arg1) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	if (textVisibility == arg1) { | 
					
						
							| 
									
										
										
										
											2014-02-12 14:24:19 -02:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	textVisibility = arg1; | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	Q_FOREACH (DiveTextItem *item, labels) { | 
					
						
							| 
									
										
										
										
											2014-02-12 14:24:19 -02:00
										 |  |  | 		item->setVisible(textVisibility); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-15 22:54:41 -02:00
										 |  |  | void DiveCartesianAxis::setLinesVisible(bool arg1) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	if (lineVisibility == arg1) { | 
					
						
							| 
									
										
										
										
											2014-02-15 22:54:41 -02:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	lineVisibility = arg1; | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	Q_FOREACH (DiveLineItem *item, lines) { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		item->setVisible(lineVisibility); | 
					
						
							| 
									
										
										
										
											2014-02-15 22:54:41 -02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | template <typename T> | 
					
						
							|  |  |  | void emptyList(QList<T *> &list, double steps) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-15 21:55:31 -02:00
										 |  |  | 	if (!list.isEmpty() && list.size() > steps) { | 
					
						
							|  |  |  | 		while (list.size() > steps) { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 			T *removedItem = list.takeLast(); | 
					
						
							|  |  |  | 			Animations::animDelete(removedItem); | 
					
						
							| 
									
										
										
										
											2014-02-15 21:55:31 -02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-28 12:45:42 -07:00
										 |  |  | void DiveCartesianAxis::updateTicks(color_indice_t color) | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-07-09 13:09:52 -07:00
										 |  |  | 	if (!scene() || (!changed && !MainWindow::instance()->graphics()->getPrintMode())) | 
					
						
							| 
									
										
										
										
											2014-01-25 07:25:03 -08:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | 	QLineF m = line(); | 
					
						
							| 
									
										
										
										
											2014-01-16 12:44:18 +07:00
										 |  |  | 	// unused so far:
 | 
					
						
							|  |  |  | 	// QGraphicsView *view = scene()->views().first();
 | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | 	double steps = (max - min) / interval; | 
					
						
							| 
									
										
										
										
											2014-02-15 22:15:45 -02:00
										 |  |  | 	double currValueText = min; | 
					
						
							|  |  |  | 	double currValueLine = min; | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-27 15:14:42 -02:00
										 |  |  | 	if (steps < 1) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-01-27 17:09:08 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-15 21:55:31 -02:00
										 |  |  | 	emptyList(labels, steps); | 
					
						
							|  |  |  | 	emptyList(lines, steps); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-14 16:24:33 -02:00
										 |  |  | 	// Move the remaining Ticks / Text to it's corerct position
 | 
					
						
							|  |  |  | 	// Regartind the possibly new values for the Axis
 | 
					
						
							| 
									
										
										
										
											2014-01-16 19:28:33 -02:00
										 |  |  | 	qreal begin, stepSize; | 
					
						
							|  |  |  | 	if (orientation == TopToBottom) { | 
					
						
							|  |  |  | 		begin = m.y1(); | 
					
						
							|  |  |  | 		stepSize = (m.y2() - m.y1()); | 
					
						
							|  |  |  | 	} else if (orientation == BottomToTop) { | 
					
						
							|  |  |  | 		begin = m.y2(); | 
					
						
							|  |  |  | 		stepSize = (m.y2() - m.y1()); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	} else if (orientation == LeftToRight) { | 
					
						
							| 
									
										
										
										
											2014-01-16 19:28:33 -02:00
										 |  |  | 		begin = m.x1(); | 
					
						
							|  |  |  | 		stepSize = (m.x2() - m.x1()); | 
					
						
							| 
									
										
										
										
											2014-06-11 09:37:12 -07:00
										 |  |  | 	} else /* if (orientation == RightToLeft) */ { | 
					
						
							| 
									
										
										
										
											2014-01-16 19:28:33 -02:00
										 |  |  | 		begin = m.x2(); | 
					
						
							|  |  |  | 		stepSize = (m.x2() - m.x1()); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-01-14 16:24:33 -02:00
										 |  |  | 	stepSize = stepSize / steps; | 
					
						
							| 
									
										
										
										
											2014-01-16 19:28:33 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-15 22:15:45 -02:00
										 |  |  | 	for (int i = 0, count = labels.size(); i < count; i++, currValueText += interval) { | 
					
						
							|  |  |  | 		qreal childPos = (orientation == TopToBottom || orientation == LeftToRight) ? | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 					 begin + i * stepSize : | 
					
						
							|  |  |  | 					 begin - i * stepSize; | 
					
						
							| 
									
										
										
										
											2014-01-27 17:09:08 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-15 22:15:45 -02:00
										 |  |  | 		labels[i]->setText(textForValue(currValueText)); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		if (orientation == LeftToRight || orientation == RightToLeft) { | 
					
						
							| 
									
										
										
										
											2014-07-11 19:13:01 -03:00
										 |  |  | 			Animations::moveTo(labels[i],childPos, m.y1() + tick_size); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2014-07-11 19:13:01 -03:00
										 |  |  | 			Animations::moveTo(labels[i],m.x1() - tick_size, childPos); | 
					
						
							| 
									
										
										
										
											2014-01-14 16:24:33 -02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-15 22:15:45 -02:00
										 |  |  | 	for (int i = 0, count = lines.size(); i < count; i++, currValueLine += interval) { | 
					
						
							|  |  |  | 		qreal childPos = (orientation == TopToBottom || orientation == LeftToRight) ? | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 					 begin + i * stepSize : | 
					
						
							|  |  |  | 					 begin - i * stepSize; | 
					
						
							| 
									
										
										
										
											2014-02-15 22:15:45 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		if (orientation == LeftToRight || orientation == RightToLeft) { | 
					
						
							| 
									
										
										
										
											2014-07-11 19:13:01 -03:00
										 |  |  | 			Animations::moveTo(lines[i],childPos, m.y1()); | 
					
						
							| 
									
										
										
										
											2014-02-15 22:15:45 -02:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2014-07-11 19:13:01 -03:00
										 |  |  | 			Animations::moveTo(lines[i],m.x1(), childPos); | 
					
						
							| 
									
										
										
										
											2014-02-15 22:15:45 -02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-14 16:28:07 -02:00
										 |  |  | 	// Add's the rest of the needed Ticks / Text.
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	for (int i = labels.size(); i < steps; i++, currValueText += interval) { | 
					
						
							| 
									
										
										
										
											2014-01-16 19:28:33 -02:00
										 |  |  | 		qreal childPos; | 
					
						
							|  |  |  | 		if (orientation == TopToBottom || orientation == LeftToRight) { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 			childPos = begin + i * stepSize; | 
					
						
							| 
									
										
										
										
											2014-01-16 19:28:33 -02:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			childPos = begin - i * stepSize; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-07 18:08:29 -02:00
										 |  |  | 		DiveTextItem *label = new DiveTextItem(this); | 
					
						
							| 
									
										
										
										
											2014-02-15 22:15:45 -02:00
										 |  |  | 		label->setText(textForValue(currValueText)); | 
					
						
							|  |  |  | 		label->setBrush(colorForValue(currValueText)); | 
					
						
							| 
									
										
										
										
											2014-02-15 11:15:57 -08:00
										 |  |  | 		label->setScale(fontLabelScale()); | 
					
						
							| 
									
										
										
										
											2014-02-15 22:49:30 -02:00
										 |  |  | 		label->setZValue(1); | 
					
						
							| 
									
										
										
										
											2014-02-07 18:08:29 -02:00
										 |  |  | 		labels.push_back(label); | 
					
						
							| 
									
										
										
										
											2014-01-16 19:28:33 -02:00
										 |  |  | 		if (orientation == RightToLeft || orientation == LeftToRight) { | 
					
						
							| 
									
										
										
										
											2014-02-07 18:08:29 -02:00
										 |  |  | 			label->setAlignment(Qt::AlignBottom | Qt::AlignHCenter); | 
					
						
							|  |  |  | 			label->setPos(scene()->sceneRect().width() + 10, m.y1() + tick_size); // position it outside of the scene);
 | 
					
						
							| 
									
										
										
										
											2014-07-11 19:13:01 -03:00
										 |  |  | 			Animations::moveTo(label,childPos, m.y1() + tick_size); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 			label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); | 
					
						
							| 
									
										
										
										
											2014-02-07 18:08:29 -02:00
										 |  |  | 			label->setPos(m.x1() - tick_size, scene()->sceneRect().height() + 10); | 
					
						
							| 
									
										
										
										
											2014-07-11 19:13:01 -03:00
										 |  |  | 			Animations::moveTo(label,m.x1() - tick_size, childPos); | 
					
						
							| 
									
										
										
										
											2014-01-14 16:28:07 -02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-12 14:24:19 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-15 22:43:27 -02:00
										 |  |  | 	// Add's the rest of the needed Ticks / Text.
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	for (int i = lines.size(); i < steps; i++, currValueText += interval) { | 
					
						
							| 
									
										
										
										
											2014-02-15 22:43:27 -02:00
										 |  |  | 		qreal childPos; | 
					
						
							|  |  |  | 		if (orientation == TopToBottom || orientation == LeftToRight) { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 			childPos = begin + i * stepSize; | 
					
						
							| 
									
										
										
										
											2014-02-15 22:43:27 -02:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			childPos = begin - i * stepSize; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		DiveLineItem *line = new DiveLineItem(this); | 
					
						
							|  |  |  | 		QPen pen; | 
					
						
							| 
									
										
										
										
											2014-04-28 12:45:42 -07:00
										 |  |  | 		pen.setBrush(getColor(color)); | 
					
						
							| 
									
										
										
										
											2014-02-15 22:43:27 -02:00
										 |  |  | 		pen.setCosmetic(true); | 
					
						
							|  |  |  | 		pen.setWidthF(2); | 
					
						
							|  |  |  | 		line->setPen(pen); | 
					
						
							| 
									
										
										
										
											2014-02-15 22:49:30 -02:00
										 |  |  | 		line->setZValue(0); | 
					
						
							| 
									
										
										
										
											2014-02-15 22:43:27 -02:00
										 |  |  | 		lines.push_back(line); | 
					
						
							|  |  |  | 		if (orientation == RightToLeft || orientation == LeftToRight) { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 			line->setLine(0, -line_size, 0, 0); | 
					
						
							| 
									
										
										
										
											2014-05-26 18:20:40 -03:00
										 |  |  | 			line->setPos(scene()->sceneRect().width() + 10, m.y1()); // position it outside of the scene);
 | 
					
						
							| 
									
										
										
										
											2014-07-11 19:13:01 -03:00
										 |  |  | 			Animations::moveTo(line,childPos, m.y1()); | 
					
						
							| 
									
										
										
										
											2014-02-15 22:43:27 -02:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			QPointF p1 = mapFromScene(3, 0); | 
					
						
							|  |  |  | 			QPointF p2 = mapFromScene(line_size, 0); | 
					
						
							|  |  |  | 			line->setLine(p1.x(), 0, p2.x(), 0); | 
					
						
							| 
									
										
										
										
											2014-05-26 18:20:40 -03:00
										 |  |  | 			line->setPos(m.x1(), scene()->sceneRect().height() + 10); | 
					
						
							| 
									
										
										
										
											2014-07-11 19:13:01 -03:00
										 |  |  | 			Animations::moveTo(line,m.x1(), childPos); | 
					
						
							| 
									
										
										
										
											2014-02-15 22:43:27 -02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	Q_FOREACH (DiveTextItem *item, labels) | 
					
						
							| 
									
										
										
										
											2014-03-03 13:25:55 -08:00
										 |  |  | 		item->setVisible(textVisibility); | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	Q_FOREACH (DiveLineItem *item, lines) | 
					
						
							| 
									
										
										
										
											2014-03-03 13:25:55 -08:00
										 |  |  | 		item->setVisible(lineVisibility); | 
					
						
							| 
									
										
										
										
											2014-05-26 18:01:38 -03:00
										 |  |  | 	changed = false; | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-29 18:48:17 -03:00
										 |  |  | void DiveCartesianAxis::setLine(const QLineF &line) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QGraphicsLineItem::setLine(line); | 
					
						
							|  |  |  | 	changed = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void DiveCartesianAxis::animateChangeLine(const QLineF &newLine) | 
					
						
							| 
									
										
										
										
											2014-01-22 17:10:18 -02:00
										 |  |  | { | 
					
						
							|  |  |  | 	setLine(newLine); | 
					
						
							|  |  |  | 	updateTicks(); | 
					
						
							|  |  |  | 	sizeChanged(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | QString DiveCartesianAxis::textForValue(double value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return QString::number(value); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DiveCartesianAxis::setTickSize(qreal size) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-07 17:59:21 -02:00
										 |  |  | 	tick_size = size; | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DiveCartesianAxis::setTickInterval(double i) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	interval = i; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | qreal DiveCartesianAxis::valueAt(const QPointF &p) const | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | { | 
					
						
							|  |  |  | 	QLineF m = line(); | 
					
						
							| 
									
										
										
										
											2014-02-11 12:05:33 -08:00
										 |  |  | 	QPointF relativePosition = p; | 
					
						
							|  |  |  | 	relativePosition -= pos(); // normalize p based on the axis' offset on screen
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	double retValue = (orientation == LeftToRight || orientation == RightToLeft) ? | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 				  max * (relativePosition.x() - m.x1()) / (m.x2() - m.x1()) : | 
					
						
							|  |  |  | 				  max * (relativePosition.y() - m.y1()) / (m.y2() - m.y1()); | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | 	return retValue; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | qreal DiveCartesianAxis::posAtValue(qreal value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QLineF m = line(); | 
					
						
							|  |  |  | 	QPointF p = pos(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	double size = max - min; | 
					
						
							| 
									
										
										
										
											2014-01-17 06:30:47 +07:00
										 |  |  | 	// unused for now:
 | 
					
						
							|  |  |  | 	// double distanceFromOrigin = value - min;
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	double percent = IS_FP_SAME(min, max) ? 0.0 : (value - min) / size; | 
					
						
							| 
									
										
										
										
											2014-01-21 21:43:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 19:28:33 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	double realSize = orientation == LeftToRight || orientation == RightToLeft ? | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 				  m.x2() - m.x1() : | 
					
						
							|  |  |  | 				  m.y2() - m.y1(); | 
					
						
							| 
									
										
										
										
											2014-01-16 19:28:33 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Inverted axis, just invert the percentage.
 | 
					
						
							| 
									
										
										
										
											2014-01-17 06:30:47 +07:00
										 |  |  | 	if (orientation == RightToLeft || orientation == BottomToTop) | 
					
						
							| 
									
										
										
										
											2014-01-16 19:28:33 -02:00
										 |  |  | 		percent = 1 - percent; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | 	double retValue = realSize * percent; | 
					
						
							| 
									
										
										
										
											2014-01-16 19:28:33 -02:00
										 |  |  | 	double adjusted = | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 		orientation == LeftToRight ? retValue + m.x1() + p.x() : | 
					
						
							| 
									
										
										
										
											2014-07-29 16:34:57 -03:00
										 |  |  | 		orientation == RightToLeft ? retValue + m.x1() + p.x() : | 
					
						
							|  |  |  | 		orientation == TopToBottom ? retValue + m.y1() + p.y() : | 
					
						
							|  |  |  | 		/* entation == BottomToTop */ retValue + m.y1() + p.y(); | 
					
						
							| 
									
										
										
										
											2014-01-16 18:39:13 -02:00
										 |  |  | 	return adjusted; | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | qreal DiveCartesianAxis::percentAt(const QPointF &p) | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | { | 
					
						
							|  |  |  | 	qreal value = valueAt(p); | 
					
						
							|  |  |  | 	double size = max - min; | 
					
						
							|  |  |  | 	double percent = value / size; | 
					
						
							|  |  |  | 	return percent; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | double DiveCartesianAxis::maximum() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return max; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | double DiveCartesianAxis::minimum() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return min; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-15 11:15:57 -08:00
										 |  |  | double DiveCartesianAxis::fontLabelScale() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return labelScale; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void DiveCartesianAxis::setColor(const QColor &color) | 
					
						
							| 
									
										
										
										
											2014-01-14 16:20:15 -02:00
										 |  |  | { | 
					
						
							|  |  |  | 	QPen defaultPen(color); | 
					
						
							|  |  |  | 	defaultPen.setJoinStyle(Qt::RoundJoin); | 
					
						
							|  |  |  | 	defaultPen.setCapStyle(Qt::RoundCap); | 
					
						
							|  |  |  | 	defaultPen.setWidth(2); | 
					
						
							|  |  |  | 	defaultPen.setCosmetic(true); | 
					
						
							|  |  |  | 	setPen(defaultPen); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-15 10:54:33 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | QString DepthAxis::textForValue(double value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-15 20:48:58 -02:00
										 |  |  | 	if (value == 0) | 
					
						
							|  |  |  | 		return QString(); | 
					
						
							| 
									
										
										
										
											2014-01-15 10:54:33 -02:00
										 |  |  | 	return get_depth_string(value, false, false); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-15 11:08:31 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-19 20:14:48 -02:00
										 |  |  | QColor DepthAxis::colorForValue(double value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Q_UNUSED(value); | 
					
						
							|  |  |  | 	return QColor(Qt::red); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-29 16:34:57 -03:00
										 |  |  | DepthAxis::DepthAxis() | 
					
						
							| 
									
										
										
										
											2014-01-22 17:10:18 -02:00
										 |  |  | { | 
					
						
							|  |  |  | 	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged())); | 
					
						
							| 
									
										
										
										
											2014-07-29 16:34:57 -03:00
										 |  |  | 	changed = true; | 
					
						
							| 
									
										
										
										
											2014-02-05 21:58:21 +01:00
										 |  |  | 	settingsChanged(); | 
					
						
							| 
									
										
										
										
											2014-01-22 17:10:18 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DepthAxis::settingsChanged() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-07-29 16:34:57 -03:00
										 |  |  | 	static int unitSystem = prefs.units.length; | 
					
						
							|  |  |  | 	if ( unitSystem == prefs.units.length ) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	changed = true; | 
					
						
							|  |  |  | 	updateTicks(); | 
					
						
							|  |  |  | 	unitSystem = prefs.units.length; | 
					
						
							| 
									
										
										
										
											2014-01-22 17:10:18 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-19 20:14:48 -02:00
										 |  |  | QColor TimeAxis::colorForValue(double value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Q_UNUSED(value); | 
					
						
							|  |  |  | 	return QColor(Qt::blue); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-15 11:08:31 -02:00
										 |  |  | QString TimeAxis::textForValue(double value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-01-27 17:09:08 -02:00
										 |  |  | 	int nr = value / 60; | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	if (maximum() < 600) | 
					
						
							|  |  |  | 		return QString("%1:%2").arg(nr).arg((int)value % 60, 2, 10, QChar('0')); | 
					
						
							|  |  |  | 	return QString::number(nr); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-16 12:32:45 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-27 17:18:35 -02:00
										 |  |  | void TimeAxis::updateTicks() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	DiveCartesianAxis::updateTicks(); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	if (maximum() > 600) { | 
					
						
							|  |  |  | 		for (int i = 0; i < labels.count(); i++) { | 
					
						
							| 
									
										
										
										
											2014-01-27 17:18:35 -02:00
										 |  |  | 			labels[i]->setVisible(i % 2); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 18:39:13 -02:00
										 |  |  | QString TemperatureAxis::textForValue(double value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	return QString::number(mkelvin_to_C((int)value)); | 
					
						
							| 
									
										
										
										
											2014-01-16 18:39:13 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-27 15:14:42 -02:00
										 |  |  | PartialGasPressureAxis::PartialGasPressureAxis() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-05-21 13:50:26 -03:00
										 |  |  | 	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged())); | 
					
						
							| 
									
										
										
										
											2014-01-27 15:14:42 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void PartialGasPressureAxis::setModel(DivePlotDataModel *m) | 
					
						
							| 
									
										
										
										
											2014-01-27 15:14:42 -02:00
										 |  |  | { | 
					
						
							|  |  |  | 	model = m; | 
					
						
							| 
									
										
										
										
											2014-05-21 13:50:26 -03:00
										 |  |  | 	connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(settingsChanged())); | 
					
						
							|  |  |  | 	settingsChanged(); | 
					
						
							| 
									
										
										
										
											2014-01-27 15:14:42 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-21 13:50:26 -03:00
										 |  |  | void PartialGasPressureAxis::settingsChanged() | 
					
						
							| 
									
										
										
										
											2014-01-27 15:14:42 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-04-16 22:03:44 +02:00
										 |  |  | 	bool showPhe = prefs.pp_graphs.phe; | 
					
						
							|  |  |  | 	bool showPn2 = prefs.pp_graphs.pn2; | 
					
						
							|  |  |  | 	bool showPo2 = prefs.pp_graphs.po2; | 
					
						
							| 
									
										
										
										
											2014-01-27 15:14:42 -02:00
										 |  |  | 	setVisible(showPhe || showPn2 || showPo2); | 
					
						
							|  |  |  | 	if (!model->rowCount()) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	double max = showPhe ? model->pheMax() : -1; | 
					
						
							|  |  |  | 	if (showPn2 && model->pn2Max() > max) | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		max = model->pn2Max(); | 
					
						
							|  |  |  | 	if (showPo2 && model->po2Max() > max) | 
					
						
							| 
									
										
										
										
											2014-01-27 15:14:42 -02:00
										 |  |  | 		max = model->po2Max(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	qreal pp = floor(max * 10.0) / 10.0 + 0.2; | 
					
						
							| 
									
										
										
										
											2014-02-10 20:43:21 -08:00
										 |  |  | 	if (IS_FP_SAME(maximum(), pp)) | 
					
						
							| 
									
										
										
										
											2014-02-04 19:21:57 -02:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-27 15:14:42 -02:00
										 |  |  | 	setMaximum(pp); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	setTickInterval(pp > 4 ? 0.5 : 0.25); | 
					
						
							| 
									
										
										
										
											2014-01-27 15:14:42 -02:00
										 |  |  | 	updateTicks(); | 
					
						
							|  |  |  | } |