diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-06-26 20:41:39 -0300 |
---|---|---|
committer | Tomaz Canabrava <tcanabrava@kde.org> | 2013-06-26 20:41:39 -0300 |
commit | 7a840d2668c364769f66a44a732983570a79c653 (patch) | |
tree | 3a610cd160834d846aa0e45806b857f5d97785d6 /qt-ui/diveplanner.cpp | |
parent | 03572e233dd25b5eef5b977d19c1fd2bd3af6bae (diff) | |
download | subsurface-7a840d2668c364769f66a44a732983570a79c653.tar.gz |
Fixes most of the issues with the dive planner.
Fixes most of the issues with the dive planner,
The lines are removed when the drag starts, and
it's repopulated after. The time ruler updates
itself with the biggest time in the dive (I'll
add later the code to keep a minimum of 60 minutes,
and increase by 15 to 15 minutes, but for now
this will work ), Removed the code to do
line manipulation while we are moving handlers
around ( because it could trigger ruler-expansion,
that woul'd move everything, and that's not nice.
This showed that something bogus is going on with
the decompression algorithm - I don't know if it's
on the data or on the algorithm itself, but it's
creating a ring with the lines on the canvas
I painted all decompression-algorithm based lines
red so it's easier to spot where the hell things
got wrong.
midnight, sleepy.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui/diveplanner.cpp')
-rw-r--r-- | qt-ui/diveplanner.cpp | 84 |
1 files changed, 30 insertions, 54 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index e1396798f..8cd389777 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -87,38 +87,18 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event) item->setPos(QPointF(xpos, ypos)); scene()->addItem(item); handles << item; - - if (lines.empty()) { - double xpos = timeLine->posAtValue(0); - double ypos = depthLine->posAtValue(0); - QGraphicsLineItem *first = new QGraphicsLineItem(xpos,ypos, mappedPos.x(), mappedPos.y()); - item->from = first; - lines.push_back(first); - createDecoStops(); - scene()->addItem(first); - } else { - clearGeneratedDeco(); - DiveHandler *prevHandle = handles.at(handles.count()-2); - QGraphicsLineItem *line = new QGraphicsLineItem(prevHandle->x(), prevHandle->y(), item->x(), item->y()); - prevHandle->to = line; - item->from = line; - lines.push_back(line); - scene()->addItem(line); - createDecoStops(); - } + createDecoStops(); } void DivePlannerGraphics::clearGeneratedDeco() { - for (int i = handles.count(); i <= lines.count(); i++) { - scene()->removeItem(lines.last()); - delete lines.last(); - lines.removeLast(); - } } void DivePlannerGraphics::createDecoStops() { + qDeleteAll(lines); + lines.clear(); + // This needs to be done in the following steps: // Get the user-input and calculate the dive info // Not sure if this is the place to create the diveplan... @@ -154,21 +134,36 @@ void DivePlannerGraphics::createDecoStops() while(dp->next) dp = dp->next; - if (timeLine->maximum() < dp->time / 60.0 + 5) { - // this causes all kinds of bad things as the - // handle that you are holding on to gets scaled out - // when we change the maximum and things accelerate from there - // BAD - // + + //if (timeLine->maximum() < dp->time / 60.0 + 5) { timeLine->setMaximum(dp->time / 60.0 + 5); timeLine->updateTicks(); - } + //} // Re-position the user generated dive handlers Q_FOREACH(DiveHandler *h, handles){ h->setPos(timeLine->posAtValue(h->sec / 60), depthLine->posAtValue(h->mm) / 1000); } + // Create all 'user entered' lines, and put it on the canvas. + double xpos = timeLine->posAtValue(0); + double ypos = depthLine->posAtValue(0); + QGraphicsLineItem *first = new QGraphicsLineItem(xpos,ypos, handles.first()->x(), handles.first()->y()); + handles.first()->from = first; + scene()->addItem(first); + lines.push_back(first); + +// +// for(int i = 0; i < handles.count()-1; i++){ +// DiveHandler *first = handles.at(i); +// DiveHandler *second = handles.at(i+1); +// QGraphicsLineItem *line = new QGraphicsLineItem(first->x(),first->y(), second->x(), second->y()); +// first->from = line; +// second->to = line; +// scene()->addItem(line); +// lines.push_back(line); +// } + // Create all 'deco' GraphicsLineItems and put it on the canvas. double lastx = handles.last()->x(); double lasty = handles.last()->y(); @@ -179,6 +174,7 @@ void DivePlannerGraphics::createDecoStops() double ypos = depthLine->posAtValue(dp->depth / 1000.0); qDebug("time/depth %f/%f", dp->time / 60.0, dp->depth / 1000.0); QGraphicsLineItem *item = new QGraphicsLineItem(lastx, lasty, xpos, ypos); + item->setPen(QPen(QBrush(Qt::red),0)); lastx = xpos; lasty = ypos; scene()->addItem(item); @@ -241,36 +237,21 @@ void DivePlannerGraphics::moveActiveHandler(const QPointF& pos) if (idx == 0 ) { // first if (newPos.x() < handles[1]->x()) { activeDraggedHandler->setPos(newPos); - moveLines = true; } } else if (idx == handles.count()-1) { // last if (newPos.x() > handles[idx-1]->x()) { activeDraggedHandler->setPos(newPos); - moveLines = true; } } else { // middle if (newPos.x() > handles[idx-1]->x() && newPos.x() < handles[idx+1]->x()) { activeDraggedHandler->setPos(newPos); - moveLines = true; } } } else { activeDraggedHandler->setPos(newPos); - moveLines = true; - } - if (moveLines) { - if (activeDraggedHandler->from) { - QLineF f = activeDraggedHandler->from->line(); - activeDraggedHandler->from->setLine(f.x1(), f.y1(), newPos.x(), newPos.y()); - } - - if (activeDraggedHandler->to) { - QLineF f = activeDraggedHandler->to->line(); - activeDraggedHandler->to->setLine(newPos.x(), newPos.y(), f.x2(), f.y2()); - } - activeDraggedHandler->sec = sec; - activeDraggedHandler->mm = mm; } + qqDeleteAll(lines); + lines.clear(); } bool DivePlannerGraphics::isPointOutOfBoundaries(const QPointF& point) @@ -307,12 +288,7 @@ void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event) activeDraggedHandler->sec = rint(timeLine->valueAt(mappedPos)) * 60; activeDraggedHandler->mm = rint(depthLine->valueAt(mappedPos)) * 1000; activeDraggedHandler->setBrush(QBrush()); - - if (activeDraggedHandler == handles.last()) { - clearGeneratedDeco(); - createDecoStops(); - } - + createDecoStops(); activeDraggedHandler = 0; } } |