diff --git a/profile-widget/divecartesianaxis.cpp b/profile-widget/divecartesianaxis.cpp index ee4756cdc..21c5b147b 100644 --- a/profile-widget/divecartesianaxis.cpp +++ b/profile-widget/divecartesianaxis.cpp @@ -170,7 +170,7 @@ void DiveCartesianAxis::updateTicks(int animSpeed, color_index_t color) begin + i * stepSize : begin - i * stepSize; - labels[i]->setText(textForValue(currValueText)); + labels[i]->set(textForValue(currValueText), colorForValue(currValueText)); if (orientation == LeftToRight || orientation == RightToLeft) { Animations::moveTo(labels[i], animSpeed, childPos, m.y1() + tick_size); } else { @@ -201,8 +201,7 @@ void DiveCartesianAxis::updateTicks(int animSpeed, color_index_t color) int alignFlags = orientation == RightToLeft || orientation == LeftToRight ? Qt::AlignBottom | Qt::AlignHCenter : Qt::AlignVCenter | Qt::AlignLeft; DiveTextItem *label = new DiveTextItem(dpr, labelScale, alignFlags, this); - label->setText(textForValue(currValueText)); - label->setBrush(colorForValue(currValueText)); + label->set(textForValue(currValueText), colorForValue(currValueText)); label->setZValue(1); labels.push_back(label); if (orientation == RightToLeft || orientation == LeftToRight) { diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index 146e19880..f4069ef63 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -143,9 +143,8 @@ void DiveProfileItem::replot(const dive *d, bool in_planner) void DiveProfileItem::plot_depth_sample(struct plot_data *entry, QFlags flags, const QColor &color) { DiveTextItem *item = new DiveTextItem(dpr, 1.0, flags, this); + item->set(get_depth_string(entry->depth, true), color); item->setPos(hAxis.posAtValue(entry->sec), vAxis.posAtValue(entry->depth)); - item->setText(get_depth_string(entry->depth, true)); - item->setBrush(color); texts.append(item); } @@ -219,9 +218,8 @@ void DiveHeartrateItem::createTextItem(int sec, int hr, bool last) int flags = last ? Qt::AlignLeft | Qt::AlignBottom : Qt::AlignRight | Qt::AlignBottom; DiveTextItem *text = new DiveTextItem(dpr, 0.7, flags, this); - text->setBrush(getColor(HR_TEXT)); + text->set(QString("%1").arg(hr), getColor(HR_TEXT)); text->setPos(QPointF(hAxis.posAtValue(sec), vAxis.posAtValue(hr))); - text->setText(QString("%1").arg(hr)); texts.append(text); } @@ -369,9 +367,8 @@ void DiveTemperatureItem::createTextItem(int sec, int mkelvin, bool last) int flags = last ? Qt::AlignLeft | Qt::AlignBottom : Qt::AlignRight | Qt::AlignBottom; DiveTextItem *text = new DiveTextItem(dpr, 0.8, flags, this); - text->setBrush(getColor(TEMP_TEXT)); + text->set(get_temperature_string(temp, true), getColor(TEMP_TEXT)); text->setPos(QPointF(hAxis.posAtValue(sec), vAxis.posAtValue(mkelvin))); - text->setText(get_temperature_string(temp, true)); texts.append(text); } @@ -435,9 +432,8 @@ void DiveMeanDepthItem::createTextItem() qDeleteAll(texts); texts.clear(); DiveTextItem *text = new DiveTextItem(dpr, 0.8, Qt::AlignRight | Qt::AlignTop, this); - text->setBrush(getColor(TEMP_TEXT)); + text->set(get_depth_string(lrint(lastRunningSum), true), getColor(TEMP_TEXT)); text->setPos(QPointF(hAxis.posAtValue(sec) + 1, vAxis.posAtValue(lastRunningSum))); - text->setText(get_depth_string(lrint(lastRunningSum), true)); texts.append(text); } @@ -571,9 +567,8 @@ void DiveGasPressureItem::plotPressureValue(int mbar, int sec, QFlagsset(QString("%1%2").arg(pressure).arg(unit), getColor(PRESSURE_TEXT)); text->setPos(hAxis.posAtValue(sec), vAxis.posAtValue(mbar) + pressure_offset ); - text->setText(QString("%1%2").arg(pressure).arg(unit)); - text->setBrush(getColor(PRESSURE_TEXT)); texts.push_back(text); } @@ -581,9 +576,8 @@ void DiveGasPressureItem::plotGasValue(int mbar, int sec, struct gasmix gasmix, { QString gas = get_gas_string(gasmix); DiveTextItem *text = new DiveTextItem(dpr, 1.0, align, this); + text->set(gas, getColor(PRESSURE_TEXT)); text->setPos(hAxis.posAtValue(sec), vAxis.posAtValue(mbar) + gasname_offset ); - text->setText(gas); - text->setBrush(getColor(PRESSURE_TEXT)); texts.push_back(text); } diff --git a/profile-widget/divetextitem.cpp b/profile-widget/divetextitem.cpp index fde530bc7..b8f03d794 100644 --- a/profile-widget/divetextitem.cpp +++ b/profile-widget/divetextitem.cpp @@ -27,17 +27,11 @@ void DiveTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti QGraphicsItemGroup::paint(painter, option, widget); } -void DiveTextItem::setBrush(const QBrush &b) +void DiveTextItem::set(const QString &t, const QBrush &b) { textItem->setBrush(b); -} - -void DiveTextItem::setText(const QString &t) -{ - if (internalText != t) { - internalText = t; - updateText(); - } + internalText = t; + updateText(); } const QString &DiveTextItem::text() diff --git a/profile-widget/divetextitem.h b/profile-widget/divetextitem.h index ebe3561d8..28bafe257 100644 --- a/profile-widget/divetextitem.h +++ b/profile-widget/divetextitem.h @@ -15,8 +15,7 @@ class DiveTextItem : public QObject, public QGraphicsItemGroup { Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity) public: DiveTextItem(double dpr, double scale, int alignFlags, QGraphicsItem *parent); - void setText(const QString &text); - void setBrush(const QBrush &brush); + void set(const QString &text, const QBrush &brush); const QString &text(); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); static QFont getFont(double dpr, double scale); diff --git a/profile-widget/profilescene.cpp b/profile-widget/profilescene.cpp index 51f916de5..9734ed9df 100644 --- a/profile-widget/profilescene.cpp +++ b/profile-widget/profilescene.cpp @@ -157,9 +157,7 @@ ProfileScene::ProfileScene(double dpr, bool printMode, bool isGrayscale) : // show the deco model parameters at the top in the center decoModelParameters->setY(0); decoModelParameters->setX(50); - decoModelParameters->setBrush(getColor(PRESSURE_TEXT)); - diveComputerText->setBrush(getColor(TIME_TEXT, isGrayscale)); diveComputerText->setPos(itemPos.dcLabel.on); tankItem->setPos(itemPos.tankBar.on); @@ -450,15 +448,15 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM if (!plannerModel) { if (decoMode(false) == VPMB) - decoModelParameters->setText(QString("VPM-B +%1").arg(prefs.vpmb_conservatism)); + decoModelParameters->set(QString("VPM-B +%1").arg(prefs.vpmb_conservatism), getColor(PRESSURE_TEXT)); else - decoModelParameters->setText(QString("GF %1/%2").arg(prefs.gflow).arg(prefs.gfhigh)); + decoModelParameters->set(QString("GF %1/%2").arg(prefs.gflow).arg(prefs.gfhigh), getColor(PRESSURE_TEXT)); } else { struct diveplan &diveplan = plannerModel->getDiveplan(); if (decoMode(inPlanner) == VPMB) - decoModelParameters->setText(QString("VPM-B +%1").arg(diveplan.vpmb_conservatism)); + decoModelParameters->set(QString("VPM-B +%1").arg(diveplan.vpmb_conservatism), getColor(PRESSURE_TEXT)); else - decoModelParameters->setText(QString("GF %1/%2").arg(diveplan.gflow).arg(diveplan.gfhigh)); + decoModelParameters->set(QString("GF %1/%2").arg(diveplan.gflow).arg(diveplan.gfhigh), getColor(PRESSURE_TEXT)); } const struct divecomputer *currentdc = get_dive_dc_const(d, dc); @@ -660,7 +658,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM if ((nr = number_of_computers(d)) > 1) dcText += tr(" (#%1 of %2)").arg(dc + 1).arg(nr); #endif - diveComputerText->setText(dcText); + diveComputerText->set(dcText, getColor(TIME_TEXT, isGrayscale)); } QImage ProfileScene::toImage(QSize size) diff --git a/profile-widget/tankitem.cpp b/profile-widget/tankitem.cpp index a53f70a97..e74a3f128 100644 --- a/profile-widget/tankitem.cpp +++ b/profile-widget/tankitem.cpp @@ -52,8 +52,7 @@ void TankItem::createBar(int startTime, int stopTime, struct gasmix gas) rect->setPen(QPen(QBrush(), 0.0)); // get rid of the thick line around the rectangle rects.push_back(rect); DiveTextItem *label = new DiveTextItem(dpr, 1.0, Qt::AlignBottom | Qt::AlignRight, rect); - label->setText(gasname(gas)); - label->setBrush(Qt::black); + label->set(gasname(gas), Qt::black); label->setPos(x + 1, 0); #ifdef SUBSURFACE_MOBILE label->setPos(x + 1, -2.5);