mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 13:10:19 +00:00
364254ed36
Better handling of the scene size for the dive plan, The scene can be resized and a transform will be applied, the handles will not resize however - they are 10x10px and that's it. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
#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(-5,-5,10,10);
|
|
item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
|
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;
|
|
}
|
|
|
|
void DivePlanner::resizeEvent(QResizeEvent* event)
|
|
{
|
|
QGraphicsView::resizeEvent(event);
|
|
fitInView(sceneRect(), Qt::KeepAspectRatio);
|
|
}
|
|
|
|
void DivePlanner::showEvent(QShowEvent* event)
|
|
{
|
|
QGraphicsView::showEvent(event);
|
|
fitInView(sceneRect(), Qt::KeepAspectRatio);
|
|
}
|
|
|