mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Better defaults for placement of dive stops.
This patch makes it impossible to create a dive stop outside of the scene - this, messing the complete planning system. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
88e7aa36be
commit
46483a096f
2 changed files with 20 additions and 7 deletions
|
@ -25,9 +25,13 @@ DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent)
|
||||||
|
|
||||||
void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event)
|
void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
|
QPointF mappedPos = mapToScene(event->pos());
|
||||||
|
if(isPointOutOfBoundaries(mappedPos))
|
||||||
|
return;
|
||||||
|
|
||||||
QGraphicsEllipseItem *item = new QGraphicsEllipseItem(-5,-5,10,10);
|
QGraphicsEllipseItem *item = new QGraphicsEllipseItem(-5,-5,10,10);
|
||||||
item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
||||||
QPointF mappedPos = mapToScene(event->pos());
|
|
||||||
|
|
||||||
item->setPos( mappedPos );
|
item->setPos( mappedPos );
|
||||||
scene()->addItem(item);
|
scene()->addItem(item);
|
||||||
|
@ -81,13 +85,20 @@ void DivePlanner::showEvent(QShowEvent* event)
|
||||||
void DivePlanner::mouseMoveEvent(QMouseEvent* event)
|
void DivePlanner::mouseMoveEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
QPointF mappedPos = mapToScene(event->pos());
|
QPointF mappedPos = mapToScene(event->pos());
|
||||||
if (mappedPos.x() > sceneRect().width()
|
if (isPointOutOfBoundaries(mappedPos))
|
||||||
|| mappedPos.x() < 0
|
|
||||||
|| mappedPos.y() < 0
|
|
||||||
|| mappedPos.y() > sceneRect().height())
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
verticalLine->setLine(mappedPos.x(), 0, mappedPos.x(), 100);
|
verticalLine->setLine(mappedPos.x(), 0, mappedPos.x(), 100);
|
||||||
horizontalLine->setLine(0, mappedPos.y(), 100, mappedPos.y());
|
horizontalLine->setLine(0, mappedPos.y(), 100, mappedPos.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DivePlanner::isPointOutOfBoundaries(QPointF point)
|
||||||
|
{
|
||||||
|
if (point.x() > sceneRect().width()
|
||||||
|
|| point.x() < 0
|
||||||
|
|| point.y() < 0
|
||||||
|
|| point.y() > sceneRect().height())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ protected:
|
||||||
virtual void mouseMoveEvent(QMouseEvent* event);
|
virtual void mouseMoveEvent(QMouseEvent* event);
|
||||||
void clear_generated_deco();
|
void clear_generated_deco();
|
||||||
void create_deco_stop();
|
void create_deco_stop();
|
||||||
|
bool isPointOutOfBoundaries(QPointF point);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DivePlanner(QWidget* parent = 0);
|
DivePlanner(QWidget* parent = 0);
|
||||||
QList<QGraphicsLineItem*> lines;
|
QList<QGraphicsLineItem*> lines;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue