This makes the add planer USABLE. <3
behold the cuteness overload of the new profile acting as the Add Widget canvas.

I said usable, not without bugs, patches welcome. :)

Keyboard handling is broken because I didn't ported *anything* of it yet.
From 5984261d4436550512679b7f0227bb63805537cd Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Fri, 23 May 2014 19:50:09 -0300
Subject: [PATCH 1/8] Change how the handler handlers itself.

This patch adds a itemChange method, that emits a 'changed'
signal when the handler is moved. I'll use that signal on
the profile to call the correct method.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/diveplanner.cpp | 20 +++++---------------
 qt-ui/diveplanner.h   |  6 +++---
 2 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index d081d0d..b7a3f01 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -544,8 +544,7 @@ void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent *event)
 DiveHandler::DiveHandler() : QGraphicsEllipseItem()
 {
 	setRect(-5, -5, 10, 10);
-	setFlag(QGraphicsItem::ItemIgnoresTransformations);
-	setFlag(QGraphicsItem::ItemIsSelectable);
+	setFlags(ItemIgnoresTransformations | ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges);
 	setBrush(Qt::white);
 	setZValue(2);
 }
@@ -587,21 +586,12 @@ void DiveHandler::changeGas()
 	plannerModel->setData(index, action->text());
 }
 
-void DiveHandler::mousePressEvent(QGraphicsSceneMouseEvent *event)
+QVariant DiveHandler::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
 {
-	if (event->button() != Qt::LeftButton)
-		return;
-
-	if (event->modifiers().testFlag(Qt::ControlModifier)) {
-		setSelected(true);
+	if (change == ItemPositionHasChanged && scene()) {
+		emit moved();
 	}
-	// mousePressEvent 'grabs' the mouse and keyboard, annoying.
-	ungrabMouse();
-
-	/* hack. Sometimes the keyboard is grabbed, sometime it's not,
-	so, let's force a grab and release, to get rid of a warning. */
-	grabKeyboard();
-	ungrabKeyboard();
+	return QGraphicsItem::itemChange(change, value);
 }
 
 Button::Button(QObject *parent, QGraphicsItem *itemParent) : QObject(parent),
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index 0166e43..b686055 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -139,9 +139,10 @@ public:
 	DiveHandler();
 
 protected:
-	void mousePressEvent(QGraphicsSceneMouseEvent *event);
 	void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
-
+	virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+signals:
+	void moved();
 private:
 	int parentIndex();
 public
@@ -161,7 +162,6 @@ protected:
 	virtual void mouseMoveEvent(QMouseEvent *event);
 	virtual void mousePressEvent(QMouseEvent *event);
 	virtual void mouseReleaseEvent(QMouseEvent *event);
-	bool isPointOutOfBoundaries(const QPointF &point);
 	qreal fromPercent(qreal percent, Qt::Orientation orientation);
 public
 slots:
-- 
1.9.3

From b1331dbfdf98255dac22cd31b893d4573416daf6 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Fri, 23 May 2014 20:51:30 -0300
Subject: [PATCH 2/8] Make the planner actually work.

This commit makes the planner actually work. There ar still
a few edges, but oh, joy - the new Profile gave a very unexpected
and nice addition to it - Grab the last handler of the initial
dive, and move it to the right, or get any handler, and move it
to the bottom to see what I mean.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/diveplanner.cpp            | 41 ++++++----------------------------------
 qt-ui/diveplanner.h              |  2 +-
 qt-ui/profile/profilewidget2.cpp | 24 +++++++++++++++++++++++
 qt-ui/profile/profilewidget2.h   |  3 +++
 4 files changed, 34 insertions(+), 36 deletions(-)

diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index b7a3f01..6ea88e1 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -480,36 +480,6 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent *event)
 #endif
 }
 
-void DivePlannerGraphics::moveActiveHandler(const QPointF &mappedPos, const int pos)
-{
-#if 0
-	divedatapoint data = plannerModel->at(pos);
-	int mintime = 0, maxtime = (timeLine->maximum() + 10) * 60;
-	if (pos > 0)
-		mintime = plannerModel->at(pos - 1).time;
-	if (pos < plannerModel->size() - 1)
-		maxtime = plannerModel->at(pos + 1).time;
-
-	int minutes = rint(timeLine->valueAt(mappedPos));
-	if (minutes * 60 <= mintime || minutes * 60 >= maxtime)
-		return;
-
-	int milimeters = rint(depthLine->valueAt(mappedPos) / M_OR_FT(1, 1)) * M_OR_FT(1, 1);
-	double xpos = timeLine->posAtValue(minutes);
-	double ypos = depthLine->posAtValue(milimeters);
-
-	data.depth = milimeters;
-	data.time = rint(timeLine->valueAt(mappedPos)) * 60;
-
-	plannerModel->editStop(pos, data);
-
-	activeDraggedHandler->setPos(QPointF(xpos, ypos));
-	qDeleteAll(lines);
-	lines.clear();
-	drawProfile();
-#endif
-}
-
 void DivePlannerGraphics::mousePressEvent(QMouseEvent *event)
 {
 	if (event->modifiers()) {
@@ -586,12 +556,13 @@ void DiveHandler::changeGas()
 	plannerModel->setData(index, action->text());
 }
 
-QVariant DiveHandler::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
+void DiveHandler::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
 {
-	if (change == ItemPositionHasChanged && scene()) {
-		emit moved();
-	}
-	return QGraphicsItem::itemChange(change, value);
+	ProfileWidget2 *view = qobject_cast<ProfileWidget2*>(scene()->views().first());
+	if(view->isPointOutOfBoundaries(event->scenePos()))
+		return;
+	QGraphicsEllipseItem::mouseMoveEvent(event);
+	emit moved();
 }
 
 Button::Button(QObject *parent, QGraphicsItem *itemParent) : QObject(parent),
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index b686055..a56d403 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -140,7 +140,7 @@ public:
 
 protected:
 	void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
-	virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+	void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
 signals:
 	void moved();
 private:
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 81ed986..dd4ecca 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -964,6 +964,7 @@ void ProfileWidget2::pointInserted(const QModelIndex &parent, int start, int end
 	scene()->addItem(item);
 	handles << item;
 
+	connect(item, SIGNAL(moved()), this, SLOT(recreatePlannedDive()));
 	QGraphicsSimpleTextItem *gasChooseBtn = new QGraphicsSimpleTextItem();
 	scene()->addItem(gasChooseBtn);
 	gasChooseBtn->setZValue(10);
@@ -1007,3 +1008,26 @@ void ProfileWidget2::repositionDiveHandlers()
 		last = i;
 	}
 }
+
+void ProfileWidget2::recreatePlannedDive()
+{
+	DiveHandler *activeHandler = qobject_cast<DiveHandler*>(sender());
+	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+	int index = handles.indexOf(activeHandler);
+
+	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);
+	data.depth = rint(profileYAxis->valueAt(activeHandler->pos()) / M_OR_FT(1, 1)) * M_OR_FT(1, 1);;
+	data.time = rint(timeAxis->valueAt(activeHandler->pos()));
+
+	plannerModel->editStop(index, data);
+}
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index 895b82c..1c1258d 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -91,6 +91,9 @@ slots: // Necessary to call from QAction's signals.
 	void pointsRemoved(const QModelIndex &, int start, int end);
 	void replot();
 
+	/* this is called for every move on the handlers. maybe we can speed up this a bit? */
+	void recreatePlannedDive();
+
 protected:
 	virtual void resizeEvent(QResizeEvent *event);
 	virtual void wheelEvent(QWheelEvent *event);
-- 
1.9.3

From fdf781a2a8d929a6daa4bc12b04f8ca96adb4ecf Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Fri, 23 May 2014 21:06:30 -0300
Subject: [PATCH 3/8] Fixes movement of DiveHandlers when moving the
 NotificationArea

The QGraphicsView system moves every selected item when the user
clicks and drags one. This patch makes a cache of all selected
items and removes the selection on them. When the user stops dragging
the Notificatio, the selection is restored.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/profile/divetooltipitem.cpp | 11 +++++++++++
 qt-ui/profile/divetooltipitem.h   |  3 +++
 2 files changed, 14 insertions(+)

diff --git a/qt-ui/profile/divetooltipitem.cpp b/qt-ui/profile/divetooltipitem.cpp
index 45f4154..032daf6 100644
--- a/qt-ui/profile/divetooltipitem.cpp
+++ b/qt-ui/profile/divetooltipitem.cpp
@@ -1,5 +1,6 @@
 #include "divetooltipitem.h"
 #include "divecartesianaxis.h"
+#include "profilewidget2.h"
 #include "profile.h"
 #include "dive.h"
 #include "membuffer.h"
@@ -180,6 +181,9 @@ void ToolTipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
 {
 	persistPos();
 	QGraphicsPathItem::mouseReleaseEvent(event);
+	Q_FOREACH (QGraphicsItem *item, oldSelection) {
+		item->setSelected(true);
+	}
 }
 
 void ToolTipItem::persistPos()
@@ -231,3 +235,10 @@ void ToolTipItem::refresh(const QPointF &pos)
 			addToolTip(item->toolTip());
 	}
 }
