From e71119b40bac8d6dc33449e33329f235350b08f5 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 15 Aug 2014 07:30:31 -0600 Subject: [PATCH] TankBar: use the itemPos as intended Which actually makes the code much clearer as now the object is at the correct spot on the canvas and the positions inside are relative to that. No more magic gradiants starting at "92" Signed-off-by: Dirk Hohndel --- qt-ui/profile/profilewidget2.cpp | 6 ++++++ qt-ui/profile/tankitem.cpp | 9 ++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index a9c7a52e8..400bedde1 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -53,6 +53,7 @@ static struct _ItemPos { }; _Pos background; _Pos dcLabel; + _Pos tankBar; _Axis depth; _Axis partialPressure; _Axis time; @@ -336,6 +337,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, @@ -818,6 +822,8 @@ void ProfileWidget2::setProfileState() } rulerItem->setVisible(prefs.rulergraph); tankItem->setVisible(true); + 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/tankitem.cpp b/qt-ui/profile/tankitem.cpp index 2db64da32..399306d2c 100644 --- a/qt-ui/profile/tankitem.cpp +++ b/qt-ui/profile/tankitem.cpp @@ -11,19 +11,18 @@ 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)); + 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, yPos), QPointF(0, yPos + height)); + QLinearGradient trimixGradient(QPointF(0, 0), QPointF(0, height)); trimixGradient.setColorAt(0.0, green); trimixGradient.setColorAt(0.49, green); trimixGradient.setColorAt(0.5, red); @@ -44,7 +43,7 @@ void TankItem::setData(DivePlotDataModel *model, struct plot_info *plotInfo, str 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); + QGraphicsRectItem *rect = new QGraphicsRectItem(x, 0, w, height, this); if (gasmix_is_air(gas)) rect->setBrush(air); else if (gas->he.permille) @@ -55,7 +54,7 @@ void TankItem::createBar(qreal x, qreal w, struct gasmix *gas) DiveTextItem *label = new DiveTextItem(rect); label->setText(gasname(gas)); label->setBrush(Qt::black); - label->setPos(x, yPos); + label->setPos(x + 1, 0); label->setAlignment(Qt::AlignBottom | Qt::AlignRight); label->setZValue(101); }