Finished the port of the plot_profile code.

There are a few regressions, mostly because the text
is not being plotted yet and the background of some
of the curves are not being applied.
This is because QGrapdien is based on the coordinates
of the items that I wanna paint, but I'v setted a
QGradient that's global and doesn't take this into
consideration.

all curves are being plotted. in Small resolutions
they plot bad. but it's just a matter of redrawing
in the correct resolution.

the Line widths are being hardcoded now, on the cairo
version they weren't, this will need a bit of porting
too.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2013-05-05 13:42:33 -03:00
parent 926224122e
commit c72609046a

View file

@ -102,7 +102,7 @@ ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent
{ {
setScene(new QGraphicsScene()); setScene(new QGraphicsScene());
setBackgroundBrush(QColor("#F3F3E6")); setBackgroundBrush(QColor("#F3F3E6"));
scene()->setSceneRect(0,0,100,100); scene()->setSceneRect(0,0,1000,1000);
fill_profile_color(); fill_profile_color();
} }
@ -344,8 +344,11 @@ void ProfileGraphicsView::plot_depth_profile(struct graphics_context *gc, struct
entry = pi->entry; entry = pi->entry;
QGraphicsPolygonItem *neatFill = new QGraphicsPolygonItem();
QPolygonF p; QPolygonF p;
QLinearGradient pat(0.0,0.0,0.0,scene()->height());
QGraphicsPolygonItem *neatFill = 0;
for (i = 0; i < pi->nr; i++, entry++) for (i = 0; i < pi->nr; i++, entry++)
p.append( QPointF( SCALE(gc, entry->sec, entry->depth) )); p.append( QPointF( SCALE(gc, entry->sec, entry->depth) ));
@ -360,79 +363,91 @@ void ProfileGraphicsView::plot_depth_profile(struct graphics_context *gc, struct
p.append( QPointF( SCALE(gc, entry->sec, entry->depth) )); p.append( QPointF( SCALE(gc, entry->sec, entry->depth) ));
} }
} }
neatFill->setPolygon(p);
QLinearGradient pat(0.0,0.0,0.0,p.boundingRect().height()); ;
pat.setColorAt(1, profile_color[DEPTH_BOTTOM].first()); pat.setColorAt(1, profile_color[DEPTH_BOTTOM].first());
pat.setColorAt(0, profile_color[DEPTH_TOP].first()); pat.setColorAt(0, profile_color[DEPTH_TOP].first());
neatFill = new QGraphicsPolygonItem();
neatFill->setPolygon(p);
neatFill->setBrush(QBrush(pat)); neatFill->setBrush(QBrush(pat));
neatFill->setPen(QPen());
scene()->addItem(neatFill); scene()->addItem(neatFill);
#if 0
/* if the user wants the deco ceiling more visible, do that here (this /* if the user wants the deco ceiling more visible, do that here (this
* basically draws over the background that we had allowed to shine * basically draws over the background that we had allowed to shine
* through so far) */ * through so far) */
if (prefs.profile_red_ceiling) { // TODO: port the prefs.profile_red_ceiling to QSettings
pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0 * plot_scale); //if (prefs.profile_red_ceiling) {
pattern_add_color_stop_rgba (gc, pat, 0, CEILING_SHALLOW); p.clear();
pattern_add_color_stop_rgba (gc, pat, 1, CEILING_DEEP); pat.setColorAt(0, profile_color[CEILING_SHALLOW].first());
cairo_set_source(gc->cr, pat); pat.setColorAt(1, profile_color[CEILING_DEEP].first());
cairo_pattern_destroy(pat);
entry = pi->entry; entry = pi->entry;
move_to(gc, 0, 0);
for (i = 0; i < pi->nr; i++, entry++) { for (i = 0; i < pi->nr; i++, entry++) {
if (entry->ndl == 0 && entry->stopdepth) { if (entry->ndl == 0 && entry->stopdepth) {
if (entry->ndl == 0 && entry->stopdepth < entry->depth) { if (entry->ndl == 0 && entry->stopdepth < entry->depth) {
line_to(gc, entry->sec, entry->stopdepth); p.append( QPointF( SCALE(gc, entry->sec, entry->stopdepth) ));
} else { } else {
line_to(gc, entry->sec, entry->depth); p.append( QPointF( SCALE(gc, entry->sec, entry->depth) ));
} }
} else { } else {
line_to(gc, entry->sec, 0); p.append( QPointF( SCALE(gc, entry->sec, 0) ));
} }
} }
cairo_close_path(gc->cr);
cairo_fill(gc->cr); neatFill = new QGraphicsPolygonItem();
} neatFill->setBrush(QBrush(pat));
neatFill->setPolygon(p);
neatFill->setPen(QPen());
scene()->addItem(neatFill);
//}
/* finally, plot the calculated ceiling over all this */ /* finally, plot the calculated ceiling over all this */
if (prefs.profile_calc_ceiling) { // TODO: Port the profile_calc_ceiling to QSettings
pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0 * plot_scale); // if (prefs.profile_calc_ceiling) {
pattern_add_color_stop_rgba (gc, pat, 0, CALC_CEILING_SHALLOW); pat.setColorAt(0, profile_color[CALC_CEILING_SHALLOW].first());
pattern_add_color_stop_rgba (gc, pat, 1, CALC_CEILING_DEEP); pat.setColorAt(1, profile_color[CALC_CEILING_DEEP].first());
cairo_set_source(gc->cr, pat);
cairo_pattern_destroy(pat);
entry = pi->entry; entry = pi->entry;
move_to(gc, 0, 0); p.clear();
p.append( QPointF(0,0));
for (i = 0; i < pi->nr; i++, entry++) { for (i = 0; i < pi->nr; i++, entry++) {
if (entry->ceiling) if (entry->ceiling)
line_to(gc, entry->sec, entry->ceiling); p.append( QPointF( SCALE(gc, entry->sec, entry->ceiling) ));
else else
line_to(gc, entry->sec, 0); p.append( QPointF( SCALE(gc, entry->sec, 0) ));
}
line_to(gc, (entry-1)->sec, 0); /* make sure we end at 0 */
cairo_close_path(gc->cr);
cairo_fill(gc->cr);
} }
p.append( QPointF( SCALE(gc, (entry-1)->sec, 0) ));
neatFill = new QGraphicsPolygonItem();
neatFill->setPolygon(p);
neatFill->setPen(QPen());
scene()->addItem(neatFill);
//}
/* next show where we have been bad and crossed the dc's ceiling */ /* next show where we have been bad and crossed the dc's ceiling */
pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0 * plot_scale); pat.setColorAt(0, profile_color[CEILING_SHALLOW].first());
pattern_add_color_stop_rgba (gc, pat, 0, CEILING_SHALLOW); pat.setColorAt(1, profile_color[CEILING_DEEP].first());
pattern_add_color_stop_rgba (gc, pat, 1, CEILING_DEEP);
cairo_set_source(gc->cr, pat);
cairo_pattern_destroy(pat);
entry = pi->entry; entry = pi->entry;
move_to(gc, 0, 0); p.clear();
p.append( QPointF(0,0));
for (i = 0; i < pi->nr; i++, entry++) for (i = 0; i < pi->nr; i++, entry++)
line_to(gc, entry->sec, entry->depth); p.append( QPointF( SCALE(gc, entry->sec, entry->depth) ));
for (i = pi->nr - 1; i >= 0; i--, entry--) { for (i = pi->nr - 1; i >= 0; i--, entry--) {
if (entry->ndl == 0 && entry->stopdepth > entry->depth) { if (entry->ndl == 0 && entry->stopdepth > entry->depth) {
line_to(gc, entry->sec, entry->stopdepth); p.append( QPointF( SCALE(gc, entry->sec, entry->stopdepth) ));
} else { } else {
line_to(gc, entry->sec, entry->depth); p.append( QPointF( SCALE(gc, entry->sec, entry->depth) ));
} }
} }
cairo_close_path(gc->cr);
cairo_fill(gc->cr); neatFill = new QGraphicsPolygonItem();
neatFill->setPolygon(p);
neatFill->setPen(QPen());
neatFill->setBrush(QBrush(pat));
scene()->addItem(neatFill);
/* Now do it again for the velocity colors */ /* Now do it again for the velocity colors */
entry = pi->entry; entry = pi->entry;
@ -442,13 +457,12 @@ void ProfileGraphicsView::plot_depth_profile(struct graphics_context *gc, struct
/* we want to draw the segments in different colors /* we want to draw the segments in different colors
* representing the vertical velocity, so we need to * representing the vertical velocity, so we need to
* chop this into short segments */ * chop this into short segments */
depth = entry->depth; depth = entry->depth;
set_source_rgba(gc, VELOCITY_COLORS_START_IDX + entry->velocity); QGraphicsLineItem *colorLine = new QGraphicsLineItem( SCALE(gc, entry[-1].sec, entry[-1].depth), SCALE(gc, sec, depth));
move_to(gc, entry[-1].sec, entry[-1].depth); colorLine->setPen(QPen(QBrush(profile_color[ (color_indice_t) (VELOCITY_COLORS_START_IDX + entry->velocity)].first()), 2 ));
line_to(gc, sec, depth); scene()->addItem(colorLine);
cairo_stroke(cr);
} }
#endif
} }