diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-10-24 07:03:22 +0200 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-10-24 07:03:22 +0200 |
commit | a72408400c67a142b9abaec89df954df7dac7a71 (patch) | |
tree | 821827d9e4599d1745bf62e9139de183327ffa74 | |
parent | 2b4fa480ae57766889c5a20ff1cb59427469d401 (diff) | |
parent | 11b62a149b0d65e37a2cedbc93c8e8d84b23e041 (diff) | |
download | subsurface-a72408400c67a142b9abaec89df954df7dac7a71.tar.gz |
Merge branch 'ui' of git://github.com/dirkhh/subsurface
* 'ui' of git://github.com/dirkhh/subsurface:
Disable sorting by dive number
Fix oversight in preference implementation
Make columns for temperature, cylinder, and nitrox optional
Show dive number in dive list
Improve time marker handling and add printing of some time labels
-rw-r--r-- | display-gtk.h | 3 | ||||
-rw-r--r-- | divelist.c | 17 | ||||
-rw-r--r-- | gtk-gui.c | 31 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | profile.c | 26 |
5 files changed, 67 insertions, 11 deletions
diff --git a/display-gtk.h b/display-gtk.h index fe373a14f..fb2b9af5b 100644 --- a/display-gtk.h +++ b/display-gtk.h @@ -12,6 +12,9 @@ typedef struct { } progressbar_t; typedef struct { + gboolean cylinder; + gboolean temperature; + gboolean nitrox; gboolean sac; gboolean otu; } visible_cols_t; diff --git a/divelist.c b/divelist.c index 5f2063e9f..3ddfb6582 100644 --- a/divelist.c +++ b/divelist.c @@ -25,7 +25,7 @@ struct DiveList { GtkWidget *tree_view; GtkWidget *container_widget; GtkListStore *model; - GtkTreeViewColumn *date, *depth, *duration, *location; + GtkTreeViewColumn *nr, *date, *depth, *duration, *location; GtkTreeViewColumn *temperature, *cylinder, *nitrox, *sac, *otu; int changed; }; @@ -38,6 +38,7 @@ static struct DiveList dive_list; */ enum { DIVE_INDEX = 0, + DIVE_NR, /* int: dive->nr */ DIVE_DATE, /* time_t: dive->when */ DIVE_DEPTH, /* int: dive->maxdepth in mm */ DIVE_DURATION, /* int: in seconds */ @@ -375,6 +376,7 @@ static void fill_one_dive(struct dive *dive, * The core data itself is unaffected by units */ gtk_list_store_set(GTK_LIST_STORE(model), iter, + DIVE_NR, dive->number, DIVE_LOCATION, location, DIVE_CYLINDER, cylinder, DIVE_SAC, sac, @@ -449,6 +451,9 @@ void update_dive_list_units(void) void update_dive_list_col_visibility(void) { + gtk_tree_view_column_set_visible(dive_list.cylinder, visible_cols.cylinder); + gtk_tree_view_column_set_visible(dive_list.temperature, visible_cols.temperature); + gtk_tree_view_column_set_visible(dive_list.nitrox, visible_cols.nitrox); gtk_tree_view_column_set_visible(dive_list.sac, visible_cols.sac); gtk_tree_view_column_set_visible(dive_list.otu, visible_cols.otu); return; @@ -469,6 +474,7 @@ static void fill_dive_list(void) gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, DIVE_INDEX, i, + DIVE_NR, dive->number, DIVE_DATE, dive->when, DIVE_DEPTH, dive->maxdepth, DIVE_DURATION, dive->duration.seconds, @@ -515,6 +521,7 @@ GtkWidget *dive_list_create(void) dive_list.model = gtk_list_store_new(DIVELIST_COLUMNS, G_TYPE_INT, /* index */ + G_TYPE_INT, /* nr */ G_TYPE_INT, /* Date */ G_TYPE_INT, /* Depth */ G_TYPE_INT, /* Duration */ @@ -533,12 +540,14 @@ GtkWidget *dive_list_create(void) gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE); gtk_widget_set_size_request(dive_list.tree_view, 200, 200); + dive_list.nr = divelist_column(&dive_list, DIVE_NR, "#", NULL, PANGO_ALIGN_RIGHT, TRUE); + gtk_tree_view_column_set_sort_column_id(dive_list.nr, -1); dive_list.date = divelist_column(&dive_list, DIVE_DATE, "Date", date_data_func, PANGO_ALIGN_LEFT, TRUE); dive_list.depth = divelist_column(&dive_list, DIVE_DEPTH, "ft", depth_data_func, PANGO_ALIGN_RIGHT, TRUE); dive_list.duration = divelist_column(&dive_list, DIVE_DURATION, "min", duration_data_func, PANGO_ALIGN_RIGHT, TRUE); - dive_list.temperature = divelist_column(&dive_list, DIVE_TEMPERATURE, UTF8_DEGREE "F", temperature_data_func, PANGO_ALIGN_RIGHT, TRUE); - dive_list.cylinder = divelist_column(&dive_list, DIVE_CYLINDER, "Cyl", NULL, PANGO_ALIGN_CENTER, TRUE); - dive_list.nitrox = divelist_column(&dive_list, DIVE_NITROX, "O" UTF8_SUBSCRIPT_2 "%", nitrox_data_func, PANGO_ALIGN_CENTER, TRUE); + dive_list.temperature = divelist_column(&dive_list, DIVE_TEMPERATURE, UTF8_DEGREE "F", temperature_data_func, PANGO_ALIGN_RIGHT, visible_cols.temperature); + dive_list.cylinder = divelist_column(&dive_list, DIVE_CYLINDER, "Cyl", NULL, PANGO_ALIGN_CENTER, visible_cols.cylinder); + dive_list.nitrox = divelist_column(&dive_list, DIVE_NITROX, "O" UTF8_SUBSCRIPT_2 "%", nitrox_data_func, PANGO_ALIGN_CENTER, visible_cols.nitrox); dive_list.sac = divelist_column(&dive_list, DIVE_SAC, "SAC", sac_data_func, PANGO_ALIGN_CENTER, visible_cols.sac); dive_list.otu = divelist_column(&dive_list, DIVE_OTU, "OTU", otu_data_func, PANGO_ALIGN_CENTER, visible_cols.otu); dive_list.location = divelist_column(&dive_list, DIVE_LOCATION, "Location", NULL, PANGO_ALIGN_LEFT, TRUE); @@ -301,6 +301,9 @@ static void name(GtkWidget *w, gpointer data) \ OPTIONCALLBACK(otu_toggle, visible_cols.otu) OPTIONCALLBACK(sac_toggle, visible_cols.sac) +OPTIONCALLBACK(nitrox_toggle, visible_cols.nitrox) +OPTIONCALLBACK(temperature_toggle, visible_cols.temperature) +OPTIONCALLBACK(cylinder_toggle, visible_cols.cylinder) static void preferences_dialog(GtkWidget *w, gpointer data) { @@ -349,6 +352,21 @@ static void preferences_dialog(GtkWidget *w, gpointer data) box = gtk_hbox_new(FALSE, 6); gtk_container_add(GTK_CONTAINER(frame), box); + button = gtk_check_button_new_with_label("Show Temp"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.temperature); + gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6); + g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(temperature_toggle), NULL); + + button = gtk_check_button_new_with_label("Show Cyl"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.cylinder); + gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6); + g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(cylinder_toggle), NULL); + + button = gtk_check_button_new_with_label("Show O" UTF8_SUBSCRIPT_2 "%"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.nitrox); + gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6); + g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(nitrox_toggle), NULL); + button = gtk_check_button_new_with_label("Show SAC"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.sac); gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6); @@ -379,7 +397,10 @@ static void preferences_dialog(GtkWidget *w, gpointer data) gconf_client_set_bool(gconf, GCONF_NAME(psi), output_units.pressure == PSI, NULL); gconf_client_set_bool(gconf, GCONF_NAME(cuft), output_units.volume == CUFT, NULL); gconf_client_set_bool(gconf, GCONF_NAME(fahrenheit), output_units.temperature == FAHRENHEIT, NULL); - gconf_client_set_bool(gconf, GCONF_NAME(SAC), ! visible_cols.sac, NULL); /* inverted to get the correct default */ + gconf_client_set_bool(gconf, GCONF_NAME(TEMPERATURE), visible_cols.temperature, NULL); + gconf_client_set_bool(gconf, GCONF_NAME(CYLINDER), visible_cols.cylinder, NULL); + gconf_client_set_bool(gconf, GCONF_NAME(NITROX), visible_cols.nitrox, NULL); + gconf_client_set_bool(gconf, GCONF_NAME(SAC), visible_cols.sac, NULL); gconf_client_set_bool(gconf, GCONF_NAME(OTU), visible_cols.otu, NULL); gconf_client_set_string(gconf, GCONF_NAME(divelist_font), divelist_font, NULL); } @@ -625,10 +646,12 @@ void init_ui(int argc, char **argv) output_units.volume = CUFT; if (gconf_client_get_bool(gconf, GCONF_NAME(fahrenheit), NULL)) output_units.temperature = FAHRENHEIT; - /* an unset key is FALSE - so in order to get the default behavior right we - invert the meaning of the SAC key */ + /* an unset key is FALSE - all these are hidden by default */ + visible_cols.cylinder = gconf_client_get_bool(gconf, GCONF_NAME(CYLINDER), NULL); + visible_cols.temperature = gconf_client_get_bool(gconf, GCONF_NAME(TEMPERATURE), NULL); + visible_cols.nitrox = gconf_client_get_bool(gconf, GCONF_NAME(NITROX), NULL); visible_cols.otu = gconf_client_get_bool(gconf, GCONF_NAME(OTU), NULL); - visible_cols.sac = ! gconf_client_get_bool(gconf, GCONF_NAME(SAC), NULL); + visible_cols.sac = gconf_client_get_bool(gconf, GCONF_NAME(SAC), NULL); divelist_font = gconf_client_get_string(gconf, GCONF_NAME(divelist_font), NULL); if (!divelist_font) @@ -203,6 +203,7 @@ void renumber_dives(int nr) for (i = 0; i < dive_table.nr; i++) { struct dive *dive = dive_table.dives[i]; dive->number = nr + i; + flush_divelist(dive); } mark_divelist_changed(TRUE); } @@ -299,23 +299,43 @@ static void plot_minmax_profile(struct graphics_context *gc, struct plot_info *p static void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi) { - int i; + int i, incr; cairo_t *cr = gc->cr; int sec, depth; struct plot_data *entry; int maxtime, maxdepth, marker; + int increments[4] = { 5*60, 10*60, 15*60, 30*60 }; /* Get plot scaling limits */ maxtime = get_maxtime(pi); maxdepth = get_maxdepth(pi); - /* Time markers: every 5 min */ + /* Time markers: at most every 5 min, but no more than 12 markers + * and for convenience we do 5, 10, 15 or 30 min intervals. + * This allows for 6h dives - enough (I hope) for even the craziest + * divers - but just in case, for those 8h depth-record-breaking dives, + * we double the interval if this still doesn't get us to 12 or fewer + * time markers */ + i = 0; + while (maxtime / increments[i] > 12 && i < 4) + i++; + incr = increments[i]; + while (maxtime / incr > 12) + incr *= 2; + gc->leftx = 0; gc->rightx = maxtime; gc->topy = 0; gc->bottomy = 1.0; - for (i = 5*60; i < maxtime; i += 5*60) { + set_source_rgba(gc, 1, 1, 1, 0.5); + for (i = incr; i < maxtime; i += incr) { move_to(gc, i, 0); line_to(gc, i, 1); } + cairo_stroke(cr); + + /* now the text on every second time marker */ + text_render_options_t tro = {10, 0.2, 1.0, 0.2, CENTER, TOP}; + for (i = incr; i < maxtime; i += 2 * incr) + plot_text(gc, &tro, i, 1, "%d", i/60); /* Depth markers: every 30 ft or 10 m*/ gc->leftx = 0; gc->rightx = 1.0; |