[gnome-calendar/wip/igaldino/flowbox-year-view] year-view: initial code for new navigator
- From: Isaque Galdino de Araujo <igaldino src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/wip/igaldino/flowbox-year-view] year-view: initial code for new navigator
- Date: Thu, 9 Feb 2017 00:06:24 +0000 (UTC)
commit c1b8c95c509e12ad9b04f49da865397e390b84b3
Author: Isaque Galdino <igaldino gmail com>
Date: Tue Jan 31 21:57:07 2017 -0200
year-view: initial code for new navigator
Year view doesn't use the same look and feel of other Calendar
components.
This patch is the initial work to fix that. It changed navigator to use
GcalDateChooser with GtkFlowbox widget to draw months.
It introduces many changes to GcalDateChooser to support that. Some
styles were also changed.
data/theme/gtk-styles.css | 30 +++++++-------------
data/ui/date-chooser.ui | 12 +++++++-
data/ui/year-view.ui | 26 +++++++++---------
src/gcal-date-chooser.c | 64 ++++++++++++++++++++++++++++++++++++++++++++
src/gcal-date-chooser.h | 5 +++
src/views/gcal-year-view.c | 43 +++++++++++++++++++++++++++++
6 files changed, 147 insertions(+), 33 deletions(-)
---
diff --git a/data/theme/gtk-styles.css b/data/theme/gtk-styles.css
index 45f23a3..b5f5f2f 100644
--- a/data/theme/gtk-styles.css
+++ b/data/theme/gtk-styles.css
@@ -77,37 +77,28 @@ calendar-view .second-view-header {
* Because of year-view widget internals, the color property should be the same
* of .calendar-view.first-view-header selector */
.year-navigator {
- padding: 6px 12px;
- color: @theme_selected_bg_color;
-}
-
-.year-navigator.header {
- color: @theme_selected_bg_color;
- font-weight: bold;
+ margin-right: 6px;
+ margin-left: 6px;
+ margin-bottom: 6px;
+ font-weight: bold;
+ padding: 0;
}
.year-navigator.lines {
- color: alpha(@theme_fg_color, 0.4);
+ color: alpha(@theme_fg_color, 0.6);
}
+.year-navigator.week-numbers,
.year-navigator.days {
+ color: @insensitive_fg_color;
+ font-size: smaller;
padding: 5px;
- color: @theme_fg_color;
- font-size: 9pt;
}
.year-navigator.sunday {
color: alpha(@theme_fg_color, 0.5);
}
-.year-navigator.week-numbers {
- font-size: 70%;
- font-weight: bold;
- border-radius: 2px;
- background-color: alpha(@theme_fg_color, 0.05);
- color: alpha(@theme_fg_color, 0.4);
-}
-
/* these two are supposed be changed in sync with .calendar-view */
.year-navigator.current {
background-color: black;
@@ -116,7 +107,8 @@ calendar-view .second-view-header {
font-weight: bold;
}
.year-navigator:selected {
- color: @theme_selected_bg_color;
+ color: @theme_selected_fg_color;
+ background-color: @theme_selected_fg_color;
font-weight: bold;
}
diff --git a/data/ui/date-chooser.ui b/data/ui/date-chooser.ui
index db20343..c4c0848 100644
--- a/data/ui/date-chooser.ui
+++ b/data/ui/date-chooser.ui
@@ -37,6 +37,16 @@
</packing>
</child>
<child>
+ <object class="GtkLabel" id="month_label">
+ <property name="visible" bind-source="GcalDateChooser" bind-property="show-month-only"
bind-flags="sync-create"/>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">1</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkGrid" id="grid">
<property name="visible">True</property>
<property name="row-homogeneous">True</property>
@@ -44,7 +54,7 @@
</object>
<packing>
<property name="left-attach">0</property>
- <property name="top-attach">1</property>
+ <property name="top-attach">2</property>
<property name="width">2</property>
</packing>
</child>
diff --git a/data/ui/year-view.ui b/data/ui/year-view.ui
index 5b1ff1b..2a4d4e6 100644
--- a/data/ui/year-view.ui
+++ b/data/ui/year-view.ui
@@ -18,20 +18,20 @@
<property name="shadow_type">none</property>
<property name="vexpand">True</property>
<child>
- <object class="GtkDrawingArea" id="navigator">
+ <object class="GtkBox" id="navigator">
<property name="visible">True</property>
- <property name="hexpand">True</property>
- <property
name="events">GDK_POINTER_MOTION_MASK|GDK_BUTTON_MOTION_MASK|GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK|GDK_STRUCTURE_MASK</property>
- <signal name="draw" handler="draw_navigator" object="GcalYearView" swapped="yes"/>
- <signal name="button-press-event" handler="navigator_button_press_cb" object="GcalYearView"
swapped="yes"/>
- <signal name="button-release-event" handler="navigator_button_release_cb"
object="GcalYearView" swapped="yes"/>
- <signal name="motion-notify-event" handler="navigator_motion_notify_cb"
object="GcalYearView" swapped="yes"/>
- <signal name="drag-motion" handler="navigator_drag_motion_cb" object="GcalYearView"
swapped="yes"/>
- <signal name="drag-drop" handler="navigator_drag_drop_cb" object="GcalYearView"
swapped="yes"/>
- <signal name="drag-leave" handler="navigator_drag_leave_cb" object="GcalYearView"
swapped="yes"/>
- <style>
- <class name="year-navigator"/>
- </style>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkLabel" id="year_label">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkFlowBox" id="flowbox">
+ <property name="visible">True</property>
+ <property name="homogeneous">True</property>
+ </object>
+ </child>
</object>
</child>
</object>
diff --git a/src/gcal-date-chooser.c b/src/gcal-date-chooser.c
index b463d56..ebf6834 100644
--- a/src/gcal-date-chooser.c
+++ b/src/gcal-date-chooser.c
@@ -32,6 +32,7 @@ struct _GcalDateChooser
GtkWidget *month_choice;
GtkWidget *year_choice;
+ GtkWidget *month_label;
GtkWidget *grid;
GtkWidget *day_grid;
@@ -49,6 +50,7 @@ struct _GcalDateChooser
gboolean show_day_names;
gboolean show_week_numbers;
gboolean no_month_change;
+ gboolean show_month_only;
GcalDateChooserDayOptionsCallback day_options_cb;
gpointer day_options_data;
@@ -72,6 +74,7 @@ enum
PROP_SHOW_DAY_NAMES,
PROP_SHOW_WEEK_NUMBERS,
PROP_NO_MONTH_CHANGE,
+ PROP_SHOW_MONTH_ONLY,
NUM_PROPERTIES
};
@@ -237,6 +240,17 @@ calendar_get_month_name (gint i)
}
static void
+calendar_set_month_label (GcalDateChooser *self,
+ gint i)
+{
+ gchar *text;
+
+ text = calendar_get_month_name (i);
+ gtk_label_set_label (GTK_LABEL (self->month_label), text);
+ g_clear_pointer (&text, g_free);
+}
+
+static void
calendar_init_weekday_display (GcalDateChooser *self)
{
gint i;
@@ -364,6 +378,10 @@ calendar_set_property (GObject *obj,
gcal_date_chooser_set_no_month_change (self, g_value_get_boolean (value));
break;
+ case PROP_SHOW_MONTH_ONLY:
+ gcal_date_chooser_set_show_month_only (self, g_value_get_boolean (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
break;
@@ -400,6 +418,10 @@ calendar_get_property (GObject *obj,
g_value_set_boolean (value, self->no_month_change);
break;
+ case PROP_SHOW_MONTH_ONLY:
+ g_value_set_boolean (value, self->show_month_only);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
break;
@@ -528,6 +550,12 @@ gcal_date_chooser_class_init (GcalDateChooserClass *class)
FALSE,
G_PARAM_READWRITE);
+ properties[PROP_SHOW_MONTH_ONLY] = g_param_spec_boolean ("show-month-only",
+ "Show Month Only",
+ "If TRUE, the heading will only display the month
name",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
signals[MONTH_CHANGED] = g_signal_new ("month-changed",
@@ -548,6 +576,7 @@ gcal_date_chooser_class_init (GcalDateChooserClass *class)
gtk_widget_class_bind_template_child (widget_class, GcalDateChooser, month_choice);
gtk_widget_class_bind_template_child (widget_class, GcalDateChooser, year_choice);
+ gtk_widget_class_bind_template_child (widget_class, GcalDateChooser, month_label);
gtk_widget_class_bind_template_child (widget_class, GcalDateChooser, grid);
gtk_widget_class_bind_template_callback (widget_class, multi_choice_changed);
@@ -567,6 +596,7 @@ gcal_date_chooser_init (GcalDateChooser *self)
self->show_day_names = TRUE;
self->show_week_numbers = TRUE;
self->no_month_change = FALSE;
+ self->show_month_only = FALSE;
self->date = g_date_time_new_now_local ();
g_date_time_get_ymd (self->date, &self->this_year, NULL, NULL);
@@ -649,8 +679,17 @@ gcal_date_chooser_init (GcalDateChooser *self)
calendar_compute_days (self);
g_date_time_get_ymd (self->date, &year, &month, NULL);
+
+ if (year == 0)
+ gcal_multi_choice_set_value (GCAL_MULTI_CHOICE (self->year_choice), 1);
gcal_multi_choice_set_value (GCAL_MULTI_CHOICE (self->year_choice), year);
+
+ if (month == 1)
+ gcal_multi_choice_set_value (GCAL_MULTI_CHOICE (self->month_choice), 1);
gcal_multi_choice_set_value (GCAL_MULTI_CHOICE (self->month_choice), month - 1);
+
+ calendar_set_month_label (self, month - 1);
+
calendar_update_selected_day_display (self);
gtk_drag_dest_set (GTK_WIDGET (self), GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_COPY);
@@ -673,6 +712,9 @@ gcal_date_chooser_set_show_heading (GcalDateChooser *self,
self->show_heading = setting;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_HEADING]);
+
+ if (setting == TRUE && self->show_month_only == TRUE)
+ gcal_date_chooser_set_show_month_only (self, FALSE);
}
gboolean
@@ -740,6 +782,27 @@ gcal_date_chooser_get_no_month_change (GcalDateChooser *self)
}
void
+gcal_date_chooser_set_show_month_only (GcalDateChooser *self,
+ gboolean setting)
+{
+ if (self->show_month_only == setting)
+ return;
+
+ self->show_month_only = setting;
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_MONTH_ONLY]);
+
+ if (setting == TRUE && self->show_heading == TRUE)
+ gcal_date_chooser_set_show_heading (self, FALSE);
+}
+
+gboolean
+gcal_date_chooser_get_show_month_only (GcalDateChooser *self)
+{
+ return self->show_month_only;
+}
+
+void
gcal_date_chooser_set_date (GcalDateChooser *self,
GDateTime *date)
{
@@ -757,6 +820,7 @@ gcal_date_chooser_set_date (GcalDateChooser *self,
{
gcal_multi_choice_set_value (GCAL_MULTI_CHOICE (self->year_choice), y2);
gcal_multi_choice_set_value (GCAL_MULTI_CHOICE (self->month_choice), m2 - 1);
+ calendar_set_month_label (self, m2 - 1);
calendar_compute_days (self);
}
diff --git a/src/gcal-date-chooser.h b/src/gcal-date-chooser.h
index cbbdf1d..0d4e253 100644
--- a/src/gcal-date-chooser.h
+++ b/src/gcal-date-chooser.h
@@ -72,6 +72,11 @@ gboolean gcal_date_chooser_get_show_week_numbers (GcalDateChoose
void gcal_date_chooser_set_show_week_numbers (GcalDateChooser *self,
gboolean setting);
+gboolean gcal_date_chooser_get_show_month_only (GcalDateChooser *self);
+
+void gcal_date_chooser_set_show_month_only (GcalDateChooser *self,
+ gboolean setting);
+
G_END_DECLS
#endif /* __GCAL_DATE_CHOOSER_H__ */
diff --git a/src/views/gcal-year-view.c b/src/views/gcal-year-view.c
index 84b59a6..c8edbe6 100644
--- a/src/views/gcal-year-view.c
+++ b/src/views/gcal-year-view.c
@@ -20,6 +20,7 @@
#include "gcal-year-view.h"
#include "gcal-view.h"
#include "gcal-utils.h"
+#include "gcal-date-chooser.h"
#include <glib/gi18n.h>
#include <math.h>
@@ -50,6 +51,8 @@ struct _GcalYearView
/* composite, GtkBuilder's widgets */
GtkWidget *navigator;
+ GtkWidget *year_label;
+ GtkWidget *flowbox;
GtkWidget *sidebar;
GtkWidget *events_sidebar;
GtkWidget *navigator_stack;
@@ -165,7 +168,12 @@ static void
update_date (GcalYearView *year_view,
icaltimetype *new_date)
{
+ gchar *year_str = NULL;
gboolean needs_reset = FALSE;
+ GtkFlowBoxChild *month_box = NULL;
+ GtkWidget *month = NULL;
+ GDateTime *date_for_month = NULL;
+
if (year_view->date != NULL && icaltime_compare_date (year_view->date, new_date) &&
year_view->start_selected_date->day != 0)
needs_reset = TRUE;
@@ -177,6 +185,23 @@ update_date (GcalYearView *year_view,
year_view->last_week_of_year = get_last_week_of_year_dmy (year_view->first_weekday,
31, G_DATE_DECEMBER, year_view->date->year);
+ year_str = g_strdup_printf ("%d", year_view->date->year);
+ gtk_label_set_text (GTK_LABEL (year_view->year_label), year_str);
+ g_clear_pointer (&year_str, g_free);
+
+ for (int i = 0; i < 12; i++)
+ {
+ date_for_month = g_date_time_new_local (year_view->date->year, i + 1, 1, 0, 0, 0);
+ month_box = gtk_flow_box_get_child_at_index (GTK_FLOW_BOX (year_view->flowbox), i);
+ if (month_box)
+ {
+ month = gtk_bin_get_child (GTK_BIN (month_box));
+ if (month)
+ gcal_date_chooser_set_date (GCAL_DATE_CHOOSER (month), date_for_month);
+ }
+ g_clear_pointer (&date_for_month, g_date_time_unref);
+ }
+
if (needs_reset)
reset_sidebar (year_view);
}
@@ -1880,6 +1905,8 @@ gcal_year_view_class_init (GcalYearViewClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/year-view.ui");
gtk_widget_class_bind_template_child (widget_class, GcalYearView, navigator);
+ gtk_widget_class_bind_template_child (widget_class, GcalYearView, year_label);
+ gtk_widget_class_bind_template_child (widget_class, GcalYearView, flowbox);
gtk_widget_class_bind_template_child (widget_class, GcalYearView, sidebar);
gtk_widget_class_bind_template_child (widget_class, GcalYearView, events_sidebar);
gtk_widget_class_bind_template_child (widget_class, GcalYearView, navigator_stack);
@@ -1906,6 +1933,8 @@ gcal_year_view_class_init (GcalYearViewClass *klass)
static void
gcal_year_view_init (GcalYearView *self)
{
+ GtkWidget *month = NULL;
+
gtk_widget_init_template (GTK_WIDGET (self));
if (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_LTR)
@@ -1926,6 +1955,20 @@ gcal_year_view_init (GcalYearView *self)
g_settings_bind (self->calendar_settings, "show-weekdate", self, "show-week-numbers",
G_SETTINGS_BIND_DEFAULT);
g_signal_connect_swapped (self->calendar_settings, "changed::show-weekdate", G_CALLBACK
(gtk_widget_queue_draw), self);
+ /* Months */
+ for (int i = 0; i < 12; i++)
+ {
+ month = gcal_date_chooser_new ();
+
+ g_settings_bind (self->calendar_settings, "show-weekdate", month, "show-week-numbers",
G_SETTINGS_BIND_DEFAULT);
+ g_signal_connect_swapped (self->calendar_settings, "changed::show-weekdate", G_CALLBACK
(gtk_widget_queue_draw), month);
+ gtk_widget_set_visible (month, TRUE);
+ gcal_date_chooser_set_show_month_only (GCAL_DATE_CHOOSER (month), TRUE);
+ gcal_date_chooser_set_show_day_names (GCAL_DATE_CHOOSER (month), FALSE);
+
+ gtk_container_add (GTK_CONTAINER (self->flowbox), month);
+ }
+
/* layout */
self->number_of_columns = 4;
calculate_sizes (self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]