week-header: created the basic skeleton of the week-header
Created the .h, .c and .ui file of week header. Also made changes in the Makefile.am for it to get built.
This commit is contained in:
committed by
Georges Basile Stavracas Neto
parent
3656c781da
commit
69cade3d77
@@ -67,6 +67,8 @@ gnome_calendar_SOURCES = \
|
||||
gcal-utils.h \
|
||||
gcal-view.c \
|
||||
gcal-view.h \
|
||||
views/gcal-week-header.c \
|
||||
views/gcal-week-header.h \
|
||||
views/gcal-week-view.c \
|
||||
views/gcal-week-view.h \
|
||||
gcal-window.h \
|
||||
|
||||
@@ -0,0 +1,293 @@
|
||||
/* gcal-week-header.c
|
||||
*
|
||||
* Copyright (C) 2016 Vamsi Krishna Gollapudi <pandu.sonu@yahoo.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "gcal-week-header.h"
|
||||
#include "gcal-week-view.h"
|
||||
#include "gcal-utils.h"
|
||||
#include "gcal-view.h"
|
||||
#include "gcal-event-widget.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#define ALL_DAY_CELLS_HEIGHT 40
|
||||
|
||||
struct _GcalWeekHeader
|
||||
{
|
||||
GtkScrolledWindow parent;
|
||||
|
||||
GtkWidget *grid;
|
||||
|
||||
GcalManager *manager;
|
||||
|
||||
gint first_weekday;
|
||||
|
||||
gboolean use_24h_format;
|
||||
|
||||
icaltimetype *current_date;
|
||||
};
|
||||
|
||||
static void gcal_week_header_finalize (GObject *object);
|
||||
|
||||
static void gcal_week_header_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *psec);
|
||||
|
||||
static void gcal_week_header_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
|
||||
static gboolean gcal_week_header_draw (GcalWeekHeader *self,
|
||||
cairo_t *cr,
|
||||
GtkWidget *widget);
|
||||
|
||||
G_DEFINE_TYPE (GcalWeekHeader, gcal_week_header, GTK_TYPE_SCROLLED_WINDOW);
|
||||
|
||||
static void
|
||||
gcal_week_header_finalize (GObject *object)
|
||||
{
|
||||
GcalWeekHeader *self = GCAL_WEEK_HEADER (object);
|
||||
|
||||
g_clear_pointer (&self->current_date, g_free);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_week_header_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GcalWeekHeader *self = GCAL_WEEK_HEADER (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_week_header_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GcalWeekHeader *self = GCAL_WEEK_HEADER (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gcal_week_header_draw (GcalWeekHeader *self,
|
||||
cairo_t *cr,
|
||||
GtkWidget *widget)
|
||||
{
|
||||
GtkStyleContext *context;
|
||||
GtkStateFlags state;
|
||||
GdkRGBA color;
|
||||
GtkAllocation *alloc;
|
||||
GtkBorder *padding;
|
||||
|
||||
PangoLayout *layout;
|
||||
PangoFontDescription *bold_font;
|
||||
|
||||
gint i;
|
||||
gint pos_i;
|
||||
gint start_grid_y;
|
||||
gint font_height;
|
||||
gdouble sidebar_width;
|
||||
gdouble cell_width;
|
||||
icaltimetype *start_of_week;
|
||||
gint current_cell;
|
||||
|
||||
cairo_pattern_t *pattern;
|
||||
|
||||
cairo_save(cr);
|
||||
start_grid_y = gcal_week_view_get_start_grid_y (widget);
|
||||
|
||||
/* Fonts and colour selection */
|
||||
context = gtk_widget_get_style_context (widget);
|
||||
state = gtk_widget_get_state_flags (widget);
|
||||
|
||||
gtk_style_context_get_padding (context, state, padding);
|
||||
gtk_widget_get_allocation (widget, alloc);
|
||||
|
||||
pattern = cairo_pattern_create_linear (0, start_grid_y - 18,
|
||||
0, start_grid_y + 6);
|
||||
|
||||
cairo_pattern_add_color_stop_rgba (pattern, 0.0, 0, 0, 0, 0.6);
|
||||
cairo_pattern_add_color_stop_rgba (pattern, 1.0, 0, 0, 0, 0.0);
|
||||
|
||||
cairo_set_source (cr, pattern);
|
||||
cairo_pattern_destroy (pattern);
|
||||
|
||||
cairo_rectangle (cr, 0, start_grid_y, alloc->width, 6);
|
||||
cairo_fill (cr);
|
||||
|
||||
gtk_style_context_get_color (context, state, &color);
|
||||
gdk_cairo_set_source_rgba (cr, &color);
|
||||
|
||||
layout = pango_cairo_create_layout (cr);
|
||||
gtk_style_context_get (context, state, "font", &bold_font, NULL);
|
||||
pango_font_description_set_weight (bold_font, PANGO_WEIGHT_SEMIBOLD);
|
||||
pango_layout_set_font_description (layout, bold_font);
|
||||
|
||||
start_of_week = gcal_week_view_get_initial_date (GCAL_VIEW (widget));
|
||||
current_cell = icaltime_day_of_week (*(self->current_date)) - 1;
|
||||
current_cell = (7 + current_cell - self->first_weekday) % 7;
|
||||
|
||||
sidebar_width = gcal_week_view_get_sidebar_width (widget);
|
||||
cell_width = (alloc->width - sidebar_width) / 7;
|
||||
pango_layout_get_pixel_size (layout, NULL, &font_height);
|
||||
|
||||
gtk_style_context_save (context);
|
||||
gtk_style_context_add_class (context, "current");
|
||||
gtk_render_background (context, cr,
|
||||
cell_width * current_cell + sidebar_width,
|
||||
font_height + padding->bottom,
|
||||
cell_width,
|
||||
ALL_DAY_CELLS_HEIGHT);
|
||||
gtk_style_context_remove_class (context, "current");
|
||||
gtk_style_context_restore (context);
|
||||
|
||||
for (i = 0; i < 7; i++)
|
||||
{
|
||||
gchar *weekday_header;
|
||||
gchar *weekday_abv;
|
||||
gint n_day;
|
||||
|
||||
n_day = start_of_week->day + i;
|
||||
if (n_day > icaltime_days_in_month (start_of_week->month,
|
||||
start_of_week->year))
|
||||
{
|
||||
n_day = n_day - icaltime_days_in_month (start_of_week->month,
|
||||
start_of_week->year);
|
||||
}
|
||||
|
||||
/* Draw the week days with dates */
|
||||
weekday_abv = gcal_get_weekday ((i + self->first_weekday) % 7);
|
||||
weekday_header = g_strdup_printf ("%s %d", weekday_abv, n_day);
|
||||
|
||||
pango_layout_set_text (layout, weekday_header, -1);
|
||||
cairo_move_to (cr,
|
||||
padding->left + cell_width * i + sidebar_width,
|
||||
0.0);
|
||||
pango_cairo_show_layout (cr, layout);
|
||||
|
||||
/* Draws the lines after each day of the week */
|
||||
cairo_save (cr);
|
||||
cairo_move_to (cr,
|
||||
cell_width * i + sidebar_width + 0.3,
|
||||
font_height + padding->bottom);
|
||||
cairo_rel_line_to (cr, 0.0, ALL_DAY_CELLS_HEIGHT);
|
||||
cairo_stroke (cr);
|
||||
cairo_restore (cr);
|
||||
|
||||
g_free (weekday_header);
|
||||
}
|
||||
|
||||
gtk_style_context_get_color (context,
|
||||
state | GTK_STATE_FLAG_INSENSITIVE,
|
||||
&color);
|
||||
gdk_cairo_set_source_rgba (cr, &color);
|
||||
pos_i = font_height + padding->bottom;
|
||||
cairo_move_to (cr, sidebar_width, pos_i + 0.3);
|
||||
cairo_rel_line_to (cr, alloc->width - sidebar_width, 0);
|
||||
|
||||
cairo_stroke (cr);
|
||||
|
||||
cairo_restore (cr);
|
||||
|
||||
g_free (start_of_week);
|
||||
pango_font_description_free (bold_font);
|
||||
g_object_unref (layout);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_week_header_class_init (GcalWeekHeaderClass *kclass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (kclass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (kclass);
|
||||
|
||||
object_class->finalize = gcal_week_header_finalize;
|
||||
object_class->get_property = gcal_week_header_get_property;
|
||||
object_class->set_property = gcal_week_header_set_property;
|
||||
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/week-header.ui");
|
||||
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, grid);
|
||||
|
||||
gtk_widget_class_bind_template_callback (widget_class, gcal_week_header_draw);
|
||||
|
||||
gtk_widget_class_set_css_name (widget_class, "calendar-view");
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_week_header_init (GcalWeekHeader *self)
|
||||
{
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
/* Public API */
|
||||
void
|
||||
gcal_week_header_set_manager (GcalWeekHeader *self,
|
||||
GcalManager *manager)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_WEEK_HEADER (self));
|
||||
|
||||
self->manager = manager;
|
||||
}
|
||||
|
||||
void
|
||||
gcal_week_header_set_first_weekday (GcalWeekHeader *self,
|
||||
gint nr_day)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_WEEK_HEADER (self));
|
||||
|
||||
self->first_weekday = nr_day;
|
||||
}
|
||||
|
||||
void
|
||||
gcal_week_header_set_use_24h_format (GcalWeekHeader *self,
|
||||
gboolean use_24h_format)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_WEEK_HEADER (self));
|
||||
|
||||
self->use_24h_format = use_24h_format;
|
||||
}
|
||||
|
||||
void
|
||||
gcal_week_header_set_current_date (GcalWeekHeader *self,
|
||||
icaltimetype *current_date)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_WEEK_HEADER (self));
|
||||
|
||||
self->current_date = current_date;
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/* gcal-week-header.h
|
||||
*
|
||||
* Copyright (C) 2016 Vamsi Krishna Gollapudi <pandu.sonu@yahoo.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GCAL_WEEK_HEADER_H
|
||||
#define GCAL_WEEK_HEADER_H
|
||||
|
||||
#include "gcal-manager.h"
|
||||
#include "gcal-event-widget.h"
|
||||
#include "gcal-subscriber-view.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GCAL_TYPE_WEEK_HEADER (gcal_week_header_get_type())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (GcalWeekHeader, gcal_week_header, GCAL, WEEK_HEADER, GtkScrolledWindow)
|
||||
|
||||
void gcal_week_header_set_manager (GcalWeekHeader *self,
|
||||
GcalManager *manager);
|
||||
void gcal_week_header_set_first_weekday (GcalWeekHeader *self,
|
||||
gint nr_day);
|
||||
void gcal_week_header_set_use_24h_format (GcalWeekHeader *self,
|
||||
gboolean use_24h_format);
|
||||
void gcal_week_header_set_current_date (GcalWeekHeader *self,
|
||||
icaltimetype *current_date);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* GCAL_WEEK_HEADER_H */
|
||||
+14
-19
@@ -22,6 +22,7 @@
|
||||
#include "gcal-utils.h"
|
||||
#include "gcal-view.h"
|
||||
#include "gcal-event-widget.h"
|
||||
#include "gcal-week-header.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
@@ -87,8 +88,6 @@ typedef struct
|
||||
gint clicked_cell;
|
||||
} GcalWeekViewPrivate;
|
||||
|
||||
static gint get_start_grid_y (GtkWidget *widget);
|
||||
|
||||
static void event_opened (GcalEventWidget *event_widget,
|
||||
gpointer user_data);
|
||||
|
||||
@@ -100,8 +99,6 @@ static void draw_header (GcalWeekView *view
|
||||
static void draw_grid_window (GcalWeekView *view,
|
||||
cairo_t *cr);
|
||||
|
||||
static gint get_sidebar_width (GtkWidget *widget);
|
||||
|
||||
static void gcal_week_view_constructed (GObject *object);
|
||||
|
||||
static void gcal_week_view_finalize (GObject *object);
|
||||
@@ -149,8 +146,6 @@ static void gcal_week_view_forall (GtkContainer *cont
|
||||
static void gcal_week_view_scroll_value_changed (GtkAdjustment *adjusment,
|
||||
gpointer user_data);
|
||||
|
||||
static icaltimetype* gcal_week_view_get_initial_date (GcalView *view);
|
||||
|
||||
static icaltimetype* gcal_week_view_get_final_date (GcalView *view);
|
||||
|
||||
static GtkWidget* gcal_week_view_get_by_uuid (GcalSubscriberView *view,
|
||||
@@ -163,7 +158,7 @@ G_DEFINE_TYPE_WITH_CODE (GcalWeekView, gcal_week_view, GCAL_TYPE_SUBSCRIBER_VIEW
|
||||
G_IMPLEMENT_INTERFACE (GCAL_TYPE_VIEW, gcal_view_interface_init));
|
||||
|
||||
/**
|
||||
* get_start_grid_y:
|
||||
* gcal_week_view_get_start_grid_y:
|
||||
*
|
||||
* In GcalMonthView this method returns the height of the headers of the view
|
||||
* and the grid. Here this points just the place where the grid_window hides
|
||||
@@ -173,8 +168,8 @@ G_DEFINE_TYPE_WITH_CODE (GcalWeekView, gcal_week_view, GCAL_TYPE_SUBSCRIBER_VIEW
|
||||
* - The grid header dislaying weekdays
|
||||
* - The cell containing all-day events.
|
||||
*/
|
||||
static gint
|
||||
get_start_grid_y (GtkWidget *widget)
|
||||
gint
|
||||
gcal_week_view_get_start_grid_y (GtkWidget *widget)
|
||||
{
|
||||
GtkStyleContext *context;
|
||||
GtkStateFlags flags;
|
||||
@@ -250,7 +245,7 @@ draw_header (GcalWeekView *view,
|
||||
widget = GTK_WIDGET (view);
|
||||
|
||||
cairo_save (cr);
|
||||
start_grid_y = get_start_grid_y (widget);
|
||||
start_grid_y = gcal_week_view_get_start_grid_y (widget);
|
||||
context = gtk_widget_get_style_context (widget);
|
||||
state = gtk_widget_get_state_flags (widget);
|
||||
|
||||
@@ -280,7 +275,7 @@ draw_header (GcalWeekView *view,
|
||||
current_cell = icaltime_day_of_week (*(priv->date)) - 1;
|
||||
current_cell = (7 + current_cell - priv->first_weekday) % 7;
|
||||
|
||||
sidebar_width = get_sidebar_width (widget);
|
||||
sidebar_width = gcal_week_view_get_sidebar_width (widget);
|
||||
cell_width = (alloc->width - sidebar_width) / 7;
|
||||
pango_layout_get_pixel_size (layout, NULL, &font_height);
|
||||
|
||||
@@ -381,7 +376,7 @@ draw_grid_window (GcalWeekView *view,
|
||||
pango_layout_set_font_description (layout, font_desc);
|
||||
gdk_cairo_set_source_rgba (cr, &color);
|
||||
|
||||
sidebar_width = get_sidebar_width (widget);
|
||||
sidebar_width = gcal_week_view_get_sidebar_width (widget);
|
||||
width = gdk_window_get_width (priv->grid_window);
|
||||
height = gdk_window_get_height (priv->grid_window);
|
||||
|
||||
@@ -463,8 +458,8 @@ draw_grid_window (GcalWeekView *view,
|
||||
g_object_unref (layout);
|
||||
}
|
||||
|
||||
static gint
|
||||
get_sidebar_width (GtkWidget *widget)
|
||||
gint
|
||||
gcal_week_view_get_sidebar_width (GtkWidget *widget)
|
||||
{
|
||||
GtkStyleContext *context;
|
||||
GtkBorder padding;
|
||||
@@ -824,7 +819,7 @@ gcal_week_view_size_allocate (GtkWidget *widget,
|
||||
gtk_widget_get_state_flags (widget),
|
||||
&padding);
|
||||
|
||||
start_grid_y = get_start_grid_y (widget);
|
||||
start_grid_y = gcal_week_view_get_start_grid_y (widget);
|
||||
|
||||
gdk_window_move_resize (priv->event_window,
|
||||
allocation->x,
|
||||
@@ -890,7 +885,7 @@ gcal_week_view_size_allocate (GtkWidget *widget,
|
||||
gtk_widget_hide (priv->vscrollbar);
|
||||
}
|
||||
|
||||
sidebar_width = get_sidebar_width (widget);
|
||||
sidebar_width = gcal_week_view_get_sidebar_width (widget);
|
||||
horizontal_block = (allocation->width - sidebar_width) / 7.0;
|
||||
vertical_block = gdk_window_get_height (priv->grid_window) / 24.0;
|
||||
|
||||
@@ -1088,7 +1083,7 @@ gcal_week_view_button_press_event (GtkWidget *widget,
|
||||
|
||||
y = event->y;
|
||||
|
||||
start_grid_y = get_start_grid_y (widget);
|
||||
start_grid_y = gcal_week_view_get_start_grid_y (widget);
|
||||
|
||||
if (y - start_grid_y < 0)
|
||||
{
|
||||
@@ -1110,7 +1105,7 @@ gcal_week_view_button_release_event (GtkWidget *widget,
|
||||
|
||||
y = event->y;
|
||||
|
||||
start_grid_y = get_start_grid_y (widget);
|
||||
start_grid_y = gcal_week_view_get_start_grid_y (widget);
|
||||
|
||||
if (y - start_grid_y < 0)
|
||||
{
|
||||
@@ -1286,7 +1281,7 @@ gcal_week_view_scroll_value_changed (GtkAdjustment *adjusment,
|
||||
* Return value: the first day of the week
|
||||
* Returns: (transfer full): Release with g_free()
|
||||
**/
|
||||
static icaltimetype*
|
||||
icaltimetype*
|
||||
gcal_week_view_get_initial_date (GcalView *view)
|
||||
{
|
||||
GcalWeekViewPrivate *priv;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#define __GCAL_WEEK_VIEW_H__
|
||||
|
||||
#include "gcal-manager.h"
|
||||
|
||||
#include "gcal-view.h"
|
||||
#include "gcal-subscriber-view.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
@@ -54,6 +54,9 @@ void gcal_week_view_set_first_weekday (GcalWeekView *view,
|
||||
gint day_nr);
|
||||
void gcal_week_view_set_use_24h_format (GcalWeekView *view,
|
||||
gboolean use_24h);
|
||||
gint gcal_week_view_get_sidebar_width (GtkWidget *widget);
|
||||
icaltimetype* gcal_week_view_get_initial_date (GcalView *view);
|
||||
gint gcal_week_view_get_start_grid_y (GtkWidget *widget);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
Reference in New Issue
Block a user