+
+void ToolTipItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+	oldSelection = scene()->selectedItems();
+	scene()->clearSelection();
+	QGraphicsItem::mousePressEvent(event);
+}
diff --git a/qt-ui/profile/divetooltipitem.h b/qt-ui/profile/divetooltipitem.h
index 1f84d06..c22287b 100644
--- a/qt-ui/profile/divetooltipitem.h
+++ b/qt-ui/profile/divetooltipitem.h
@@ -45,6 +45,7 @@ public:
 	bool isExpanded() const;
 	void persistPos();
 	void readPos();
+	void mousePressEvent(QGraphicsSceneMouseEvent *event);
 	void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
 	void setTimeAxis(DiveCartesianAxis *axis);
 	void setPlotInfo(const plot_info &plot);
@@ -64,6 +65,8 @@ private:
 	DiveCartesianAxis *timeAxis;
 	plot_info pInfo;
 	int lastTime;
+
+	QList<QGraphicsItem*> oldSelection;
 };
 
 #endif // DIVETOOLTIPITEM_H
-- 
1.9.3

From 3e09e23a7b86ed5a766cb70c39ea9dc6eaf1a67a Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Fri, 23 May 2014 21:29:14 -0300
Subject: [PATCH 4/8] Removed code already ported to the new profile.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/diveplanner.cpp | 31 -------------------------------
 qt-ui/diveplanner.h   |  2 --
 2 files changed, 33 deletions(-)

diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 6ea88e1..2c0b429 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -480,37 +480,6 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent *event)
 #endif
 }
 
-void DivePlannerGraphics::mousePressEvent(QMouseEvent *event)
-{
-	if (event->modifiers()) {
-		QGraphicsView::mousePressEvent(event);
-		return;
-	}
-
-	QPointF mappedPos = mapToScene(event->pos());
-	if (event->button() == Qt::LeftButton) {
-		Q_FOREACH (QGraphicsItem *item, scene()->items(mappedPos, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, transform())) {
-			if (DiveHandler *h = qgraphicsitem_cast<DiveHandler *>(item)) {
-				activeDraggedHandler = h;
-				activeDraggedHandler->setBrush(Qt::red);
-				originalHandlerPos = activeDraggedHandler->pos();
-			}
-		}
-	}
-	QGraphicsView::mousePressEvent(event);
-}
-
-void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent *event)
-{
-	if (activeDraggedHandler) {
-		/* we already deal with all the positioning in the life update,
-		 * so all we need to do here is change the color of the handler */
-		activeDraggedHandler->setBrush(QBrush(Qt::white));
-		activeDraggedHandler = 0;
-		drawProfile();
-	}
-}
-
 DiveHandler::DiveHandler() : QGraphicsEllipseItem()
 {
 	setRect(-5, -5, 10, 10);
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index a56d403..e6b5344 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -160,8 +160,6 @@ protected:
 	virtual void showEvent(QShowEvent *event);
 	virtual void resizeEvent(QResizeEvent *event);
 	virtual void mouseMoveEvent(QMouseEvent *event);
-	virtual void mousePressEvent(QMouseEvent *event);
-	virtual void mouseReleaseEvent(QMouseEvent *event);
 	qreal fromPercent(qreal percent, Qt::Orientation orientation);
 public
 slots:
-- 
1.9.3

From 48b7cb7b42d7189a7456d5de3dc4787dd546f503 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Fri, 23 May 2014 21:32:25 -0300
Subject: [PATCH 5/8] Remove unused code.

This code is not ported to the new profile, but from what I
can understand from it, it doesn't need to be. The purpose
of this code was to setup the correct colors and strings
for the current mouse position, we already do this on the
Profile in a different way, on the Notification Area.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/diveplanner.cpp | 50 --------------------------------------------------
 qt-ui/diveplanner.h   |  1 -
 2 files changed, 51 deletions(-)

diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 2c0b429..b594861 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -430,56 +430,6 @@ void DivePlannerGraphics::showEvent(QShowEvent *event)
 	fitInView(sceneRect(), Qt::IgnoreAspectRatio);
 }
 
