void get_gas_string(const struct gasmix *gasmix, char *text, int len) { if (gasmix_is_air(gasmix)) snprintf(text, len, "%s", translate("gettextFromC", "air")); else if (get_he(gasmix) == 0) snprintf(text, len, translate("gettextFromC", "EAN%d"), (get_o2(gasmix) + 5) / 10); else snprintf(text, len, "(%d/%d)", (get_o2(gasmix) + 5) / 10, (get_he(gasmix) + 5) / 10); }
/* Quite crude reverse-blender-function, but it produces a approx result */ static void get_gas_parts(struct gasmix mix, volume_t vol, int o2_in_topup, volume_t *o2, volume_t *he) { volume_t air = {}; if (gasmix_is_air(&mix)) { o2->mliter = 0; he->mliter = 0; return; } air.mliter = rint(((double)vol.mliter * (1000 - get_he(&mix) - get_o2(&mix))) / (1000 - o2_in_topup)); he->mliter = rint(((double)vol.mliter * get_he(&mix)) / 1000.0); o2->mliter += vol.mliter - he->mliter - air.mliter; }
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 if (gas->o2.permille == 1000) rect->setBrush(oxygen); 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 DiveEventItem::setupPixmap() { const IconMetrics& metrics = defaultIconMetrics(); int sz_bigger = metrics.sz_med + metrics.sz_small; // ex 40px int sz_pix = sz_bigger/2; // ex 20px #define EVENT_PIXMAP(PIX) QPixmap(QString(PIX)).scaled(sz_pix, sz_pix, Qt::KeepAspectRatio, Qt::SmoothTransformation) #define EVENT_PIXMAP_BIGGER(PIX) QPixmap(QString(PIX)).scaled(sz_bigger, sz_bigger, Qt::KeepAspectRatio, Qt::SmoothTransformation) if (same_string(internalEvent->name, "")) { setPixmap(EVENT_PIXMAP(":warning")); } else if (internalEvent->type == SAMPLE_EVENT_BOOKMARK) { setPixmap(EVENT_PIXMAP(":flag")); } else if (strcmp(internalEvent->name, "heading") == 0 || (same_string(internalEvent->name, "SP change") && internalEvent->time.seconds == 0)) { // 2 cases: // a) some dive computers have heading in every sample // b) at t=0 we might have an "SP change" to indicate dive type // in both cases we want to get the right data into the tooltip but don't want the visual clutter // so set an "almost invisible" pixmap (a narrow but somewhat tall, basically transparent pixmap) // that allows tooltips to work when we don't want to show a specific // pixmap for an event, but want to show the event value in the tooltip QPixmap transparentPixmap(4, 20); transparentPixmap.fill(QColor::fromRgbF(1.0, 1.0, 1.0, 0.01)); setPixmap(transparentPixmap); } else if (event_is_gaschange(internalEvent)) { if (internalEvent->gas.mix.he.permille) setPixmap(EVENT_PIXMAP_BIGGER(":gaschangeTrimix")); else if (gasmix_is_air(&internalEvent->gas.mix)) setPixmap(EVENT_PIXMAP_BIGGER(":gaschangeAir")); else setPixmap(EVENT_PIXMAP_BIGGER(":gaschangeNitrox")); } else { setPixmap(EVENT_PIXMAP(":warning")); } #undef EVENT_PIXMAP }
QString gasToStr(struct gasmix gas) { uint o2 = (get_o2(&gas) + 5) / 10, he = (get_he(&gas) + 5) / 10; QString result = gasmix_is_air(&gas) ? QObject::tr("AIR") : he == 0 ? QString("EAN%1").arg(o2, 2, 10, QChar('0')) : QString("%1/%2").arg(o2).arg(he); return result; }