summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-20 14:46:40 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-20 14:46:40 -0300
commit607f82ade30e7d72370654a158e1d58f6444d67e (patch)
treebea67dfb3ee6a481bd757ac9a6667e3b20d86836 /qt-ui
parent021a6a076e76e45bf5f6f8b976e2178a666ec1bd (diff)
downloadsubsurface-607f82ade30e7d72370654a158e1d58f6444d67e.tar.gz
Added drag and drop code to the dive plan
Added drag and drop code to the dive plan, it can move the user- inputted data, but will not touch the computer generated ones. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/diveplanner.cpp36
-rw-r--r--qt-ui/diveplanner.h4
2 files changed, 39 insertions, 1 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 07f195120..d64eab18f 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -8,7 +8,7 @@ DivePlanner* DivePlanner::instance()
return self;
}
-DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent)
+DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0)
{
setMouseTracking(true);
setScene( new QGraphicsScene());
@@ -98,6 +98,25 @@ void DivePlanner::mouseMoveEvent(QMouseEvent* event)
verticalLine->setLine(mappedPos.x(), 0, mappedPos.x(), 100);
horizontalLine->setLine(0, mappedPos.y(), 100, mappedPos.y());
+ if (activeDraggedHandler){
+ int idx = handles.indexOf(activeDraggedHandler);
+ activeDraggedHandler->setPos(mappedPos);
+ if (activeDraggedHandler->from){
+ QLineF f = activeDraggedHandler->from->line();
+ activeDraggedHandler->from->setLine(f.x1(), f.y1(), mappedPos.x(), mappedPos.y());
+ }
+
+ if(activeDraggedHandler == handles.last()){
+ clear_generated_deco();
+ create_deco_stop();
+ }
+
+ if (activeDraggedHandler->to){
+ QLineF f = activeDraggedHandler->to->line();
+ activeDraggedHandler->to->setLine(mappedPos.x(), mappedPos.y(), f.x2(), f.y2());
+ }
+ }
+
if (!handles.count())
return;
@@ -122,7 +141,22 @@ bool DivePlanner::isPointOutOfBoundaries(QPointF point)
return false;
}
+void DivePlanner::mousePressEvent(QMouseEvent* event)
+{
+ QPointF mappedPos = mapToScene(event->pos());
+ Q_FOREACH(QGraphicsItem *item, scene()->items(mappedPos)){
+ if (DiveHandler *h = qgraphicsitem_cast<DiveHandler*>(item)){
+ activeDraggedHandler = h;
+ activeDraggedHandler->setBrush(Qt::red);
+ }
+ }
+}
+void DivePlanner::mouseReleaseEvent(QMouseEvent* event)
+{
+ if (activeDraggedHandler)
+ activeDraggedHandler = 0;
+}
DiveHandler::DiveHandler(): QGraphicsEllipseItem(), from(0), to(0)
{
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index 33f647fe6..db94900c1 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -20,6 +20,9 @@ protected:
virtual void showEvent(QShowEvent* event);
virtual void resizeEvent(QResizeEvent* event);
virtual void mouseMoveEvent(QMouseEvent* event);
+ virtual void mousePressEvent(QMouseEvent* event);
+ virtual void mouseReleaseEvent(QMouseEvent* event);
+
void clear_generated_deco();
void create_deco_stop();
bool isPointOutOfBoundaries(QPointF point);
@@ -30,5 +33,6 @@ private:
QList<DiveHandler *> handles;
QGraphicsLineItem *verticalLine;
QGraphicsLineItem *horizontalLine;
+ DiveHandler *activeDraggedHandler;
};
#endif