From b43dd86b4e4c8127706895547b7815f206a3e21a Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 27 Feb 2014 15:31:56 -0300
Subject: [PATCH 6/6] Toggle on / off the ruler via settings.

This patch toggles on / off the ruler via QSettings.
when the user clicks on the Toolbar, this sets the settings
to true / false, in a way that if the user turns Subsurface
on/ off, we still get the last choosed option.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/profile/profilewidget2.cpp | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index c2de05d..ca176a3 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -433,6 +433,11 @@ void ProfileWidget2::settingsChanged()
 		dataModel->clear();
 		plotDives(QList<dive*>() << getDiveById(diveId));
 	}
+
+	bool rulerVisible = s.value("rulergraph", false).toBool();
+	rulerItem->setVisible(rulerVisible);
+	rulerItem->destNode()->setVisible(rulerVisible );
+	rulerItem->sourceNode()->setVisible(rulerVisible );
 }
 
 void ProfileWidget2::resizeEvent(QResizeEvent* event)
@@ -591,7 +596,7 @@ void ProfileWidget2::setProfileState()
 		}
 	}
 
-	bool rulerVisible = s.value("rulervisible", false).toBool();
+	bool rulerVisible = s.value("rulergraph", false).toBool();
 	rulerItem->setVisible(rulerVisible);
 	rulerItem->destNode()->setVisible(rulerVisible );
 	rulerItem->sourceNode()->setVisible(rulerVisible );
-- 
1.9.0

From 2a16ba829390c0636579abf353d2b27d3c27e81d Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 27 Feb 2014 15:20:03 -0300
Subject: [PATCH 5/6] Added the RulerItem on the new profile.

This patch adds the RulerItem inside of the new profile, and
already takes settings into consideration.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/profile/profilewidget2.cpp | 15 ++++++++++++++-
 qt-ui/profile/profilewidget2.h   |  2 ++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 2ec0694..c2de05d 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -12,6 +12,7 @@
 #include "animationfunctions.h"
 #include "planner.h"
 #include "device.h"
+#include "ruleritem.h"
 #include <QSignalTransition>
 #include <QPropertyAnimation>
 #include <QMenu>
@@ -78,7 +79,8 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
 	po2GasItem( new PartialPressureGasItem()),
 	heartBeatAxis(new DiveCartesianAxis()),
 	heartBeatItem(new DiveHeartrateItem()),
-	isPlotZoomed(prefs.zoomed_plot)
+	isPlotZoomed(prefs.zoomed_plot),
+	rulerItem(new RulerItem2())
 {
 	memset(&plotInfo, 0, sizeof(plotInfo));
 
@@ -118,6 +120,9 @@ void ProfileWidget2::addItemsToScene()
 	scene()->addItem(po2GasItem);
 	scene()->addItem(heartBeatAxis);
 	scene()->addItem(heartBeatItem);
+	scene()->addItem(rulerItem);
+	scene()->addItem(rulerItem->sourceNode());
+	scene()->addItem(rulerItem->destNode());
 	Q_FOREACH(DiveCalculatedTissue *tissue, allTissues){
 		scene()->addItem(tissue);
 	}
@@ -526,6 +531,9 @@ void ProfileWidget2::setEmptyState()
 	diveComputerText->setVisible(false);
 	diveCeiling->setVisible(false);
 	reportedCeiling->setVisible(false);
+	rulerItem->setVisible(false);
+	rulerItem->destNode()->setVisible(false);
+	rulerItem->sourceNode()->setVisible(false);
 	Q_FOREACH(DiveCalculatedTissue *tissue, allTissues){
 		tissue->setVisible(false);
 	}
@@ -582,6 +590,11 @@ void ProfileWidget2::setProfileState()
 			tissue->setVisible(true);
 		}
 	}
+
+	bool rulerVisible = s.value("rulervisible", false).toBool();
+	rulerItem->setVisible(rulerVisible);
+	rulerItem->destNode()->setVisible(rulerVisible );
+	rulerItem->sourceNode()->setVisible(rulerVisible );
 }
 
 extern struct ev_select *ev_namelist;
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index 2b5d19d..e824698 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -16,6 +16,7 @@
 #include "graphicsview-common.h"
 #include "divelineitem.h"
 
+class RulerItem2;
 struct dive;
 struct plot_info;
 class ToolTipItem;
@@ -101,6 +102,7 @@ private:
 	PartialPressureGasItem *po2GasItem;
 	DiveCartesianAxis *heartBeatAxis;
 	DiveHeartrateItem *heartBeatItem;
+	RulerItem2 *rulerItem;
 };
 
 #endif // PROFILEWIDGET2_H
-- 
1.9.0

From 2783e1e8c3c65acc5867c7042ecb4fab21c24fad Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 27 Feb 2014 14:59:41 -0300
Subject: [PATCH 4/6] DiveRuler Compiles / not working yet.

This patch removes the GC macros and change the calling to
use the DiveCartesianAxis.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/profile/ruleritem.cpp | 58 +++++++++++++++++++++++++++++----------------
 qt-ui/profile/ruleritem.h   | 14 +++++++----
 2 files changed, 47 insertions(+), 25 deletions(-)

diff --git a/qt-ui/profile/ruleritem.cpp b/qt-ui/profile/ruleritem.cpp
index b7b3a82..e3362ad 100644
--- a/qt-ui/profile/ruleritem.cpp
+++ b/qt-ui/profile/ruleritem.cpp
@@ -4,10 +4,12 @@
 #include <QPainter>
 #include <QGraphicsScene>
 
+#include <stdint.h>
+
 #include "profile.h"
 #include "display.h"
 
-RulerNodeItem2::RulerNodeItem2(QGraphicsItem *parent) : QGraphicsEllipseItem(parent),  entry(NULL) , ruler(NULL)
+RulerNodeItem2::RulerNodeItem2() : entry(NULL) , ruler(NULL)
 {
 	setRect(QRect(QPoint(-8,8),QPoint(8,-8)));
 	setBrush(QColor(0xff, 0, 0, 127));
@@ -24,23 +26,22 @@ void RulerNodeItem2::setRuler(RulerItem2 *r)
 
 void RulerNodeItem2::recalculate()
 {
-	// Port that away from the SCALEGC
-	//struct plot_info *pi = &gc.pi;
-	//struct plot_data *data = pi->entry+(pi->nr-1);
-	//uint16_t count = 0;
-// 	if (x() < 0) {
-// 		setPos(0, y());
-// 	} else if (x() > SCALEXGC(data->sec)) {
-// 		setPos(SCALEXGC(data->sec), y());
-// 	} else {
-// 		data = pi->entry;
-// 		count=0;
-// 		while (SCALEXGC(data->sec) < x() && count < pi->nr) {
-// 			data = pi->entry+count;
-// 			count++;
-// 		}
-// 		setPos(SCALEGC(data->sec, data->depth));
-//		entry=data;
+	struct plot_data *data = pInfo->entry+(pInfo->nr-1);
+	uint16_t count = 0;
+	if (x() < 0) {
+		setPos(0, y());
+	} else if (x() > timeAxis->posAtValue(data->sec)) {
+		setPos(timeAxis->posAtValue(data->sec), y());
+	} else {
+		data = pInfo->entry;
+		count=0;
+		while (timeAxis->posAtValue(data->sec) < x() && count < pInfo->nr) {
+			data = pInfo->entry+count;
+			count++;
+		}
+		setPos(timeAxis->posAtValue(data->sec), depthAxis->posAtValue(data->depth));
+		entry=data;
+	}
 }
 
 QVariant RulerNodeItem2::itemChange(GraphicsItemChange change, const QVariant &value)
@@ -56,9 +57,16 @@ QVariant RulerNodeItem2::itemChange(GraphicsItemChange change, const QVariant &v
 	return QGraphicsEllipseItem::itemChange(change, value);
 }
 
-RulerItem2::RulerItem2(QGraphicsItem *parent, RulerNodeItem2 *sourceNode, RulerNodeItem2 *destNode) : QGraphicsObject(parent), source(sourceNode), dest(destNode)
+RulerItem2::RulerItem2():
+	pInfo(NULL),
+	timeAxis(NULL),
+	depthAxis(NULL),
+	source(new RulerNodeItem2()),
+	dest(new RulerNodeItem2())
 {
-	recalculate();
+
+	source->setRuler(this);
+	dest->setRuler(this);
 }
 
 void RulerItem2::recalculate()
@@ -68,7 +76,7 @@ void RulerItem2::recalculate()
 	QFont font;
 	QFontMetrics fm(font);
 
-	if (source == NULL || dest == NULL)
+	if (timeAxis == NULL || depthAxis == NULL || pInfo == NULL)
 		return;
 
 	prepareGeometryChange();
@@ -159,3 +167,11 @@ QPainterPath RulerItem2::shape() const
 	path.lineTo(startPoint);
 	return path;
 }
