mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Created a class DiveHandle to make drag drop work.
Create d a class DiveHandle to make drag drop works, it has a from and to Lines, and it will move them around. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
1fb023d3c6
commit
021a6a076e
2 changed files with 23 additions and 7 deletions
|
@ -33,23 +33,25 @@ void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsEllipseItem *item = new QGraphicsEllipseItem(-5,-5,10,10);
|
DiveHandler *item = new DiveHandler ();
|
||||||
|
item->setRect(-5,-5,10,10);
|
||||||
item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
||||||
|
|
||||||
|
|
||||||
item->setPos( mappedPos );
|
item->setPos( mappedPos );
|
||||||
scene()->addItem(item);
|
scene()->addItem(item);
|
||||||
handles << item;
|
handles << item;
|
||||||
|
|
||||||
if (lines.empty()){
|
if (lines.empty()){
|
||||||
QGraphicsLineItem *first = new QGraphicsLineItem(0,0, mappedPos.x(), mappedPos.y());
|
QGraphicsLineItem *first = new QGraphicsLineItem(0,0, mappedPos.x(), mappedPos.y());
|
||||||
|
item->from = first;
|
||||||
lines.push_back(first);
|
lines.push_back(first);
|
||||||
create_deco_stop();
|
create_deco_stop();
|
||||||
scene()->addItem(first);
|
scene()->addItem(first);
|
||||||
}else{
|
}else{
|
||||||
clear_generated_deco();
|
clear_generated_deco();
|
||||||
QGraphicsEllipseItem *prevHandle = handles.at( handles.count()-2);
|
DiveHandler *prevHandle = handles.at( handles.count()-2);
|
||||||
QGraphicsLineItem *line = new QGraphicsLineItem(prevHandle->x(), prevHandle->y(), item->x(), item->y());
|
QGraphicsLineItem *line = new QGraphicsLineItem(prevHandle->x(), prevHandle->y(), item->x(), item->y());
|
||||||
|
prevHandle->to = line;
|
||||||
|
item->from = line;
|
||||||
lines.push_back(line);
|
lines.push_back(line);
|
||||||
scene()->addItem(line);
|
scene()->addItem(line);
|
||||||
create_deco_stop();
|
create_deco_stop();
|
||||||
|
@ -68,7 +70,8 @@ void DivePlanner::clear_generated_deco()
|
||||||
void DivePlanner::create_deco_stop()
|
void DivePlanner::create_deco_stop()
|
||||||
{
|
{
|
||||||
// this needs to create everything
|
// this needs to create everything
|
||||||
// for the calculated deco.
|
// for the calculated deco. it should return the *first*
|
||||||
|
// line that's calculated, so the
|
||||||
QGraphicsLineItem *item = new QGraphicsLineItem(handles.last()->x(), handles.last()->y(), 100, 0);
|
QGraphicsLineItem *item = new QGraphicsLineItem(handles.last()->x(), handles.last()->y(), 100, 0);
|
||||||
scene()->addItem(item);
|
scene()->addItem(item);
|
||||||
lines << item;
|
lines << item;
|
||||||
|
@ -118,3 +121,9 @@ bool DivePlanner::isPointOutOfBoundaries(QPointF point)
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DiveHandler::DiveHandler(): QGraphicsEllipseItem(), from(0), to(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,13 @@
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QGraphicsPathItem>
|
#include <QGraphicsPathItem>
|
||||||
|
|
||||||
|
class DiveHandler : public QGraphicsEllipseItem{
|
||||||
|
public:
|
||||||
|
DiveHandler();
|
||||||
|
|
||||||
|
QGraphicsLineItem *from;
|
||||||
|
QGraphicsLineItem *to;
|
||||||
|
};
|
||||||
class DivePlanner : public QGraphicsView {
|
class DivePlanner : public QGraphicsView {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -16,11 +23,11 @@ protected:
|
||||||
void clear_generated_deco();
|
void clear_generated_deco();
|
||||||
void create_deco_stop();
|
void create_deco_stop();
|
||||||
bool isPointOutOfBoundaries(QPointF point);
|
bool isPointOutOfBoundaries(QPointF point);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DivePlanner(QWidget* parent = 0);
|
DivePlanner(QWidget* parent = 0);
|
||||||
QList<QGraphicsLineItem*> lines;
|
QList<QGraphicsLineItem*> lines;
|
||||||
QList<QGraphicsEllipseItem*> handles;
|
QList<DiveHandler *> handles;
|
||||||
QGraphicsLineItem *verticalLine;
|
QGraphicsLineItem *verticalLine;
|
||||||
QGraphicsLineItem *horizontalLine;
|
QGraphicsLineItem *horizontalLine;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue