2013-06-20 12:33:26 -03:00
|
|
|
#include "diveplanner.h"
|
2013-06-20 12:37:41 -03:00
|
|
|
#include <QMouseEvent>
|
2013-06-20 13:20:41 -03:00
|
|
|
#include <boost/graph/graph_concepts.hpp>
|
2013-06-20 12:33:26 -03:00
|
|
|
|
|
|
|
DivePlanner* DivePlanner::instance()
|
|
|
|
{
|
|
|
|
static DivePlanner *self = new DivePlanner();
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent)
|
|
|
|
{
|
2013-06-20 12:37:41 -03:00
|
|
|
setScene( new QGraphicsScene());
|
|
|
|
scene()->setSceneRect(0,0,100,100);
|
2013-06-20 12:33:26 -03:00
|
|
|
}
|
2013-06-20 12:37:41 -03:00
|
|
|
|
|
|
|
void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event)
|
|
|
|
{
|
2013-06-20 13:28:04 -03:00
|
|
|
QGraphicsEllipseItem *item = new QGraphicsEllipseItem(-5,-5,10,10);
|
|
|
|
item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
2013-06-20 13:20:41 -03:00
|
|
|
QPointF mappedPos = mapToScene(event->pos());
|
|
|
|
|
|
|
|
item->setPos( mappedPos );
|
2013-06-20 12:37:41 -03:00
|
|
|
scene()->addItem(item);
|
2013-06-20 13:20:41 -03:00
|
|
|
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;
|
2013-06-20 12:37:41 -03:00
|
|
|
}
|
|
|
|
|
2013-06-20 13:28:04 -03:00
|
|
|
void DivePlanner::resizeEvent(QResizeEvent* event)
|
|
|
|
{
|
|
|
|
QGraphicsView::resizeEvent(event);
|
|
|
|
fitInView(sceneRect(), Qt::KeepAspectRatio);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlanner::showEvent(QShowEvent* event)
|
|
|
|
{
|
|
|
|
QGraphicsView::showEvent(event);
|
|
|
|
fitInView(sceneRect(), Qt::KeepAspectRatio);
|
|
|
|
}
|
|
|
|
|