+
+void RulerItem2::setPlotInfo(plot_info* info)
+{
+	pInfo = info;
+	dest->pInfo = info;
+	source->pInfo = info;
+	recalculate();
+}
diff --git a/qt-ui/profile/ruleritem.h b/qt-ui/profile/ruleritem.h
index 68d6c31..29b7923 100644
--- a/qt-ui/profile/ruleritem.h
+++ b/qt-ui/profile/ruleritem.h
@@ -4,6 +4,7 @@
 #include <QObject>
 #include <QGraphicsEllipseItem>
 #include <QGraphicsObject>
+#include "divecartesianaxis.h"
 
 struct plot_data;
 class RulerItem2;
@@ -13,7 +14,7 @@ class RulerNodeItem2 : public QObject, public QGraphicsEllipseItem
 	Q_OBJECT
 	friend class RulerItem2;
 public:
-	explicit RulerNodeItem2(QGraphicsItem* parent);
+	explicit RulerNodeItem2();
 	void setRuler(RulerItem2 *r);
 	void recalculate();
 
@@ -21,19 +22,21 @@ protected:
 	QVariant itemChange(GraphicsItemChange change, const QVariant & value );
 
 private:
+	struct plot_info *pInfo;
 	struct plot_data *entry;
 	RulerItem2* ruler;
+	DiveCartesianAxis *timeAxis;
+	DiveCartesianAxis *depthAxis;
 };
 
 class RulerItem2 : public QGraphicsObject
 {
 	Q_OBJECT
 public:
-	explicit RulerItem2(QGraphicsItem* parent,
-			   RulerNodeItem2 *sourceMarker,
-			   RulerNodeItem2 *destMarker);
+	explicit RulerItem2();
 	void recalculate();
 
+	void setPlotInfo(struct plot_info *pInfo);
 	RulerNodeItem2* sourceNode() const;
 	RulerNodeItem2* destNode() const;
 	void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * widget = 0);
@@ -41,10 +44,13 @@ public:
 	QPainterPath shape() const;
 
 private:
+	struct plot_info *pInfo;
 	QPointF startPoint, endPoint;
 	RulerNodeItem2 *source, *dest;
 	QString text;
 	int height;
 	int paint_direction;
+	DiveCartesianAxis *timeAxis;
+	DiveCartesianAxis *depthAxis;
 };
 #endif
\ No newline at end of file
-- 
1.9.0

From 86e85a431e619699d77e2c328cebe517893bf252 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 27 Feb 2014 13:28:58 -0300
Subject: [PATCH 3/6] Move the code of the RulerItem to the new Profile.

