summaryrefslogtreecommitdiffstats
path: root/qt-ui/diveplanner.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui/diveplanner.cpp')
-rw-r--r--qt-ui/diveplanner.cpp841
1 files changed, 21 insertions, 820 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 24aa7f697..ada2b4e73 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -43,264 +43,6 @@ QString dpGasToStr(const divedatapoint &p)
static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
-DivePlannerGraphics::DivePlannerGraphics(QWidget *parent) : QGraphicsView(parent),
- verticalLine(new QGraphicsLineItem(fromPercent(0, Qt::Horizontal), fromPercent(0, Qt::Vertical), fromPercent(0, Qt::Horizontal), fromPercent(100, Qt::Vertical))),
- horizontalLine(new QGraphicsLineItem(fromPercent(0, Qt::Horizontal), fromPercent(0, Qt::Vertical), fromPercent(100, Qt::Horizontal), fromPercent(0, Qt::Vertical))),
- activeDraggedHandler(0),
- diveBg(new QGraphicsPolygonItem()),
- timeLine(new Ruler()),
- timeString(new QGraphicsSimpleTextItem()),
- depthString(new QGraphicsSimpleTextItem()),
- depthHandler(new ExpanderGraphics()),
- timeHandler(new ExpanderGraphics()),
- minMinutes(TIME_INITIAL_MAX),
- minDepth(M_OR_FT(40, 120)),
- dpMaxTime(0)
-{
- setBackgroundBrush(profile_color[BACKGROUND].at(0));
- setMouseTracking(true);
- setScene(new QGraphicsScene());
- scene()->setSceneRect(0, 0, 1920, 1080);
-
- verticalLine->setPen(QPen(Qt::DotLine));
- scene()->addItem(verticalLine);
-
- horizontalLine->setPen(QPen(Qt::DotLine));
- scene()->addItem(horizontalLine);
-
- timeLine->setMinimum(0);
- timeLine->setMaximum(TIME_INITIAL_MAX);
- timeLine->setTickInterval(10);
- timeLine->setColor(getColor(TIME_GRID));
- timeLine->setLine(fromPercent(10, Qt::Horizontal),
- fromPercent(85, Qt::Vertical),
- fromPercent(90, Qt::Horizontal),
- fromPercent(85, Qt::Vertical));
- timeLine->setOrientation(Qt::Horizontal);
- timeLine->setTickSize(fromPercent(1, Qt::Vertical));
- timeLine->setTextColor(getColor(TIME_TEXT));
- timeLine->updateTicks();
- scene()->addItem(timeLine);
-
- depthLine = new Ruler();
- depthLine->setMinimum(0);
- depthLine->setMaximum(M_OR_FT(40, 120));
- depthLine->setTickInterval(M_OR_FT(10, 30));
- depthLine->setLine(fromPercent(10, Qt::Horizontal),
- fromPercent(10, Qt::Vertical),
- fromPercent(10, Qt::Horizontal),
- fromPercent(85, Qt::Vertical));
- depthLine->setOrientation(Qt::Vertical);
- depthLine->setTickSize(fromPercent(1, Qt::Horizontal));
- depthLine->setColor(getColor(DEPTH_GRID));
- depthLine->setTextColor(getColor(SAMPLE_DEEP));
- depthLine->updateTicks();
- depthLine->unitSystem = prefs.units.length;
- scene()->addItem(depthLine);
-
- timeString->setFlag(QGraphicsItem::ItemIgnoresTransformations);
- timeString->setBrush(profile_color[TIME_TEXT].at(0));
- scene()->addItem(timeString);
-
- depthString->setFlag(QGraphicsItem::ItemIgnoresTransformations);
- depthString->setBrush(profile_color[SAMPLE_DEEP].at(0));
- scene()->addItem(depthString);
-
- diveBg->setPen(QPen(QBrush(), 0));
- scene()->addItem(diveBg);
-
- QString incrText;
- if (prefs.units.length == units::METERS)
- incrText = tr("10m");
- else
- incrText = tr("30ft");
-
- timeHandler->increaseBtn->setPixmap(QString(":plan_plus"));
- timeHandler->decreaseBtn->setPixmap(QString(":plan_minus"));
- timeHandler->icon->setPixmap(QString(":icon_time"));
- connect(timeHandler->increaseBtn, SIGNAL(clicked()), this, SLOT(increaseTime()));
- connect(timeHandler->decreaseBtn, SIGNAL(clicked()), this, SLOT(decreaseTime()));
- timeHandler->setPos(fromPercent(83, Qt::Horizontal), fromPercent(100, Qt::Vertical));
- timeHandler->setZValue(-2);
- scene()->addItem(timeHandler);
-
- depthHandler->increaseBtn->setPixmap(QString(":arrow_down"));
- depthHandler->decreaseBtn->setPixmap(QString(":arrow_up"));
- depthHandler->icon->setPixmap(QString(":icon_depth"));
- connect(depthHandler->decreaseBtn, SIGNAL(clicked()), this, SLOT(decreaseDepth()));
- connect(depthHandler->increaseBtn, SIGNAL(clicked()), this, SLOT(increaseDepth()));
- depthHandler->setPos(fromPercent(0, Qt::Horizontal), fromPercent(100, Qt::Vertical));
- depthHandler->setZValue(-2);
- scene()->addItem(depthHandler);
-
- QAction *action = NULL;
-
-#define ADD_ACTION(SHORTCUT, Slot) \
- action = new QAction(this); \
- action->setShortcut(SHORTCUT); \
- action->setShortcutContext(Qt::WindowShortcut); \
- addAction(action); \
- connect(action, SIGNAL(triggered(bool)), this, SLOT(Slot))
-
- ADD_ACTION(Qt::Key_Escape, keyEscAction());
- ADD_ACTION(Qt::Key_Delete, keyDeleteAction());
- ADD_ACTION(Qt::Key_Up, keyUpAction());
- ADD_ACTION(Qt::Key_Down, keyDownAction());
- ADD_ACTION(Qt::Key_Left, keyLeftAction());
- ADD_ACTION(Qt::Key_Right, keyRightAction());
-#undef ADD_ACTION
-
- connect(plannerModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(drawProfile()));
- connect(plannerModel, SIGNAL(cylinderModelEdited()), this, SLOT(drawProfile()));
-
- connect(plannerModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
- this, SLOT(pointInserted(const QModelIndex &, int, int)));
- connect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
- this, SLOT(pointsRemoved(const QModelIndex &, int, int)));
- setRenderHint(QPainter::Antialiasing);
-}
-
-void DivePlannerGraphics::settingsChanged()
-{
- if (depthLine->unitSystem == prefs.units.length)
- return;
-
- depthLine->setTickInterval(M_OR_FT(10, 30));
- depthLine->updateTicks();
- depthLine->unitSystem = prefs.units.length;
-}
-
-void DivePlannerGraphics::pointInserted(const QModelIndex &parent, int start, int end)
-{
- DiveHandler *item = new DiveHandler();
- scene()->addItem(item);
- handles << item;
-
- QGraphicsSimpleTextItem *gasChooseBtn = new QGraphicsSimpleTextItem();
- scene()->addItem(gasChooseBtn);
- gasChooseBtn->setZValue(10);
- gasChooseBtn->setFlag(QGraphicsItem::ItemIgnoresTransformations);
- gases << gasChooseBtn;
- if (plannerModel->recalcQ())
- drawProfile();
-}
-
-void DivePlannerGraphics::keyDownAction()
-{
- Q_FOREACH(QGraphicsItem * i, scene()->selectedItems()) {
- if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) {
- int row = handles.indexOf(handler);
- divedatapoint dp = plannerModel->at(row);
- if (dp.depth >= depthLine->maximum())
- continue;
-
- dp.depth += M_OR_FT(1, 5);
- plannerModel->editStop(row, dp);
- }
- }
-}
-
-void DivePlannerGraphics::keyUpAction()
-{
- Q_FOREACH(QGraphicsItem * i, scene()->selectedItems()) {
- if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) {
- int row = handles.indexOf(handler);
- divedatapoint dp = plannerModel->at(row);
-
- if (dp.depth <= 0)
- continue;
-
- dp.depth -= M_OR_FT(1, 5);
- plannerModel->editStop(row, dp);
- }
- }
- drawProfile();
-}
-
-void DivePlannerGraphics::keyLeftAction()
-{
- Q_FOREACH(QGraphicsItem * i, scene()->selectedItems()) {
- if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) {
- int row = handles.indexOf(handler);
- divedatapoint dp = plannerModel->at(row);
-
- if (dp.time / 60 <= 0)
- continue;
-
- // don't overlap positions.
- // maybe this is a good place for a 'goto'?
- double xpos = timeLine->posAtValue((dp.time - 60) / 60);
- bool nextStep = false;
- Q_FOREACH(DiveHandler * h, handles) {
- if (IS_FP_SAME(h->pos().x(), xpos)) {
- nextStep = true;
- break;
- }
- }
- if (nextStep)
- continue;
-
- dp.time -= 60;
- plannerModel->editStop(row, dp);
- }
- }
-}
-
-void DivePlannerGraphics::keyRightAction()
-{
- Q_FOREACH(QGraphicsItem * i, scene()->selectedItems()) {
- if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) {
- int row = handles.indexOf(handler);
- divedatapoint dp = plannerModel->at(row);
- if (dp.time / 60 >= timeLine->maximum())
- continue;
-
- // don't overlap positions.
- // maybe this is a good place for a 'goto'?
- double xpos = timeLine->posAtValue((dp.time + 60) / 60);
- bool nextStep = false;
- Q_FOREACH(DiveHandler * h, handles) {
- if (IS_FP_SAME(h->pos().x(), xpos)) {
- nextStep = true;
- break;
- }
- }
- if (nextStep)
- continue;
-
- dp.time += 60;
- plannerModel->editStop(row, dp);
- }
- }
-}
-
-void DivePlannerGraphics::keyDeleteAction()
-{
- int selCount = scene()->selectedItems().count();
- if (selCount) {
- QVector<int> selectedIndexes;
- Q_FOREACH(QGraphicsItem * i, scene()->selectedItems()) {
- if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) {
- selectedIndexes.push_back(handles.indexOf(handler));
- }
- }
- plannerModel->removeSelectedPoints(selectedIndexes);
- }
-}
-
-void DivePlannerGraphics::pointsRemoved(const QModelIndex &, int start, int end)
-{ // start and end are inclusive.
- int num = (end - start) + 1;
- for (int i = num; i != 0; i--) {
- delete handles.back();
- handles.pop_back();
- delete gases.back();
- gases.pop_back();
- }
- scene()->clearSelection();
- drawProfile();
-}
-
bool intLessThan(int a, int b)
{
return a <= b;
@@ -317,83 +59,6 @@ void DivePlannerPointsModel::removeSelectedPoints(const QVector<int> &rows)
endRemoveRows();
}
-void DivePlannerGraphics::keyEscAction()
-{
- if (scene()->selectedItems().count()) {
- scene()->clearSelection();
- return;
- }
- if (DivePlannerPointsModel::instance()->isPlanner())
- plannerModel->cancelPlan();
-}
-
-qreal DivePlannerGraphics::fromPercent(qreal percent, Qt::Orientation orientation)
-{
- qreal total = orientation == Qt::Horizontal ? sceneRect().width() : sceneRect().height();
- qreal result = (total * percent) / 100;
- return result;
-}
-
-void DivePlannerGraphics::increaseDepth()
-{
- if (depthLine->maximum() + M_OR_FT(10, 30) > MAX_DEPTH)
- return;
- minDepth += M_OR_FT(10, 30);
- depthLine->setMaximum(minDepth);
- depthLine->updateTicks();
- drawProfile();
-}
-
-void DivePlannerGraphics::increaseTime()
-{
- minMinutes += 10;
- timeLine->setMaximum(minMinutes);
- timeLine->updateTicks();
- drawProfile();
-}
-
-void DivePlannerGraphics::decreaseDepth()
-{
- if (depthLine->maximum() - M_OR_FT(10, 30) < MIN_DEPTH)
- return;
-
- Q_FOREACH(DiveHandler * d, handles) {
- if (depthLine->valueAt(d->pos()) > depthLine->maximum() - M_OR_FT(10, 30)) {
- QMessageBox::warning(MainWindow::instance(),
- tr("Handler Position Error"),
- tr("One or more of your stops will be lost with this operations, \n"
- "Please, remove them first."));
- return;
- }
- }
- minDepth -= M_OR_FT(10, 30);
- depthLine->setMaximum(minDepth);
- depthLine->updateTicks();
- drawProfile();
-}
-
-void DivePlannerGraphics::decreaseTime()
-{
- if (timeLine->maximum() - 10 < TIME_INITIAL_MAX || timeLine->maximum() - 10 < dpMaxTime)
- return;
-
- minMinutes -= 10;
- timeLine->setMaximum(timeLine->maximum() - 10);
- timeLine->updateTicks();
- drawProfile();
-}
-
-void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent *event)
-{
- QPointF mappedPos = mapToScene(event->pos());
- if (isPointOutOfBoundaries(mappedPos))
- return;
-
- int minutes = rint(timeLine->valueAt(mappedPos));
- int milimeters = rint(depthLine->valueAt(mappedPos) / M_OR_FT(1, 1)) * M_OR_FT(1, 1);
- plannerModel->addStop(milimeters, minutes * 60, -1, 0, 0, true);
-}
-
void DivePlannerPointsModel::createSimpleDive()
{
// plannerModel->addStop(0, 0, O2_IN_AIR, 0, 0);
@@ -470,252 +135,31 @@ void DivePlannerPointsModel::removeDeco()
setRecalc(oldrec);
}
+#if 0
void DivePlannerGraphics::drawProfile()
{
- if (!plannerModel->recalcQ())
- return;
- qDeleteAll(lines);
- lines.clear();
-
- plannerModel->createTemporaryPlan();
- struct diveplan diveplan = plannerModel->getDiveplan();
- struct divedatapoint *dp = diveplan.dp;
- unsigned int max_depth = 0;
-
- if (!dp) {
- plannerModel->deleteTemporaryPlan();
- return;
- }
- //TODO: divedatapoint_list_get_max_depth on C - code?
- while (dp->next) {
- if (dp->time && dp->depth > max_depth)
- max_depth = dp->depth;
- dp = dp->next;
- }
-
- if (!activeDraggedHandler && (timeLine->maximum() < dp->time / 60.0 + 5 || dp->time / 60.0 + 15 < timeLine->maximum())) {
- minMinutes = fmax(dp->time / 60.0 + 5, minMinutes);
- timeLine->setMaximum(minMinutes);
- timeLine->updateTicks();
- }
- if (!activeDraggedHandler && (depthLine->maximum() < max_depth + M_OR_FT(10, 30) || max_depth + M_OR_FT(10, 30) < depthLine->maximum())) {
- minDepth = fmax(max_depth + M_OR_FT(10, 30), minDepth);
- depthLine->setMaximum(minDepth);
- depthLine->updateTicks();
- }
-
- // Re-position the user generated dive handlers
- int last = 0;
- for (int i = 0; i < plannerModel->rowCount(); i++) {
- struct divedatapoint datapoint = plannerModel->at(i);
- if (datapoint.time == 0) // those are the magic entries for tanks
- continue;
- DiveHandler *h = handles.at(i);
- h->setPos(timeLine->posAtValue(datapoint.time / 60), depthLine->posAtValue(datapoint.depth));
- QPointF p1 = (last == i) ? QPointF(timeLine->posAtValue(0), depthLine->posAtValue(0)) : handles[last]->pos();
- QPointF p2 = handles[i]->pos();
- QLineF line(p1, p2);
- QPointF pos = line.pointAt(0.5);
- gases[i]->setPos(pos);
- gases[i]->setText(dpGasToStr(plannerModel->at(i)));
- last = i;
- }
-
- // (re-) create the profile with different colors for segments that were
- // entered vs. segments that were calculated
- double lastx = timeLine->posAtValue(0);
- double lasty = depthLine->posAtValue(0);
-
- QPolygonF poly;
- poly.append(QPointF(lastx, lasty));
-
+ // Code ported to the new profile is deleted. This part that I left here
+ // is because I didn't fully understood the reason of the magic with
+ // the plannerModel.
bool oldRecalc = plannerModel->setRecalc(false);
plannerModel->removeDeco();
-
- unsigned int lastdepth = 0;
- for (dp = diveplan.dp; dp != NULL; dp = dp->next) {
- if (dp->time == 0) // magic entry for available tank
- continue;
- double xpos = timeLine->posAtValue(dp->time / 60.0);
- double ypos = depthLine->posAtValue(dp->depth);
- if (!dp->entered) {
- QGraphicsLineItem *item = new QGraphicsLineItem(lastx, lasty, xpos, ypos);
- item->setPen(QPen(QBrush(Qt::red), 0));
-
- scene()->addItem(item);
- lines << item;
- if (dp->depth) {
- if (dp->depth == lastdepth || dp->o2 != dp->next->o2 || dp->he != dp->next->he)
- plannerModel->addStop(dp->depth, dp->time, dp->next->o2, dp->next->he, 0, false);
- lastdepth = dp->depth;
- }
- }
- lastx = xpos;
- lasty = ypos;
- poly.append(QPointF(lastx, lasty));
- }
+ // Here we plotted the old planner profile. why there's the magic with the plannerModel here?
plannerModel->setRecalc(oldRecalc);
-
- diveBg->setPolygon(poly);
- QRectF b = poly.boundingRect();
- QLinearGradient pat(
- b.x(),
- b.y(),
- b.x(),
- b.height() + b.y());
-
- pat.setColorAt(1, profile_color[DEPTH_BOTTOM].first());
- pat.setColorAt(0, profile_color[DEPTH_TOP].first());
- diveBg->setBrush(pat);
-
plannerModel->deleteTemporaryPlan();
}
-
-void DivePlannerGraphics::resizeEvent(QResizeEvent *event)
-{
- QGraphicsView::resizeEvent(event);
- fitInView(sceneRect(), Qt::IgnoreAspectRatio);
-}
-
-void DivePlannerGraphics::showEvent(QShowEvent *event)
-{
- QGraphicsView::showEvent(event);
- fitInView(sceneRect(), Qt::IgnoreAspectRatio);
-}
-
-void DivePlannerGraphics::mouseMoveEvent(QMouseEvent *event)
-{
- QPointF mappedPos = mapToScene(event->pos());
-
-
- double xpos = timeLine->valueAt(mappedPos);
- double ypos = depthLine->valueAt(mappedPos);
-
- xpos = (xpos > timeLine->maximum()) ? timeLine->posAtValue(timeLine->maximum()) : (xpos < timeLine->minimum()) ? timeLine->posAtValue(timeLine->minimum()) : timeLine->posAtValue(xpos);
-
- ypos = (ypos > depthLine->maximum()) ? depthLine->posAtValue(depthLine->maximum()) : (ypos < depthLine->minimum()) ? depthLine->posAtValue(depthLine->minimum()) : depthLine->posAtValue(ypos);
-
- verticalLine->setPos(xpos, fromPercent(0, Qt::Vertical));
- horizontalLine->setPos(fromPercent(0, Qt::Horizontal), ypos);
-
- depthString->setPos(fromPercent(1, Qt::Horizontal), ypos);
- timeString->setPos(xpos + 1, fromPercent(95, Qt::Vertical));
-
- if (isPointOutOfBoundaries(mappedPos))
- return;
-
- depthString->setText(get_depth_string(depthLine->valueAt(mappedPos), true, false));
- timeString->setText(QString::number(rint(timeLine->valueAt(mappedPos))) + "min");
-
- // calculate the correct color for the depthString.
- // QGradient doesn't returns it's interpolation, meh.
- double percent = depthLine->percentAt(mappedPos);
- QColor &startColor = profile_color[SAMPLE_SHALLOW].first();
- QColor &endColor = profile_color[SAMPLE_DEEP].first();
- short redDelta = (endColor.red() - startColor.red()) * percent + startColor.red();
- short greenDelta = (endColor.green() - startColor.green()) * percent + startColor.green();
- short blueDelta = (endColor.blue() - startColor.blue()) * percent + startColor.blue();
- depthString->setBrush(QColor(redDelta, greenDelta, blueDelta));
-
- if (activeDraggedHandler)
- moveActiveHandler(mappedPos, handles.indexOf(activeDraggedHandler));
- if (!handles.count())
- return;
-
- if (handles.last()->x() > mappedPos.x()) {
- verticalLine->setPen(QPen(QBrush(Qt::red), 0, Qt::SolidLine));
- horizontalLine->setPen(QPen(QBrush(Qt::red), 0, Qt::SolidLine));
- } else {
- verticalLine->setPen(QPen(Qt::DotLine));
- horizontalLine->setPen(QPen(Qt::DotLine));
- }
-}
-
-void DivePlannerGraphics::moveActiveHandler(const QPointF &mappedPos, const int pos)
-{
- divedatapoint data = plannerModel->at(pos);
- int mintime = 0, maxtime = (timeLine->maximum() + 10) * 60;
- if (pos > 0)
- mintime = plannerModel->at(pos - 1).time;
- if (pos < plannerModel->size() - 1)
- maxtime = plannerModel->at(pos + 1).time;
-
- int minutes = rint(timeLine->valueAt(mappedPos));
- if (minutes * 60 <= mintime || minutes * 60 >= maxtime)
- return;
-
- int milimeters = rint(depthLine->valueAt(mappedPos) / M_OR_FT(1, 1)) * M_OR_FT(1, 1);
- double xpos = timeLine->posAtValue(minutes);
- double ypos = depthLine->posAtValue(milimeters);
-
- data.depth = milimeters;
- data.time = rint(timeLine->valueAt(mappedPos)) * 60;
-
- plannerModel->editStop(pos, data);
-
- activeDraggedHandler->setPos(QPointF(xpos, ypos));
- qDeleteAll(lines);
- lines.clear();
- drawProfile();
-}
-
-bool DivePlannerGraphics::isPointOutOfBoundaries(const QPointF &point)
-{
- double xpos = timeLine->valueAt(point);
- double ypos = depthLine->valueAt(point);
-
- if (xpos > timeLine->maximum() ||
- xpos < timeLine->minimum() ||
- ypos > depthLine->maximum() ||
- ypos < depthLine->minimum()) {
- return true;
- }
- return false;
-}
-
-void DivePlannerGraphics::mousePressEvent(QMouseEvent *event)
-{
- if (event->modifiers()) {
- QGraphicsView::mousePressEvent(event);
- return;
- }
-
- QPointF mappedPos = mapToScene(event->pos());
- if (event->button() == Qt::LeftButton) {
- Q_FOREACH(QGraphicsItem * item, scene()->items(mappedPos, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, transform())) {
- if (DiveHandler *h = qgraphicsitem_cast<DiveHandler *>(item)) {
- activeDraggedHandler = h;
- activeDraggedHandler->setBrush(Qt::red);
- originalHandlerPos = activeDraggedHandler->pos();
- }
- }
- }
- QGraphicsView::mousePressEvent(event);
-}
-
-void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent *event)
-{
- if (activeDraggedHandler) {
- /* we already deal with all the positioning in the life update,
- * so all we need to do here is change the color of the handler */
- activeDraggedHandler->setBrush(QBrush(Qt::white));
- activeDraggedHandler = 0;
- drawProfile();
- }
-}
+#endif
DiveHandler::DiveHandler() : QGraphicsEllipseItem()
{
setRect(-5, -5, 10, 10);
- setFlag(QGraphicsItem::ItemIgnoresTransformations);
- setFlag(QGraphicsItem::ItemIsSelectable);
+ setFlags(ItemIgnoresTransformations | ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges);
setBrush(Qt::white);
setZValue(2);
}
int DiveHandler::parentIndex()
{
- DivePlannerGraphics *view = qobject_cast<DivePlannerGraphics *>(scene()->views().first());
+ ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
return view->handles.indexOf(this);
}
@@ -739,7 +183,7 @@ void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void DiveHandler::selfRemove()
{
setSelected(true);
- DivePlannerGraphics *view = qobject_cast<DivePlannerGraphics *>(scene()->views().first());
+ ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
view->keyDeleteAction();
}
@@ -750,210 +194,13 @@ void DiveHandler::changeGas()
plannerModel->setData(index, action->text());
}
-void DiveHandler::mousePressEvent(QGraphicsSceneMouseEvent *event)
+void DiveHandler::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
- if (event->button() != Qt::LeftButton)
+ ProfileWidget2 *view = qobject_cast<ProfileWidget2*>(scene()->views().first());
+ if(view->isPointOutOfBoundaries(event->scenePos()))
return;
-
- if (event->modifiers().testFlag(Qt::ControlModifier)) {
- setSelected(true);
- }
- // mousePressEvent 'grabs' the mouse and keyboard, annoying.
- ungrabMouse();
-
- /* hack. Sometimes the keyboard is grabbed, sometime it's not,
- so, let's force a grab and release, to get rid of a warning. */
- grabKeyboard();
- ungrabKeyboard();
-}
-
-void Ruler::setMaximum(double maximum)
-{
- max = maximum;
-}
-
-void Ruler::setMinimum(double minimum)
-{
- min = minimum;
-}
-
-void Ruler::setTextColor(const QColor &color)
-{
- textColor = color;
-}
-
-void Ruler::eraseAll()
-{
- qDeleteAll(ticks);
- ticks.clear();
- qDeleteAll(labels);
- labels.clear();
-}
-
-Ruler::Ruler() : unitSystem(0),
- orientation(Qt::Horizontal),
- min(0),
- max(0),
- interval(0),
- tickSize(0)
-{
-}
-
-Ruler::~Ruler()
-{
- eraseAll();
-}
-
-void Ruler::setOrientation(Qt::Orientation o)
-{
- orientation = o;
- // position the elements on the screen.
- setMinimum(minimum());
- setMaximum(maximum());
-}
-
-void Ruler::updateTicks()
-{
- eraseAll();
-
- QLineF m = line();
- QGraphicsLineItem *item = NULL;
- QGraphicsSimpleTextItem *label = NULL;
-
- double steps = (max - min) / interval;
- qreal pos;
- double currValue = min;
-
- if (orientation == Qt::Horizontal) {
- double stepSize = (m.x2() - m.x1()) / steps;
- for (pos = m.x1(); pos <= m.x2(); pos += stepSize, currValue += interval) {
- item = new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this);
- item->setPen(pen());
- ticks.push_back(item);
-
- label = new QGraphicsSimpleTextItem(QString::number(currValue), this);
- label->setBrush(QBrush(textColor));
- label->setFlag(ItemIgnoresTransformations);
- label->setPos(pos - label->boundingRect().width() / 2, m.y1() + tickSize + 5);
- labels.push_back(label);
- }
- } else {
- double stepSize = (m.y2() - m.y1()) / steps;
- for (pos = m.y1(); pos <= m.y2(); pos += stepSize, currValue += interval) {
- item = new QGraphicsLineItem(m.x1(), pos, m.x1() - tickSize, pos, this);
- item->setPen(pen());
- ticks.push_back(item);
-
- label = new QGraphicsSimpleTextItem(get_depth_string(currValue, false, false), this);
- label->setBrush(QBrush(textColor));
- label->setFlag(ItemIgnoresTransformations);
- label->setPos(m.x2() - 80, pos);
- labels.push_back(label);
- }
- }
-}
-
-void Ruler::setTickSize(qreal size)
-{
- tickSize = size;
-}
-
-void Ruler::setTickInterval(double i)
-{
- interval = i;
-}
-
-qreal Ruler::valueAt(const QPointF &p)
-{
- QLineF m = line();
- double retValue = orientation == Qt::Horizontal ?
- max * (p.x() - m.x1()) / (m.x2() - m.x1()) :
- max * (p.y() - m.y1()) / (m.y2() - m.y1());
- return retValue;
-}
-
-qreal Ruler::posAtValue(qreal value)
-{
- QLineF m = line();
- double size = max - min;
- double percent = value / size;
- double realSize = orientation == Qt::Horizontal ?
- m.x2() - m.x1() :
- m.y2() - m.y1();
- double retValue = realSize * percent;
- retValue = (orientation == Qt::Horizontal) ?
- retValue + m.x1() :
- retValue + m.y1();
- return retValue;
-}
-
-qreal Ruler::percentAt(const QPointF &p)
-{
- qreal value = valueAt(p);
- double size = max - min;
- double percent = value / size;
- return percent;
-}
-
-double Ruler::maximum() const
-{
- return max;
-}
-
-double Ruler::minimum() const
-{
- return min;
-}
-
-void Ruler::setColor(const QColor &color)
-{
- QPen defaultPen(color);
- defaultPen.setJoinStyle(Qt::RoundJoin);
- defaultPen.setCapStyle(Qt::RoundCap);
- defaultPen.setWidth(2);
- defaultPen.setCosmetic(true);
- setPen(defaultPen);
-}
-
-Button::Button(QObject *parent, QGraphicsItem *itemParent) : QObject(parent),
- QGraphicsRectItem(itemParent),
- icon(new QGraphicsPixmapItem(this)),
- text(new QGraphicsSimpleTextItem(this))
-{
- icon->setPos(0, 0);
- text->setPos(0, 0);
- setFlag(ItemIgnoresTransformations);
- setPen(QPen(QBrush(), 0));
-}
-
-void Button::setPixmap(const QPixmap &pixmap)
-{
- icon->setPixmap(pixmap);
- if (pixmap.isNull())
- icon->hide();
- else
- icon->show();
-
- setRect(childrenBoundingRect());
-}
-
-void Button::setText(const QString &t)
-{
- text->setText(t);
- if (icon->pixmap().isNull()) {
- icon->hide();
- text->setPos(0, 0);
- } else {
- icon->show();
- text->setPos(22, 0);
- }
- setRect(childrenBoundingRect());
-}
-
-void Button::mousePressEvent(QGraphicsSceneMouseEvent *event)
-{
- event->ignore();
- emit clicked();
+ QGraphicsEllipseItem::mouseMoveEvent(event);
+ emit moved();
}
DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
@@ -982,11 +229,11 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
connect(CylindersModel::instance(), SIGNAL(rowsRemoved(QModelIndex, int, int)),
GasSelectionModel::instance(), SLOT(repopulate()));
connect(CylindersModel::instance(), SIGNAL(dataChanged(QModelIndex, QModelIndex)),
- plannerModel, SLOT(emitCylinderModelEdited()));
+ plannerModel, SIGNAL(cylinderModelEdited()));
connect(CylindersModel::instance(), SIGNAL(rowsInserted(QModelIndex, int, int)),
- plannerModel, SLOT(emitCylinderModelEdited()));
+ plannerModel, SIGNAL(cylinderModelEdited()));
connect(CylindersModel::instance(), SIGNAL(rowsRemoved(QModelIndex, int, int)),
- plannerModel, SLOT(emitCylinderModelEdited()));
+ plannerModel, SIGNAL(cylinderModelEdited()));
ui.tableWidget->setBtnToolTip(tr("add dive data point"));
connect(ui.startTime, SIGNAL(timeChanged(QTime)), plannerModel, SLOT(setStartTime(QTime)));
@@ -1067,11 +314,6 @@ bool DivePlannerPointsModel::recalcQ()
return recalc;
}
-void DivePlannerPointsModel::emitCylinderModelEdited()
-{
- cylinderModelEdited();
-}
-
int DivePlannerPointsModel::columnCount(const QModelIndex &parent) const
{
return COLUMNS;
@@ -1264,7 +506,9 @@ bool DivePlannerPointsModel::addGas(int o2, int he)
sanitize_gasmix(&cyl->gasmix);
/* The depth to change to that gas is given by the depth where its pO2 is 1.6 bar.
* The user should be able to change this depth manually. */
- cyl->depth.mm = 1600 * 1000 / get_o2(&mix) * 10 - 10000;
+ pressure_t modppO2;
+ modppO2.mbar = 1600;
+ cyl->depth = gas_mod(&cyl->gasmix, modppO2);
CylindersModel::instance()->setDive(stagingDive);
return true;
}
@@ -1388,7 +632,7 @@ void DivePlannerPointsModel::remove(const QModelIndex &index)
endRemoveRows();
}
-struct diveplan DivePlannerPointsModel::getDiveplan()
+struct diveplan &DivePlannerPointsModel::getDiveplan()
{
return diveplan;
}
@@ -1619,46 +863,3 @@ void DivePlannerPointsModel::createPlan()
CylindersModel::instance()->update();
plannerModel->setRecalc(oldRecalc);
}
-
-ExpanderGraphics::ExpanderGraphics(QGraphicsItem *parent) : QGraphicsRectItem(parent),
- icon(new QGraphicsPixmapItem(this)),
- increaseBtn(new Button(0, this)),
- decreaseBtn(new Button(0, this)),
- bg(new QGraphicsPixmapItem(this)),
- leftWing(new QGraphicsPixmapItem(this)),
- rightWing(new QGraphicsPixmapItem(this))
-{
- QPixmap p;
-#define CREATE(item, pixmap) \
- p = QPixmap(QString(pixmap)); \
- item->setPixmap(p);
-
- CREATE(icon, ":icon_time");
- CREATE(bg, ":round_base");
- CREATE(leftWing, ":left_wing");
- CREATE(rightWing, ":right_wing");
-#undef CREATE
-
- decreaseBtn->setPixmap(QPixmap(":arrow_down"));
- increaseBtn->setPixmap(QPixmap(":arrow_up"));
-
- setFlag(ItemIgnoresTransformations);
- leftWing->setZValue(-2);
- rightWing->setZValue(-2);
- bg->setZValue(-1);
-
- leftWing->setPos(0, 0);
- bg->setPos(leftWing->pos().x() + leftWing->boundingRect().width() - 60, 5);
- rightWing->setPos(leftWing->pos().x() + leftWing->boundingRect().width() - 20, 0);
- decreaseBtn->setPos(leftWing->pos().x(), leftWing->pos().y());
- increaseBtn->setPos(rightWing->pos().x(), rightWing->pos().y());
- icon->setPos(bg->pos().x(), bg->pos().y() - 5);
-
- //I need to bottom align the items, I need to make the 0,0 ( orgin ) to be
- // the bottom of this item, so shift everything up.
- QRectF r = childrenBoundingRect();
- Q_FOREACH(QGraphicsItem * i, childItems()) {
- i->setPos(i->pos().x(), i->pos().y() - r.height());
- }
- setScale(0.7);
-}