aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/diveplanner.cpp
blob: 90d6771773eb9bf0637fb6d12e398ae841653d5b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "diveplanner.h"
#include <QMouseEvent>
#include <boost/graph/graph_concepts.hpp>

DivePlanner* DivePlanner::instance()
{
	static DivePlanner *self = new DivePlanner();
	return self;
}

DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent)
{
	setScene( new QGraphicsScene());
	scene()->setSceneRect(0,0,100,100);
}

void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event)
{
	QGraphicsEllipseItem *item = new QGraphicsEllipseItem(-10,-10,20,20);
	QPointF mappedPos = mapToScene(event->pos());

	item->setPos( mappedPos );
    scene()->addItem(item);
	handles << item;

	if (lines.empty()){
		QGraphicsLineItem *first = new QGraphicsLineItem(0,0, mappedPos.x(), mappedPos.y());
		lines << first;
		create_deco_stop();
		scene()->addItem(first);
	}else{
		clear_generated_deco();
		create_deco_stop();
	}
}

void DivePlanner::clear_generated_deco()
{
	for(int i = handles.count(); i < lines.count(); i++){
		scene()->removeItem(lines.last());
		delete lines.last();
		lines.removeLast();
	}
}

void DivePlanner::create_deco_stop()
{
	// this needs to create everything
	// for the calculated deco.
	QGraphicsLineItem *item = new QGraphicsLineItem(handles.last()->x(), handles.last()->y(), 100, 0);
	scene()->addItem(item);
	lines << item;
}