diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-05-08 15:46:16 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-05-08 15:46:16 -0700 |
commit | 656b58f20554f31bd25ec7a2c3b65a1b19046062 (patch) | |
tree | 61198748a02009e9fde2c21a0a24ed5cd8a5de08 /qt-ui/profilegraphics.cpp | |
parent | 6f06c31d0b9db9ffae45d409557864469ab169b0 (diff) | |
download | subsurface-656b58f20554f31bd25ec7a2c3b65a1b19046062.tar.gz |
Add tooltip data and cleanup size calculations
Tomaz' code had a fixed height per tooltip item and some rather suspicious
logic how to position them (and how to size the surrounding box), based on
a fixed height in pixels per item - which of course fails if you use
larger fonts or multi line items.
This uses the bounding rects to correctly calculate the sizes and populates
the tooltip with the other dive data that we already had in a helper
function.
This also fixes a small formatting issue for gas change events.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/profilegraphics.cpp')
-rw-r--r-- | qt-ui/profilegraphics.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp index b3893ed90..93502f637 100644 --- a/qt-ui/profilegraphics.cpp +++ b/qt-ui/profilegraphics.cpp @@ -135,6 +135,10 @@ ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent void ProfileGraphicsView::mouseMoveEvent(QMouseEvent* event) { toolTip->clear(); + int time = (mapToScene(event->pos()).x() * gc.maxtime) / scene()->sceneRect().width(); + char buffer[500]; + get_plot_details(&gc, time, buffer, 500); + toolTip->addToolTip(QString(buffer)); QList<QGraphicsItem*> items = scene()->items(mapToScene(event->pos()), Qt::IntersectsItemShape, Qt::DescendingOrder, transform()); Q_FOREACH(QGraphicsItem *item, items) { if (!item->toolTip().isEmpty()) @@ -356,9 +360,10 @@ void ProfileGraphicsView::plot_one_event(struct event *ev) unsigned int he = ev->value >> 16; unsigned int o2 = ev->value & 0xffff; + name += ": "; name += (he) ? QString("%1/%2").arg(o2, he) - : (o2 == 21) ? name += tr(":air") - : QString("%1 %% %2").arg(o2).arg("O" UTF8_SUBSCRIPT_2); + : (o2 == 21) ? name += tr("air") + : QString("%1% %2").arg(o2).arg("O" UTF8_SUBSCRIPT_2); } else if (ev->name && !strcmp(ev->name, "SP change")) { name += QString(":%1").arg((double) ev->value / 1000); @@ -664,8 +669,10 @@ void ProfileGraphicsView::plot_temperature_profile() void ToolTipItem::addToolTip(const QString& toolTip, const QIcon& icon) { QGraphicsPixmapItem *iconItem = 0; - double yValue = title->boundingRect().height() + SPACING + toolTips.keys().size() * ICON_SMALL + SPACING; - + double yValue = title->boundingRect().height() + SPACING; + Q_FOREACH(ToolTip t, toolTips) { + yValue += t.second->boundingRect().height(); + } if (!icon.isNull()) { iconItem = new QGraphicsPixmapItem(icon.pixmap(ICON_SMALL,ICON_SMALL), this); iconItem->setPos(SPACING, yValue); @@ -764,13 +771,12 @@ void ToolTipItem::expand() QRectF currentRect = rectangle; QRectF nextRectangle; - double width = 0; + double width = 0, height = title->boundingRect().height() + SPACING; Q_FOREACH(ToolTip t, toolTips) { if (t.second->boundingRect().width() > width) width = t.second->boundingRect().width(); + height += t.second->boundingRect().height(); } - - double height = toolTips.count() * 18 + title->boundingRect().height() + SPACING; /* Left padding, Icon Size, space, right padding */ width += SPACING + ICON_SMALL + SPACING + SPACING; |