summaryrefslogtreecommitdiffstats
path: root/qt-ui/profile/tankitem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui/profile/tankitem.cpp')
-rw-r--r--qt-ui/profile/tankitem.cpp77
1 files changed, 42 insertions, 35 deletions
diff --git a/qt-ui/profile/tankitem.cpp b/qt-ui/profile/tankitem.cpp
index 6608216be..2db64da32 100644
--- a/qt-ui/profile/tankitem.cpp
+++ b/qt-ui/profile/tankitem.cpp
@@ -1,5 +1,6 @@
#include "tankitem.h"
#include "diveplotdatamodel.h"
+#include "divetextitem.h"
#include "profile.h"
#include <QGradient>
#include <QDebug>
@@ -10,6 +11,25 @@ TankItem::TankItem(QObject *parent) :
dive(0),
pInfo(0)
{
+ yPos = 92;
+ height = 3;
+ QColor red(PERSIANRED1);
+ QColor blue(AIR_BLUE);
+ QColor yellow(NITROX_YELLOW);
+ QColor green(NITROX_GREEN);
+ QLinearGradient nitroxGradient(QPointF(0, yPos), QPointF(0, yPos + 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, yPos), QPointF(0, yPos + 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)
@@ -21,6 +41,25 @@ void TankItem::setData(DivePlotDataModel *model, struct plot_info *plotInfo, str
modelDataChanged();
}
+void TankItem::createBar(qreal x, qreal w, struct gasmix *gas)
+{
+ // pick the right gradient, size, position and text
+ QGraphicsRectItem *rect = new QGraphicsRectItem(x, yPos, w, height, this);
+ if (gasmix_is_air(gas))
+ rect->setBrush(air);
+ else if (gas->he.permille)
+ rect->setBrush(trimix);
+ else
+ rect->setBrush(nitrox);
+ rects.push_back(rect);
+ DiveTextItem *label = new DiveTextItem(rect);
+ label->setText(gasname(gas));
+ label->setBrush(Qt::black);
+ label->setPos(x, yPos);
+ 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.
@@ -34,59 +73,27 @@ void TankItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &b
}
rects.clear();
- // define the position on the profile
- qreal width, left, yPos, height;
- yPos = 95.0;
- height = 3.0;
-
- // set up the three patterns
- QLinearGradient nitrox(QPointF(0, yPos), QPointF(0, yPos + height));
- nitrox.setColorAt(0.0, Qt::green);
- nitrox.setColorAt(0.49, Qt::green);
- nitrox.setColorAt(0.5, Qt::yellow);
- nitrox.setColorAt(1.0, Qt::yellow);
- QLinearGradient trimix(QPointF(0, yPos), QPointF(0, yPos + height));
- trimix.setColorAt(0.0, Qt::green);
- trimix.setColorAt(0.49, Qt::green);
- trimix.setColorAt(0.5, Qt::red);
- trimix.setColorAt(1.0, Qt::red);
- QColor air(Qt::blue);
- air.lighter();
-
// 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);
- QGraphicsRectItem *rect = new QGraphicsRectItem(left, yPos, width, height, this);
- if (gasmix_is_air(gas))
- rect->setBrush(air);
- else if (gas->he.permille)
- rect->setBrush(trimix);
- else
- rect->setBrush(nitrox);
- rects << rect;
+ 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);
- QGraphicsRectItem *rect = new QGraphicsRectItem(left, yPos, width, height, this);
- if (gasmix_is_air(gas))
- rect->setBrush(air);
- else if (gas->he.permille)
- rect->setBrush(trimix);
- else
- rect->setBrush(nitrox);
- rects << rect;
+ createBar(left, width, gas);
}
void TankItem::setHorizontalAxis(DiveCartesianAxis *horizontal)