project: Adjust color rendering to use GdkPaintable
This commit is contained in:
@@ -151,18 +151,18 @@ fill_sources_menu (GcalEventEditorDialog *self)
|
||||
|
||||
for (aux = list; aux != NULL; aux = aux->next)
|
||||
{
|
||||
g_autoptr (GdkPaintable) paintable = NULL;
|
||||
g_autoptr (GMenuItem) item = NULL;
|
||||
g_autoptr (GdkPixbuf) pix = NULL;
|
||||
GcalCalendar *calendar;
|
||||
const GdkRGBA *color;
|
||||
cairo_surface_t *surface;
|
||||
|
||||
calendar = GCAL_CALENDAR (aux->data);
|
||||
|
||||
/* retrieve color */
|
||||
color = gcal_calendar_get_color (calendar);
|
||||
surface = get_circle_surface_from_color (color, 16);
|
||||
pix = gdk_pixbuf_get_from_surface (surface, 0, 0, 16, 16);
|
||||
paintable = get_circle_paintable_from_color (color, 16);
|
||||
pix = paintable_to_pixbuf (paintable);
|
||||
|
||||
/* menu item */
|
||||
item = g_menu_item_new (gcal_calendar_get_name (calendar), "select-calendar");
|
||||
@@ -180,8 +180,6 @@ fill_sources_menu (GcalEventEditorDialog *self)
|
||||
}
|
||||
|
||||
g_menu_append_item (self->sources_menu, item);
|
||||
|
||||
g_clear_pointer (&surface, cairo_surface_destroy);
|
||||
}
|
||||
|
||||
gtk_popover_bind_model (GTK_POPOVER (self->sources_popover), G_MENU_MODEL (self->sources_menu), "edit");
|
||||
@@ -243,19 +241,17 @@ on_calendar_selected_action_cb (GSimpleAction *action,
|
||||
|
||||
if (g_strcmp0 (gcal_calendar_get_id (calendar), uid) == 0)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
g_autoptr (GdkPaintable) paintable = NULL;
|
||||
const GdkRGBA *color;
|
||||
|
||||
/* retrieve color */
|
||||
color = gcal_calendar_get_color (calendar);
|
||||
surface = get_circle_surface_from_color (color, 16);
|
||||
gtk_image_set_from_surface (GTK_IMAGE (self->source_image), surface);
|
||||
paintable = get_circle_paintable_from_color (color, 16);
|
||||
gtk_image_set_from_paintable (GTK_IMAGE (self->source_image), paintable);
|
||||
|
||||
self->selected_calendar = calendar;
|
||||
|
||||
gtk_label_set_label (GTK_LABEL (self->subtitle_label), gcal_calendar_get_name (calendar));
|
||||
|
||||
g_clear_pointer (&surface, cairo_surface_destroy);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -597,10 +593,10 @@ gcal_event_editor_dialog_set_event (GcalEventEditorDialog *self,
|
||||
GcalEvent *event,
|
||||
gboolean new_event)
|
||||
{
|
||||
g_autoptr (GdkPaintable) paintable = NULL;
|
||||
g_autoptr (GcalEvent) cloned_event = NULL;
|
||||
GcalEventEditorFlags flags;
|
||||
GcalCalendar *calendar;
|
||||
cairo_surface_t *surface;
|
||||
gint i;
|
||||
|
||||
GCAL_ENTRY;
|
||||
@@ -625,9 +621,8 @@ gcal_event_editor_dialog_set_event (GcalEventEditorDialog *self,
|
||||
fill_sources_menu (self);
|
||||
|
||||
/* dialog titlebar's title & subtitle */
|
||||
surface = get_circle_surface_from_color (gcal_event_get_color (cloned_event), 10);
|
||||
gtk_image_set_from_surface (GTK_IMAGE (self->source_image), surface);
|
||||
g_clear_pointer (&surface, cairo_surface_destroy);
|
||||
paintable = get_circle_paintable_from_color (gcal_event_get_color (cloned_event), 10);
|
||||
gtk_image_set_from_paintable (GTK_IMAGE (self->source_image), paintable);
|
||||
|
||||
g_clear_pointer (&self->event_title_binding, g_binding_unbind);
|
||||
self->event_title_binding = g_object_bind_property (cloned_event,
|
||||
|
||||
@@ -59,9 +59,9 @@ static GParamSpec *properties [N_PROPS];
|
||||
static GtkWidget*
|
||||
make_calendar_row (GcalCalendar *calendar)
|
||||
{
|
||||
g_autoptr (GdkPaintable) paintable = NULL;
|
||||
GtkWidget *label, *icon, *checkbox, *box, *row;
|
||||
GtkStyleContext *context;
|
||||
cairo_surface_t *surface;
|
||||
const GdkRGBA *color;
|
||||
|
||||
row = gtk_list_box_row_new ();
|
||||
@@ -78,8 +78,8 @@ make_calendar_row (GcalCalendar *calendar)
|
||||
|
||||
/* source color icon */
|
||||
color = gcal_calendar_get_color (calendar);
|
||||
surface = get_circle_surface_from_color (color, 16);
|
||||
icon = gtk_image_new_from_surface (surface);
|
||||
paintable = get_circle_paintable_from_color (color, 16);
|
||||
icon = gtk_image_new_from_paintable (paintable);
|
||||
|
||||
gtk_style_context_add_class (gtk_widget_get_style_context (icon), "calendar-color-image");
|
||||
|
||||
@@ -106,8 +106,6 @@ make_calendar_row (GcalCalendar *calendar)
|
||||
|
||||
gtk_widget_show_all (row);
|
||||
|
||||
g_clear_pointer (&surface, cairo_surface_destroy);
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ static GtkWidget*
|
||||
create_calendar_row (GcalManager *manager,
|
||||
GcalCalendar *calendar)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
g_autoptr (GdkPaintable) paintable = NULL;
|
||||
const GdkRGBA *color;
|
||||
GtkWidget *row, *box, *icon, *label, *selected_icon;
|
||||
gboolean read_only;
|
||||
@@ -85,8 +85,8 @@ create_calendar_row (GcalManager *manager,
|
||||
|
||||
/* The icon with the source color */
|
||||
color = gcal_calendar_get_color (calendar);
|
||||
surface = get_circle_surface_from_color (color, 16);
|
||||
icon = gtk_image_new_from_surface (surface);
|
||||
paintable = get_circle_paintable_from_color (color, 16);
|
||||
icon = gtk_image_new_from_paintable (paintable);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (box), icon);
|
||||
|
||||
@@ -135,7 +135,6 @@ create_calendar_row (GcalManager *manager,
|
||||
gtk_widget_show (box);
|
||||
gtk_widget_show (row);
|
||||
|
||||
g_clear_pointer (&surface, cairo_surface_destroy);
|
||||
g_free (parent_name);
|
||||
g_free (tooltip);
|
||||
|
||||
@@ -176,7 +175,7 @@ static void
|
||||
select_row (GcalQuickAddPopover *self,
|
||||
GtkListBoxRow *row)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
g_autoptr (GdkPaintable) paintable = NULL;
|
||||
const GdkRGBA *color;
|
||||
GcalCalendar *calendar;
|
||||
GtkWidget *icon;
|
||||
@@ -200,8 +199,8 @@ select_row (GcalQuickAddPopover *self,
|
||||
gtk_label_set_label (GTK_LABEL (self->calendar_name_label), gcal_calendar_get_name (calendar));
|
||||
|
||||
color = gcal_calendar_get_color (calendar);
|
||||
surface = get_circle_surface_from_color (color, 16);
|
||||
gtk_image_set_from_surface (GTK_IMAGE (self->color_image), surface);
|
||||
paintable = get_circle_paintable_from_color (color, 16);
|
||||
gtk_image_set_from_paintable (GTK_IMAGE (self->color_image), paintable);
|
||||
|
||||
/* Return to the events page */
|
||||
gtk_stack_set_visible_child_name (GTK_STACK (self->stack), "events");
|
||||
@@ -209,8 +208,6 @@ select_row (GcalQuickAddPopover *self,
|
||||
/* Focus back the event Entry */
|
||||
if (gtk_widget_get_visible (GTK_WIDGET (self)))
|
||||
gtk_entry_grab_focus_without_selecting (GTK_ENTRY (self->summary_entry));
|
||||
|
||||
g_clear_pointer (&surface, cairo_surface_destroy);
|
||||
}
|
||||
|
||||
static gint
|
||||
@@ -536,7 +533,7 @@ on_calendar_changed (GcalManager *manager,
|
||||
GcalCalendar *calendar,
|
||||
GcalQuickAddPopover *self)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
g_autoptr (GdkPaintable) paintable = NULL;
|
||||
const GdkRGBA *color;
|
||||
GtkWidget *row, *color_icon, *name_label;
|
||||
gboolean read_only;
|
||||
@@ -567,10 +564,8 @@ on_calendar_changed (GcalManager *manager,
|
||||
|
||||
/* Setup the source color, in case it changed */
|
||||
color = gcal_calendar_get_color (calendar);
|
||||
surface = get_circle_surface_from_color (color, 16);
|
||||
gtk_image_set_from_surface (GTK_IMAGE (color_icon), surface);
|
||||
|
||||
g_clear_pointer (&surface, cairo_surface_destroy);
|
||||
paintable = get_circle_paintable_from_color (color, 16);
|
||||
gtk_image_set_from_paintable (GTK_IMAGE (color_icon), paintable);
|
||||
|
||||
/* Also setup the row name, in case we just changed the source name */
|
||||
gtk_label_set_text (GTK_LABEL (name_label), gcal_calendar_get_name (calendar));
|
||||
|
||||
@@ -109,21 +109,21 @@ static GtkWidget*
|
||||
create_calendar_row (GcalManager *manager,
|
||||
GcalCalendar *calendar)
|
||||
{
|
||||
g_autoptr (GdkPaintable) paintable = NULL;
|
||||
g_autofree gchar *parent_name = NULL;
|
||||
cairo_surface_t *surface;
|
||||
const GdkRGBA *color;
|
||||
GtkWidget *icon;
|
||||
GtkWidget *row;
|
||||
|
||||
color = gcal_calendar_get_color (calendar);
|
||||
surface = get_circle_surface_from_color (color, 16);
|
||||
paintable = get_circle_paintable_from_color (color, 16);
|
||||
get_source_parent_name_color (manager,
|
||||
gcal_calendar_get_source (calendar),
|
||||
&parent_name,
|
||||
NULL);
|
||||
|
||||
/* The icon with the source color */
|
||||
icon = gtk_image_new_from_surface (surface);
|
||||
icon = gtk_image_new_from_paintable (paintable);
|
||||
gtk_style_context_add_class (gtk_widget_get_style_context (icon), "calendar-color-image");
|
||||
gtk_widget_show (icon);
|
||||
|
||||
@@ -141,8 +141,6 @@ create_calendar_row (GcalManager *manager,
|
||||
g_object_set_data_full (G_OBJECT (row), "calendar", g_object_ref (calendar), g_object_unref);
|
||||
g_object_set_data (G_OBJECT (row), "color-icon", icon);
|
||||
|
||||
g_clear_pointer (&surface, cairo_surface_destroy);
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
@@ -175,7 +173,7 @@ static void
|
||||
select_row (GcalImportDialog *self,
|
||||
GtkListBoxRow *row)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
g_autoptr (GdkPaintable) paintable = NULL;
|
||||
const GdkRGBA *color;
|
||||
GcalCalendar *calendar;
|
||||
|
||||
@@ -187,10 +185,8 @@ select_row (GcalImportDialog *self,
|
||||
gtk_label_set_label (self->calendar_name_label, gcal_calendar_get_name (calendar));
|
||||
|
||||
color = gcal_calendar_get_color (calendar);
|
||||
surface = get_circle_surface_from_color (color, 16);
|
||||
gtk_image_set_from_surface (self->calendar_color_image, surface);
|
||||
|
||||
g_clear_pointer (&surface, cairo_surface_destroy);
|
||||
paintable = get_circle_paintable_from_color (color, 16);
|
||||
gtk_image_set_from_paintable (self->calendar_color_image, paintable);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -449,7 +445,7 @@ on_manager_calendar_changed_cb (GcalManager *manager,
|
||||
GcalCalendar *calendar,
|
||||
GcalImportDialog *self)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
g_autoptr (GdkPaintable) paintable = NULL;
|
||||
const GdkRGBA *color;
|
||||
GtkWidget *row, *color_icon;
|
||||
gboolean read_only;
|
||||
@@ -475,13 +471,11 @@ on_manager_calendar_changed_cb (GcalManager *manager,
|
||||
|
||||
/* Setup the source color, in case it changed */
|
||||
color = gcal_calendar_get_color (calendar);
|
||||
surface = get_circle_surface_from_color (color, 16);
|
||||
paintable = get_circle_paintable_from_color (color, 16);
|
||||
color_icon = g_object_get_data (G_OBJECT (row), "color-icon");
|
||||
gtk_image_set_from_surface (GTK_IMAGE (color_icon), surface);
|
||||
gtk_image_set_from_paintable (GTK_IMAGE (color_icon), paintable);
|
||||
|
||||
gtk_list_box_invalidate_sort (GTK_LIST_BOX (self->calendars_listbox));
|
||||
|
||||
g_clear_pointer (&surface, cairo_surface_destroy);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user