-
-void DivePlannerGraphics::mouseMoveEvent(QMouseEvent *event)
-{
-	QPointF mappedPos = mapToScene(event->pos());
-
-#if 0
-	double xpos = timeLine->valueAt(mappedPos);
-	double ypos = depthLine->valueAt(mappedPos);
-
-	xpos = (xpos > timeLine->maximum()) ? timeLine->posAtValue(timeLine->maximum()) : (xpos < timeLine->minimum()) ? timeLine->posAtValue(timeLine->minimum()) : timeLine->posAtValue(xpos);
-
-	ypos = (ypos > depthLine->maximum()) ? depthLine->posAtValue(depthLine->maximum()) : (ypos < depthLine->minimum()) ? depthLine->posAtValue(depthLine->minimum()) : depthLine->posAtValue(ypos);
-
-	verticalLine->setPos(xpos, fromPercent(0, Qt::Vertical));
-	horizontalLine->setPos(fromPercent(0, Qt::Horizontal), ypos);
-
-	depthString->setPos(fromPercent(1, Qt::Horizontal), ypos);
-	timeString->setPos(xpos + 1, fromPercent(95, Qt::Vertical));
-
-	if (isPointOutOfBoundaries(mappedPos))
-		return;
-
-	depthString->setText(get_depth_string(depthLine->valueAt(mappedPos), true, false));
-	timeString->setText(QString::number(rint(timeLine->valueAt(mappedPos))) + "min");
-
-	// calculate the correct color for the depthString.
-	// QGradient doesn't returns it's interpolation, meh.
-	double percent = depthLine->percentAt(mappedPos);
-	QColor &startColor = profile_color[SAMPLE_SHALLOW].first();
-	QColor &endColor = profile_color[SAMPLE_DEEP].first();
-	short redDelta = (endColor.red() - startColor.red()) * percent + startColor.red();
-	short greenDelta = (endColor.green() - startColor.green()) * percent + startColor.green();
-	short blueDelta = (endColor.blue() - startColor.blue()) * percent + startColor.blue();
-	depthString->setBrush(QColor(redDelta, greenDelta, blueDelta));
-
-	if (activeDraggedHandler)
-		moveActiveHandler(mappedPos, handles.indexOf(activeDraggedHandler));
-	if (!handles.count())
-		return;
-
-	if (handles.last()->x() > mappedPos.x()) {
-		verticalLine->setPen(QPen(QBrush(Qt::red), 0, Qt::SolidLine));
-		horizontalLine->setPen(QPen(QBrush(Qt::red), 0, Qt::SolidLine));
-	} else {
-		verticalLine->setPen(QPen(Qt::DotLine));
-		horizontalLine->setPen(QPen(Qt::DotLine));
-	}
-#endif
-}
-
 DiveHandler::DiveHandler() : QGraphicsEllipseItem()
 {
 	setRect(-5, -5, 10, 10);
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index e6b5344..524c95f 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -159,7 +159,6 @@ public:
 protected:
 	virtual void showEvent(QShowEvent *event);
 	virtual void resizeEvent(QResizeEvent *event);
-	virtual void mouseMoveEvent(QMouseEvent *event);
 	qreal fromPercent(qreal percent, Qt::Orientation orientation);
 public
 slots:
-- 
1.9.3

From 3083425735c3a3b250895d0c01f5b9aa2990d342 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Fri, 23 May 2014 22:22:02 -0300
Subject: [PATCH 6/8] Make mouse dragging work as it should.

This patch makes mouse dragging work as it should, a tiny
bit different than the old version, but I think it's a better
way. What's missing: Keyboard actions.

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

diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index dd4ecca..b1bf57f 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -1009,12 +1009,29 @@ void ProfileWidget2::repositionDiveHandlers()
 	}
 }
 
+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()) {
+			handles.swap(index, index-1);
+			return index - 1;
+		}
+		DiveHandler *after = handles[index + 1];
+		if (after->pos().x() < activeHandler->pos().x()) {
+			handles.swap(index, index+1);
+			return index + 1;
+		}
+	}
+	return index;
+}
+
 void ProfileWidget2::recreatePlannedDive()
 {
 	DiveHandler *activeHandler = qobject_cast<DiveHandler*>(sender());
 	DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
-	int index = handles.indexOf(activeHandler);
-
+	int index = fixHandlerIndex(activeHandler);
 	int mintime = 0, maxtime = (timeAxis->maximum() + 10) * 60;
 	if (index > 0)
 		mintime = plannerModel->at(index - 1).time;
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index 1c1258d..4b1d881 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -149,6 +149,7 @@ private:
 	QList<DiveHandler *> handles;
 	QList<QGraphicsSimpleTextItem *> gases;
 	void repositionDiveHandlers();
+	int fixHandlerIndex(DiveHandler *activeHandler);
 };
 
 #endif // PROFILEWIDGET2_H
-- 
1.9.3

From ac6e01260160b6f28936005ee4000af9394b8015 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Fri, 23 May 2014 22:25:49 -0300
Subject: [PATCH 7/8] Removed the depth / time increase and decrease functions.

Since we had to use the controllers for depth and time,
and now the profile does this in a much better way ( by dragging
the handler to the bottom or to the right ) those are uneeded.

And also removed a few other unused methods anymore.
Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/diveplanner.cpp | 80 ---------------------------------------------------
 qt-ui/diveplanner.h   |  8 ------
 2 files changed, 88 deletions(-)

diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index b594861..21fa085 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -122,10 +122,6 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget *parent) : QGraphicsView(parent
 	setRenderHint(QPainter::Antialiasing);
 }
 
-void DivePlannerGraphics::settingsChanged()
-{
-}
-
 void DivePlannerGraphics::keyDownAction()
 {
 #if 0
@@ -266,70 +262,6 @@ void DivePlannerGraphics::keyEscAction()
 		plannerModel->cancelPlan();
 }
 
-qreal DivePlannerGraphics::fromPercent(qreal percent, Qt::Orientation orientation)
-{
-	qreal total = orientation == Qt::Horizontal ? sceneRect().width() : sceneRect().height();
-	qreal result = (total * percent) / 100;
-	return result;
-}
-
-void DivePlannerGraphics::increaseDepth()
-{
-#if 0
-	if (depthLine->maximum() + M_OR_FT(10, 30) > MAX_DEPTH)
-		return;
-	minDepth += M_OR_FT(10, 30);
-	depthLine->setMaximum(minDepth);
-	depthLine->updateTicks();
-	drawProfile();
-#endif
-}
-
-void DivePlannerGraphics::increaseTime()
-{
-#if 0
-	minMinutes += 10;
-	timeLine->setMaximum(minMinutes);
-	timeLine->updateTicks();
-	drawProfile();
-#endif
-}
-
-void DivePlannerGraphics::decreaseDepth()
-{
-#if 0
-	if (depthLine->maximum() - M_OR_FT(10, 30) < MIN_DEPTH)
-		return;
-
-	Q_FOREACH (DiveHandler *d, handles) {
-		if (depthLine->valueAt(d->pos()) > depthLine->maximum() - M_OR_FT(10, 30)) {
-			QMessageBox::warning(MainWindow::instance(),
-					     tr("Handler Position Error"),
-					     tr("One or more of your stops will be lost with this operations, \n"
-						"Please, remove them first."));
-			return;
-		}
-	}
-	minDepth -= M_OR_FT(10, 30);
-	depthLine->setMaximum(minDepth);
-	depthLine->updateTicks();
-	drawProfile();
-#endif
-}
-
-void DivePlannerGraphics::decreaseTime()
-{
-#if 0
-	if (timeLine->maximum() - 10 < TIME_INITIAL_MAX || timeLine->maximum() - 10 < dpMaxTime)
-		return;
-
-	minMinutes -= 10;
-	timeLine->setMaximum(timeLine->maximum() - 10);
-	timeLine->updateTicks();
-	drawProfile();
-#endif
-}
-
 void DivePlannerPointsModel::createSimpleDive()
 {
 	//	plannerModel->addStop(0, 0, O2_IN_AIR, 0, 0);
@@ -418,18 +350,6 @@ void DivePlannerGraphics::drawProfile()
 	plannerModel->deleteTemporaryPlan();
 }
 
