week-view: Port to GTK4

This commit is contained in:
Georges Basile Stavracas Neto
2022-02-12 13:08:50 -03:00
parent 132d4435f6
commit b31b16da17
15 changed files with 1040 additions and 1354 deletions
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -28,7 +28,7 @@ G_BEGIN_DECLS
#define GCAL_TYPE_WEEK_GRID (gcal_week_grid_get_type()) #define GCAL_TYPE_WEEK_GRID (gcal_week_grid_get_type())
G_DECLARE_FINAL_TYPE (GcalWeekGrid, gcal_week_grid, GCAL, WEEK_GRID, GtkContainer) G_DECLARE_FINAL_TYPE (GcalWeekGrid, gcal_week_grid, GCAL, WEEK_GRID, GtkWidget)
void gcal_week_grid_set_context (GcalWeekGrid *week_grid, void gcal_week_grid_set_context (GcalWeekGrid *week_grid,
GcalContext *context); GcalContext *context);
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -30,7 +30,7 @@ G_BEGIN_DECLS
#define GCAL_TYPE_WEEK_HEADER (gcal_week_header_get_type()) #define GCAL_TYPE_WEEK_HEADER (gcal_week_header_get_type())
G_DECLARE_FINAL_TYPE (GcalWeekHeader, gcal_week_header, GCAL, WEEK_HEADER, GtkGrid) G_DECLARE_FINAL_TYPE (GcalWeekHeader, gcal_week_header, GCAL, WEEK_HEADER, GtkBox)
void gcal_week_header_set_context (GcalWeekHeader *self, void gcal_week_header_set_context (GcalWeekHeader *self,
GcalContext *context); GcalContext *context);
+31 -112
View File
@@ -1,19 +1,17 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<interface> <interface>
<template class="GcalWeekHeader" parent="GtkGrid"> <template class="GcalWeekHeader" parent="GtkBox">
<property name="visible">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="vexpand">False</property> <property name="vexpand">False</property>
<property name="orientation">vertical</property>
<style> <style>
<class name="week-header" /> <class name="week-header" />
</style> </style>
<child> <child>
<object class="GtkBox" id="header_labels_box"> <object class="GtkBox" id="header_labels_box">
<property name="visible">True</property>
<property name="orientation">horizontal</property> <property name="orientation">horizontal</property>
<child> <child>
<object class="GtkLabel" id="month_label"> <object class="GtkLabel" id="month_label">
<property name="visible">True</property>
<property name="label">Month</property> <property name="label">Month</property>
<property name="yalign">0</property> <property name="yalign">0</property>
<style> <style>
@@ -23,7 +21,6 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="week_label"> <object class="GtkLabel" id="week_label">
<property name="visible">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="xalign">0</property> <property name="xalign">0</property>
<property name="yalign">0</property> <property name="yalign">0</property>
@@ -35,7 +32,6 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="year_label"> <object class="GtkLabel" id="year_label">
<property name="visible">True</property>
<property name="label">Year</property> <property name="label">Year</property>
<property name="yalign">0</property> <property name="yalign">0</property>
<style> <style>
@@ -44,159 +40,82 @@
</object> </object>
</child> </child>
</object> </object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child> </child>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">horizontal</property> <property name="orientation">horizontal</property>
<child> <child>
<object class="GtkBox" id="expand_button_box"> <object class="GtkBox" id="expand_button_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">False</property> <property name="hexpand">False</property>
<child> <child>
<object class="GtkButton" id="expand_button"> <object class="GtkButton" id="expand_button">
<property name="can_focus">True</property> <property name="visible">False</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="halign">center</property> <property name="halign">center</property>
<property name="valign">end</property> <property name="valign">end</property>
<property name="margin-bottom">6</property> <property name="margin-bottom">6</property>
<property name="icon_name">go-down-symbolic</property>
<signal name="clicked" handler="on_expand_action_activated" object="GcalWeekHeader" swapped="yes"/> <signal name="clicked" handler="on_expand_action_activated" object="GcalWeekHeader" swapped="yes"/>
<style> <style>
<class name="flat" /> <class name="flat" />
<class name="circular" /> <class name="circular" />
</style> </style>
<child>
<object class="GtkImage" id="expand_button_image">
<property name="visible">True</property>
<property name="icon_name">go-down-symbolic</property>
</object>
</child>
</object> </object>
</child> </child>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkEventBox"> <object class="GtkBox">
<property name="visible">True</property> <property name="orientation">vertical</property>
<signal name="button-press-event" handler="on_button_pressed" object="GcalWeekHeader" swapped="yes" />
<signal name="motion-notify-event" handler="on_motion_notify" object="GcalWeekHeader" swapped="yes" /> <!-- Gestures -->
<signal name="button-release-event" handler="on_button_released" object="GcalWeekHeader" swapped="yes" /> <child>
<object class="GtkGestureClick">
<property name="button">1</property>
<signal name="pressed" handler="on_button_pressed" object="GcalWeekHeader" swapped="no" />
<signal name="released" handler="on_button_released" object="GcalWeekHeader" swapped="no" />
</object>
</child>
<child>
<object class="GtkEventControllerMotion" id="motion_controller">
<property name="propagation-phase">none</property>
<signal name="motion" handler="on_motion_notify" object="GcalWeekHeader" swapped="no" />
</object>
</child>
<child>
<object class="GtkBox" id="weekdays_box">
<property name="homogeneous">True</property>
</object>
</child>
<child> <child>
<object class="GtkScrolledWindow" id="scrolledwindow"> <object class="GtkScrolledWindow" id="scrolledwindow">
<property name="visible">True</property>
<property name="hscrollbar-policy">never</property> <property name="hscrollbar-policy">never</property>
<property name="vscrollbar-policy">never</property> <property name="vscrollbar-policy">never</property>
<property name="propagate-natural-height">True</property> <property name="propagate-natural-height">True</property>
<property name="margin-bottom">2</property> <property name="margin-bottom">2</property>
<child> <child>
<object class="GtkViewport"> <object class="GtkViewport">
<property name="visible">True</property>
<property name="shadow_type">none</property>
<child> <child>
<object class="GtkGrid" id="grid"> <object class="GtkGrid" id="grid">
<property name="visible">True</property>
<property name="column-homogeneous">True</property> <property name="column-homogeneous">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="column-spacing">6</property> <property name="column-spacing">6</property>
<property name="row-spacing">2</property> <property name="row-spacing">2</property>
<property name="margin-start">6</property> <property name="margin-start">6</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">4</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">5</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">6</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object> </object>
</child> </child>
</object> </object>
</child> </child>
</object> </object>
</child> </child>
</object> </object>
</child> </child>
</object> </object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child> </child>
</template> </template>
<object class="GtkSizeGroup" id="sizegroup"> <object class="GtkSizeGroup" id="sizegroup">
+144
View File
@@ -0,0 +1,144 @@
/* gcal-week-hour-bar.c
*
* Copyright 2022 Georges Basile Stavracas Neto <georges.stavracas@gmail.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/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "gcal-week-hour-bar.h"
#include "gcal-week-view-common.h"
#include <glib/gi18n.h>
struct _GcalWeekHourBar
{
GtkBox parent_instance;
GtkLabel *labels[24];
GcalContext *context;
};
G_DEFINE_FINAL_TYPE (GcalWeekHourBar, gcal_week_hour_bar, GTK_TYPE_BOX)
static void
update_labels (GcalWeekHourBar *self)
{
GcalTimeFormat time_format;
gint i;
time_format = gcal_context_get_time_format (self->context);
for (i = 0; i < 24; i++)
{
g_autofree gchar *hours = NULL;
if (time_format == GCAL_TIME_FORMAT_24H)
{
hours = g_strdup_printf ("%02d:00", i);
}
else
{
hours = g_strdup_printf ("%d %s",
i % 12 == 0 ? 12 : i % 12,
i >= 12 ? _("PM") : _("AM"));
}
gtk_label_set_label (self->labels[i], hours);
}
}
static void
gcal_week_hour_bar_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot)
{
GtkStyleContext *context;
GtkWidget *child;
GdkRGBA color;
context = gtk_widget_get_style_context (widget);
gtk_style_context_save (context);
gtk_style_context_add_class (context, "lines");
gtk_style_context_get_color (context, &color);
gtk_style_context_restore (context);
gcal_week_view_common_snapshot_hour_lines (widget,
snapshot,
GTK_ORIENTATION_VERTICAL,
&color,
gtk_widget_get_width (widget),
gtk_widget_get_height (widget));
for (child = gtk_widget_get_first_child (widget);
child;
child = gtk_widget_get_next_sibling (child))
{
gtk_widget_snapshot_child (widget, child, snapshot);
}
}
static void
gcal_week_hour_bar_class_init (GcalWeekHourBarClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
widget_class->snapshot = gcal_week_hour_bar_snapshot;
gtk_widget_class_set_css_name (widget_class, "weekhourbar");
}
static void
gcal_week_hour_bar_init (GcalWeekHourBar *self)
{
gint i;
g_object_set (self,
"orientation", GTK_ORIENTATION_VERTICAL,
"homogeneous", TRUE,
"spacing", 1,
NULL);
for (i = 0; i < 24; i++)
{
GtkWidget *label = gtk_label_new ("");
gtk_widget_add_css_class (label, "line");
gtk_widget_add_css_class (label, "dim-label");
gtk_widget_set_vexpand (label, TRUE);
gtk_label_set_yalign (GTK_LABEL (label), 0.20);
gtk_box_append (GTK_BOX (self), label);
self->labels[i] = GTK_LABEL (label);
}
}
void
gcal_week_hour_bar_set_context (GcalWeekHourBar *self,
GcalContext *context)
{
g_return_if_fail (GCAL_IS_WEEK_HOUR_BAR (self));
self->context = context;
g_signal_connect_object (context,
"notify::time-format",
G_CALLBACK (update_labels),
self,
G_CONNECT_SWAPPED);
update_labels (self);
}
+35
View File
@@ -0,0 +1,35 @@
/* gcal-week-hour-bar.h
*
* Copyright 2022 Georges Basile Stavracas Neto <georges.stavracas@gmail.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/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#pragma once
#include "gcal-context.h"
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GCAL_TYPE_WEEK_HOUR_BAR (gcal_week_hour_bar_get_type())
G_DECLARE_FINAL_TYPE (GcalWeekHourBar, gcal_week_hour_bar, GCAL, WEEK_HOUR_BAR, GtkBox)
void gcal_week_hour_bar_set_context (GcalWeekHourBar *self,
GcalContext *context);
G_END_DECLS
+87
View File
@@ -0,0 +1,87 @@
/* gcal-week-view-common.c
*
* Copyright 2022 Georges Basile Stavracas Neto <georges.stavracas@gmail.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/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "gcal-week-view-common.h"
#include "gcal-utils.h"
void
gcal_week_view_common_snapshot_hour_lines (GtkWidget *widget,
GtkSnapshot *snapshot,
GtkOrientation orientation,
const GdkRGBA *line_color,
gint width,
gint height)
{
GdkRGBA color;
gboolean ltr;
gdouble column_width;
guint i;
ltr = gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL;
color = *line_color;
column_width = width / 7.0;
switch (orientation)
{
case GTK_ORIENTATION_HORIZONTAL:
for (i = 0; i < 7; i++)
{
gdouble x;
if (ltr)
x = column_width * i;
else
x = width - column_width * i;
gtk_snapshot_append_color (snapshot,
&color,
&GRAPHENE_RECT_INIT (x, 0.f, 1.0, height));
}
break;
case GTK_ORIENTATION_VERTICAL:
/* Main lines */
for (i = 1; i < 24; i++)
{
gtk_snapshot_append_color (snapshot,
line_color,
&GRAPHENE_RECT_INIT (0.f,
ALIGNED ((height / 24.0) * i),
width,
1.0));
}
/* In-between lines */
color.alpha /= 2.0;
for (i = 0; i < 24; i++)
{
gdouble half_cell_height = (height / 24.0) / 2.0;
gtk_snapshot_append_color (snapshot,
&color,
&GRAPHENE_RECT_INIT (0.f,
ALIGNED ((height / 24.0) * i + half_cell_height),
width,
1.0));
}
break;
}
}
+34
View File
@@ -0,0 +1,34 @@
/* gcal-week-view-common.h
*
* Copyright 2022 Georges Basile Stavracas Neto <georges.stavracas@gmail.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/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#pragma once
#include <gtk/gtk.h>
G_BEGIN_DECLS
void gcal_week_view_common_snapshot_hour_lines (GtkWidget *widget,
GtkSnapshot *snapshot,
GtkOrientation orientation,
const GdkRGBA *line_color,
gint width,
gint height);
G_END_DECLS
+25 -188
View File
@@ -25,27 +25,21 @@
#include "gcal-utils.h" #include "gcal-utils.h"
#include "gcal-view.h" #include "gcal-view.h"
#include "gcal-week-header.h" #include "gcal-week-header.h"
#include "gcal-week-hour-bar.h"
#include "gcal-week-grid.h" #include "gcal-week-grid.h"
#include "gcal-week-view.h" #include "gcal-week-view.h"
#include <adwaita.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <math.h> #include <math.h>
#define ALL_DAY_CELLS_HEIGHT 40
static const double dashed [] =
{
5.0,
6.0
};
struct _GcalWeekView struct _GcalWeekView
{ {
GtkBox parent; GtkBox parent;
GtkWidget *header; GtkWidget *header;
GtkWidget *hours_bar; GcalWeekHourBar *hours_bar;
GtkWidget *scrolled_window; GtkWidget *scrolled_window;
GtkWidget *week_grid; GtkWidget *week_grid;
@@ -54,6 +48,7 @@ struct _GcalWeekView
GcalContext *context; GcalContext *context;
guint scroll_grid_timeout_id; guint scroll_grid_timeout_id;
gulong stack_page_changed_id;
gint clicked_cell; gint clicked_cell;
}; };
@@ -87,16 +82,16 @@ on_event_activated (GcalWeekView *self,
} }
static void static void
stack_visible_child_changed_cb (GtkStack *stack, stack_visible_child_changed_cb (AdwViewStack *stack,
GParamSpec *pspec, GParamSpec *pspec,
GcalWeekView *self) GcalWeekView *self)
{ {
if (gtk_stack_get_visible_child (stack) != (GtkWidget*) self) if (adw_view_stack_get_visible_child (stack) != (GtkWidget*) self)
return; return;
schedule_position_scroll (self); schedule_position_scroll (self);
g_signal_handlers_disconnect_by_func (stack, stack_visible_child_changed_cb, self); g_clear_signal_handler (&self->stack_page_changed_id, stack);
} }
/* Auxiliary methods */ /* Auxiliary methods */
@@ -115,15 +110,16 @@ update_grid_scroll_position (GcalWeekView *self)
if (!gtk_widget_get_realized (self->scrolled_window) || if (!gtk_widget_get_realized (self->scrolled_window) ||
!gtk_widget_get_mapped (self->scrolled_window)) !gtk_widget_get_mapped (self->scrolled_window))
{ {
GtkWidget *stack; if (self->stack_page_changed_id == 0)
{
GtkWidget *stack = gtk_widget_get_ancestor (GTK_WIDGET (self), ADW_TYPE_VIEW_STACK);
stack = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_STACK); self->stack_page_changed_id = g_signal_connect_object (stack,
"notify::visible-child",
g_signal_connect_object (stack, G_CALLBACK (stack_visible_child_changed_cb),
"notify::visible-child", self,
G_CALLBACK (stack_visible_child_changed_cb), 0);
self, }
0);
self->scroll_grid_timeout_id = 0; self->scroll_grid_timeout_id = 0;
@@ -260,59 +256,6 @@ gcal_view_interface_init (GcalViewInterface *iface)
iface->get_previous_date = gcal_week_view_get_previous_date; iface->get_previous_date = gcal_week_view_get_previous_date;
} }
static void
update_hours_sidebar_size (GcalWeekView *self)
{
GtkStyleContext *context;
GtkStateFlags state;
GtkSizeGroup *sidebar_sizegroup;
GtkWidget *widget;
GtkBorder padding;
PangoLayout *layout;
PangoFontDescription *font_desc;
gint hours_12_width, hours_24_width, sidebar_width;
gint hours_12_height, hours_24_height, cell_height;
widget = GTK_WIDGET (self);
context = gtk_widget_get_style_context (widget);
state = gtk_style_context_get_state (context);
gtk_style_context_save (context);
gtk_style_context_add_class (context, "hours");
gtk_style_context_get (context, state,
"font", &font_desc,
NULL);
gtk_style_context_get_padding (context, state, &padding);
layout = pango_layout_new (gtk_widget_get_pango_context (widget));
pango_layout_set_font_description (layout, font_desc);
pango_layout_set_text (layout, _("00 AM"), -1);
pango_layout_get_pixel_size (layout, &hours_12_width, &hours_12_height);
pango_layout_set_text (layout, _("00:00"), -1);
pango_layout_get_pixel_size (layout, &hours_24_width, &hours_24_height);
sidebar_width = MAX (hours_12_width, hours_24_width) + padding.left + padding.right;
cell_height = MAX (hours_12_height, hours_24_height) + padding.top + padding.bottom + 1;
gtk_style_context_restore (context);
/* Update the size requests */
gtk_widget_set_size_request (self->hours_bar,
sidebar_width,
48 * cell_height);
/* Sync with the week header sidebar */
sidebar_sizegroup = gcal_week_header_get_sidebar_size_group (GCAL_WEEK_HEADER (self->header));
gtk_size_group_add_widget (sidebar_sizegroup, self->hours_bar);
pango_font_description_free (font_desc);
g_object_unref (layout);
}
/* /*
* GcalTimelineSubscriber iface * GcalTimelineSubscriber iface
@@ -386,114 +329,10 @@ gcal_timeline_subscriber_interface_init (GcalTimelineSubscriberInterface *iface)
iface->remove_event = gcal_week_view_remove_event; iface->remove_event = gcal_week_view_remove_event;
} }
static gboolean
gcal_week_view_draw_hours (GcalWeekView *self,
cairo_t *cr,
GtkWidget *widget)
{
GtkStyleContext *context;
GcalTimeFormat time_format;
GtkStateFlags state;
GtkBorder padding;
GdkRGBA color;
gboolean ltr; /*
gint i, width, height; * GObject overrides
gint font_width; */
PangoLayout *layout;
PangoFontDescription *font_desc;
time_format = gcal_context_get_time_format (self->context);
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
ltr = gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL;
gtk_style_context_save (context);
gtk_style_context_add_class (context, "hours");
gtk_style_context_get_color (context, state, &color);
gtk_style_context_get_padding (context, state, &padding);
gtk_style_context_get (context, state, "font", &font_desc, NULL);
layout = pango_cairo_create_layout (cr);
pango_layout_set_font_description (layout, font_desc);
gdk_cairo_set_source_rgba (cr, &color);
/* Gets the size of the widget */
width = gtk_widget_get_allocated_width (widget);
height = gtk_widget_get_allocated_height (widget);
/* Draws the hours in the sidebar */
for (i = 0; i < 24; i++)
{
gchar *hours;
if (time_format == GCAL_TIME_FORMAT_24H)
{
hours = g_strdup_printf ("%02d:00", i);
}
else
{
hours = g_strdup_printf ("%d %s",
i % 12 == 0 ? 12 : i % 12,
i >= 12 ? _("PM") : _("AM"));
}
pango_layout_set_text (layout, hours, -1);
pango_layout_get_pixel_size (layout, &font_width, NULL);
gtk_render_layout (context,
cr,
ltr ? padding.left : width - font_width - padding.right,
(height / 24) * i + padding.top,
layout);
g_free (hours);
}
gtk_style_context_restore (context);
gtk_style_context_save (context);
gtk_style_context_add_class (context, "lines");
gtk_style_context_get_color (context, state, &color);
gdk_cairo_set_source_rgba (cr, &color);
cairo_set_line_width (cr, 0.65);
if (!ltr)
{
cairo_move_to (cr, 0.5, 0);
cairo_rel_line_to (cr, 0, height);
}
/* Draws the horizontal complete lines */
for (i = 1; i < 24; i++)
{
cairo_move_to (cr, 0, (height / 24) * i + 0.4);
cairo_rel_line_to (cr, width, 0);
}
cairo_stroke (cr);
cairo_set_dash (cr, dashed, 2, 0);
/* Draws the horizontal dashed lines */
for (i = 0; i < 24; i++)
{
cairo_move_to (cr, 0, (height / 24) * i + (height / 48) + 0.4);
cairo_rel_line_to (cr, width, 0);
}
cairo_stroke (cr);
gtk_style_context_restore (context);
pango_font_description_free (font_desc);
g_object_unref (layout);
return FALSE;
}
static void static void
gcal_week_view_finalize (GObject *object) gcal_week_view_finalize (GObject *object)
@@ -530,12 +369,7 @@ gcal_week_view_set_property (GObject *object,
gcal_week_grid_set_context (GCAL_WEEK_GRID (self->week_grid), self->context); gcal_week_grid_set_context (GCAL_WEEK_GRID (self->week_grid), self->context);
gcal_week_header_set_context (GCAL_WEEK_HEADER (self->header), self->context); gcal_week_header_set_context (GCAL_WEEK_HEADER (self->header), self->context);
gcal_week_hour_bar_set_context (self->hours_bar, self->context);
g_signal_connect_object (self->context,
"notify::time-format",
G_CALLBACK (gtk_widget_queue_draw),
self->hours_bar,
G_CONNECT_SWAPPED);
break; break;
default: default:
@@ -579,6 +413,7 @@ gcal_week_view_class_init (GcalWeekViewClass *klass)
g_type_ensure (GCAL_TYPE_WEEK_GRID); g_type_ensure (GCAL_TYPE_WEEK_GRID);
g_type_ensure (GCAL_TYPE_WEEK_HEADER); g_type_ensure (GCAL_TYPE_WEEK_HEADER);
g_type_ensure (GCAL_TYPE_WEEK_HOUR_BAR);
object_class->finalize = gcal_week_view_finalize; object_class->finalize = gcal_week_view_finalize;
object_class->set_property = gcal_week_view_set_property; object_class->set_property = gcal_week_view_set_property;
@@ -594,7 +429,6 @@ gcal_week_view_class_init (GcalWeekViewClass *klass)
gtk_widget_class_bind_template_child (widget_class, GcalWeekView, scrolled_window); gtk_widget_class_bind_template_child (widget_class, GcalWeekView, scrolled_window);
gtk_widget_class_bind_template_child (widget_class, GcalWeekView, week_grid); gtk_widget_class_bind_template_child (widget_class, GcalWeekView, week_grid);
gtk_widget_class_bind_template_callback (widget_class, gcal_week_view_draw_hours);
gtk_widget_class_bind_template_callback (widget_class, on_event_activated); gtk_widget_class_bind_template_callback (widget_class, on_event_activated);
gtk_widget_class_set_css_name (widget_class, "calendar-view"); gtk_widget_class_set_css_name (widget_class, "calendar-view");
@@ -603,8 +437,11 @@ gcal_week_view_class_init (GcalWeekViewClass *klass)
static void static void
gcal_week_view_init (GcalWeekView *self) gcal_week_view_init (GcalWeekView *self)
{ {
GtkSizeGroup *size_group;
gtk_widget_init_template (GTK_WIDGET (self)); gtk_widget_init_template (GTK_WIDGET (self));
update_hours_sidebar_size (self); size_group = gcal_week_header_get_sidebar_size_group (GCAL_WEEK_HEADER (self->header));
gtk_size_group_add_widget (size_group, GTK_WIDGET (self->hours_bar));
} }
+1 -9
View File
@@ -1,39 +1,31 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<interface> <interface>
<template class="GcalWeekView" parent="GtkBox"> <template class="GcalWeekView" parent="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<style> <style>
<class name="week-view" /> <class name="week-view" />
</style> </style>
<child> <child>
<object class="GcalWeekHeader" id="header"> <object class="GcalWeekHeader" id="header">
<property name="visible">True</property>
<signal name="event-activated" handler="on_event_activated" object="GcalWeekView" swapped="yes" /> <signal name="event-activated" handler="on_event_activated" object="GcalWeekView" swapped="yes" />
</object> </object>
</child> </child>
<child> <child>
<object class="GtkScrolledWindow" id="scrolled_window"> <object class="GtkScrolledWindow" id="scrolled_window">
<property name="visible">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<child> <child>
<object class="GtkViewport"> <object class="GtkViewport">
<property name="visible">True</property>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">horizontal</property> <property name="orientation">horizontal</property>
<child> <child>
<object class="GtkDrawingArea" id="hours_bar"> <object class="GcalWeekHourBar" id="hours_bar">
<property name="visible">True</property>
<property name="height-request">2568</property> <property name="height-request">2568</property>
<signal name="draw" handler="gcal_week_view_draw_hours" object="GcalWeekView" swapped="yes" />
</object> </object>
</child> </child>
<child> <child>
<object class="GcalWeekGrid" id="week_grid"> <object class="GcalWeekGrid" id="week_grid">
<property name="visible">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<signal name="event-activated" handler="on_event_activated" object="GcalWeekView" swapped="yes" /> <signal name="event-activated" handler="on_event_activated" object="GcalWeekView" swapped="yes" />
+2
View File
@@ -13,6 +13,8 @@ sources += files(
'gcal-view.c', 'gcal-view.c',
'gcal-week-grid.c', 'gcal-week-grid.c',
'gcal-week-header.c', 'gcal-week-header.c',
'gcal-week-hour-bar.c',
'gcal-week-view.c', 'gcal-week-view.c',
'gcal-week-view-common.c',
'gcal-year-view.c', 'gcal-year-view.c',
) )
+7 -26
View File
@@ -386,18 +386,12 @@ label.month-name {
color: alpha(@theme_fg_color, 0.25); color: alpha(@theme_fg_color, 0.25);
} }
.week-header.week-names, .week-header.week-temperature { .week-header.week-temperature {
font-size: 10pt; font-size: 10pt;
font-weight: bold; font-weight: bold;
color: alpha(@theme_fg_color, 0.55); color: alpha(@theme_fg_color, 0.55);
} }
.week-header.week-dates {
font-size: 16pt;
font-weight: bold;
color: alpha(@theme_fg_color, 0.70);
}
.week-header.lines { .week-header.lines {
color: alpha(@theme_fg_color, 0.4); color: alpha(@theme_fg_color, 0.4);
} }
@@ -406,37 +400,24 @@ label.month-name {
color: alpha(@theme_fg_color, 0.6); color: alpha(@theme_fg_color, 0.6);
} }
.week-header .today { weekhourbar > label {
color: @theme_selected_bg_color;
}
.week-view {
padding: 0px;
}
.week-view .hours {
font-size: 10pt; font-size: 10pt;
color: alpha(@theme_fg_color, 0.8); padding: 4px 6px;
padding: 8px 12px;
} }
.week-view .lines { .week-view .lines {
color: alpha(@theme_fg_color, 0.30); color: alpha(@window_fg_color, 0.30);
} }
weekgrid.now-strip { weekgrid > widget.now-strip {
background-color: alpha(@theme_selected_bg_color, 0.8); background-color: alpha(@accent_bg_color, 0.8);
margin: 0 0 0 1px; margin: 0 0 0 1px;
min-height: 2px; min-height: 2px;
} }
weekgrid:selected, weekgrid:selected,
.week-header:selected { .week-header:selected {
background-color: alpha(@theme_selected_bg_color, 0.25); background-color: alpha(@accent_bg_color, 0.25);
}
.week-header:selected {
border: solid 1px alpha(@theme_selected_bg_color, 0.8);
} }
+14 -12
View File
@@ -1112,29 +1112,30 @@ is_workday (guint day)
} }
GList* GList*
filter_event_list_by_uid_and_modtype (GList *widgets, filter_children_by_uid_and_modtype (GtkWidget *widget,
GcalRecurrenceModType mod, GcalRecurrenceModType mod,
const gchar *uid) const gchar *uid)
{ {
GtkWidget *child;
GcalEvent *event; GcalEvent *event;
GList *result; GList *result;
GList *l;
event = NULL; event = NULL;
result = NULL; result = NULL;
/* First pass: find the GcalEvent */ /* First pass: find the GcalEvent */
for (l = widgets; l != NULL; l = l->next) for (child = gtk_widget_get_first_child (widget);
child;
child = gtk_widget_get_next_sibling (child))
{ {
GcalEventWidget *event_widget; GcalEventWidget *event_widget;
GcalEvent *ev; GcalEvent *ev;
event_widget = l->data;
/* Safeguard against stray widgets */ /* Safeguard against stray widgets */
if (!GCAL_IS_EVENT_WIDGET (event_widget)) if (!GCAL_IS_EVENT_WIDGET (child))
continue; continue;
event_widget = GCAL_EVENT_WIDGET (child);
ev = gcal_event_widget_get_event (event_widget); ev = gcal_event_widget_get_event (event_widget);
/* /*
@@ -1161,17 +1162,18 @@ filter_event_list_by_uid_and_modtype (GList *widgets,
id = e_cal_component_get_id (component); id = e_cal_component_get_id (component);
id_prefix = g_strdup_printf ("%s:%s", gcal_calendar_get_id (calendar), e_cal_component_id_get_uid (id)); id_prefix = g_strdup_printf ("%s:%s", gcal_calendar_get_id (calendar), e_cal_component_id_get_uid (id));
for (l = widgets; l != NULL; l = l->next) for (child = gtk_widget_get_first_child (widget);
child;
child = gtk_widget_get_next_sibling (child))
{ {
GcalEventWidget *event_widget; GcalEventWidget *event_widget;
GcalEvent *ev; GcalEvent *ev;
event_widget = l->data;
/* Safeguard against stray widgets */ /* Safeguard against stray widgets */
if (!GCAL_IS_EVENT_WIDGET (event_widget)) if (!GCAL_IS_EVENT_WIDGET (child))
continue; continue;
event_widget = GCAL_EVENT_WIDGET (child);
ev = gcal_event_widget_get_event (event_widget); ev = gcal_event_widget_get_event (event_widget);
if (g_str_equal (gcal_event_get_uid (ev), uid)) if (g_str_equal (gcal_event_get_uid (ev), uid))
+1 -1
View File
@@ -116,7 +116,7 @@ gboolean ask_recurrence_modification_type (GtkWidget
gboolean is_workday (guint day); gboolean is_workday (guint day);
GList* filter_event_list_by_uid_and_modtype (GList *widgets, GList* filter_children_by_uid_and_modtype (GtkWidget *widget,
GcalRecurrenceModType mod, GcalRecurrenceModType mod,
const gchar *uid); const gchar *uid);