summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--profile.c100
-rw-r--r--profile.h5
-rw-r--r--qt-ui/profilegraphics.cpp104
-rw-r--r--qt-ui/profilegraphics.h2
4 files changed, 113 insertions, 98 deletions
diff --git a/profile.c b/profile.c
index 15fb0ff42..2a8d5e4ed 100644
--- a/profile.c
+++ b/profile.c
@@ -158,13 +158,9 @@ int get_maxdepth(struct plot_info *pi)
}
/* collect all event names and whether we display them */
-struct ev_select {
- char *ev_name;
- gboolean plot_ev;
-};
-static struct ev_select *ev_namelist;
-static int evn_allocated;
-static int evn_used;
+struct ev_select *ev_namelist;
+int evn_allocated;
+int evn_used;
int evn_foreach(void (*callback)(const char *, int *, void *), void *data)
{
@@ -205,95 +201,7 @@ void remember_event(const char *eventname)
evn_used++;
}
-#if USE_GTK_UI
-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;
- }
-}
-
+#if 0
static void render_depth_sample(struct graphics_context *gc, struct plot_data *entry, const text_render_options_t *tro)
{
int sec = entry->sec, decimals;
diff --git a/profile.h b/profile.h
index 8f58082d1..d22589c68 100644
--- a/profile.h
+++ b/profile.h
@@ -39,6 +39,11 @@ struct plot_data {
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 ev_select {
+ char *ev_name;
+ bool plot_ev;
+};
+
/*
* When showing dive profiles, we scale things to the
* current dive. However, we don't scale past less than
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp
index d4c918ac6..b3163add4 100644
--- a/qt-ui/profilegraphics.cpp
+++ b/qt-ui/profilegraphics.cpp
@@ -6,6 +6,7 @@
#include <QPen>
#include <QBrush>
#include <QDebug>
+#include <QLineF>
#include "../color.h"
#include "../display.h"
@@ -106,6 +107,10 @@ struct text_render_options{
double hpos, vpos;
};
+extern struct ev_select *ev_namelist;
+extern int evn_allocated;
+extern int evn_used;
+
ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent)
{
setScene(new QGraphicsScene());
@@ -198,9 +203,9 @@ void ProfileGraphicsView::plot(struct dive *dive)
/* Depth profile */
plot_depth_profile(&gc, pi);
-#if 0
- plot_events(gc, pi, dc);
+ plot_events(&gc, pi, dc);
+#if 0
/* Temperature profile */
plot_temperature_profile(gc, pi);
@@ -257,6 +262,101 @@ void ProfileGraphicsView::plot(struct dive *dive)
#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)
{
diff --git a/qt-ui/profilegraphics.h b/qt-ui/profilegraphics.h
index 0b472f8b5..928c8ea89 100644
--- a/qt-ui/profilegraphics.h
+++ b/qt-ui/profilegraphics.h
@@ -20,6 +20,8 @@ protected:
private:
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_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;
QBrush defaultBrush;