-void DivePlannerGraphics::resizeEvent(QResizeEvent *event)
-{
-	QGraphicsView::resizeEvent(event);
-	fitInView(sceneRect(), Qt::IgnoreAspectRatio);
-}
-
-void DivePlannerGraphics::showEvent(QShowEvent *event)
-{
-	QGraphicsView::showEvent(event);
-	fitInView(sceneRect(), Qt::IgnoreAspectRatio);
-}
-
 DiveHandler::DiveHandler() : QGraphicsEllipseItem()
 {
 	setRect(-5, -5, 10, 10);
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index 524c95f..e5bdcaa 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -160,9 +160,6 @@ protected:
 	virtual void showEvent(QShowEvent *event);
 	virtual void resizeEvent(QResizeEvent *event);
 	qreal fromPercent(qreal percent, Qt::Orientation orientation);
-public
-slots:
-	void settingsChanged();
 private
 slots:
 	void keyEscAction();
@@ -171,11 +168,6 @@ slots:
 	void keyDownAction();
 	void keyLeftAction();
 	void keyRightAction();
-	void increaseTime();
-	void increaseDepth();
-	void decreaseTime();
-	void decreaseDepth();
-	void drawProfile();
 
 private:
 	void moveActiveHandler(const QPointF &MappedPos, const int pos);
-- 
1.9.3

From 94fe111006c4f35c01e5ab679460e38cf916a9ac Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Fri, 23 May 2014 22:39:51 -0300
Subject: [PATCH 8/8] Removed a ton of code.

This code removed was already ported to the New Profile.
we managed to clean quite a bit. huhhy

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/diveplanner.cpp          | 150 +++--------------------------------------
 qt-ui/diveplanner.h            |  77 ---------------------
 qt-ui/mainwindow.cpp           |   3 -
 qt-ui/profile/profilewidget2.h |   1 +
 4 files changed, 9 insertions(+), 222 deletions(-)

diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 21fa085..b01cbf2 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -43,67 +43,9 @@ QString dpGasToStr(const divedatapoint &p)
 
 static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
 
-DivePlannerGraphics::DivePlannerGraphics(QWidget *parent) : QGraphicsView(parent),
-	verticalLine(new QGraphicsLineItem(fromPercent(0, Qt::Horizontal), fromPercent(0, Qt::Vertical), fromPercent(0, Qt::Horizontal), fromPercent(100, Qt::Vertical))),
-	horizontalLine(new QGraphicsLineItem(fromPercent(0, Qt::Horizontal), fromPercent(0, Qt::Vertical), fromPercent(100, Qt::Horizontal), fromPercent(0, Qt::Vertical))),
-	activeDraggedHandler(0),
-	diveBg(new QGraphicsPolygonItem()),
-	timeString(new QGraphicsSimpleTextItem()),
-	depthString(new QGraphicsSimpleTextItem()),
-	depthHandler(new ExpanderGraphics()),
-	timeHandler(new ExpanderGraphics()),
-	minMinutes(TIME_INITIAL_MAX),
-	minDepth(M_OR_FT(40, 120)),
-	dpMaxTime(0)
-{
-	setBackgroundBrush(profile_color[BACKGROUND].at(0));
-	setMouseTracking(true);
-	setScene(new QGraphicsScene());
-	scene()->setSceneRect(0, 0, 1920, 1080);
-
-	verticalLine->setPen(QPen(Qt::DotLine));
-	scene()->addItem(verticalLine);
-
-	horizontalLine->setPen(QPen(Qt::DotLine));
-	scene()->addItem(horizontalLine);
-
-	timeString->setFlag(QGraphicsItem::ItemIgnoresTransformations);
-	timeString->setBrush(profile_color[TIME_TEXT].at(0));
-	scene()->addItem(timeString);
-
-	depthString->setFlag(QGraphicsItem::ItemIgnoresTransformations);
-	depthString->setBrush(profile_color[SAMPLE_DEEP].at(0));
-	scene()->addItem(depthString);
-
-	diveBg->setPen(QPen(QBrush(), 0));
-	scene()->addItem(diveBg);
-
-	QString incrText;
-	if (prefs.units.length == units::METERS)
-		incrText = tr("10m");
-	else
-		incrText = tr("30ft");
-
-	timeHandler->increaseBtn->setPixmap(QString(":plan_plus"));
-	timeHandler->decreaseBtn->setPixmap(QString(":plan_minus"));
-	timeHandler->icon->setPixmap(QString(":icon_time"));
-	connect(timeHandler->increaseBtn, SIGNAL(clicked()), this, SLOT(increaseTime()));
-	connect(timeHandler->decreaseBtn, SIGNAL(clicked()), this, SLOT(decreaseTime()));
-	timeHandler->setPos(fromPercent(83, Qt::Horizontal), fromPercent(100, Qt::Vertical));
-	timeHandler->setZValue(-2);
-	scene()->addItem(timeHandler);
-
-	depthHandler->increaseBtn->setPixmap(QString(":arrow_down"));
-	depthHandler->decreaseBtn->setPixmap(QString(":arrow_up"));
-	depthHandler->icon->setPixmap(QString(":icon_depth"));
-	connect(depthHandler->decreaseBtn, SIGNAL(clicked()), this, SLOT(decreaseDepth()));
-	connect(depthHandler->increaseBtn, SIGNAL(clicked()), this, SLOT(increaseDepth()));
-	depthHandler->setPos(fromPercent(0, Qt::Horizontal), fromPercent(100, Qt::Vertical));
-	depthHandler->setZValue(-2);
-	scene()->addItem(depthHandler);
-
+DivePlannerGraphics::DivePlannerGraphics(QWidget *parent) : QGraphicsView(parent)
+{
 	QAction *action = NULL;
-
 #define ADD_ACTION(SHORTCUT, Slot)                      \
 	action = new QAction(this);                     \
 	action->setShortcut(SHORTCUT);                  \
@@ -118,8 +60,6 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget *parent) : QGraphicsView(parent
 	ADD_ACTION(Qt::Key_Left, keyLeftAction());
 	ADD_ACTION(Qt::Key_Right, keyRightAction());
 #undef ADD_ACTION
-
-	setRenderHint(QPainter::Antialiasing);
 }
 
 void DivePlannerGraphics::keyDownAction()
@@ -337,7 +277,7 @@ void DivePlannerPointsModel::removeDeco()
 	removeSelectedPoints(computedPoints);
 	setRecalc(oldrec);
 }
-
+#if 0
 void DivePlannerGraphics::drawProfile()
 {
 	// Code ported to the new profile is deleted. This part that I left here
@@ -349,6 +289,7 @@ void DivePlannerGraphics::drawProfile()
 	plannerModel->setRecalc(oldRecalc);
 	plannerModel->deleteTemporaryPlan();
 }
+#endif
 
 DiveHandler::DiveHandler() : QGraphicsEllipseItem()
 {
@@ -360,7 +301,7 @@ DiveHandler::DiveHandler() : QGraphicsEllipseItem()
 
 int DiveHandler::parentIndex()
 {
-	DivePlannerGraphics *view = qobject_cast<DivePlannerGraphics *>(scene()->views().first());
+	ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
 	return view->handles.indexOf(this);
 }
 
@@ -383,9 +324,11 @@ void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
 
 void DiveHandler::selfRemove()
 {
+#if 0
 	setSelected(true);
-	DivePlannerGraphics *view = qobject_cast<DivePlannerGraphics *>(scene()->views().first());
+	ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
 	view->keyDeleteAction();
+#endif
 }
 
 void DiveHandler::changeGas()
@@ -404,47 +347,6 @@ void DiveHandler::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
 	emit moved();
 }
 
-Button::Button(QObject *parent, QGraphicsItem *itemParent) : QObject(parent),
-	QGraphicsRectItem(itemParent),
-	icon(new QGraphicsPixmapItem(this)),
-	text(new QGraphicsSimpleTextItem(this))
-{
-	icon->setPos(0, 0);
-	text->setPos(0, 0);
-	setFlag(ItemIgnoresTransformations);
-	setPen(QPen(QBrush(), 0));
-}
-
-void Button::setPixmap(const QPixmap &pixmap)
-{
-	icon->setPixmap(pixmap);
-	if (pixmap.isNull())
-		icon->hide();
-	else
-		icon->show();
-
-	setRect(childrenBoundingRect());
-}
-
-void Button::setText(const QString &t)
-{
-	text->setText(t);
-	if (icon->pixmap().isNull()) {
-		icon->hide();
-		text->setPos(0, 0);
-	} else {
-		icon->show();
-		text->setPos(22, 0);
-	}
-	setRect(childrenBoundingRect());
-}
-
-void Button::mousePressEvent(QGraphicsSceneMouseEvent *event)
-{
-	event->ignore();
-	emit clicked();
-}
-
 DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
 {
 	ui.setupUi(this);
@@ -1099,39 +1001,3 @@ void DivePlannerPointsModel::createPlan()
 	CylindersModel::instance()->update();
 	plannerModel->setRecalc(oldRecalc);
 }
-
-ExpanderGraphics::ExpanderGraphics(QGraphicsItem *parent) : QGraphicsRectItem(parent),
-	icon(new QGraphicsPixmapItem(this)),
-	increaseBtn(new Button(0, this)),
-	decreaseBtn(new Button(0, this)),
-	bg(new QGraphicsPixmapItem(this)),
-	leftWing(new QGraphicsPixmapItem(this)),
-	rightWing(new QGraphicsPixmapItem(this))
-{
-	icon->setPixmap(QPixmap(":icon_time"));
-	bg->setPixmap(QPixmap(":round_base"));
-	leftWing->setPixmap(QPixmap(":left_wing"));
-	rightWing->setPixmap(QPixmap(":right_wing"));
-	decreaseBtn->setPixmap(QPixmap(":arrow_down"));
-	increaseBtn->setPixmap(QPixmap(":arrow_up"));
-
-	setFlag(ItemIgnoresTransformations);
-	leftWing->setZValue(-2);
-	rightWing->setZValue(-2);
-	bg->setZValue(-1);
-
-	leftWing->setPos(0, 0);
-	bg->setPos(leftWing->pos().x() + leftWing->boundingRect().width() - 60, 5);
-	rightWing->setPos(leftWing->pos().x() + leftWing->boundingRect().width() - 20, 0);
-	decreaseBtn->setPos(leftWing->pos().x(), leftWing->pos().y());
-	increaseBtn->setPos(rightWing->pos().x(), rightWing->pos().y());
-	icon->setPos(bg->pos().x(), bg->pos().y() - 5);
-
-	//I need to bottom align the items, I need to make the 0,0 ( orgin ) to be
-	// the bottom of this item, so shift everything up.
-	QRectF r = childrenBoundingRect();
-	Q_FOREACH (QGraphicsItem *i, childItems()) {
-		i->setPos(i->pos().x(), i->pos().y() - r.height());
-	}
-	setScale(0.7);
-}
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index e5bdcaa..42bf154 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -101,38 +101,6 @@ private:
 	QVector<QPair<int, int> > oldGases;
 };
 