This patch just creates two files for the rulerItem, a
.h and a .cpp. nothing was done to make it visible on
the new profile yet - will do that on the next commits

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/mainwindow.ui         |   5 --
 qt-ui/profile/ruleritem.cpp | 161 ++++++++++++++++++++++++++++++++++++++++++++
 qt-ui/profile/ruleritem.h   |  50 ++++++++++++++
 subsurface.pro              |   6 +-
 4 files changed, 215 insertions(+), 7 deletions(-)
 create mode 100644 qt-ui/profile/ruleritem.cpp
 create mode 100644 qt-ui/profile/ruleritem.h

diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui
index e6adb5b..accfe47 100644
--- a/qt-ui/mainwindow.ui
+++ b/qt-ui/mainwindow.ui
@@ -807,11 +807,6 @@
     <string>Auto Group</string>
    </property>
   </action>
-  <action name="actionToggleZoom">
-   <property name="text">
-    <string>Toggle &amp;Zoom</string>
-   </property>
-  </action>
   <action name="actionYearlyStatistics">
    <property name="text">
     <string>&amp;Yearly Statistics</string>
diff --git a/qt-ui/profile/ruleritem.cpp b/qt-ui/profile/ruleritem.cpp
new file mode 100644
index 0000000..b7b3a82
--- /dev/null
+++ b/qt-ui/profile/ruleritem.cpp
@@ -0,0 +1,161 @@
+#include "ruleritem.h"
+#include <QFont>
+#include <QFontMetrics>
+#include <QPainter>
+#include <QGraphicsScene>
+
+#include "profile.h"
+#include "display.h"
+
+RulerNodeItem2::RulerNodeItem2(QGraphicsItem *parent) : QGraphicsEllipseItem(parent),  entry(NULL) , ruler(NULL)
+{
+	setRect(QRect(QPoint(-8,8),QPoint(8,-8)));
+	setBrush(QColor(0xff, 0, 0, 127));
+	setPen(QColor("#FF0000"));
+	setFlag(QGraphicsItem::ItemIsMovable);
+	setFlag(ItemSendsGeometryChanges);
+	setFlag(ItemIgnoresTransformations);
+}
+
+void RulerNodeItem2::setRuler(RulerItem2 *r)
+{
+	ruler = r;
+}
+
+void RulerNodeItem2::recalculate()
+{
+	// Port that away from the SCALEGC
+	//struct plot_info *pi = &gc.pi;
+	//struct plot_data *data = pi->entry+(pi->nr-1);
+	//uint16_t count = 0;
+// 	if (x() < 0) {
+// 		setPos(0, y());
+// 	} else if (x() > SCALEXGC(data->sec)) {
+// 		setPos(SCALEXGC(data->sec), y());
+// 	} else {
+// 		data = pi->entry;
+// 		count=0;
+// 		while (SCALEXGC(data->sec) < x() && count < pi->nr) {
+// 			data = pi->entry+count;
+// 			count++;
+// 		}
+// 		setPos(SCALEGC(data->sec, data->depth));
+//		entry=data;
+}
+
+QVariant RulerNodeItem2::itemChange(GraphicsItemChange change, const QVariant &value)
+{
+	if (change == ItemPositionHasChanged) {
+		recalculate();
+		if (ruler != NULL)
+			ruler->recalculate();
+		if (scene()) {
+			scene()->update();
+		}
+	}
+	return QGraphicsEllipseItem::itemChange(change, value);
+}
+
+RulerItem2::RulerItem2(QGraphicsItem *parent, RulerNodeItem2 *sourceNode, RulerNodeItem2 *destNode) : QGraphicsObject(parent), source(sourceNode), dest(destNode)
+{
+	recalculate();
+}
+
+void RulerItem2::recalculate()
+{
+	char buffer[500];
+	QPointF tmp;
+	QFont font;
+	QFontMetrics fm(font);
+
+	if (source == NULL || dest == NULL)
+		return;
+
+	prepareGeometryChange();
+	startPoint = mapFromItem(source, 0, 0);
+	endPoint = mapFromItem(dest, 0, 0);
+	if (startPoint.x() > endPoint.x()) {
+		tmp = endPoint;
+		endPoint = startPoint;
+		startPoint = tmp;
+	}
+	QLineF line(startPoint, endPoint);
+
+	compare_samples(source->entry, dest->entry, buffer, 500, 1);
+	text = QString(buffer);
+
+	QRect r = fm.boundingRect(QRect(QPoint(10,-1*INT_MAX), QPoint(line.length()-10, 0)), Qt::TextWordWrap, text);
+	if (r.height() < 10)
+		height = 10;
+	else
+		height = r.height();
+
+	QLineF line_n = line.normalVector();
+	line_n.setLength(height);
+	if (scene()) {
+		/* Determine whether we draw down or upwards */
+		if (scene()->sceneRect().contains(line_n.p2()) &&
+		    scene()->sceneRect().contains(endPoint+QPointF(line_n.dx(),line_n.dy())))
+			paint_direction = -1;
+		else
+			paint_direction = 1;
+	}
+}
+
+RulerNodeItem2 *RulerItem2::sourceNode() const
+{
+	return source;
+}
+
+RulerNodeItem2 *RulerItem2::destNode() const
+{
+	return dest;
+}
+
+void RulerItem2::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+	Q_UNUSED(option);
+	Q_UNUSED(widget);
+	QLineF line(startPoint, endPoint);
+	QLineF line_n = line.normalVector();
+	painter->setPen(QColor(Qt::black));
+	painter->setBrush(Qt::NoBrush);
+	line_n.setLength(height);
+
+	if (paint_direction == 1)
+		line_n.setAngle(line_n.angle()+180);
+	painter->drawLine(line);
+	painter->drawLine(line_n);
+	painter->drawLine(line_n.p1() + QPointF(line.dx(), line.dy()), line_n.p2() + QPointF(line.dx(), line.dy()));
+
+	//Draw Text
+	painter->save();
+	painter->translate(startPoint.x(), startPoint.y());
+	painter->rotate(line.angle()*-1);
+	if (paint_direction == 1)
+		painter->translate(0, height);
+	painter->setPen(Qt::black);
+	painter->drawText(QRectF(QPointF(10,-1*height), QPointF(line.length()-10, 0)), Qt::TextWordWrap, text);
+	painter->restore();
+}
+
+QRectF RulerItem2::boundingRect() const
+{
+	return shape().controlPointRect();
+}
+
+QPainterPath RulerItem2::shape() const
+{
+	QPainterPath path;
+	QLineF line(startPoint, endPoint);
+	QLineF line_n = line.normalVector();
+	line_n.setLength(height);
+	if (paint_direction == 1)
+		line_n.setAngle(line_n.angle()+180);
+	path.moveTo(startPoint);
+	path.lineTo(line_n.p2());
+	path.lineTo(line_n.p2() + QPointF(line.dx(), line.dy()));
+	path.lineTo(endPoint);
+	path.lineTo(startPoint);
+	return path;
+}
diff --git a/qt-ui/profile/ruleritem.h b/qt-ui/profile/ruleritem.h
new file mode 100644
index 0000000..68d6c31
--- /dev/null
+++ b/qt-ui/profile/ruleritem.h
@@ -0,0 +1,50 @@
+#ifndef RULERITEM_H
+#define RULERITEM_H
+
+#include <QObject>
+#include <QGraphicsEllipseItem>
+#include <QGraphicsObject>
+
+struct plot_data;
+class RulerItem2;
+
+class RulerNodeItem2 : public QObject, public QGraphicsEllipseItem
+{
+	Q_OBJECT
+	friend class RulerItem2;
+public:
+	explicit RulerNodeItem2(QGraphicsItem* parent);
+	void setRuler(RulerItem2 *r);
+	void recalculate();
+
+protected:
+	QVariant itemChange(GraphicsItemChange change, const QVariant & value );
+
+private:
+	struct plot_data *entry;
+	RulerItem2* ruler;
+};
+
+class RulerItem2 : public QGraphicsObject
+{
+	Q_OBJECT
+public:
+	explicit RulerItem2(QGraphicsItem* parent,
+			   RulerNodeItem2 *sourceMarker,
+			   RulerNodeItem2 *destMarker);
+	void recalculate();
+
+	RulerNodeItem2* sourceNode() const;
+	RulerNodeItem2* destNode() const;
+	void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * widget = 0);
+	QRectF boundingRect() const;
+	QPainterPath shape() const;
+
+private:
+	QPointF startPoint, endPoint;
+	RulerNodeItem2 *source, *dest;
+	QString text;
+	int height;
+	int paint_direction;
+};
+#endif
\ No newline at end of file
diff --git a/subsurface.pro b/subsurface.pro
index 7ba8e51..3a73a0c 100644
--- a/subsurface.pro
+++ b/subsurface.pro
@@ -75,7 +75,8 @@ HEADERS = \
 	qt-ui/profile/diveplotdatamodel.h \
 	qt-ui/profile/diveprofileitem.h \
 	qt-ui/profile/diveeventitem.h \
