diff options
Diffstat (limited to 'qt-ui/profile')
-rw-r--r-- | qt-ui/profile/profilewidget2.cpp | 42 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.h | 2 | ||||
-rw-r--r-- | qt-ui/profile/tankitem.cpp | 105 | ||||
-rw-r--r-- | qt-ui/profile/tankitem.h | 38 |
4 files changed, 184 insertions, 3 deletions
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 413414ec8..409328918 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -13,6 +13,7 @@ #include "planner.h" #include "device.h" #include "ruleritem.h" +#include "tankitem.h" #include "dive.h" #include "pref.h" #include <libdivecomputer/parser.h> @@ -52,8 +53,10 @@ static struct _ItemPos { }; _Pos background; _Pos dcLabel; + _Pos tankBar; _Axis depth; _Axis partialPressure; + _Axis partialPressureWithTankBar; _Axis time; _Axis cylinder; _Axis temperature; @@ -89,6 +92,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent), mouseFollowerVertical(new DiveLineItem()), mouseFollowerHorizontal(new DiveLineItem()), rulerItem(new RulerItem2()), + tankItem(new TankItem()), isGrayscale(false), printMode(false), shouldCalculateMaxTime(true), @@ -160,6 +164,7 @@ void ProfileWidget2::addItemsToScene() scene()->addItem(rulerItem); scene()->addItem(rulerItem->sourceNode()); scene()->addItem(rulerItem->destNode()); + scene()->addItem(tankItem); scene()->addItem(mouseFollowerHorizontal); scene()->addItem(mouseFollowerVertical); QPen pen(QColor(Qt::red).lighter()); @@ -177,6 +182,7 @@ void ProfileWidget2::setupItemOnScene() toolTipItem->setZValue(9998); toolTipItem->setTimeAxis(timeAxis); rulerItem->setZValue(9997); + tankItem->setZValue(100); profileYAxis->setOrientation(DiveCartesianAxis::TopToBottom); profileYAxis->setMinimum(0); @@ -219,6 +225,7 @@ void ProfileWidget2::setupItemOnScene() diveComputerText->setBrush(getColor(TIME_TEXT, isGrayscale)); rulerItem->setAxis(timeAxis, profileYAxis); + tankItem->setHorizontalAxis(timeAxis); setupItem(reportedCeiling, timeAxis, profileYAxis, dataModel, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1); setupItem(diveCeiling, timeAxis, profileYAxis, dataModel, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1); @@ -301,6 +308,8 @@ void ProfileWidget2::setupItemSizes() itemPos.partialPressure.pos.off.setY(63); itemPos.partialPressure.expanded.setP1(QPointF(0, 0)); itemPos.partialPressure.expanded.setP2(QPointF(0, 30)); + itemPos.partialPressureWithTankBar = itemPos.partialPressure; + itemPos.partialPressureWithTankBar.expanded.setP2(QPointF(0, 27)); // cylinder axis config itemPos.cylinder.pos.on.setX(3); @@ -331,6 +340,9 @@ void ProfileWidget2::setupItemSizes() itemPos.dcLabel.on.setY(100); itemPos.dcLabel.off.setX(-10); itemPos.dcLabel.off.setY(100); + + itemPos.tankBar.on.setX(0); + itemPos.tankBar.on.setY(92); } void ProfileWidget2::setupItem(AbstractProfilePolygonItem *item, DiveCartesianAxis *hAxis, @@ -409,6 +421,14 @@ void ProfileWidget2::plotDive(struct dive *d, bool force) // reset some item visibility on printMode changes toolTipItem->setVisible(!printMode); rulerItem->setVisible(prefs.rulergraph && !printMode); + tankItem->setVisible(prefs.tankbar); + if (prefs.tankbar) { + gasYAxis->setPos(itemPos.partialPressureWithTankBar.pos.on); + gasYAxis->setLine(itemPos.partialPressureWithTankBar.expanded); + } else { + gasYAxis->setPos(itemPos.partialPressure.pos.on); + gasYAxis->setLine(itemPos.partialPressure.expanded); + } if (currentState == EMPTY) setProfileState(); @@ -487,6 +507,7 @@ void ProfileWidget2::plotDive(struct dive *d, bool force) cylinderPressureAxis->setMaximum(pInfo.maxpressure); rulerItem->setPlotInfo(pInfo); + tankItem->setData(dataModel, &pInfo, &displayed_dive); meanDepth->setVisible(prefs.show_average_depth); meanDepth->setMeanDepth(pInfo.meandepth); meanDepth->setLine(0, 0, timeAxis->posAtValue(currentdc->duration.seconds), 0); @@ -552,6 +573,13 @@ void ProfileWidget2::settingsChanged() temperatureAxis->animateChangeLine(itemPos.temperature.expanded); cylinderPressureAxis->animateChangeLine(itemPos.cylinder.expanded); } + if (prefs.tankbar) { + gasYAxis->setPos(itemPos.partialPressureWithTankBar.pos.on); + gasYAxis->animateChangeLine(itemPos.partialPressureWithTankBar.expanded); + } else { + gasYAxis->setPos(itemPos.partialPressure.pos.on); + gasYAxis->animateChangeLine(itemPos.partialPressure.expanded); + } if (prefs.zoomed_plot != isPlotZoomed) { isPlotZoomed = prefs.zoomed_plot; needReplot = true; @@ -727,6 +755,7 @@ void ProfileWidget2::setEmptyState() diveCeiling->setVisible(false); reportedCeiling->setVisible(false); rulerItem->setVisible(false); + tankItem->setVisible(false); pn2GasItem->setVisible(false); po2GasItem->setVisible(false); pheGasItem->setVisible(false); @@ -784,9 +813,13 @@ void ProfileWidget2::setProfileState() po2GasItem->setVisible(prefs.pp_graphs.po2); pheGasItem->setVisible(prefs.pp_graphs.phe); - gasYAxis->setPos(itemPos.partialPressure.pos.on); - gasYAxis->setLine(itemPos.partialPressure.expanded); - + if (prefs.tankbar) { + gasYAxis->setPos(itemPos.partialPressureWithTankBar.pos.on); + gasYAxis->setLine(itemPos.partialPressureWithTankBar.expanded); + } else { + gasYAxis->setPos(itemPos.partialPressure.pos.on); + gasYAxis->setLine(itemPos.partialPressure.expanded); + } timeAxis->setPos(itemPos.time.pos.on); timeAxis->setLine(itemPos.time.expanded); @@ -809,6 +842,9 @@ void ProfileWidget2::setProfileState() } } rulerItem->setVisible(prefs.rulergraph); + tankItem->setVisible(prefs.tankbar); + tankItem->setPos(itemPos.tankBar.on); + #define HIDE_ALL(TYPE, CONTAINER) \ Q_FOREACH (TYPE *item, CONTAINER) item->setVisible(false); HIDE_ALL(DiveHandler, handles); diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h index c3db9845c..fa5e53e26 100644 --- a/qt-ui/profile/profilewidget2.h +++ b/qt-ui/profile/profilewidget2.h @@ -40,6 +40,7 @@ class DiveCalculatedTissue; class PartialPressureGasItem; class PartialGasPressureAxis; class AbstractProfilePolygonItem; +class TankItem; class DiveHandler; class QGraphicsSimpleTextItem; class QModelIndex; @@ -164,6 +165,7 @@ private: DiveLineItem *mouseFollowerVertical; DiveLineItem *mouseFollowerHorizontal; RulerItem2 *rulerItem; + TankItem *tankItem; bool isGrayscale; bool printMode; diff --git a/qt-ui/profile/tankitem.cpp b/qt-ui/profile/tankitem.cpp new file mode 100644 index 000000000..a5ec5050c --- /dev/null +++ b/qt-ui/profile/tankitem.cpp @@ -0,0 +1,105 @@ +#include "tankitem.h" +#include "diveplotdatamodel.h" +#include "divetextitem.h" +#include "profile.h" +#include <QGradient> +#include <QDebug> +#include <QPen> + +TankItem::TankItem(QObject *parent) : + QGraphicsRectItem(), + dataModel(0), + dive(0), + pInfo(0) +{ + height = 3; + QColor red(PERSIANRED1); + QColor blue(AIR_BLUE); + QColor yellow(NITROX_YELLOW); + QColor green(NITROX_GREEN); + QLinearGradient nitroxGradient(QPointF(0, 0), QPointF(0, height)); + nitroxGradient.setColorAt(0.0, green); + nitroxGradient.setColorAt(0.49, green); + nitroxGradient.setColorAt(0.5, yellow); + nitroxGradient.setColorAt(1.0, yellow); + nitrox = nitroxGradient; + QLinearGradient trimixGradient(QPointF(0, 0), QPointF(0, height)); + trimixGradient.setColorAt(0.0, green); + trimixGradient.setColorAt(0.49, green); + trimixGradient.setColorAt(0.5, red); + trimixGradient.setColorAt(1.0, red); + trimix = trimixGradient; + air = blue; +} + +void TankItem::setData(DivePlotDataModel *model, struct plot_info *plotInfo, struct dive *d) +{ + pInfo = plotInfo; + dive = d; + dataModel = model; + connect(dataModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(modelDataChanged(QModelIndex, QModelIndex))); + modelDataChanged(); +} + +void TankItem::createBar(qreal x, qreal w, struct gasmix *gas) +{ + // pick the right gradient, size, position and text + QGraphicsRectItem *rect = new QGraphicsRectItem(x, 0, w, height, this); + if (gasmix_is_air(gas)) + rect->setBrush(air); + else if (gas->he.permille) + rect->setBrush(trimix); + else + rect->setBrush(nitrox); + rect->setPen(QPen(QBrush(), 0.0)); // get rid of the thick line around the rectangle + rects.push_back(rect); + DiveTextItem *label = new DiveTextItem(rect); + label->setText(gasname(gas)); + label->setBrush(Qt::black); + label->setPos(x + 1, 0); + label->setAlignment(Qt::AlignBottom | Qt::AlignRight); + label->setZValue(101); +} + +void TankItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) +{ + // We don't have enougth data to calculate things, quit. + + if (!dive || !dataModel || !pInfo || !pInfo->nr) + return; + + // remove the old rectangles + foreach (QGraphicsRectItem *r, rects) { + delete(r); + } + rects.clear(); + + // walk the list and figure out which tanks go where + struct plot_data *entry = pInfo->entry; + int cylIdx = entry->cylinderindex; + int i = -1; + int startTime = 0; + struct gasmix *gas = &dive->cylinder[cylIdx].gasmix; + qreal width, left; + while (++i < pInfo->nr) { + entry = &pInfo->entry[i]; + if (entry->cylinderindex == cylIdx) + continue; + width = hAxis->posAtValue(entry->sec) - hAxis->posAtValue(startTime); + left = hAxis->posAtValue(startTime); + createBar(left, width, gas); + cylIdx = entry->cylinderindex; + gas = &dive->cylinder[cylIdx].gasmix; + startTime = entry->sec; + } + width = hAxis->posAtValue(entry->sec) - hAxis->posAtValue(startTime); + left = hAxis->posAtValue(startTime); + createBar(left, width, gas); +} + +void TankItem::setHorizontalAxis(DiveCartesianAxis *horizontal) +{ + hAxis = horizontal; + connect(hAxis, SIGNAL(sizeChanged()), this, SLOT(modelDataChanged())); + modelDataChanged(); +} diff --git a/qt-ui/profile/tankitem.h b/qt-ui/profile/tankitem.h new file mode 100644 index 000000000..615a7017d --- /dev/null +++ b/qt-ui/profile/tankitem.h @@ -0,0 +1,38 @@ +#ifndef TANKITEM_H +#define TANKITEM_H + +#include <QGraphicsItem> +#include <QModelIndex> +#include <QBrush> +#include "divelineitem.h" +#include "divecartesianaxis.h" +#include "dive.h" + +class TankItem : public QObject, public QGraphicsRectItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsItem) + +public: + explicit TankItem(QObject *parent = 0); + void setHorizontalAxis(DiveCartesianAxis *horizontal); + void setData(DivePlotDataModel *model, struct plot_info *plotInfo, struct dive *d); + +signals: + +public slots: + virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()); + +private: + void createBar(qreal x, qreal w, struct gasmix *gas); + DivePlotDataModel *dataModel; + DiveCartesianAxis *hAxis; + int hDataColumn; + struct dive *dive; + struct plot_info *pInfo; + qreal yPos, height; + QBrush air, nitrox, trimix; + QList<QGraphicsRectItem *> rects; +}; + +#endif // TANKITEM_H |