-class Button : public QObject, public QGraphicsRectItem {
-	Q_OBJECT
-public:
-	Button(QObject *parent = 0, QGraphicsItem *itemParent = 0);
-	void setText(const QString &text);
-	void setPixmap(const QPixmap &pixmap);
-
-protected:
-	virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
-signals:
-	void clicked();
-
-private:
-	QGraphicsPixmapItem *icon;
-	QGraphicsSimpleTextItem *text;
-};
-
-
-class ExpanderGraphics : public QGraphicsRectItem {
-public:
-	ExpanderGraphics(QGraphicsItem *parent = 0);
-
-	QGraphicsPixmapItem *icon;
-	Button *increaseBtn;
-	Button *decreaseBtn;
-
-private:
-	QGraphicsPixmapItem *bg;
-	QGraphicsPixmapItem *leftWing;
-	QGraphicsPixmapItem *rightWing;
-};
-
 class DiveHandler : public QObject, public QGraphicsEllipseItem {
 	Q_OBJECT
 public:
@@ -155,11 +123,6 @@ class DivePlannerGraphics : public QGraphicsView {
 	Q_OBJECT
 public:
 	DivePlannerGraphics(QWidget *parent = 0);
-
-protected:
-	virtual void showEvent(QShowEvent *event);
-	virtual void resizeEvent(QResizeEvent *event);
-	qreal fromPercent(qreal percent, Qt::Orientation orientation);
 private
 slots:
 	void keyEscAction();
@@ -168,46 +131,6 @@ slots:
 	void keyDownAction();
 	void keyLeftAction();
 	void keyRightAction();
-
-private:
-	void moveActiveHandler(const QPointF &MappedPos, const int pos);
-
-	/* This are the lines of the plotted dive. */
-	QList<QGraphicsLineItem *> lines;
-
-	/* This is the user-entered handles. */
-	QList<DiveHandler *> handles;
-	QList<QGraphicsSimpleTextItem *> gases;
-
-	/* those are the lines that follows the mouse. */
-	QGraphicsLineItem *verticalLine;
-	QGraphicsLineItem *horizontalLine;
-
-	/* This is the handler that's being dragged. */
-	DiveHandler *activeDraggedHandler;
-
-	// When we start to move the handler, this pos is saved.
-	// so we can revert it later.
-	QPointF originalHandlerPos;
-
-	/* this is the background of the dive, the blue-gradient. */
-	QGraphicsPolygonItem *diveBg;
-
-	/* This is the bottom ruler - the x axis, and it's associated text */
-	QGraphicsSimpleTextItem *timeString;
-
-	/* this is the left ruler, the y axis, and it's associated text. */
-	QGraphicsSimpleTextItem *depthString;
-
-	/* Buttons */
-	ExpanderGraphics *depthHandler;
-	ExpanderGraphics *timeHandler;
-
-	int minMinutes; // this holds the minimum requested window time
-	int minDepth;   // this holds the minimum requested window depth
-	int dpMaxTime;  // this is the time of the dive calculated by the deco.
-
-	friend class DiveHandler;
 };
 
 #include "ui_diveplanner.h"
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 6cb318b..339ee8e 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -68,7 +68,6 @@ MainWindow::MainWindow() : QMainWindow(),
 	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.ListWidget, SLOT(update()));
 	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.ListWidget, SLOT(reloadHeaderActions()));
 	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.InfoWidget, SLOT(updateDiveInfo()));
