diff options
Diffstat (limited to 'qt-ui/profilegraphics.cpp')
-rw-r--r-- | qt-ui/profilegraphics.cpp | 74 |
1 files changed, 51 insertions, 23 deletions
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp index c1e51ac25..6e699fe51 100644 --- a/qt-ui/profilegraphics.cpp +++ b/qt-ui/profilegraphics.cpp @@ -119,7 +119,6 @@ ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent gc.printer = false; setScene(new QGraphicsScene()); setBackgroundBrush(QColor("#F3F3E6")); - scene()->setSceneRect(0,0,1000,1000); scene()->installEventFilter(this); setRenderHint(QPainter::Antialiasing); @@ -166,7 +165,12 @@ void ProfileGraphicsView::mouseMoveEvent(QMouseEvent* event) toolTip->refresh(&gc, mapToScene(event->pos())); QPoint toolTipPos = mapFromScene(toolTip->pos()); - ensureVisible(event->pos().x(), event->pos().y(), 10, 10, 100, 100); + + double dx = sceneRect().x(); + double dy = sceneRect().y(); + + ensureVisible(event->pos().x() + dx, event->pos().y() + dy, 1, 1); + toolTip->setPos(mapToScene(toolTipPos).x(), mapToScene(toolTipPos).y()); if (zoomLevel < 0) @@ -196,16 +200,26 @@ static void plot_set_scale(scale_mode_t scale) } } +void ProfileGraphicsView::showEvent(QShowEvent* event) +{ + if (dive) + plot(dive); +} + void ProfileGraphicsView::plot(struct dive *d) { - scene()->clear(); + scene()->clear(); if (dive != d){ resetTransform(); zoomLevel = 0; dive = d; } + if(!isVisible()){ + return; + } + if(!dive) return; @@ -293,15 +307,16 @@ void ProfileGraphicsView::plot(struct dive *d) scene()->addItem(rect); /* Put the dive computer name in the lower left corner */ - const char *nickname; - nickname = get_dc_nickname(dc->model, dc->deviceid); - if (!nickname || *nickname == '\0') - nickname = dc->model; - if (nickname) { + QString nick(get_dc_nickname(dc->model, dc->deviceid)); + if (nick.isEmpty()) + nick = QString(dc->model); + + if (!nick.isEmpty()) { text_render_options_t computer = {DC_TEXT_SIZE, TIME_TEXT, LEFT, MIDDLE}; - plot_text(&computer, gc.leftx, gc.bottomy, nickname); + diveComputer = plot_text(&computer, QPointF(gc.leftx, gc.bottomy), nick); } - + // The Time ruler should be right after the DiveComputer: + timeMarkers->setPos(0, diveComputer->y()); if (PP_GRAPHS_ENABLED) { plot_pp_gas_profile(); @@ -327,7 +342,11 @@ void ProfileGraphicsView::plot(struct dive *d) } #endif - scene()->setSceneRect(scene()->itemsBoundingRect()); + QRectF r = scene()->itemsBoundingRect(); + scene()->setSceneRect(r.x() - 15, r.y() -15, r.width() + 30, r.height() + 30); + if(zoomLevel == 0){ + fitInView(sceneRect()); + } } void ProfileGraphicsView::plot_depth_scale() @@ -351,10 +370,13 @@ void ProfileGraphicsView::plot_depth_scale() * partial pressure graphs) where this would look out * of place - so we only make sure that we print the next * marker below the actual maxdepth of the dive */ + depthMarkers = new QGraphicsRectItem(); for (i = marker; i <= gc.pi.maxdepth + marker; i += marker) { double d = get_depth_units(i, NULL, NULL); - plot_text(&tro, -0.002, i, QString::number(d)); + plot_text(&tro, QPointF(-0.002, i), QString::number(d), depthMarkers); } + scene()->addItem(depthMarkers); + depthMarkers->setPos(depthMarkers->pos().x() - 10, 0); } void ProfileGraphicsView::plot_pp_text() @@ -375,7 +397,7 @@ void ProfileGraphicsView::plot_pp_text() pen.setColor(c); item->setPen(pen); scene()->addItem(item); - plot_text(&tro, hpos + 30, m, QString::number(m)); + plot_text(&tro, QPointF(hpos + 30, m), QString::number(m)); } } @@ -514,7 +536,7 @@ void ProfileGraphicsView::plot_deco_text() float y = gc.topy = 1.0; static text_render_options_t tro = {PRESSURE_TEXT_SIZE, PRESSURE_TEXT, CENTER, -0.2}; gc.bottomy = 0.0; - plot_text(&tro, x, y, QString("GF %1/%2").arg(prefs.gflow * 100).arg(prefs.gfhigh * 100)); + plot_text(&tro, QPointF(x, y), QString("GF %1/%2").arg(prefs.gflow * 100).arg(prefs.gfhigh * 100)); } } @@ -563,7 +585,7 @@ void ProfileGraphicsView::plot_pressure_value(int mbar, int sec, double xalign, pressure = get_pressure_units(mbar, &unit); static text_render_options_t tro = {PRESSURE_TEXT_SIZE, PRESSURE_TEXT, xalign, yalign}; - plot_text(&tro, sec, mbar, QString("%1 %2").arg(pressure).arg(unit)); + plot_text(&tro, QPointF(sec, mbar), QString("%1 %2").arg(pressure).arg(unit)); } void ProfileGraphicsView::plot_depth_text() @@ -617,7 +639,7 @@ void ProfileGraphicsView::plot_depth_sample(struct plot_data *entry,text_render_ d = get_depth_units(entry->depth, &decimals, NULL); - plot_text(tro, sec, entry->depth, QString("%1").arg(d)); // , decimals, d); + plot_text(tro, QPointF(sec, entry->depth), QString("%1").arg(d)); // , decimals, d); } @@ -666,7 +688,7 @@ void ProfileGraphicsView::plot_single_temp_text(int sec, int mkelvin) const char *unit; static text_render_options_t tro = {TEMP_TEXT_SIZE, TEMP_TEXT, LEFT, TOP}; deg = get_temp_units(mkelvin, &unit); - plot_text(&tro, sec, mkelvin, QString("%1%2").arg(deg).arg(unit)); //"%.2g%s" + plot_text(&tro, QPointF(sec, mkelvin), QString("%1%2").arg(deg).arg(unit)); //"%.2g%s" } void ProfileGraphicsView::plot_cylinder_pressure(struct dive *dive, struct divecomputer *dc) @@ -889,17 +911,20 @@ void ProfileGraphicsView::plot_depth_profile() scene()->addItem(item); } + timeMarkers = new QGraphicsRectItem(); /* now the text on the time markers */ struct text_render_options tro = {DEPTH_TEXT_SIZE, TIME_TEXT, CENTER, TOP}; if (maxtime < 600) { /* Be a bit more verbose with shorter dives */ for (i = incr; i < maxtime; i += incr) - plot_text(&tro, i, 1, QString("%1:%2").arg(i/60).arg(i%60)); + plot_text(&tro, QPointF(i, 0), QString("%1:%2").arg(i/60).arg(i%60), timeMarkers); } else { /* Only render the time on every second marker for normal dives */ for (i = incr; i < maxtime; i += 2 * incr) - plot_text(&tro, i, 1, QString::number(i/60)); + plot_text(&tro, QPointF(i, 0), QString("%1").arg(QString::number(i/60)), timeMarkers); } + timeMarkers->setPos(0,0); + scene()->addItem(timeMarkers); /* Depth markers: every 30 ft or 10 m*/ gc.leftx = 0; gc.rightx = 1.0; @@ -1077,20 +1102,23 @@ void ProfileGraphicsView::plot_depth_profile() } } -void ProfileGraphicsView::plot_text(text_render_options_t *tro, double x, double y, const QString& text) +QGraphicsSimpleTextItem *ProfileGraphicsView::plot_text(text_render_options_t *tro,const QPointF& pos, const QString& text, QGraphicsItem *parent) { QFontMetrics fm(font()); double dx = tro->hpos * (fm.width(text)); double dy = tro->vpos * (fm.height()); - QGraphicsSimpleTextItem *item = new QGraphicsSimpleTextItem(text); - QPointF point(SCALEGC(x, y)); // This is neded because of the SCALE macro. + QGraphicsSimpleTextItem *item = new QGraphicsSimpleTextItem(text, parent); + QPointF point(SCALEGC(pos.x(), pos.y())); // This is neded because of the SCALE macro. item->setPos(point.x() + dx, point.y() +dy); item->setBrush(QBrush(profile_color[tro->color].first())); item->setFlag(QGraphicsItem::ItemIgnoresTransformations); - scene()->addItem(item); + + if(!parent) + scene()->addItem(item); + return item; } void ProfileGraphicsView::resizeEvent(QResizeEvent *event) |