From 865d1a0101a055d74a12e10fec6060a3106e29f6 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 7 Nov 2010 09:44:57 +0100 Subject: [PATCH] Added divisions on GtkCalExViewDay. --- src/gtkcalex.c | 4 +++ src/gtkcalex.h | 4 +++ src/gtkcalexviewday.c | 84 +++++++++++++++++++++++++++++++++---------- src/gtkcalexviewday.h | 3 ++ 4 files changed, 77 insertions(+), 18 deletions(-) diff --git a/src/gtkcalex.c b/src/gtkcalex.c index cd7d95c..1bfec69 100644 --- a/src/gtkcalex.c +++ b/src/gtkcalex.c @@ -80,6 +80,10 @@ struct _GtkCalExPrivate GDate *date; GObject *view; + + GList *calendars; + GList *categories; + GList *events; }; G_DEFINE_TYPE (GtkCalEx, gtk_calex, GTK_TYPE_BIN) diff --git a/src/gtkcalex.h b/src/gtkcalex.h index 8f4acaf..ba6e3f7 100644 --- a/src/gtkcalex.h +++ b/src/gtkcalex.h @@ -73,9 +73,13 @@ void gtk_calex_set_date (GtkCalEx *calex, GDate *date); void gtk_calex_add_calendar (GtkCalEx *calex, GtkCalExCalendar *calendar); void gtk_calex_remove_calendar (GtkCalEx *calex, GtkCalExCalendar *calendar); +GList *gtk_calex_get_calendars (GtkCalEx *calex); + void gtk_calex_add_category (GtkCalEx *calex, GtkCalExCategory *category); void gtk_calex_remove_category (GtkCalEx *calex, GtkCalExCategory *category); +GList *gtk_calex_get_categories (GtkCalEx *calex); + void gtk_calex_add_event (GtkCalEx *calex, GtkCalExEvent *event); void gtk_calex_remove_event (GtkCalEx *calex, GtkCalExEvent *event); diff --git a/src/gtkcalexviewday.c b/src/gtkcalexviewday.c index dc97185..f96f3f6 100644 --- a/src/gtkcalexviewday.c +++ b/src/gtkcalexviewday.c @@ -50,6 +50,8 @@ struct _GtkCalExViewDayPrivate GooCanvasItem *goo_canvas_root; GDate *date; gboolean working_week; + + guint division; }; G_DEFINE_TYPE (GtkCalExViewDay, gtk_calex_view_day, G_TYPE_OBJECT) @@ -69,6 +71,8 @@ static void gtk_calex_view_day_init (GtkCalExViewDay *gtk_calex_view_day) { GtkCalExViewDayPrivate *priv = GTK_CALEX_VIEW_DAY_GET_PRIVATE (gtk_calex_view_day); + + priv->division = 30; } static void @@ -125,42 +129,86 @@ GtkCalExViewDay return gtk_calex_view_day; } +void +gtk_calex_view_day_set_division (GtkCalExViewDay *view_day, guint division) +{ + g_return_if_fail (IS_GTK_CALEX_VIEW_DAY (view_day)); + + GtkCalExViewDayPrivate *priv = GTK_CALEX_VIEW_DAY_GET_PRIVATE (view_day); + + priv->division = division; + + gtk_calex_view_day_draw (view_day); +} + +guint +gtk_calex_view_day_get_division (GtkCalExViewDay *view_day) +{ + g_return_if_fail (IS_GTK_CALEX_VIEW_DAY (view_day)); + + GtkCalExViewDayPrivate *priv = GTK_CALEX_VIEW_DAY_GET_PRIVATE (view_day); + + return priv->division; +} + static void gtk_calex_view_day_draw (GtkCalExViewDay *gtk_calex_view_day) { guint hour; + guint division; + guint divisions; + + gdouble y; + g_return_if_fail (IS_GTK_CALEX_VIEW_DAY (gtk_calex_view_day)); GtkCalExViewDayPrivate *priv = GTK_CALEX_VIEW_DAY_GET_PRIVATE (gtk_calex_view_day); + divisions = 60 / priv->division; + y = -20; for (hour = 0; hour < 24; hour++) { - goo_canvas_text_new (priv->goo_canvas_root, g_strdup_printf ("%d", hour), - 0, hour * 40, 50, - GTK_ANCHOR_NORTH_WEST, - "font", "Sans 24", - NULL); - goo_canvas_text_new (priv->goo_canvas_root, "00", - 25, hour * 40, 25, - GTK_ANCHOR_NORTH_WEST, - "font", "Sans 12", - NULL); - goo_canvas_polyline_new_line (priv->goo_canvas_root, 0, hour * 40, 50, hour * 40, + y += 20; + goo_canvas_polyline_new_line (priv->goo_canvas_root, + 0, y, 50, y, "stroke-color", "black", NULL); - goo_canvas_rect_new (priv->goo_canvas_root, 55, hour * 40, 400, 20, + goo_canvas_rect_new (priv->goo_canvas_root, + 55, y, 400, 20, "line-width", 1.0, "stroke-color", "black", "fill-color", "yellow", NULL); - goo_canvas_polyline_new_line (priv->goo_canvas_root, 25, hour * 40 + 20, 50, hour * 40 + 20, - "stroke-color", "black", + goo_canvas_text_new (priv->goo_canvas_root, g_strdup_printf ("%d", hour), + 0, y, 50, + GTK_ANCHOR_NORTH_WEST, + "font", "Sans 24", NULL); - goo_canvas_rect_new (priv->goo_canvas_root, 55, hour * 40 + 20, 400, 20, - "line-width", 1.0, - "stroke-color", "black", - "fill-color", "yellow", + goo_canvas_text_new (priv->goo_canvas_root, "00", + 25, y, 25, + GTK_ANCHOR_NORTH_WEST, + "font", "Sans 12", NULL); + + for (division = 1; division < divisions; division++) + { + y += 20; + goo_canvas_polyline_new_line (priv->goo_canvas_root, + 25, y, 50, y, + "stroke-color", "black", + NULL); + goo_canvas_text_new (priv->goo_canvas_root, g_strdup_printf ("%02d", 60 / divisions * division), + 25, y, 25, + GTK_ANCHOR_NORTH_WEST, + "font", "Sans 12", + NULL); + goo_canvas_rect_new (priv->goo_canvas_root, + 55, y, 400, 20, + "line-width", 1.0, + "stroke-color", "black", + "fill-color", "yellow", + NULL); + } } } diff --git a/src/gtkcalexviewday.h b/src/gtkcalexviewday.h index b8d92f7..7ee2be3 100644 --- a/src/gtkcalexviewday.h +++ b/src/gtkcalexviewday.h @@ -54,6 +54,9 @@ GType gtk_calex_view_day_get_type (void) G_GNUC_CONST; GtkCalExViewDay *gtk_calex_view_day_new (GooCanvasItem *root, GDate *date, gboolean working_week); +void gtk_calex_view_day_set_division (GtkCalExViewDay *view_day, guint division); +guint gtk_calex_view_day_get_division (GtkCalExViewDay *view_day); + G_END_DECLS -- 2.49.0