-	qt-ui/profile/divetooltipitem.h
+	qt-ui/profile/divetooltipitem.h \
+	qt-ui/profile/ruleritem.h
 
 SOURCES =  \
 	deco.c \
@@ -138,7 +139,8 @@ SOURCES =  \
 	qt-ui/profile/diveplotdatamodel.cpp \
 	qt-ui/profile/diveprofileitem.cpp \
 	qt-ui/profile/diveeventitem.cpp \
-	qt-ui/profile/divetooltipitem.cpp
+	qt-ui/profile/divetooltipitem.cpp \
+	qt-ui/profile/ruleritem.cpp
 
 linux*: SOURCES += linux.c
 mac: SOURCES += macos.c
-- 
1.9.0

From de41201c3ba465e2e4f60f85b9fc815c1fb4b721 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 27 Feb 2014 12:39:53 -0300
Subject: [PATCH 2/6] Plugged the Scale Action on the New Profile.

Just a quick'n dirty glue code so that when the user
clicks on the Scale ToolBar item, the New Profile
graphic is scaled.

Lovely thing: Animations for free. <3

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/profile/profilewidget2.cpp | 9 ++++++++-
 qt-ui/profile/profilewidget2.h   | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 3cb9fb2..2ec0694 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -77,7 +77,8 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
 	pheGasItem( new PartialPressureGasItem()),
 	po2GasItem( new PartialPressureGasItem()),
 	heartBeatAxis(new DiveCartesianAxis()),