-	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.divePlanner, SLOT(settingsChanged()));
 	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.divePlannerWidget, SLOT(settingsChanged()));
 	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), TankInfoModel::instance(), SLOT(update()));
 	connect(ui.actionRecent1, SIGNAL(triggered(bool)), this, SLOT(recentFileTriggered(bool)));
@@ -86,10 +85,8 @@ MainWindow::MainWindow() : QMainWindow(),
 	ui.globe->reload();
 	ui.ListWidget->expand(ui.ListWidget->model()->index(0, 0));
 	ui.ListWidget->scrollTo(ui.ListWidget->model()->index(0, 0), QAbstractItemView::PositionAtCenter);
-	ui.divePlanner->settingsChanged();
 	ui.divePlannerWidget->settingsChanged();
 
-
 #ifndef ENABLE_PLANNER
 	ui.menuLog->removeAction(ui.actionDivePlanner);
 #endif
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index 4b1d881..5ce275e 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -150,6 +150,7 @@ private:
 	QList<QGraphicsSimpleTextItem *> gases;
 	void repositionDiveHandlers();
 	int fixHandlerIndex(DiveHandler *activeHandler);
+	friend class DiveHandler;
 };
 
 #endif // PROFILEWIDGET2_H
-- 
1.9.3

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

Reply via email to