mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 20:23:25 +00:00
Plotting the Events done
There are subtle differences, the Cairo version looks prettier - but that's fixable. I did a small triangle and a exclamation mark on it. maybe a gradient would make a good difference there. this item has a ItemIgnoresTransformation tag, so scalling, rotating or zooming will not change it's size. The tooltips are not yet ported. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
55f31dc011
commit
867435442b
4 changed files with 113 additions and 98 deletions
100
profile.c
100
profile.c
|
@ -158,13 +158,9 @@ int get_maxdepth(struct plot_info *pi)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* collect all event names and whether we display them */
|
/* collect all event names and whether we display them */
|
||||||
struct ev_select {
|
struct ev_select *ev_namelist;
|
||||||
char *ev_name;
|
int evn_allocated;
|
||||||
gboolean plot_ev;
|
int evn_used;
|
||||||
};
|
|
||||||
static struct ev_select *ev_namelist;
|
|
||||||
static int evn_allocated;
|
|
||||||
static int evn_used;
|
|
||||||
|
|
||||||
int evn_foreach(void (*callback)(const char *, int *, void *), void *data)
|
int evn_foreach(void (*callback)(const char *, int *, void *), void *data)
|
||||||
{
|
{
|
||||||
|
@ -205,95 +201,7 @@ void remember_event(const char *eventname)
|
||||||
evn_used++;
|
evn_used++;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USE_GTK_UI
|
#if 0
|
||||||
static void plot_one_event(struct graphics_context *gc, struct plot_info *pi, struct event *event)
|
|
||||||
{
|
|
||||||
int i, depth = 0;
|
|
||||||
int x,y;
|
|
||||||
char buffer[256];
|
|
||||||
|
|
||||||
/* is plotting this event disabled? */
|
|
||||||
if (event->name) {
|
|
||||||
for (i = 0; i < evn_used; i++) {
|
|
||||||
if (! strcmp(event->name, ev_namelist[i].ev_name)) {
|
|
||||||
if (ev_namelist[i].plot_ev)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (event->time.seconds < 30 && !strcmp(event->name, "gaschange"))
|
|
||||||
/* a gas change in the first 30 seconds is the way of some dive computers
|
|
||||||
* to tell us the gas that is used; let's not plot a marker for that */
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (i = 0; i < pi->nr; i++) {
|
|
||||||
struct plot_data *data = pi->entry + i;
|
|
||||||
if (event->time.seconds < data->sec)
|
|
||||||
break;
|
|
||||||
depth = data->depth;
|
|
||||||
}
|
|
||||||
/* draw a little triangular marker and attach tooltip */
|
|
||||||
x = SCALEX(gc, event->time.seconds);
|
|
||||||
y = SCALEY(gc, depth);
|
|
||||||
set_source_rgba(gc, ALERT_BG);
|
|
||||||
cairo_move_to(gc->cr, x-6, y+12);
|
|
||||||
cairo_line_to(gc->cr, x+6, y+12);
|
|
||||||
cairo_line_to(gc->cr, x , y);
|
|
||||||
cairo_line_to(gc->cr, x-6, y+12);
|
|
||||||
cairo_stroke_preserve(gc->cr);
|
|
||||||
cairo_fill(gc->cr);
|
|
||||||
set_source_rgba(gc, ALERT_FG);
|
|
||||||
cairo_move_to(gc->cr, x, y+3);
|
|
||||||
cairo_line_to(gc->cr, x, y+7);
|
|
||||||
cairo_move_to(gc->cr, x, y+10);
|
|
||||||
cairo_line_to(gc->cr, x, y+10);
|
|
||||||
cairo_stroke(gc->cr);
|
|
||||||
/* we display the event on screen - so translate */
|
|
||||||
if (event->value) {
|
|
||||||
if (event->name && !strcmp(event->name, "gaschange")) {
|
|
||||||
unsigned int he = event->value >> 16;
|
|
||||||
unsigned int o2 = event->value & 0xffff;
|
|
||||||
if (he) {
|
|
||||||
snprintf(buffer, sizeof(buffer), "%s:%u/%u",
|
|
||||||
_(event->name), o2, he);
|
|
||||||
} else {
|
|
||||||
if (o2 == 21)
|
|
||||||
snprintf(buffer, sizeof(buffer), "%s:%s",
|
|
||||||
_(event->name), _("air"));
|
|
||||||
else
|
|
||||||
snprintf(buffer, sizeof(buffer), "%s:%u%% %s",
|
|
||||||
_(event->name), o2, "O" UTF8_SUBSCRIPT_2);
|
|
||||||
}
|
|
||||||
} else if (event->name && !strcmp(event->name, "SP change")) {
|
|
||||||
snprintf(buffer, sizeof(buffer), "%s:%0.1f", _(event->name), (double) event->value / 1000);
|
|
||||||
} else {
|
|
||||||
snprintf(buffer, sizeof(buffer), "%s:%d", _(event->name), event->value);
|
|
||||||
}
|
|
||||||
} else if (event->name && !strcmp(event->name, "SP change")) {
|
|
||||||
snprintf(buffer, sizeof(buffer), _("Bailing out to OC"));
|
|
||||||
} else {
|
|
||||||
snprintf(buffer, sizeof(buffer), "%s%s", _(event->name),
|
|
||||||
event->flags == SAMPLE_FLAGS_BEGIN ? C_("Starts with space!"," begin") :
|
|
||||||
event->flags == SAMPLE_FLAGS_END ? C_("Starts with space!", " end") : "");
|
|
||||||
}
|
|
||||||
attach_tooltip(x-6, y, 12, 12, buffer, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void plot_events(struct graphics_context *gc, struct plot_info *pi, struct divecomputer *dc)
|
|
||||||
{
|
|
||||||
struct event *event = dc->events;
|
|
||||||
|
|
||||||
if (gc->printer)
|
|
||||||
return;
|
|
||||||
|
|
||||||
while (event) {
|
|
||||||
plot_one_event(gc, pi, event);
|
|
||||||
event = event->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void render_depth_sample(struct graphics_context *gc, struct plot_data *entry, const text_render_options_t *tro)
|
static void render_depth_sample(struct graphics_context *gc, struct plot_data *entry, const text_render_options_t *tro)
|
||||||
{
|
{
|
||||||
int sec = entry->sec, decimals;
|
int sec = entry->sec, decimals;
|
||||||
|
|
|
@ -39,6 +39,11 @@ struct plot_data {
|
||||||
void calculate_max_limits(struct dive *dive, struct divecomputer *dc, struct graphics_context *gc);
|
void calculate_max_limits(struct dive *dive, struct divecomputer *dc, struct graphics_context *gc);
|
||||||
struct plot_info *create_plot_info(struct dive *dive, struct divecomputer *dc, struct graphics_context *gc);
|
struct plot_info *create_plot_info(struct dive *dive, struct divecomputer *dc, struct graphics_context *gc);
|
||||||
|
|
||||||
|
struct ev_select {
|
||||||
|
char *ev_name;
|
||||||
|
bool plot_ev;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* When showing dive profiles, we scale things to the
|
* When showing dive profiles, we scale things to the
|
||||||
* current dive. However, we don't scale past less than
|
* current dive. However, we don't scale past less than
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QPen>
|
#include <QPen>
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QLineF>
|
||||||
|
|
||||||
#include "../color.h"
|
#include "../color.h"
|
||||||
#include "../display.h"
|
#include "../display.h"
|
||||||
|
@ -106,6 +107,10 @@ struct text_render_options{
|
||||||
double hpos, vpos;
|
double hpos, vpos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern struct ev_select *ev_namelist;
|
||||||
|
extern int evn_allocated;
|
||||||
|
extern int evn_used;
|
||||||
|
|
||||||
ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent)
|
ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent)
|
||||||
{
|
{
|
||||||
setScene(new QGraphicsScene());
|
setScene(new QGraphicsScene());
|
||||||
|
@ -198,9 +203,9 @@ void ProfileGraphicsView::plot(struct dive *dive)
|
||||||
|
|
||||||
/* Depth profile */
|
/* Depth profile */
|
||||||
plot_depth_profile(&gc, pi);
|
plot_depth_profile(&gc, pi);
|
||||||
#if 0
|
|
||||||
plot_events(gc, pi, dc);
|
|
||||||
|
|
||||||
|
plot_events(&gc, pi, dc);
|
||||||
|
#if 0
|
||||||
/* Temperature profile */
|
/* Temperature profile */
|
||||||
plot_temperature_profile(gc, pi);
|
plot_temperature_profile(gc, pi);
|
||||||
|
|
||||||
|
@ -257,6 +262,101 @@ void ProfileGraphicsView::plot(struct dive *dive)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProfileGraphicsView::plot_events(struct graphics_context *gc, struct plot_info *pi, struct divecomputer *dc)
|
||||||
|
{
|
||||||
|
struct event *event = dc->events;
|
||||||
|
|
||||||
|
// if (gc->printer){
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
while (event) {
|
||||||
|
plot_one_event(gc, pi, event);
|
||||||
|
event = event->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProfileGraphicsView::plot_one_event(struct graphics_context *gc, struct plot_info *pi, struct event *ev)
|
||||||
|
{
|
||||||
|
int i, depth = 0;
|
||||||
|
|
||||||
|
/* is plotting this event disabled? */
|
||||||
|
if (ev->name) {
|
||||||
|
for (i = 0; i < evn_used; i++) {
|
||||||
|
if (! strcmp(ev->name, ev_namelist[i].ev_name)) {
|
||||||
|
if (ev_namelist[i].plot_ev)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ev->time.seconds < 30 && !strcmp(ev->name, "gaschange"))
|
||||||
|
/* a gas change in the first 30 seconds is the way of some dive computers
|
||||||
|
* to tell us the gas that is used; let's not plot a marker for that */
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (i = 0; i < pi->nr; i++) {
|
||||||
|
struct plot_data *data = pi->entry + i;
|
||||||
|
if (ev->time.seconds < data->sec)
|
||||||
|
break;
|
||||||
|
depth = data->depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* draw a little triangular marker and attach tooltip */
|
||||||
|
QPolygonF poly;
|
||||||
|
poly.push_back(QPointF(-8, 16));
|
||||||
|
poly.push_back(QPointF(8, 16));
|
||||||
|
poly.push_back(QPointF(0, 0));
|
||||||
|
poly.push_back(QPointF(-8, 16));
|
||||||
|
|
||||||
|
int x = SCALEX(gc, ev->time.seconds);
|
||||||
|
int y = SCALEY(gc, depth);
|
||||||
|
|
||||||
|
QGraphicsPolygonItem *triangle = new QGraphicsPolygonItem();
|
||||||
|
triangle->setPolygon(poly);
|
||||||
|
triangle->setBrush(QBrush(profile_color[ALERT_BG].first()));
|
||||||
|
triangle->setPen(QPen(QBrush(profile_color[ALERT_FG].first()), 1));
|
||||||
|
triangle->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
||||||
|
triangle->setPos(x, y);
|
||||||
|
|
||||||
|
QGraphicsLineItem *line = new QGraphicsLineItem(0,5,0,10, triangle);
|
||||||
|
line->setPen(QPen(QBrush(Qt::black), 2));
|
||||||
|
|
||||||
|
QGraphicsEllipseItem *ball = new QGraphicsEllipseItem(-1, 12, 2,2, triangle);
|
||||||
|
ball->setBrush(QBrush(Qt::black));
|
||||||
|
|
||||||
|
scene()->addItem(triangle);
|
||||||
|
|
||||||
|
/* we display the event on screen - so translate */
|
||||||
|
QString name = tr(ev->name);
|
||||||
|
if (ev->value) {
|
||||||
|
if (ev->name && name == "gaschange") {
|
||||||
|
unsigned int he = ev->value >> 16;
|
||||||
|
unsigned int o2 = ev->value & 0xffff;
|
||||||
|
if (he) {
|
||||||
|
name += QString("%1/%2").arg(o2, he);
|
||||||
|
} else {
|
||||||
|
if (o2 == 21)
|
||||||
|
name += tr(":air");
|
||||||
|
else
|
||||||
|
name += 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 );
|
||||||
|
} else {
|
||||||
|
name += QString(":%1").arg(ev->value);
|
||||||
|
}
|
||||||
|
} else if (ev->name && name == "SP change") {
|
||||||
|
name += tr("Bailing out to OC");
|
||||||
|
} else {
|
||||||
|
//name += ev->flags == SAMPLE_FLAGS_BEGIN ? C_("Starts with space!"," begin") :
|
||||||
|
// ev->flags == SAMPLE_FLAGS_END ? C_("Starts with space!", " end") : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
//attach_tooltip(x-6, y, 12, 12, buffer, ev);
|
||||||
|
}
|
||||||
|
|
||||||
void ProfileGraphicsView::plot_depth_profile(struct graphics_context *gc, struct plot_info *pi)
|
void ProfileGraphicsView::plot_depth_profile(struct graphics_context *gc, struct plot_info *pi)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,6 +20,8 @@ protected:
|
||||||
private:
|
private:
|
||||||
void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi);
|
void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi);
|
||||||
void plot_text(struct graphics_context *gc, text_render_options_t *tro, double x, double y, const QString &text);
|
void plot_text(struct graphics_context *gc, text_render_options_t *tro, double x, double y, const QString &text);
|
||||||
|
void plot_events(struct graphics_context *gc, struct plot_info *pi, struct divecomputer *dc);
|
||||||
|
void plot_one_event(struct graphics_context *gc, struct plot_info *pi, struct event *event);
|
||||||
|
|
||||||
QPen defaultPen;
|
QPen defaultPen;
|
||||||
QBrush defaultBrush;
|
QBrush defaultBrush;
|
||||||
|
|
Loading…
Add table
Reference in a new issue