-	heartBeatItem(new DiveHeartrateItem())
+	heartBeatItem(new DiveHeartrateItem()),
+	isPlotZoomed(prefs.zoomed_plot)
 {
 	memset(&plotInfo, 0, sizeof(plotInfo));
 
@@ -421,6 +422,12 @@ void ProfileWidget2::settingsChanged()
 		temperatureAxis->animateChangeLine(itemPos.temperature.expanded);
 		cylinderPressureAxis->animateChangeLine(itemPos.cylinder.expanded);
 	}
+	if(s.value("zoomed_plot").toBool() != isPlotZoomed){
+		isPlotZoomed = s.value("zoomed_plot").toBool();
+		int diveId = dataModel->id();
+		dataModel->clear();
+		plotDives(QList<dive*>() << getDiveById(diveId));
+	}
 }
 
 void ProfileWidget2::resizeEvent(QResizeEvent* event)
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index 31f8064..2b5d19d 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -77,6 +77,7 @@ private:
 	DivePixmapItem *background;
 	QString backgroundFile;
 	ToolTipItem *toolTipItem;
+	bool isPlotZoomed;
 	// All those here should probably be merged into one structure,
 	// So it's esyer to replicate for more dives later.
 	// In the meantime, keep it here.
-- 
1.9.0

