diff options
-rw-r--r-- | qt-ui/diveplanner.cpp | 29 | ||||
-rw-r--r-- | qt-ui/diveplanner.h | 7 |
2 files changed, 34 insertions, 2 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index a94c3daf8..9115203f5 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -246,7 +246,14 @@ void DivePlannerGraphics::keyRightAction() void DivePlannerGraphics::keyDeleteAction() { - if(scene()->selectedItems().count()){ + int selCount = scene()->selectedItems().count(); + if(selCount){ + + while(selCount--){ + Button *btn = gases.takeLast(); + delete btn; + } + Q_FOREACH(QGraphicsItem *i, scene()->selectedItems()){ if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler*>(i)){ handles.removeAll(handler); @@ -254,6 +261,7 @@ void DivePlannerGraphics::keyDeleteAction() delete i; } } + createDecoStops(); } } @@ -368,6 +376,14 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event) item->setPos(QPointF(xpos, ypos)); scene()->addItem(item); handles << item; + + Button *gasChooseBtn = new Button(); + gasChooseBtn ->setText(tr("Air")); + scene()->addItem(gasChooseBtn); + gasChooseBtn->setZValue(10); + connect(gasChooseBtn, SIGNAL(clicked()), this, SLOT(changeGas())); + + gases << gasChooseBtn; createDecoStops(); } @@ -428,6 +444,17 @@ void DivePlannerGraphics::createDecoStops() h->setPos(timeLine->posAtValue(h->sec / 60), depthLine->posAtValue(h->mm / 1000)); } + int gasCount = gases.count(); + for(int i = 0; i < gasCount; i++){ + QPointF p1 = (i == 0) ? QPointF(timeLine->posAtValue(0), depthLine->posAtValue(0)) : handles[i-1]->pos(); + QPointF p2 = handles[i]->pos(); + + QLineF line(p1, p2); + QPointF pos = line.pointAt(0.5); + gases[i]->setPos(pos); + qDebug() << "Adding a gas at" << pos; + } + // (re-) create the profile with different colors for segments that were // entered vs. segments that were calculated double lastx = timeLine->posAtValue(0); diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index b1da61cac..cab3773e8 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -28,7 +28,6 @@ public: int mm; protected: void mousePressEvent(QGraphicsSceneMouseEvent* event); - }; class Ruler : public QGraphicsLineItem{ @@ -97,6 +96,12 @@ private: /* This is the user-entered handles. */ QList<DiveHandler *> handles; + /* this is the user-entered gases. + This must be a button, so the + user cna click to choose a new gas. + */ + QList<Button*> gases; + /* those are the lines that follows the mouse. */ QGraphicsLineItem *verticalLine; QGraphicsLineItem *horizontalLine; |