From de7840f087cf55f8f1fc203e4ad6bd06f8c4bc46 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 27 Feb 2014 12:31:00 -0300
Subject: [PATCH 1/6] Store Zoomed Plot on Preferences

This patch makes the 'Zoomed Plot' a preference that can
be stored and retrieved, this way if the user setted the
plot to be 'zoomed', this information will persist even
if closed or opened subsurface again.

Also, added the 'Scale' button on the new profile, but
didn't did the glue code yet.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 display.h                 |  2 +-
 pref.h                    |  1 +
 profile.c                 |  5 ++---
 qt-ui/mainwindow.cpp      | 12 ++++++------
 qt-ui/mainwindow.h        |  2 +-
 qt-ui/mainwindow.ui       | 31 +++++++++++++++++++++++++++----
 qt-ui/preferences.cpp     |  1 +
 qt-ui/profilegraphics.cpp |  3 ++-
 8 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/display.h b/display.h
index 30fd206..64d481e 100644
--- a/display.h
+++ b/display.h
@@ -52,7 +52,7 @@ struct options {
 	int profile_height, notes_height, tanks_height;
 };
 
-extern char zoomed_plot, dc_number;
+extern char dc_number;
 
 extern unsigned int amount_selected;
 
diff --git a/pref.h b/pref.h
index 4157435..83e88cd 100644
--- a/pref.h
+++ b/pref.h
@@ -38,6 +38,7 @@ struct preferences {
 	struct units units;
 	short show_sac;
 	bool display_unused_tanks;
+	bool zoomed_plot;
 };
 enum unit_system_values { METRIC, IMPERIAL, PERSONALIZE };
 
diff --git a/profile.c b/profile.c
index 5ab59ce..84ba30f 100644
--- a/profile.c
+++ b/profile.c
@@ -16,7 +16,6 @@
 #include "membuffer.h"
 
 int selected_dive = -1; /* careful: 0 is a valid value */
-char zoomed_plot = 0;
 char dc_number = 0;
 
 
@@ -61,7 +60,7 @@ static void dump_pi (struct plot_info *pi)
 int get_maxtime(struct plot_info *pi)
 {
 	int seconds = pi->maxtime;
-	if (zoomed_plot) {
+	if (prefs.zoomed_plot) {
 		/* Rounded up to one minute, with at least 2.5 minutes to
 		 * spare.
 		 * For dive times shorter than 10 minutes, we use seconds/4 to
@@ -86,7 +85,7 @@ int get_maxdepth(struct plot_info *pi)
 	unsigned mm = pi->maxdepth;
 	int md;
 
-	if (zoomed_plot) {
+	if (prefs.zoomed_plot) {
 		/* Rounded up to 10m, with at least 3m to spare */
 		md = ROUND_UP(mm+3000, 10000);
 	} else {
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 70415f0..59ebf2f 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -364,12 +364,6 @@ void MainWindow::on_actionAutoGroup_triggered()
 	mark_divelist_changed(true);
 }
 
-void MainWindow::on_actionToggleZoom_triggered()
-{
-	zoomed_plot = !zoomed_plot;
-	ui.ProfileWidget->refresh();
-}
-
 void MainWindow::on_actionYearlyStatistics_triggered()
 {
 	QTreeView *view = new QTreeView();
@@ -1066,4 +1060,10 @@ void MainWindow::on_profSAC_clicked(bool triggered)
 	TOOLBOX_PREF_PROFILE(show_sac);
 }
 
+void MainWindow::on_profScaled_clicked(bool triggered)
+{
+	prefs.zoomed_plot = triggered;
+	TOOLBOX_PREF_PROFILE(zoomed_plot);
+}
+
 #undef TOOLBOX_PREF_PROFILE
diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h
index 24d3d70..a9c2d47 100644
--- a/qt-ui/mainwindow.h
+++ b/qt-ui/mainwindow.h
@@ -81,7 +81,6 @@ private slots:
 	void on_actionAddDive_triggered();
 	void on_actionRenumber_triggered();
 	void on_actionAutoGroup_triggered();
-	void on_actionToggleZoom_triggered();
 	void on_actionYearlyStatistics_triggered();
 
 	/* view menu actions */
@@ -123,6 +122,7 @@ private slots:
 	void on_profPn2_clicked(bool triggered);
 	void on_profRuler_clicked(bool triggered);
 	void on_profSAC_clicked(bool triggered);
+	void on_profScaled_clicked(bool triggered);
 
 protected:
 	void closeEvent(QCloseEvent *);
diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui
index 6e1489e..e6adb5b 100644
--- a/qt-ui/mainwindow.ui
+++ b/qt-ui/mainwindow.ui
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>763</width>
-    <height>667</height>
+    <width>1418</width>
+    <height>1084</height>
    </rect>
   </property>
   <widget class="QWidget" name="centralwidget">
@@ -454,7 +454,7 @@
                     <string>...</string>
                    </property>
                    <property name="icon">
-                    <iconset>
+                    <iconset resource="../subsurface.qrc">
                      <normaloff>:/flag</normaloff>:/flag</iconset>
                    </property>
                    <property name="iconSize">
@@ -472,6 +472,29 @@
                   </widget>
                  </item>
                  <item>
+                  <widget class="QToolButton" name="profScaled">
+                   <property name="text">
+                    <string>...</string>
+                   </property>
+                   <property name="icon">
+                    <iconset resource="../subsurface.qrc">
+                     <normaloff>:/scale</normaloff>:/scale</iconset>
+                   </property>
+                   <property name="iconSize">
+                    <size>
+                     <width>24</width>
+                     <height>24</height>
+                    </size>
+                   </property>
+                   <property name="checkable">
+                    <bool>true</bool>
+                   </property>
+                   <property name="autoRaise">
+                    <bool>true</bool>
+                   </property>
+                  </widget>
+                 </item>
+                 <item>
                   <spacer name="verticalSpacer">
                    <property name="orientation">
                     <enum>Qt::Vertical</enum>
@@ -564,7 +587,7 @@
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>763</width>
+     <width>1418</width>
      <height>25</height>
     </rect>
    </property>
diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp
index c1c03e8..4d3816f 100644
--- a/qt-ui/preferences.cpp
+++ b/qt-ui/preferences.cpp
@@ -264,6 +264,7 @@ void PreferencesDialog::loadSettings()
 	GET_INT("gflow", gflow);
 	GET_INT("gfhigh", gfhigh);
 	GET_BOOL("gf_low_at_maxdepth", gf_low_at_maxdepth);
+	GET_BOOL("zoomed_plot", zoomed_plot);
 	set_gf(prefs.gflow, prefs.gfhigh, prefs.gf_low_at_maxdepth);
 	GET_BOOL("show_sac", show_sac);
 	GET_BOOL("display_unused_tanks", display_unused_tanks);
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp
index c63f715..2ec9039 100644
--- a/qt-ui/profilegraphics.cpp
+++ b/qt-ui/profilegraphics.cpp
@@ -1453,9 +1453,10 @@ void ProfileGraphicsView::on_rulerAction()
 
 void ProfileGraphicsView::on_scaleAction()
 {
-	zoomed_plot = !zoomed_plot;
+	prefs.zoomed_plot = !prefs.zoomed_plot;
 	refresh();
 }
+
 QColor EventItem::getColor(const color_indice_t i)
 {
 	return profile_color[i].at((isGrayscale) ? 1 : 0);
-- 
1.9.0

_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to