From 34682cacbca9cc2232f3d2a404ac05dc35afd08e Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Tue, 21 Apr 2020 07:23:38 +0000 Subject: [PATCH 01/22] Started to work on WeekView based upon GNOME Calendar --- src/WeekView/WeekGrid.vala | 43 ++++++++++++++++++++++++++++++++++++ src/WeekView/WeekHeader.vala | 32 +++++++++++++++++++++++++++ src/WeekView/WeekView.vala | 30 +++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 src/WeekView/WeekGrid.vala create mode 100644 src/WeekView/WeekHeader.vala create mode 100644 src/WeekView/WeekView.vala diff --git a/src/WeekView/WeekGrid.vala b/src/WeekView/WeekGrid.vala new file mode 100644 index 000000000..15e76d92e --- /dev/null +++ b/src/WeekView/WeekGrid.vala @@ -0,0 +1,43 @@ +/*- + * Copyright (c) 2020 elementary, Inc. (https://elementary.io) + * + * 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 . + * + * Authored by: Marco Betschart + */ + +namespace Maya.View { + +/** + * TODO: Documentation + */ +public class WeekGrid : Gtk.Box { + + construct { + visible = true; + orientation = Gtk.Orientation.VERTICAL; + + var header = new WeekHeader (); + header.event_activated.connect (() => { /* TODO */ }); + + var scrolled_window = new Gtk.ScrolledWindow (); + scrolled_window.expand = true; + + var grid = new WeekGrid (); + scrolled_window.add (grid); + + add (header); + add (scrolled_window); + } +} diff --git a/src/WeekView/WeekHeader.vala b/src/WeekView/WeekHeader.vala new file mode 100644 index 000000000..0965daf6a --- /dev/null +++ b/src/WeekView/WeekHeader.vala @@ -0,0 +1,32 @@ +/*- + * Copyright (c) 2020 elementary, Inc. (https://elementary.io) + * + * 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 . + * + * Authored by: Marco Betschart + */ + +namespace Maya.View { + +/** + * TODO: Documentation + */ +public class WeekHeader : Gtk.Grid { + + public signal void event_activated (/* TODO */); + + construct { + /* TODO */ + } +} diff --git a/src/WeekView/WeekView.vala b/src/WeekView/WeekView.vala new file mode 100644 index 000000000..dec61a659 --- /dev/null +++ b/src/WeekView/WeekView.vala @@ -0,0 +1,30 @@ +/*- + * Copyright (c) 2020 elementary, Inc. (https://elementary.io) + * + * 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 . + * + * Authored by: Marco Betschart + */ + +namespace Maya.View { + +/** + * TODO: Documentation + */ +public class WeekView : Gtk.Container { + + construct { + + } +} From b505cd4ec940c1596dbaa332c9b9a51988ef0574 Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Tue, 21 Apr 2020 13:05:07 +0000 Subject: [PATCH 02/22] Sketching WeekView and WeekHeader based on GNOME Calendar --- src/WeekView/WeekGrid.vala | 14 +-------- src/WeekView/WeekHeader.vala | 61 +++++++++++++++++++++++++++++++++++- src/WeekView/WeekView.vala | 21 ++++++++++++- 3 files changed, 81 insertions(+), 15 deletions(-) diff --git a/src/WeekView/WeekGrid.vala b/src/WeekView/WeekGrid.vala index 15e76d92e..1639f50d8 100644 --- a/src/WeekView/WeekGrid.vala +++ b/src/WeekView/WeekGrid.vala @@ -21,23 +21,11 @@ namespace Maya.View { /** * TODO: Documentation + * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-grid.c */ public class WeekGrid : Gtk.Box { construct { - visible = true; - orientation = Gtk.Orientation.VERTICAL; - var header = new WeekHeader (); - header.event_activated.connect (() => { /* TODO */ }); - - var scrolled_window = new Gtk.ScrolledWindow (); - scrolled_window.expand = true; - - var grid = new WeekGrid (); - scrolled_window.add (grid); - - add (header); - add (scrolled_window); } } diff --git a/src/WeekView/WeekHeader.vala b/src/WeekView/WeekHeader.vala index 0965daf6a..6baaf7e09 100644 --- a/src/WeekView/WeekHeader.vala +++ b/src/WeekView/WeekHeader.vala @@ -21,12 +21,71 @@ namespace Maya.View { /** * TODO: Documentation + * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-header.ui */ public class WeekHeader : Gtk.Grid { public signal void event_activated (/* TODO */); + private Gtk.Grid grid; + construct { - /* TODO */ + hexpand = true; + vexpand = false; + get_style_context ().add_class ("week-header"); + + var month_label = new Gtk.Label (_("Month")); + month_label.yalign = 0; + month_label.get_style_context ().add_class ("primary-label"); + + var week_label = new Gtk.Label (_("Week")); + week_label.hexpand = true; + week_label.xalign = week_label.yalign = 0; + week_label.get_style_context ().add_class ("secondary-label"); + + var year_label = new Gtk.Label (_("Year")); + year_label.yalign = 0; + year_label.get_style_context ().add_class ("secondary-label"); + + var header_labels_box = new Gtk.Box (); + header_labels_box.orientation = Gtk.Orientation.horizontal; + + header_labels_box.add (month_label); + header_labels_box.add (week_label); + header_labels_box.add (year_label); + + var expand_button = new Gtk.Button.from_icon_name ("go-down-symbolic"); + expand_button.can_focus = false; + expand_button.hexpand = true; + expand_button.halign = Gtk.Align.CENTER; + expand_button.valign = Gtk.Align.END; + + var expand_button_style_context = expand_button.get_style_context (); + expand_button_style_context.add_class ("flat"); + expand_button_style_context.add_class ("circular"); + + var grid = new Gtk.Grid (); + grid.hexpand = true; + grid.column_homogeneous = true; + grid.column_spacing = 6; + grid.row_spacing = 2; + + grid.add (new Gtk.Box ()); + grid.add (new Gtk.Box ()); + grid.add (new Gtk.Box ()); + grid.add (new Gtk.Box ()); + grid.add (new Gtk.Box ()); + grid.add (new Gtk.Box ()); + grid.add (new Gtk.Box ()); + + var scrolled_window = new Gtk.ScrolledWindow (); + scrolled_window.hscrollbar_policy = scrolled_window.vscrollbar_policy = Gtk.PolicyType.NEVER; + scrolled_window.propagate_natural_height = true; + + scrolled_window.add (grid); + + add (header_labels_box); + add (expand_button); + add (scrolled_window); } } diff --git a/src/WeekView/WeekView.vala b/src/WeekView/WeekView.vala index dec61a659..47c64f3ff 100644 --- a/src/WeekView/WeekView.vala +++ b/src/WeekView/WeekView.vala @@ -21,10 +21,29 @@ namespace Maya.View { /** * TODO: Documentation + * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-view.ui */ -public class WeekView : Gtk.Container { +public class WeekView : Gtk.Box { construct { + visible = true; + orientation = Gtk.Orientation.VERTICAL; + get_style_context ().add_class ("week-view"); + var header = new WeekHeader (); + + var hours_bar = new Gtk.DrawingArea (); + hours_bar.height_request (2568); + + var week_grid = new WeekGrid (); + + var scrolled_window = new Gtk.ScrolledWindow (); + scrolled_window.expand = true; + + scrolled_window.add (hours_bar); + scrolled_window.add (week_grid); + + add (header); + add (scrolled_window); } } From 550655c12f8b11198a35d24c918e384ab411cc5d Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Tue, 21 Apr 2020 13:44:58 +0000 Subject: [PATCH 03/22] Introducing new namespace Maya.Week --- .../WeekGrid.vala => Week/Grid.vala} | 4 ++-- .../WeekHeader.vala => Week/Header.vala} | 4 ++-- src/Week/Util.vala | 24 +++++++++++++++++++ .../WeekView.vala => Week/View.vala} | 4 ++-- 4 files changed, 30 insertions(+), 6 deletions(-) rename src/{WeekView/WeekGrid.vala => Week/Grid.vala} (94%) rename src/{WeekView/WeekHeader.vala => Week/Header.vala} (98%) create mode 100644 src/Week/Util.vala rename src/{WeekView/WeekView.vala => Week/View.vala} (96%) diff --git a/src/WeekView/WeekGrid.vala b/src/Week/Grid.vala similarity index 94% rename from src/WeekView/WeekGrid.vala rename to src/Week/Grid.vala index 1639f50d8..0c176f307 100644 --- a/src/WeekView/WeekGrid.vala +++ b/src/Week/Grid.vala @@ -17,13 +17,13 @@ * Authored by: Marco Betschart */ -namespace Maya.View { +namespace Maya.Week { /** * TODO: Documentation * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-grid.c */ -public class WeekGrid : Gtk.Box { +public class Grid : Gtk.Box { construct { diff --git a/src/WeekView/WeekHeader.vala b/src/Week/Header.vala similarity index 98% rename from src/WeekView/WeekHeader.vala rename to src/Week/Header.vala index 6baaf7e09..a190c3a4b 100644 --- a/src/WeekView/WeekHeader.vala +++ b/src/Week/Header.vala @@ -17,13 +17,13 @@ * Authored by: Marco Betschart */ -namespace Maya.View { +namespace Maya.Week { /** * TODO: Documentation * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-header.ui */ -public class WeekHeader : Gtk.Grid { +public class Header : Gtk.Grid { public signal void event_activated (/* TODO */); diff --git a/src/Week/Util.vala b/src/Week/Util.vala new file mode 100644 index 000000000..eeb02c6e8 --- /dev/null +++ b/src/Week/Util.vala @@ -0,0 +1,24 @@ +/*- + * Copyright (c) 2020 elementary, Inc. (https://elementary.io) + * + * 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 . + * + * Authored by: Marco Betschart + */ + +namespace Maya.Week.Util { + + public const MINUTES_PER_DAY = 1440; + +} diff --git a/src/WeekView/WeekView.vala b/src/Week/View.vala similarity index 96% rename from src/WeekView/WeekView.vala rename to src/Week/View.vala index 47c64f3ff..73d8e9632 100644 --- a/src/WeekView/WeekView.vala +++ b/src/Week/View.vala @@ -17,13 +17,13 @@ * Authored by: Marco Betschart */ -namespace Maya.View { +namespace Maya.Week { /** * TODO: Documentation * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-view.ui */ -public class WeekView : Gtk.Box { +public class View : Gtk.Box { construct { visible = true; From b38beb8a1a894962817b359579b1168a5b08c42d Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Tue, 21 Apr 2020 13:56:36 +0000 Subject: [PATCH 04/22] Fixed compile errors --- src/Week/Grid.vala | 14 +++-- src/Week/Header.vala | 136 +++++++++++++++++++++---------------------- src/Week/Util.vala | 3 +- src/Week/View.vala | 39 +++++++------ src/meson.build | 4 ++ 5 files changed, 102 insertions(+), 94 deletions(-) diff --git a/src/Week/Grid.vala b/src/Week/Grid.vala index 0c176f307..d2564b7b8 100644 --- a/src/Week/Grid.vala +++ b/src/Week/Grid.vala @@ -19,13 +19,15 @@ namespace Maya.Week { -/** - * TODO: Documentation - * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-grid.c - */ -public class Grid : Gtk.Box { + /** + * TODO: Documentation + * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-grid.c + */ + public class Grid : Gtk.Box { - construct { + construct { + } } + } diff --git a/src/Week/Header.vala b/src/Week/Header.vala index a190c3a4b..de56f1259 100644 --- a/src/Week/Header.vala +++ b/src/Week/Header.vala @@ -19,73 +19,73 @@ namespace Maya.Week { -/** - * TODO: Documentation - * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-header.ui - */ -public class Header : Gtk.Grid { - - public signal void event_activated (/* TODO */); - - private Gtk.Grid grid; - - construct { - hexpand = true; - vexpand = false; - get_style_context ().add_class ("week-header"); - - var month_label = new Gtk.Label (_("Month")); - month_label.yalign = 0; - month_label.get_style_context ().add_class ("primary-label"); - - var week_label = new Gtk.Label (_("Week")); - week_label.hexpand = true; - week_label.xalign = week_label.yalign = 0; - week_label.get_style_context ().add_class ("secondary-label"); - - var year_label = new Gtk.Label (_("Year")); - year_label.yalign = 0; - year_label.get_style_context ().add_class ("secondary-label"); - - var header_labels_box = new Gtk.Box (); - header_labels_box.orientation = Gtk.Orientation.horizontal; - - header_labels_box.add (month_label); - header_labels_box.add (week_label); - header_labels_box.add (year_label); - - var expand_button = new Gtk.Button.from_icon_name ("go-down-symbolic"); - expand_button.can_focus = false; - expand_button.hexpand = true; - expand_button.halign = Gtk.Align.CENTER; - expand_button.valign = Gtk.Align.END; - - var expand_button_style_context = expand_button.get_style_context (); - expand_button_style_context.add_class ("flat"); - expand_button_style_context.add_class ("circular"); - - var grid = new Gtk.Grid (); - grid.hexpand = true; - grid.column_homogeneous = true; - grid.column_spacing = 6; - grid.row_spacing = 2; - - grid.add (new Gtk.Box ()); - grid.add (new Gtk.Box ()); - grid.add (new Gtk.Box ()); - grid.add (new Gtk.Box ()); - grid.add (new Gtk.Box ()); - grid.add (new Gtk.Box ()); - grid.add (new Gtk.Box ()); - - var scrolled_window = new Gtk.ScrolledWindow (); - scrolled_window.hscrollbar_policy = scrolled_window.vscrollbar_policy = Gtk.PolicyType.NEVER; - scrolled_window.propagate_natural_height = true; - - scrolled_window.add (grid); - - add (header_labels_box); - add (expand_button); - add (scrolled_window); + /** + * TODO: Documentation + * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-header.ui + */ + public class Header : Gtk.Grid { + + public signal void event_activated (/* TODO */); + + private Gtk.Grid grid; + + construct { + hexpand = true; + vexpand = false; + get_style_context ().add_class ("week-header"); + + var month_label = new Gtk.Label (_("Month")); + month_label.yalign = 0; + month_label.get_style_context ().add_class ("primary-label"); + + var week_label = new Gtk.Label (_("Week")); + week_label.hexpand = true; + week_label.xalign = week_label.yalign = 0; + week_label.get_style_context ().add_class ("secondary-label"); + + var year_label = new Gtk.Label (_("Year")); + year_label.yalign = 0; + year_label.get_style_context ().add_class ("secondary-label"); + + var header_labels_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); + + header_labels_box.add (month_label); + header_labels_box.add (week_label); + header_labels_box.add (year_label); + + var expand_button = new Gtk.Button.from_icon_name ("go-down-symbolic"); + expand_button.can_focus = false; + expand_button.hexpand = true; + expand_button.halign = Gtk.Align.CENTER; + expand_button.valign = Gtk.Align.END; + + var expand_button_style_context = expand_button.get_style_context (); + expand_button_style_context.add_class ("flat"); + expand_button_style_context.add_class ("circular"); + + var grid = new Gtk.Grid (); + grid.hexpand = true; + grid.column_homogeneous = true; + grid.column_spacing = 6; + grid.row_spacing = 2; + + /*grid.add (new Gtk.Box ()); + grid.add (new Gtk.Box ()); + grid.add (new Gtk.Box ()); + grid.add (new Gtk.Box ()); + grid.add (new Gtk.Box ()); + grid.add (new Gtk.Box ()); + grid.add (new Gtk.Box ());*/ + + var scrolled_window = new Gtk.ScrolledWindow (null, null); + scrolled_window.hscrollbar_policy = scrolled_window.vscrollbar_policy = Gtk.PolicyType.NEVER; + scrolled_window.propagate_natural_height = true; + + scrolled_window.add (grid); + + add (header_labels_box); + add (expand_button); + add (scrolled_window); + } } } diff --git a/src/Week/Util.vala b/src/Week/Util.vala index eeb02c6e8..1c5b9a360 100644 --- a/src/Week/Util.vala +++ b/src/Week/Util.vala @@ -19,6 +19,7 @@ namespace Maya.Week.Util { - public const MINUTES_PER_DAY = 1440; + public const int MINUTES_PER_DAY = 1440; + public const int MAX_MINUTES = (7 * MINUTES_PER_DAY); } diff --git a/src/Week/View.vala b/src/Week/View.vala index 73d8e9632..728a14fab 100644 --- a/src/Week/View.vala +++ b/src/Week/View.vala @@ -19,31 +19,32 @@ namespace Maya.Week { -/** - * TODO: Documentation - * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-view.ui - */ -public class View : Gtk.Box { + /** + * TODO: Documentation + * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-view.ui + */ + public class View : Gtk.Box { - construct { - visible = true; - orientation = Gtk.Orientation.VERTICAL; - get_style_context ().add_class ("week-view"); + construct { + visible = true; + orientation = Gtk.Orientation.VERTICAL; + get_style_context ().add_class ("week-view"); - var header = new WeekHeader (); + var header = new Header (); - var hours_bar = new Gtk.DrawingArea (); - hours_bar.height_request (2568); + var hours_bar = new Gtk.DrawingArea (); + //hours_bar.height_request (2568); - var week_grid = new WeekGrid (); + var week_grid = new Grid (); - var scrolled_window = new Gtk.ScrolledWindow (); - scrolled_window.expand = true; + var scrolled_window = new Gtk.ScrolledWindow (null, null); + scrolled_window.expand = true; - scrolled_window.add (hours_bar); - scrolled_window.add (week_grid); + scrolled_window.add (hours_bar); + scrolled_window.add (week_grid); - add (header); - add (scrolled_window); + add (header); + add (scrolled_window); + } } } diff --git a/src/meson.build b/src/meson.build index 7e529db2d..322095fb1 100644 --- a/src/meson.build +++ b/src/meson.build @@ -27,6 +27,10 @@ calendar_files = files( 'SourceDialog/SourceDialog.vala', 'SourceDialog/SourceItem.vala', 'SourceDialog/SourceSelector.vala', + 'Week/Grid.vala', + 'Week/Header.vala', + 'Week/Util.vala', + 'Week/View.vala', 'Widgets/AgendaEventRow.vala', 'Widgets/CalendarButton.vala', 'Widgets/ContractorButtonWithMenu.vala', From ecfd2141bec74a5646d9fbd9f5012a89327a22e8 Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Tue, 21 Apr 2020 14:19:16 +0000 Subject: [PATCH 05/22] Draw for Week.Grid --- src/Week/Grid.vala | 71 ++++++++++++++++++++++++++++++++++++++++++++-- src/Week/Util.vala | 3 ++ 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/Week/Grid.vala b/src/Week/Grid.vala index d2564b7b8..e723e42a4 100644 --- a/src/Week/Grid.vala +++ b/src/Week/Grid.vala @@ -25,9 +25,76 @@ namespace Maya.Week { */ public class Grid : Gtk.Box { - construct { + static const double dashed[] = { 5.0, 6.0 }; + + public override bool draw (Cairo.Context context) { + var style_context = get_style_context (); + var state = get_state_flags (); + var ltr = get_direction () != Gtk.TextDirection.RTL; + + style_context.save (); + style_context.add_class ("lines"); + + var color = style_context.get_color (state); + var padding = style_context.get_padding (state); + + context.set_source_rgba (color.red, color.green, color.blue, color.alpha); + + double column_width = width / 7.0; + double minutes_height = height / Util.MINUTES_PER_DAY; + double x; + int i, width, height, today_column; + + wdith = get_allocated_width (); + height = get_allocated_height (); + + context.set_line_width (0.65); + + /* First, draw the selection */ + // TODO: if (self->selection_start != -1 && self->selection_end != -1) + + /* Drag and Drop highlight */ + // TODO: if (self->dnd_cell != -1) + + /* Vertical lines */ + for (i = 0; i < 7; i++) { + if (ltr) { + x = column_width * i; + } else { + x = width - column_width * i; + } + + context.move_to (Utils.aligned (x) * i); + context.line_to (0, height); + } + + /* Horizontal lines */ + for (i = 1; i < 24; i++) { + context.move_to (0, Utils.aligned ((height / 24.0) * i)); + context.line_to (width, 0); + } + + context.stroke (); + + /* Dashed lines between the vertical lines */ + context.set_dash (Grid.dashed, 2); + + for (i = 0; i < 24; i++) { + context.move_to (0, Utils.aligned((height / 24.0) * i + (height / 48.0))); + context.line_to (width, 0); + } + + context.stroke (); + context.restore (); + + base.draw (context); + + /* Today column */ + // today_column = get_today_column (GCAL_WEEK_GRID (widget)); + // TODO: if (today_column != -1) + + return false; } } - } diff --git a/src/Week/Util.vala b/src/Week/Util.vala index 1c5b9a360..25137cbcd 100644 --- a/src/Week/Util.vala +++ b/src/Week/Util.vala @@ -22,4 +22,7 @@ namespace Maya.Week.Util { public const int MINUTES_PER_DAY = 1440; public const int MAX_MINUTES = (7 * MINUTES_PER_DAY); + public double aligned (double x) { + return round (x) + 0.5; + } } From 46eef357db86c9a22f51e5dcf95e4154db0c8b31 Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Tue, 21 Apr 2020 14:56:40 +0000 Subject: [PATCH 06/22] Fixed compile errors for Week.Grid.draw --- src/Week/Grid.vala | 15 ++++++++------- src/Week/Util.vala | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Week/Grid.vala b/src/Week/Grid.vala index e723e42a4..f4315023b 100644 --- a/src/Week/Grid.vala +++ b/src/Week/Grid.vala @@ -25,7 +25,7 @@ namespace Maya.Week { */ public class Grid : Gtk.Box { - static const double dashed[] = { 5.0, 6.0 }; + const double dashed[] = { 5.0, 6.0 }; public override bool draw (Cairo.Context context) { @@ -41,14 +41,15 @@ namespace Maya.Week { context.set_source_rgba (color.red, color.green, color.blue, color.alpha); - double column_width = width / 7.0; - double minutes_height = height / Util.MINUTES_PER_DAY; double x; int i, width, height, today_column; - wdith = get_allocated_width (); + width = get_allocated_width (); height = get_allocated_height (); + double column_width = width / 7.0; + double minutes_height = height / Util.MINUTES_PER_DAY; + context.set_line_width (0.65); /* First, draw the selection */ @@ -65,13 +66,13 @@ namespace Maya.Week { x = width - column_width * i; } - context.move_to (Utils.aligned (x) * i); + context.move_to (Util.aligned (x), 0); context.line_to (0, height); } /* Horizontal lines */ for (i = 1; i < 24; i++) { - context.move_to (0, Utils.aligned ((height / 24.0) * i)); + context.move_to (0, Util.aligned ((height / 24.0) * i)); context.line_to (width, 0); } @@ -81,7 +82,7 @@ namespace Maya.Week { context.set_dash (Grid.dashed, 2); for (i = 0; i < 24; i++) { - context.move_to (0, Utils.aligned((height / 24.0) * i + (height / 48.0))); + context.move_to (0, Util.aligned((height / 24.0) * i + (height / 48.0))); context.line_to (width, 0); } diff --git a/src/Week/Util.vala b/src/Week/Util.vala index 25137cbcd..4fa4a7c35 100644 --- a/src/Week/Util.vala +++ b/src/Week/Util.vala @@ -23,6 +23,6 @@ namespace Maya.Week.Util { public const int MAX_MINUTES = (7 * MINUTES_PER_DAY); public double aligned (double x) { - return round (x) + 0.5; + return Math.round (x) + 0.5; } } From f3e614507549cbf619fff53ef68028a128b00806 Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Tue, 21 Apr 2020 15:24:25 +0000 Subject: [PATCH 07/22] Added possibility to switch between month and week view --- src/MainWindow.vala | 33 ++++++++++++++++++++++++++++----- src/Widgets/HeaderBar.vala | 12 ++++++++++-- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index e0e7c9211..3ac9c34c6 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -6,12 +6,12 @@ * 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 . * @@ -20,15 +20,21 @@ */ public class Maya.MainWindow : Gtk.ApplicationWindow { + private Gtk.Stack calview_stack; + private Week.View week_view; + private Gtk.Paned hpaned; + public View.CalendarView calview; public const string ACTION_PREFIX = "win."; public const string ACTION_NEW_EVENT = "action_new_event"; public const string ACTION_SHOW_TODAY = "action_show_today"; + public const string ACTION_SHOW_WEEK = "action_show_week"; private const ActionEntry[] ACTION_ENTRIES = { { ACTION_NEW_EVENT, action_new_event }, - { ACTION_SHOW_TODAY, action_show_today } + { ACTION_SHOW_TODAY, action_show_today }, + { ACTION_SHOW_WEEK, action_show_week } }; private uint configure_id; @@ -77,14 +83,23 @@ public class Maya.MainWindow : Gtk.ApplicationWindow { calview = new View.CalendarView (); calview.vexpand = true; - var hpaned = new Gtk.Paned (Gtk.Orientation.HORIZONTAL); + week_view = new Week.View (); + + hpaned = new Gtk.Paned (Gtk.Orientation.HORIZONTAL); hpaned.pack1 (calview, true, false); hpaned.pack2 (sidebar, true, false); + calview_stack = new Gtk.Stack (); + calview_stack.transition_type = Gtk.StackTransitionType.CROSSFADE; + calview_stack.expand = true; + + calview_stack.add (hpaned); + calview_stack.add (week_view); + var grid = new Gtk.Grid (); grid.orientation = Gtk.Orientation.VERTICAL; grid.add (infobar); - grid.add (hpaned); + grid.add (calview_stack); add (grid); set_titlebar (headerbar); @@ -121,6 +136,14 @@ public class Maya.MainWindow : Gtk.ApplicationWindow { calview.today (); } + private void action_show_week () { + if (calview_stack.visible_child == hpaned) { + calview_stack.visible_child = week_view; + } else { + calview_stack.visible_child = hpaned; + } + } + private void on_remove (ECal.Component comp) { Model.CalendarModel.get_default ().remove_event (comp.get_data ("source"), comp, ECal.ObjModType.THIS); } diff --git a/src/Widgets/HeaderBar.vala b/src/Widgets/HeaderBar.vala index b11bf5296..4cfa13c1d 100644 --- a/src/Widgets/HeaderBar.vala +++ b/src/Widgets/HeaderBar.vala @@ -6,12 +6,12 @@ * 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 . * @@ -41,6 +41,13 @@ namespace Maya.View { _("Create a new event") ); + var button_week_view = new Gtk.Button.from_icon_name ("view-reader", Gtk.IconSize.LARGE_TOOLBAR); + button_week_view.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_SHOW_WEEK; + button_week_view.tooltip_markup = Granite.markup_accel_tooltip ( + application_instance.get_accels_for_action (button_week_view.action_name), + _("Show week view") + ); + var button_today = new Gtk.Button.from_icon_name ("calendar-go-today", Gtk.IconSize.LARGE_TOOLBAR); button_today.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_SHOW_TODAY; button_today.tooltip_markup = Granite.markup_accel_tooltip ( @@ -72,6 +79,7 @@ namespace Maya.View { pack_start (button_add); pack_start (spinner); + pack_start (button_week_view); set_custom_title (title_grid); pack_end (menu_button); pack_end (contractor); From bcc007f2b23428b91a8f1e8294095bb405f6b7eb Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Tue, 21 Apr 2020 15:51:29 +0000 Subject: [PATCH 08/22] First size allocation steps --- src/Week/Grid.vala | 86 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/src/Week/Grid.vala b/src/Week/Grid.vala index f4315023b..5b23c33b8 100644 --- a/src/Week/Grid.vala +++ b/src/Week/Grid.vala @@ -23,10 +23,94 @@ namespace Maya.Week { * TODO: Documentation * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-grid.c */ - public class Grid : Gtk.Box { + public class Grid : Gtk.Container { const double dashed[] = { 5.0, 6.0 }; + private int today_column { + get { + DateTime today, week_start; + int days_diff; + + // TODO + + return 3; + } + } + + +/* + GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + container_class->add = gcal_week_grid_add; + container_class->remove = gcal_week_grid_remove; + container_class->forall = gcal_week_grid_forall; + + object_class->finalize = gcal_week_grid_finalize; + object_class->get_property = gcal_week_grid_get_property; + object_class->set_property = gcal_week_grid_set_property; + + widget_class->draw = gcal_week_grid_draw; + widget_class->size_allocate = gcal_week_grid_size_allocate; + widget_class->realize = gcal_week_grid_realize; + widget_class->unrealize = gcal_week_grid_unrealize; + widget_class->map = gcal_week_grid_map; + widget_class->unmap = gcal_week_grid_unmap; + widget_class->get_preferred_height = gcal_week_grid_get_preferred_height; + widget_class->button_press_event = gcal_week_grid_button_press; + widget_class->motion_notify_event = gcal_week_grid_motion_notify_event; + widget_class->button_release_event = gcal_week_grid_button_release; + widget_class->drag_motion = gcal_week_grid_drag_motion; + widget_class->drag_leave = gcal_week_grid_drag_leave; + widget_class->drag_drop = gcal_week_grid_drag_drop; + + signals[EVENT_ACTIVATED] = g_signal_new ("event-activated", + GCAL_TYPE_WEEK_GRID, + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, + 1, + GCAL_TYPE_EVENT_WIDGET); + + gtk_widget_class_set_css_name (widget_class, "weekgrid"); + */ + + public override void size_allocate (Gtk.Allocation allocation) { + DateTime week_start = null; + //RangeTree overlaps; + bool ltr; + double minutes_height; + double column_width; + int i, x, y; + + /* Allocate the widget */ + set_allocation (allocation); + + ltr = get_direction () != Gtk.TextDirection.RTL; + + if (get_realized ()) { + // TODO + } + + /* Preliminary calculations */ + minutes_height = allocation.height / Util.MINUTES_PER_DAY; + column_width = allocation.width / 7.0; + + /* Temporary range tree to hold positioned events' indexes */ + //overlaps = gcal_range_tree_new (); + + //week_start = + + /* + * Iterate through weekdays; we don't have to worry about events that + * jump between days because they're already handled by GcalWeekHeader. + */ + for (i = 0; i < 7; i++) { + // ... + } + } public override bool draw (Cairo.Context context) { var style_context = get_style_context (); From 70493b5aee4e9c264036a25b13ae8fb3ff0827a6 Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Tue, 21 Apr 2020 17:25:44 +0000 Subject: [PATCH 09/22] Basic realization of Week.Grid --- src/Week/Grid.vala | 69 ++++++++++++++++++++++++++++++++++++++++++++-- src/Week/View.vala | 13 ++++++--- 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/src/Week/Grid.vala b/src/Week/Grid.vala index 5b23c33b8..481c8c3f7 100644 --- a/src/Week/Grid.vala +++ b/src/Week/Grid.vala @@ -25,7 +25,8 @@ namespace Maya.Week { */ public class Grid : Gtk.Container { - const double dashed[] = { 5.0, 6.0 }; + private Gdk.Window event_window; + private const double dashed[] = { 5.0, 6.0 }; private int today_column { get { @@ -77,6 +78,37 @@ namespace Maya.Week { gtk_widget_class_set_css_name (widget_class, "weekgrid"); */ + public override void realize () { + var parent_window = get_parent_window (); + + set_realized (true); + set_window (parent_window); + + Gtk.Allocation allocation; + get_allocation (out allocation); + + var attributes = new Gdk.WindowAttr(); + attributes.window_type = Gdk.WindowType.CHILD; + attributes.wclass = Gdk.WindowWindowClass.INPUT_ONLY; + attributes.x = allocation.x; + attributes.y = allocation.y; + attributes.width = allocation.width; + attributes.height = allocation.height; + attributes.event_mask = get_events (); + attributes.event_mask |= (Gdk.EventMask.BUTTON_PRESS_MASK | + Gdk.EventMask.BUTTON_RELEASE_MASK | + Gdk.EventMask.BUTTON1_MOTION_MASK | + Gdk.EventMask.POINTER_MOTION_HINT_MASK | + Gdk.EventMask.POINTER_MOTION_MASK | + Gdk.EventMask.ENTER_NOTIFY_MASK | + Gdk.EventMask.LEAVE_NOTIFY_MASK | + Gdk.EventMask.SCROLL_MASK | + Gdk.EventMask.SMOOTH_SCROLL_MASK); + var attributes_mask = (Gdk.WindowAttributesType.X | Gdk.WindowAttributesType.Y); + event_window = new Gdk.Window (parent_window, attributes, attributes_mask); + register_window (event_window); + } + public override void size_allocate (Gtk.Allocation allocation) { DateTime week_start = null; //RangeTree overlaps; @@ -91,7 +123,7 @@ namespace Maya.Week { ltr = get_direction () != Gtk.TextDirection.RTL; if (get_realized ()) { - // TODO + event_window.move_resize (allocation.x, allocation.y, allocation.width, allocation.height); } /* Preliminary calculations */ @@ -112,6 +144,39 @@ namespace Maya.Week { } } + public override void get_preferred_height (out int minimum_height, out int natural_height) { + int hours_12_height, hours_24_height, cell_height, height; + + var style_context = get_style_context (); + var state = style_context.get_state (); + + style_context.save (); + style_context.add_class ("hours"); + + Pango.FontDescription font_desc; + style_context.@get (state, "font", out font_desc, null); + var padding = style_context.get_padding (state); + + var pango_context = get_pango_context (); + var pango_layout = new Pango.Layout (pango_context); + pango_layout.set_font_description (font_desc); + + pango_layout.set_text (_("00 AM"), -1); + pango_layout.get_pixel_size (null, out hours_12_height); + + pango_layout.set_text (_("00:00"), -1); + pango_layout.get_pixel_size (null, out hours_24_height); + + cell_height = int.max (hours_12_height, hours_24_height) + padding.top + padding.bottom; + height = cell_height * 48; + + style_context.restore (); + + /* Report the height */ + minimum_height = height; + natural_height = height; + } + public override bool draw (Cairo.Context context) { var style_context = get_style_context (); var state = get_state_flags (); diff --git a/src/Week/View.vala b/src/Week/View.vala index 728a14fab..a04ac1bc8 100644 --- a/src/Week/View.vala +++ b/src/Week/View.vala @@ -23,7 +23,7 @@ namespace Maya.Week { * TODO: Documentation * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-view.ui */ - public class View : Gtk.Box { + public class View : Gtk.Grid { construct { visible = true; @@ -37,11 +37,16 @@ namespace Maya.Week { var week_grid = new Grid (); + var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); + box.add (hours_bar); + box.add (week_grid); + + var viewport = new Gtk.Viewport (null, null); + viewport.add (box); + var scrolled_window = new Gtk.ScrolledWindow (null, null); scrolled_window.expand = true; - - scrolled_window.add (hours_bar); - scrolled_window.add (week_grid); + scrolled_window.add (viewport); add (header); add (scrolled_window); From bf17c7793c26a7376a9880247659d5f4a2a39dab Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Tue, 21 Apr 2020 18:13:40 +0000 Subject: [PATCH 10/22] Further steps towards week view... --- data/maya.gresource.xml | 1 + data/style/WeekView.css | 21 +++++++++++++++++ src/Week/Grid.vala | 52 +++++++++++++++++++++++++++++++++++++++-- src/Week/View.vala | 12 +++++++++- 4 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 data/style/WeekView.css diff --git a/data/maya.gresource.xml b/data/maya.gresource.xml index de5b1cf43..9f0e53606 100644 --- a/data/maya.gresource.xml +++ b/data/maya.gresource.xml @@ -19,5 +19,6 @@ style/Grid.css style/Header.css style/WeekLabels.css + style/WeekView.css diff --git a/data/style/WeekView.css b/data/style/WeekView.css new file mode 100644 index 000000000..1de7b03ff --- /dev/null +++ b/data/style/WeekView.css @@ -0,0 +1,21 @@ +/* +* Copyright 2020 elementary, Inc. (https://elementary.io) +* +* 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 . +*/ + +.week-view .lines { + /*color: alpha(@theme_fg_color, 0.30);*/ + color: black; +} diff --git a/src/Week/Grid.vala b/src/Week/Grid.vala index 481c8c3f7..862628a4c 100644 --- a/src/Week/Grid.vala +++ b/src/Week/Grid.vala @@ -26,6 +26,20 @@ namespace Maya.Week { public class Grid : Gtk.Container { private Gdk.Window event_window; + + private DateTime active_date; + private Maya.Util.DateRange date_range; + + /* + * These fields are "cells" rather than minutes. Each cell + * correspond to 30 minutes. + */ + private int selection_start; + private int selection_end; + private int dnd_cell; + + + private const double dashed[] = { 5.0, 6.0 }; private int today_column { @@ -77,6 +91,18 @@ namespace Maya.Week { gtk_widget_class_set_css_name (widget_class, "weekgrid"); */ + construct { + set_has_window (false); + + selection_start = -1; + selection_end = -1; + dnd_cell = -1; + + /* Setup the week view as a drag n' drop destination */ + Gtk.drag_dest_set (this, Gtk.DestDefaults.ALL, null, Gdk.DragAction.MOVE); + + get_style_context ().add_provider (Maya.Week.View.css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + } public override void realize () { var parent_window = get_parent_window (); @@ -87,7 +113,7 @@ namespace Maya.Week { Gtk.Allocation allocation; get_allocation (out allocation); - var attributes = new Gdk.WindowAttr(); + var attributes = Gdk.WindowAttr(); attributes.window_type = Gdk.WindowType.CHILD; attributes.wclass = Gdk.WindowWindowClass.INPUT_ONLY; attributes.x = allocation.x; @@ -109,6 +135,26 @@ namespace Maya.Week { register_window (event_window); } + public override void unrealize () { + if (event_window != null) { + unregister_window (event_window); + event_window.destroy (); + event_window = null; + } + } + + public override void map () { + if (event_window != null) { + event_window.show (); + } + } + + public override void unmap () { + if (event_window != null) { + event_window.hide (); + } + } + public override void size_allocate (Gtk.Allocation allocation) { DateTime week_start = null; //RangeTree overlaps; @@ -188,6 +234,8 @@ namespace Maya.Week { var color = style_context.get_color (state); var padding = style_context.get_padding (state); + debug (@">>>>>>>>>>>>>>>>>>>> lines.color: $(color)"); + context.set_source_rgba (color.red, color.green, color.blue, color.alpha); double x; @@ -236,7 +284,7 @@ namespace Maya.Week { } context.stroke (); - context.restore (); + style_context.restore (); base.draw (context); diff --git a/src/Week/View.vala b/src/Week/View.vala index a04ac1bc8..0b08ec45b 100644 --- a/src/Week/View.vala +++ b/src/Week/View.vala @@ -25,10 +25,20 @@ namespace Maya.Week { */ public class View : Gtk.Grid { + internal static Gtk.CssProvider css_provider; + + static construct { + css_provider = new Gtk.CssProvider (); + css_provider.load_from_resource ("/io/elementary/calendar/WeekView.css"); + } + construct { visible = true; orientation = Gtk.Orientation.VERTICAL; - get_style_context ().add_class ("week-view"); + + var style_context = get_style_context (); + style_context.add_class ("week-view"); + style_context.add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); var header = new Header (); From fb0260f43fcda74c2bf0845c4b005ab109a78ce5 Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Tue, 21 Apr 2020 18:42:56 +0000 Subject: [PATCH 11/22] Further progress in adapting GNOME Calendar Codebase --- src/Week/Grid.vala | 47 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/Week/Grid.vala b/src/Week/Grid.vala index 862628a4c..8ef922d88 100644 --- a/src/Week/Grid.vala +++ b/src/Week/Grid.vala @@ -250,10 +250,43 @@ namespace Maya.Week { context.set_line_width (0.65); /* First, draw the selection */ - // TODO: if (self->selection_start != -1 && self->selection_end != -1) + if (selection_start != -1 && selection_end != -1) { + int selection_height, column, start, end; + + start = selection_start; + end = selection_end; + + /* Swap cells if needed */ + if (start > end) { + start = start + end; + end = start -end; + start = start - end; + } + + column = start * 30 / Util.MINUTES_PER_DAY; + selection_height = (end - start + 1) * 30 * (int)minutes_height; + + x = column * column_width; + + style_context.save (); + style_context.set_state (state | Gtk.StateFlags.SELECTED); + + style_context.render_background (context, Util.aligned (x), Math.round ((start * 30 % Util.MINUTES_PER_DAY) * minutes_height), column_width, selection_height); + + style_context.restore (); + } /* Drag and Drop highlight */ - // TODO: if (self->dnd_cell != -1) + if (dnd_cell != -1) { + double cell_height; + int column, row; + + cell_height = minutes_height * 30; + column = dnd_cell / (Util.MINUTES_PER_DAY / 30); + row = dnd_cell - column * 48; + + style_context.render_background (context, column * column_width, row * cell_height, column_width, cell_height); + } /* Vertical lines */ for (i = 0; i < 7; i++) { @@ -294,5 +327,15 @@ namespace Maya.Week { return false; } + + public override void add (Gtk.Widget widget) { + if (widget.get_parent () == null) { + widget.set_parent (this); + } + } + + public override void remove (Gtk.Widget widget) { + + } } } From 3407241394fbb7efd24e0fd781af053e471e0bbe Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Wed, 22 Apr 2020 07:12:29 +0000 Subject: [PATCH 12/22] Week grid render does work --- data/style/WeekView.css | 3 +- src/Week/Grid.vala | 25 +++++++---- src/Week/Header.vala | 91 ----------------------------------------- src/Week/View.vala | 6 +-- src/meson.build | 1 - 5 files changed, 21 insertions(+), 105 deletions(-) delete mode 100644 src/Week/Header.vala diff --git a/data/style/WeekView.css b/data/style/WeekView.css index 1de7b03ff..bf59d78b4 100644 --- a/data/style/WeekView.css +++ b/data/style/WeekView.css @@ -16,6 +16,5 @@ */ .week-view .lines { - /*color: alpha(@theme_fg_color, 0.30);*/ - color: black; + color: alpha(@theme_fg_color, 0.30); } diff --git a/src/Week/Grid.vala b/src/Week/Grid.vala index 8ef922d88..f55446daf 100644 --- a/src/Week/Grid.vala +++ b/src/Week/Grid.vala @@ -101,7 +101,9 @@ namespace Maya.Week { /* Setup the week view as a drag n' drop destination */ Gtk.drag_dest_set (this, Gtk.DestDefaults.ALL, null, Gdk.DragAction.MOVE); - get_style_context ().add_provider (Maya.Week.View.css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + var style_context = get_style_context (); + style_context.add_class ("grid"); + style_context.add_provider (View.css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); } public override void realize () { @@ -141,18 +143,21 @@ namespace Maya.Week { event_window.destroy (); event_window = null; } + base.unrealize (); } public override void map () { if (event_window != null) { event_window.show (); } + base.map (); } public override void unmap () { if (event_window != null) { event_window.hide (); } + base.unmap (); } public override void size_allocate (Gtk.Allocation allocation) { @@ -223,6 +228,7 @@ namespace Maya.Week { natural_height = height; } + public override bool draw (Cairo.Context context) { var style_context = get_style_context (); var state = get_state_flags (); @@ -230,12 +236,11 @@ namespace Maya.Week { style_context.save (); style_context.add_class ("lines"); + style_context.add_provider (View.css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); var color = style_context.get_color (state); var padding = style_context.get_padding (state); - debug (@">>>>>>>>>>>>>>>>>>>> lines.color: $(color)"); - context.set_source_rgba (color.red, color.green, color.blue, color.alpha); double x; @@ -297,13 +302,13 @@ namespace Maya.Week { } context.move_to (Util.aligned (x), 0); - context.line_to (0, height); + context.rel_line_to (0, height); } /* Horizontal lines */ for (i = 1; i < 24; i++) { context.move_to (0, Util.aligned ((height / 24.0) * i)); - context.line_to (width, 0); + context.rel_line_to (width, 0); } context.stroke (); @@ -313,7 +318,7 @@ namespace Maya.Week { for (i = 0; i < 24; i++) { context.move_to (0, Util.aligned((height / 24.0) * i + (height / 48.0))); - context.line_to (width, 0); + context.rel_line_to (width, 0); } context.stroke (); @@ -335,7 +340,13 @@ namespace Maya.Week { } public override void remove (Gtk.Widget widget) { - + if (widget.get_parent () != null) { + widget.unparent (); + } } + + /*public override void forall (Gtk.Callback callback) { + // TODO + }*/ } } diff --git a/src/Week/Header.vala b/src/Week/Header.vala deleted file mode 100644 index de56f1259..000000000 --- a/src/Week/Header.vala +++ /dev/null @@ -1,91 +0,0 @@ -/*- - * Copyright (c) 2020 elementary, Inc. (https://elementary.io) - * - * 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 . - * - * Authored by: Marco Betschart - */ - -namespace Maya.Week { - - /** - * TODO: Documentation - * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-header.ui - */ - public class Header : Gtk.Grid { - - public signal void event_activated (/* TODO */); - - private Gtk.Grid grid; - - construct { - hexpand = true; - vexpand = false; - get_style_context ().add_class ("week-header"); - - var month_label = new Gtk.Label (_("Month")); - month_label.yalign = 0; - month_label.get_style_context ().add_class ("primary-label"); - - var week_label = new Gtk.Label (_("Week")); - week_label.hexpand = true; - week_label.xalign = week_label.yalign = 0; - week_label.get_style_context ().add_class ("secondary-label"); - - var year_label = new Gtk.Label (_("Year")); - year_label.yalign = 0; - year_label.get_style_context ().add_class ("secondary-label"); - - var header_labels_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); - - header_labels_box.add (month_label); - header_labels_box.add (week_label); - header_labels_box.add (year_label); - - var expand_button = new Gtk.Button.from_icon_name ("go-down-symbolic"); - expand_button.can_focus = false; - expand_button.hexpand = true; - expand_button.halign = Gtk.Align.CENTER; - expand_button.valign = Gtk.Align.END; - - var expand_button_style_context = expand_button.get_style_context (); - expand_button_style_context.add_class ("flat"); - expand_button_style_context.add_class ("circular"); - - var grid = new Gtk.Grid (); - grid.hexpand = true; - grid.column_homogeneous = true; - grid.column_spacing = 6; - grid.row_spacing = 2; - - /*grid.add (new Gtk.Box ()); - grid.add (new Gtk.Box ()); - grid.add (new Gtk.Box ()); - grid.add (new Gtk.Box ()); - grid.add (new Gtk.Box ()); - grid.add (new Gtk.Box ()); - grid.add (new Gtk.Box ());*/ - - var scrolled_window = new Gtk.ScrolledWindow (null, null); - scrolled_window.hscrollbar_policy = scrolled_window.vscrollbar_policy = Gtk.PolicyType.NEVER; - scrolled_window.propagate_natural_height = true; - - scrolled_window.add (grid); - - add (header_labels_box); - add (expand_button); - add (scrolled_window); - } - } -} diff --git a/src/Week/View.vala b/src/Week/View.vala index 0b08ec45b..4e78502df 100644 --- a/src/Week/View.vala +++ b/src/Week/View.vala @@ -23,7 +23,7 @@ namespace Maya.Week { * TODO: Documentation * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-view.ui */ - public class View : Gtk.Grid { + public class View : Gtk.Box { internal static Gtk.CssProvider css_provider; @@ -40,12 +40,11 @@ namespace Maya.Week { style_context.add_class ("week-view"); style_context.add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); - var header = new Header (); - var hours_bar = new Gtk.DrawingArea (); //hours_bar.height_request (2568); var week_grid = new Grid (); + week_grid.expand = true; var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); box.add (hours_bar); @@ -58,7 +57,6 @@ namespace Maya.Week { scrolled_window.expand = true; scrolled_window.add (viewport); - add (header); add (scrolled_window); } } diff --git a/src/meson.build b/src/meson.build index 322095fb1..105e44f7e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -28,7 +28,6 @@ calendar_files = files( 'SourceDialog/SourceItem.vala', 'SourceDialog/SourceSelector.vala', 'Week/Grid.vala', - 'Week/Header.vala', 'Week/Util.vala', 'Week/View.vala', 'Widgets/AgendaEventRow.vala', From 081f511e7bb31379f813c585d1c404b1bdabcb90 Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Wed, 22 Apr 2020 08:21:01 +0000 Subject: [PATCH 13/22] Rendering Hour Sidebar --- data/style/WeekView.css | 6 ++ src/Week/Grid.vala | 8 +-- src/Week/Util.vala | 7 ++- src/Week/View.vala | 134 +++++++++++++++++++++++++++++++++++++++- 4 files changed, 143 insertions(+), 12 deletions(-) diff --git a/data/style/WeekView.css b/data/style/WeekView.css index bf59d78b4..457f71d59 100644 --- a/data/style/WeekView.css +++ b/data/style/WeekView.css @@ -18,3 +18,9 @@ .week-view .lines { color: alpha(@theme_fg_color, 0.30); } + +.week-view .hours { + font-size: 10pt; + color: alpha(@theme_fg_color, 0.8); + padding: 8px 12px; +} diff --git a/src/Week/Grid.vala b/src/Week/Grid.vala index f55446daf..7aa48a202 100644 --- a/src/Week/Grid.vala +++ b/src/Week/Grid.vala @@ -38,10 +38,6 @@ namespace Maya.Week { private int selection_end; private int dnd_cell; - - - private const double dashed[] = { 5.0, 6.0 }; - private int today_column { get { DateTime today, week_start; @@ -102,7 +98,6 @@ namespace Maya.Week { Gtk.drag_dest_set (this, Gtk.DestDefaults.ALL, null, Gdk.DragAction.MOVE); var style_context = get_style_context (); - style_context.add_class ("grid"); style_context.add_provider (View.css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); } @@ -236,7 +231,6 @@ namespace Maya.Week { style_context.save (); style_context.add_class ("lines"); - style_context.add_provider (View.css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); var color = style_context.get_color (state); var padding = style_context.get_padding (state); @@ -314,7 +308,7 @@ namespace Maya.Week { context.stroke (); /* Dashed lines between the vertical lines */ - context.set_dash (Grid.dashed, 2); + context.set_dash (Util.dashed, 2); for (i = 0; i < 24; i++) { context.move_to (0, Util.aligned((height / 24.0) * i + (height / 48.0))); diff --git a/src/Week/Util.vala b/src/Week/Util.vala index 4fa4a7c35..991fc6070 100644 --- a/src/Week/Util.vala +++ b/src/Week/Util.vala @@ -19,10 +19,11 @@ namespace Maya.Week.Util { - public const int MINUTES_PER_DAY = 1440; - public const int MAX_MINUTES = (7 * MINUTES_PER_DAY); + internal const int MINUTES_PER_DAY = 1440; + internal const int MAX_MINUTES = (7 * MINUTES_PER_DAY); + internal const double dashed[] = { 5.0, 6.0 }; - public double aligned (double x) { + internal double aligned (double x) { return Math.round (x) + 0.5; } } diff --git a/src/Week/View.vala b/src/Week/View.vala index 4e78502df..2fbac045f 100644 --- a/src/Week/View.vala +++ b/src/Week/View.vala @@ -26,6 +26,7 @@ namespace Maya.Week { public class View : Gtk.Box { internal static Gtk.CssProvider css_provider; + private Gtk.DrawingArea hours_bar; static construct { css_provider = new Gtk.CssProvider (); @@ -40,8 +41,8 @@ namespace Maya.Week { style_context.add_class ("week-view"); style_context.add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); - var hours_bar = new Gtk.DrawingArea (); - //hours_bar.height_request (2568); + hours_bar = new Gtk.DrawingArea (); + hours_bar.height_request = 2568; var week_grid = new Grid (); week_grid.expand = true; @@ -58,6 +59,135 @@ namespace Maya.Week { scrolled_window.add (viewport); add (scrolled_window); + + hours_bar.draw.connect (draw_hours); + + update_hours_sidebar_size (); + } + + private bool draw_hours (Cairo.Context context) { + Gdk.RGBA color; + int i; + //var time_format = ?? + + var style_context = get_style_context (); + var state = style_context.get_state (); + var ltr = get_direction () != Gtk.TextDirection.RTL; + + style_context.save (); + style_context.add_class ("hours"); + + color = style_context.get_color (state); + var padding = style_context.get_padding (state); + + Pango.FontDescription font_desc; + style_context.@get (state, "font", out font_desc, null); + + var pango_layout = Pango.cairo_create_layout (context); + pango_layout.set_font_description (font_desc); + + context.set_source_rgba (color.red, color.green, color.blue, color.alpha); + + /* Gets the size of the widget */ + var width = hours_bar.get_allocated_width (); + var height = hours_bar.get_allocated_height (); + + /* Draws the hours in the sidebar */ + for (i = 0; i < 24; i++) { + string hours; + + // TODO: Honor User Time Format (12/24h): + // if (time_format == GCAL_TIME_FORMAT_24H): + hours = "%02d:00".printf(i); + // else: + /*hours = "%d %s".printf ( + i % 12 == 0 ? 12 : i % 12, + i >= 12 ? _("PM") : _("AM") + );*/ + + pango_layout.set_text (hours, -1); + + int font_width; + pango_layout.get_pixel_size (out font_width, null); + + style_context.render_layout ( + context, + ltr ? padding.left : width - font_width - padding.right, + (height / 24) * i + padding.top, + pango_layout + ); + } + + style_context.restore (); + style_context.save (); + + style_context.add_class ("lines"); + color = style_context.get_color (state); + + context.set_source_rgba (color.red, color.green, color.blue, color.alpha); + context.set_line_width (0.65); + + if (!ltr) { + context.move_to (0.5, 0); + context.rel_line_to (0, height); + } + + /* Draws the horizontal complete lines */ + for (i = 1; i < 24; i++) { + context.move_to (0, (height / 24) * i + 0.4); + context.rel_line_to (width, 0); + } + + context.stroke (); + context.set_dash (Util.dashed, 2); + + /* Draws the horizontal dashed lines */ + for (i = 0; i < 24; i++) { + context.move_to (0, (height / 24) * i + (height / 48) + 0.4); + context.rel_line_to (width, 0); + } + + context.stroke (); + style_context.restore (); + + return false; + } + + private void update_hours_sidebar_size () { + int hours_12_width, hours_24_width, sidebar_width; + int hours_12_height, hours_24_height, cell_height; + + var style_context = get_style_context (); + var state = style_context.get_state (); + + style_context.save (); + style_context.add_class ("hours"); + + Pango.FontDescription font_desc; + style_context.@get (state, "font", out font_desc, null); + var padding = style_context.get_padding (state); + + var pango_context = get_pango_context (); + var pango_layout = new Pango.Layout (pango_context); + pango_layout.set_font_description (font_desc); + + pango_layout.set_text (_("00 AM"), -1); + pango_layout.get_pixel_size (out hours_12_width, out hours_12_height); + + pango_layout.set_text (_("00:00"), -1); + pango_layout.get_pixel_size (out hours_24_width, out hours_24_height); + + sidebar_width = int.max (hours_12_width, hours_24_width) + padding.left + padding.right; + cell_height = int.max (hours_12_height, hours_24_height) + padding.top + padding.bottom; + + style_context.restore (); + + /* Update the size requests */ + hours_bar.set_size_request (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); } } } From 7418da0605927edece5db3c4b6f900e8a128ad90 Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Wed, 22 Apr 2020 08:38:20 +0000 Subject: [PATCH 14/22] Moved drawing of hours into own class --- src/Week/Sidebar.vala | 121 ++++++++++++++++++++++++++++++++++++++++++ src/Week/View.vala | 95 +-------------------------------- src/meson.build | 1 + 3 files changed, 124 insertions(+), 93 deletions(-) create mode 100644 src/Week/Sidebar.vala diff --git a/src/Week/Sidebar.vala b/src/Week/Sidebar.vala new file mode 100644 index 000000000..44f161584 --- /dev/null +++ b/src/Week/Sidebar.vala @@ -0,0 +1,121 @@ +/*- + * Copyright (c) 2020 elementary, Inc. (https://elementary.io) + * + * 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 . + * + * Authored by: Marco Betschart + */ + +namespace Maya.Week { + + /** + * TODO: Documentation + * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-view.c + */ + public class Sidebar : Gtk.DrawingArea { + + construct { + height_request = 2568; + get_style_context ().add_provider (View.css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + } + + public override bool draw (Cairo.Context context) { + Gdk.RGBA color; + int i; + //var time_format = ?? + + var style_context = get_style_context (); + var state = style_context.get_state (); + var ltr = get_direction () != Gtk.TextDirection.RTL; + + style_context.save (); + style_context.add_class ("hours"); + + color = style_context.get_color (state); + var padding = style_context.get_padding (state); + + Pango.FontDescription font_desc; + style_context.@get (state, "font", out font_desc, null); + + var pango_layout = Pango.cairo_create_layout (context); + pango_layout.set_font_description (font_desc); + + context.set_source_rgba (color.red, color.green, color.blue, color.alpha); + + /* Gets the size of the widget */ + var width = get_allocated_width (); + var height = get_allocated_height (); + + /* Draws the hours in the sidebar */ + for (i = 0; i < 24; i++) { + string hours; + + // TODO: Honor User Time Format (12/24h): + // if (time_format == GCAL_TIME_FORMAT_24H): + hours = "%02d:00".printf(i); + // else: + /*hours = "%d %s".printf ( + i % 12 == 0 ? 12 : i % 12, + i >= 12 ? _("PM") : _("AM") + );*/ + + pango_layout.set_text (hours, -1); + + int font_width; + pango_layout.get_pixel_size (out font_width, null); + + style_context.render_layout ( + context, + ltr ? padding.left : width - font_width - padding.right, + (height / 24) * i + padding.top, + pango_layout + ); + } + + style_context.restore (); + style_context.save (); + + style_context.add_class ("lines"); + color = style_context.get_color (state); + + context.set_source_rgba (color.red, color.green, color.blue, color.alpha); + context.set_line_width (0.65); + + if (!ltr) { + context.move_to (0.5, 0); + context.rel_line_to (0, height); + } + + /* Draws the horizontal complete lines */ + for (i = 1; i < 24; i++) { + context.move_to (0, (height / 24) * i + 0.4); + context.rel_line_to (width, 0); + } + + context.stroke (); + context.set_dash (Util.dashed, 2); + + /* Draws the horizontal dashed lines */ + for (i = 0; i < 24; i++) { + context.move_to (0, (height / 24) * i + (height / 48) + 0.4); + context.rel_line_to (width, 0); + } + + context.stroke (); + style_context.restore (); + + return false; + } + } +} diff --git a/src/Week/View.vala b/src/Week/View.vala index 2fbac045f..f20f3011d 100644 --- a/src/Week/View.vala +++ b/src/Week/View.vala @@ -26,7 +26,7 @@ namespace Maya.Week { public class View : Gtk.Box { internal static Gtk.CssProvider css_provider; - private Gtk.DrawingArea hours_bar; + private Sidebar hours_bar; static construct { css_provider = new Gtk.CssProvider (); @@ -41,8 +41,7 @@ namespace Maya.Week { style_context.add_class ("week-view"); style_context.add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); - hours_bar = new Gtk.DrawingArea (); - hours_bar.height_request = 2568; + hours_bar = new Sidebar (); var week_grid = new Grid (); week_grid.expand = true; @@ -60,99 +59,9 @@ namespace Maya.Week { add (scrolled_window); - hours_bar.draw.connect (draw_hours); - update_hours_sidebar_size (); } - private bool draw_hours (Cairo.Context context) { - Gdk.RGBA color; - int i; - //var time_format = ?? - - var style_context = get_style_context (); - var state = style_context.get_state (); - var ltr = get_direction () != Gtk.TextDirection.RTL; - - style_context.save (); - style_context.add_class ("hours"); - - color = style_context.get_color (state); - var padding = style_context.get_padding (state); - - Pango.FontDescription font_desc; - style_context.@get (state, "font", out font_desc, null); - - var pango_layout = Pango.cairo_create_layout (context); - pango_layout.set_font_description (font_desc); - - context.set_source_rgba (color.red, color.green, color.blue, color.alpha); - - /* Gets the size of the widget */ - var width = hours_bar.get_allocated_width (); - var height = hours_bar.get_allocated_height (); - - /* Draws the hours in the sidebar */ - for (i = 0; i < 24; i++) { - string hours; - - // TODO: Honor User Time Format (12/24h): - // if (time_format == GCAL_TIME_FORMAT_24H): - hours = "%02d:00".printf(i); - // else: - /*hours = "%d %s".printf ( - i % 12 == 0 ? 12 : i % 12, - i >= 12 ? _("PM") : _("AM") - );*/ - - pango_layout.set_text (hours, -1); - - int font_width; - pango_layout.get_pixel_size (out font_width, null); - - style_context.render_layout ( - context, - ltr ? padding.left : width - font_width - padding.right, - (height / 24) * i + padding.top, - pango_layout - ); - } - - style_context.restore (); - style_context.save (); - - style_context.add_class ("lines"); - color = style_context.get_color (state); - - context.set_source_rgba (color.red, color.green, color.blue, color.alpha); - context.set_line_width (0.65); - - if (!ltr) { - context.move_to (0.5, 0); - context.rel_line_to (0, height); - } - - /* Draws the horizontal complete lines */ - for (i = 1; i < 24; i++) { - context.move_to (0, (height / 24) * i + 0.4); - context.rel_line_to (width, 0); - } - - context.stroke (); - context.set_dash (Util.dashed, 2); - - /* Draws the horizontal dashed lines */ - for (i = 0; i < 24; i++) { - context.move_to (0, (height / 24) * i + (height / 48) + 0.4); - context.rel_line_to (width, 0); - } - - context.stroke (); - style_context.restore (); - - return false; - } - private void update_hours_sidebar_size () { int hours_12_width, hours_24_width, sidebar_width; int hours_12_height, hours_24_height, cell_height; diff --git a/src/meson.build b/src/meson.build index 105e44f7e..3a706f138 100644 --- a/src/meson.build +++ b/src/meson.build @@ -28,6 +28,7 @@ calendar_files = files( 'SourceDialog/SourceItem.vala', 'SourceDialog/SourceSelector.vala', 'Week/Grid.vala', + 'Week/Sidebar.vala', 'Week/Util.vala', 'Week/View.vala', 'Widgets/AgendaEventRow.vala', From 804e049483e493ef1e3eee6d7db4f9de338a98d4 Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Wed, 22 Apr 2020 12:24:10 +0000 Subject: [PATCH 15/22] Added week header rendering --- data/style/WeekView.css | 16 +++ src/Week/Header.vala | 272 ++++++++++++++++++++++++++++++++++++++++ src/Week/Sidebar.vala | 11 ++ src/Week/Util.vala | 94 ++++++++++++++ src/Week/View.vala | 11 +- src/meson.build | 1 + 6 files changed, 403 insertions(+), 2 deletions(-) create mode 100644 src/Week/Header.vala diff --git a/data/style/WeekView.css b/data/style/WeekView.css index 457f71d59..b939d2ee9 100644 --- a/data/style/WeekView.css +++ b/data/style/WeekView.css @@ -15,6 +15,22 @@ * along with this program. If not, see . */ +.week-header .week-names { + font-size: 10pt; + font-weight: bold; + 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 .today { + color: @theme_selected_bg_color; +} + .week-view .lines { color: alpha(@theme_fg_color, 0.30); } diff --git a/src/Week/Header.vala b/src/Week/Header.vala new file mode 100644 index 000000000..939c7c155 --- /dev/null +++ b/src/Week/Header.vala @@ -0,0 +1,272 @@ +/*- + * Copyright (c) 2020 elementary, Inc. (https://elementary.io) + * + * 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 . + * + * Authored by: Marco Betschart + */ + +namespace Maya.Week { + + /** + * TODO: Documentation + * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-header.ui + */ + public class Header : Gtk.Box { + + public Gtk.SizeGroup sidebar_sizegroup { get; construct; } + + private DateTime active_date; + private int first_weekday; + + private Gtk.ScrolledWindow scrolled_window; + private Gtk.Box expand_button_box; + + public Header (Gtk.SizeGroup sidebar_sizegroup) { + Object ( + orientation: Gtk.Orientation.HORIZONTAL, + spacing: 0, + sidebar_sizegroup: sidebar_sizegroup + ); + } + + construct { + active_date = new DateTime.now_local (); + first_weekday = Util.get_first_weekday (); + + var style_context = get_style_context (); + style_context.add_class ("week-header"); + style_context.add_provider (View.css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + + expand_button_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); + sidebar_sizegroup.add_widget (expand_button_box); + add (expand_button_box); + + var grid = new Gtk.Grid (); + grid.column_homogeneous = true; + grid.hexpand = true; + grid.column_spacing = 6; + grid.row_spacing = 2; + grid.margin_start = 6; + + for (int i = 0; i < 7; i++) { + var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); + grid.attach (box, i, 0); + } + + var viewport = new Gtk.Viewport (null, null); + viewport.shadow_type = Gtk.ShadowType.NONE; + viewport.add (grid); + + scrolled_window = new Gtk.ScrolledWindow (null, null); + scrolled_window.hscrollbar_policy = scrolled_window.vscrollbar_policy = Gtk.PolicyType.NEVER; + scrolled_window.propagate_natural_height = true; + scrolled_window.margin_bottom = 2; + scrolled_window.add (viewport); + + var event_box = new Gtk.EventBox (); + event_box.add (scrolled_window); + + add (event_box); + } + + // TODO: int get_today_column + + private int get_weekday_names_height () { + Pango.FontDescription font_desc; + Gtk.Border padding; + int font_height; + int final_height; + + var style_context = get_style_context (); + var state = style_context.get_state (); + + var pango_layout = create_pango_layout ("A"); + + style_context.save (); + style_context.add_class ("week-dates"); + + padding = style_context.get_padding (state); + + style_context.@get (state, "font", out font_desc, null); + pango_layout.set_font_description (font_desc); + pango_layout.get_pixel_size (out font_height, null); + + style_context.restore (); + + final_height = padding.top + font_height + padding.bottom; + + style_context.save (); + style_context.add_class ("week-names"); + + padding = style_context.get_padding (state); + + style_context.@get (state, "font", out font_desc, null); + pango_layout.set_font_description (font_desc); + pango_layout.get_pixel_size (out font_height, null); + + final_height += padding.top + font_height + padding.bottom; + + // TODO: multiply by 2 should not be necessary here :( + return final_height * 2; + } + + + public override void size_allocate (Gtk.Allocation allocation) { + var min_header_height = get_weekday_names_height (); + scrolled_window.margin_top = min_header_height; + + base.size_allocate (allocation); + } + + public override bool draw (Cairo.Context context) { + Pango.FontDescription bold_font; + DateTime week_start, week_end; + Gdk.RGBA color; + + double cell_width; + int i, day_abv_font_height, current_cell, today_column; + int start_x, start_y; + + context.save (); + + /* Fonts and colour selection */ + var style_context = get_style_context (); + var state = style_context.get_state (); + var ltr = get_direction () != Gtk.TextDirection.RTL; + + start_x = ltr ? expand_button_box.get_allocated_width () : 0; + start_y = 0; + + var padding = style_context.get_padding (state); + + Gtk.Allocation alloc; + get_allocation (out alloc); + + if (!ltr) { + alloc.width -= expand_button_box.get_allocated_width (); + } + + color = style_context.get_color (state); + context.set_source_rgba (color.red, color.green, color.blue, color.alpha); + + var pango_layout = Pango.cairo_create_layout (context); + style_context.@get (state, "font", out bold_font, null); + bold_font.set_weight (Pango.Weight.MEDIUM); + pango_layout.set_font_description (bold_font); + + week_start = Util.get_start_of_week (active_date); + week_end = week_start.add_days (6); + + current_cell = active_date.get_day_of_week () - 1; + current_cell = (7 + current_cell - first_weekday) % 7; + today_column = 2; // TODO: get_today_column (); + + cell_width = (alloc.width - start_x) / 7.0; + + /* Drag and Drop highlight */ + // TODO: if (self->dnd_cell != -1) + + /* Draw the selection background */ + // TODO: if (self->selection_start != -1 && self->selection_end != -1) + + pango_layout.get_pixel_size (null, out day_abv_font_height); + + for (i = 0; i < 7; i++) { + var day = week_start.add_days (i); + var n_day = day.get_day_of_month (); + var days_in_month = Util.get_days_in_month (week_start); + + string weekday_abv, weekday; + int font_width, day_num_font_height, day_num_font_baseline; + double x; + + if (n_day > days_in_month) { + n_day = n_day - days_in_month; + } + + /* Draws the date of days in the week */ + var weekday_date = "%d".printf (n_day); + + style_context.save (); + style_context.add_class ("week-dates"); + + style_context.@get (state, "font", out bold_font, null); + + if (i == today_column) { + style_context.add_class ("today"); + } + + pango_layout.set_font_description (bold_font); + pango_layout.set_text (weekday_date, -1); + + pango_layout.get_pixel_size (out font_width, out day_num_font_height); + day_num_font_baseline = pango_layout.get_baseline () / Pango.SCALE; + + if (ltr) { + x = padding.left + cell_width * i + Util.COLUMN_PADDING + start_x; + } else { + x = alloc.width - (cell_width * i + font_width + Util.COLUMN_PADDING + start_x); + } + + style_context.render_layout (context, x, day_abv_font_height + padding.bottom + start_y, pango_layout); + style_context.restore (); + + /* Draws the days name */ + weekday = day.format ("%a"); + weekday_abv = weekday.up (); + + style_context.save (); + style_context.add_class ("week-names"); + style_context.@get (state, "font", out bold_font, null); + + if (i == today_column) { + style_context.add_class ("today"); + } + + pango_layout.set_font_description (bold_font); + pango_layout.set_text (weekday_abv, -1); + + pango_layout.get_pixel_size (out font_width, null); + + if (ltr) { + x = padding.left + cell_width * i + Util.COLUMN_PADDING + start_x; + } else { + x = alloc.width - (cell_width * i + font_width + Util.COLUMN_PADDING + start_x); + } + + style_context.render_layout (context, x, start_y, pango_layout); + style_context.restore (); + + /* Draws the lines after each day of the week */ + style_context.save (); + style_context.add_class ("lines"); + + color = style_context.get_color (state); + context.set_source_rgba (color.red, color.green, color.blue, color.alpha); + context.set_line_width (0.25); + context.move_to (Util.aligned (ltr ? (cell_width * i + start_x) : (alloc.width - (cell_width * i + start_x))), day_abv_font_height + padding.bottom + start_y); + context.rel_line_to (0.0, get_allocated_height () - day_abv_font_height - start_y + padding.bottom); + context.stroke (); + + style_context.restore (); + } + + context.restore (); + base.draw (context); + + return false; + } + } +} diff --git a/src/Week/Sidebar.vala b/src/Week/Sidebar.vala index 44f161584..8319a8133 100644 --- a/src/Week/Sidebar.vala +++ b/src/Week/Sidebar.vala @@ -25,8 +25,19 @@ namespace Maya.Week { */ public class Sidebar : Gtk.DrawingArea { + public Gtk.SizeGroup sidebar_sizegroup { get; construct; } + + public Sidebar (Gtk.SizeGroup sidebar_sizegroup) { + Object ( + sidebar_sizegroup: sidebar_sizegroup + ); + } + construct { height_request = 2568; + + sidebar_sizegroup.add_widget (this); + get_style_context ().add_provider (View.css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); } diff --git a/src/Week/Util.vala b/src/Week/Util.vala index 991fc6070..b701df102 100644 --- a/src/Week/Util.vala +++ b/src/Week/Util.vala @@ -22,8 +22,102 @@ namespace Maya.Week.Util { internal const int MINUTES_PER_DAY = 1440; internal const int MAX_MINUTES = (7 * MINUTES_PER_DAY); internal const double dashed[] = { 5.0, 6.0 }; + internal const int COLUMN_PADDING = 6; internal double aligned (double x) { return Math.round (x) + 0.5; } + + /** + * TODO: https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/utils/gcal-utils.c#L301 + */ + internal int get_first_weekday () { + return 0; + } + + + /** + * Retrieves the first day of the week @date is in, at 00:00 + * of the local timezone. + * + * This date is inclusive. + */ + internal DateTime get_start_of_week (DateTime date) { + var first_weekday = get_first_weekday (); + var weekday = date.get_day_of_week () % 7; + var n_days_after_week_start = (weekday - first_weekday) % 7; + + var start_of_week = date.add_days (-n_days_after_week_start); + + return new DateTime.local ( + start_of_week.get_year (), + start_of_week.get_month (), + start_of_week.get_day_of_month (), + 0, 0, 0); + } + + + /** + * Retrieves the last day of the week @date is in, at 23:59:59 + * of the local timezone. + * + * Because this date is exclusive, it actually is start of the + * next week. + */ + internal DateTime get_end_of_week (DateTime date) { + var week_start = get_start_of_week (date); + return week_start.add_weeks (1); + } + + internal int get_days_in_month (DateTime datetime) { + DateMonth month; + + switch (datetime.get_month ()) { + case 1: + month = DateMonth.JANUARY; + break; + case 2: + month = DateMonth.FEBRUARY; + break; + case 3: + month = DateMonth.MARCH; + break; + case 4: + month = DateMonth.APRIL; + break; + case 5: + month = DateMonth.MAY; + break; + case 6: + month = DateMonth.JUNE; + break; + case 7: + month = DateMonth.JULY; + break; + case 8: + month = DateMonth.AUGUST; + break; + case 9: + month = DateMonth.SEPTEMBER; + break; + case 10: + month = DateMonth.OCTOBER; + break; + case 11: + month = DateMonth.NOVEMBER; + break; + case 12: + month = DateMonth.DECEMBER; + break; + default: + month = DateMonth.BAD_MONTH; + break; + } + + // TODO: Make DateYear dynamic: datetime.get_year () + // how do I convert int into ushort ...?! + DateYear year = 2020; + + return month.get_days_in_month (year); + } } diff --git a/src/Week/View.vala b/src/Week/View.vala index f20f3011d..a4981b53a 100644 --- a/src/Week/View.vala +++ b/src/Week/View.vala @@ -26,7 +26,9 @@ namespace Maya.Week { public class View : Gtk.Box { internal static Gtk.CssProvider css_provider; + private Sidebar hours_bar; + private Gtk.SizeGroup sidebar_sizegroup; static construct { css_provider = new Gtk.CssProvider (); @@ -41,7 +43,9 @@ namespace Maya.Week { style_context.add_class ("week-view"); style_context.add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); - hours_bar = new Sidebar (); + + sidebar_sizegroup = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL); + hours_bar = new Sidebar (sidebar_sizegroup); var week_grid = new Grid (); week_grid.expand = true; @@ -57,6 +61,9 @@ namespace Maya.Week { scrolled_window.expand = true; scrolled_window.add (viewport); + var header = new Header (sidebar_sizegroup); + + add (header); add (scrolled_window); update_hours_sidebar_size (); @@ -95,7 +102,7 @@ namespace Maya.Week { hours_bar.set_size_request (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)); + //gcal_week_header_get_sidebar_size_group (GCAL_WEEK_HEADER (self->header)); //gtk_size_group_add_widget (sidebar_sizegroup, self->hours_bar); } } diff --git a/src/meson.build b/src/meson.build index 3a706f138..a9ba554c2 100644 --- a/src/meson.build +++ b/src/meson.build @@ -28,6 +28,7 @@ calendar_files = files( 'SourceDialog/SourceItem.vala', 'SourceDialog/SourceSelector.vala', 'Week/Grid.vala', + 'Week/Header.vala', 'Week/Sidebar.vala', 'Week/Util.vala', 'Week/View.vala', From f116f1352099adb454861c04fafed444b42da814 Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Wed, 22 Apr 2020 12:59:07 +0000 Subject: [PATCH 16/22] Use application accentColor for today --- data/style/WeekView.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/style/WeekView.css b/data/style/WeekView.css index b939d2ee9..c8115db05 100644 --- a/data/style/WeekView.css +++ b/data/style/WeekView.css @@ -28,7 +28,7 @@ } .week-header .today { - color: @theme_selected_bg_color; + color: @colorAccent; } .week-view .lines { From 5a6f3ffa41e390e1ab735350b6dc1ed9913b0e51 Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Wed, 22 Apr 2020 13:27:51 +0000 Subject: [PATCH 17/22] Changed Icon to switch views --- src/MainWindow.vala | 3 + src/Week/Grid.vala | 50 ++++---------- src/Week/View.vala | 134 ++++++++++++++++++++++++++++++++++--- src/Widgets/HeaderBar.vala | 4 +- 4 files changed, 142 insertions(+), 49 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 3ac9c34c6..74d63e7ed 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -107,6 +107,9 @@ public class Maya.MainWindow : Gtk.ApplicationWindow { calview.on_event_add.connect ((date) => on_tb_add_clicked (date)); calview.selection_changed.connect ((date) => sidebar.set_selected_date (date)); + week_view.on_event_add.connect ((date) => on_tb_add_clicked (date)); + week_view.selection_changed.connect ((date) => sidebar.set_selected_date (date)); + infobar.response.connect ((id) => infobar.hide ()); sidebar.event_removed.connect (on_remove); diff --git a/src/Week/Grid.vala b/src/Week/Grid.vala index 7aa48a202..87b24f589 100644 --- a/src/Week/Grid.vala +++ b/src/Week/Grid.vala @@ -49,44 +49,6 @@ namespace Maya.Week { } } - -/* - GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - container_class->add = gcal_week_grid_add; - container_class->remove = gcal_week_grid_remove; - container_class->forall = gcal_week_grid_forall; - - object_class->finalize = gcal_week_grid_finalize; - object_class->get_property = gcal_week_grid_get_property; - object_class->set_property = gcal_week_grid_set_property; - - widget_class->draw = gcal_week_grid_draw; - widget_class->size_allocate = gcal_week_grid_size_allocate; - widget_class->realize = gcal_week_grid_realize; - widget_class->unrealize = gcal_week_grid_unrealize; - widget_class->map = gcal_week_grid_map; - widget_class->unmap = gcal_week_grid_unmap; - widget_class->get_preferred_height = gcal_week_grid_get_preferred_height; - widget_class->button_press_event = gcal_week_grid_button_press; - widget_class->motion_notify_event = gcal_week_grid_motion_notify_event; - widget_class->button_release_event = gcal_week_grid_button_release; - widget_class->drag_motion = gcal_week_grid_drag_motion; - widget_class->drag_leave = gcal_week_grid_drag_leave; - widget_class->drag_drop = gcal_week_grid_drag_drop; - - signals[EVENT_ACTIVATED] = g_signal_new ("event-activated", - GCAL_TYPE_WEEK_GRID, - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, - 1, - GCAL_TYPE_EVENT_WIDGET); - - gtk_widget_class_set_css_name (widget_class, "weekgrid"); - */ construct { set_has_window (false); @@ -333,6 +295,18 @@ namespace Maya.Week { } } + /** + * Puts the given event on the grid. + */ + public void add_event (ECal.Component event) { + /*foreach (var grid_day in data.values) { + if (Util.calcomp_is_on_day (event, grid_day.date)) { + var button = new EventButton (event); + grid_day.add_event_button (button); + } + } */ + } + public override void remove (Gtk.Widget widget) { if (widget.get_parent () != null) { widget.unparent (); diff --git a/src/Week/View.vala b/src/Week/View.vala index a4981b53a..1e78c35d4 100644 --- a/src/Week/View.vala +++ b/src/Week/View.vala @@ -25,10 +25,19 @@ namespace Maya.Week { */ public class View : Gtk.Box { + /* + * Event emitted when the day is double clicked or the ENTER key is pressed. + */ + public signal void on_event_add (DateTime date); + public signal void selection_changed (DateTime new_date); + + public DateTime? selected_date { get; private set; } + internal static Gtk.CssProvider css_provider; - private Sidebar hours_bar; + private Sidebar sidebar; private Gtk.SizeGroup sidebar_sizegroup; + private Grid grid; static construct { css_provider = new Gtk.CssProvider (); @@ -36,23 +45,22 @@ namespace Maya.Week { } construct { - visible = true; + selected_date = Settings.SavedState.get_default ().get_selected (); orientation = Gtk.Orientation.VERTICAL; var style_context = get_style_context (); style_context.add_class ("week-view"); style_context.add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); - sidebar_sizegroup = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL); - hours_bar = new Sidebar (sidebar_sizegroup); + sidebar = new Sidebar (sidebar_sizegroup); - var week_grid = new Grid (); - week_grid.expand = true; + grid = new Grid (); + grid.expand = true; var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); - box.add (hours_bar); - box.add (week_grid); + box.add (sidebar); + box.add (grid); var viewport = new Gtk.Viewport (null, null); viewport.add (box); @@ -67,6 +75,15 @@ namespace Maya.Week { add (scrolled_window); update_hours_sidebar_size (); + + sync_with_model (); + + var model = Model.CalendarModel.get_default (); + model.parameters_changed.connect (on_model_parameters_changed); + + model.events_added.connect (on_events_added); + model.events_updated.connect (on_events_updated); + model.events_removed.connect (on_events_removed); } private void update_hours_sidebar_size () { @@ -99,11 +116,110 @@ namespace Maya.Week { style_context.restore (); /* Update the size requests */ - hours_bar.set_size_request (sidebar_width, 48 * cell_height); + sidebar.set_size_request (sidebar_width, 48 * cell_height); /* Sync with the week header sidebar */ //gcal_week_header_get_sidebar_size_group (GCAL_WEEK_HEADER (self->header)); //gtk_size_group_add_widget (sidebar_sizegroup, self->hours_bar); } + + void on_events_added (E.Source source, Gee.Collection events) { + Idle.add ( () => { + foreach (var event in events) + add_event (source, event); + + return false; + }); + } + + void on_events_updated (E.Source source, Gee.Collection events) { + Idle.add ( () => { + foreach (var event in events) + update_event (source, event); + + return false; + }); + } + + void on_events_removed (E.Source source, Gee.Collection events) { + Idle.add ( () => { + foreach (var event in events) + remove_event (source, event); + + return false; + }); + } + + /* Indicates the month has changed */ + void on_model_parameters_changed () { + /*var model = Model.CalendarModel.get_default (); + if (grid.grid_range != null && model.data_range.equals (grid.grid_range)) + return; // nothing to do + + Idle.add ( () => { + remove_all_events (); + sync_with_model (); + return false; + });*/ + } + + //--- Helper Methods ---// + + /* Sets the calendar widgets to the date range of the model */ + void sync_with_model () { + /* + var model = Model.CalendarModel.get_default (); + if (grid.grid_range != null && (model.data_range.equals (grid.grid_range) || grid.grid_range.first_dt.compare (model.data_range.first_dt) == 0)) + return; // nothing to do + + DateTime previous_first = null; + if (grid.grid_range != null) + previous_first = grid.grid_range.first_dt; + + big_grid = create_big_grid (); + stack.add (big_grid); + + header.update_columns (model.week_starts_on); + weeks.update (model.data_range.first_dt, model.num_weeks); + grid.set_range (model.data_range, model.month_start); + + // keep focus date on the same day of the month + if (selected_date != null) { + var bumpdate = model.month_start.add_days (selected_date.get_day_of_month () - 1); + grid.focus_date (bumpdate); + } + + if (previous_first != null) { + if (previous_first.compare (grid.grid_range.first_dt) == -1) { + stack.transition_type = Gtk.StackTransitionType.SLIDE_UP; + } else { + stack.transition_type = Gtk.StackTransitionType.SLIDE_DOWN; + } + } + + stack.set_visible_child (big_grid); */ + } + + /* Render new event on the grid */ + void add_event (E.Source source, ECal.Component event) { + critical ("add_event"); + //event.set_data ("source", source); + grid.add_event (event); + } + + /* Update the event on the grid */ + void update_event (E.Source source, ECal.Component event) { + // grid.update_event (event); + } + + /* Remove event from the grid */ + void remove_event (E.Source source, ECal.Component event) { + //grid.remove_event (event); + } + + /* Remove all events from the grid */ + void remove_all_events () { + //grid.remove_all_events (); + } } } diff --git a/src/Widgets/HeaderBar.vala b/src/Widgets/HeaderBar.vala index 4cfa13c1d..fa1e82c25 100644 --- a/src/Widgets/HeaderBar.vala +++ b/src/Widgets/HeaderBar.vala @@ -41,7 +41,7 @@ namespace Maya.View { _("Create a new event") ); - var button_week_view = new Gtk.Button.from_icon_name ("view-reader", Gtk.IconSize.LARGE_TOOLBAR); + var button_week_view = new Gtk.Button.from_icon_name ("office-calendar", Gtk.IconSize.LARGE_TOOLBAR); button_week_view.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_SHOW_WEEK; button_week_view.tooltip_markup = Granite.markup_accel_tooltip ( application_instance.get_accels_for_action (button_week_view.action_name), @@ -74,12 +74,12 @@ namespace Maya.View { title_grid.add (button_today); title_grid.add (month_switcher); title_grid.add (year_switcher); + title_grid.add (button_week_view); var spinner = new Widgets.DynamicSpinner (); pack_start (button_add); pack_start (spinner); - pack_start (button_week_view); set_custom_title (title_grid); pack_end (menu_button); pack_end (contractor); From 37aa843a21fa58f6da23dc4f6a6140f5e1df722a Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Wed, 22 Apr 2020 18:35:59 +0000 Subject: [PATCH 18/22] Made CalendarModel more generic and introducing new EventWidget --- core/DisplayMode.vala | 26 +++++ core/Model/CalendarModel.vala | 62 ++++++---- core/Settings/SavedState.vala | 22 +++- core/Utils.vala | 97 ++++++++++++++++ core/meson.build | 1 + daemon/Daemon.vala | 2 +- data/io.elementary.calendar.gschema.xml | 11 +- src/Application.vala | 3 +- src/Grid/CalendarView.vala | 8 +- src/Grid/Grid.vala | 8 +- src/Week/EventWidget.vala | 147 ++++++++++++++++++++++++ src/Week/Grid.vala | 3 + src/Week/Header.vala | 6 +- src/Week/Util.vala | 93 --------------- src/Widgets/HeaderBar.vala | 4 +- 15 files changed, 357 insertions(+), 136 deletions(-) create mode 100644 core/DisplayMode.vala create mode 100644 src/Week/EventWidget.vala diff --git a/core/DisplayMode.vala b/core/DisplayMode.vala new file mode 100644 index 000000000..ee3c2427d --- /dev/null +++ b/core/DisplayMode.vala @@ -0,0 +1,26 @@ +/*- + * Copyright (c) 2020 elementary, Inc. (https://elementary.io) + * + * 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 . + * + * Authored by: Marco Betschart + */ + +namespace Maya { + + public enum DisplayMode { + MONTH, + WEEK + } +} diff --git a/core/Model/CalendarModel.vala b/core/Model/CalendarModel.vala index f0981a5d2..f1f7aec7d 100644 --- a/core/Model/CalendarModel.vala +++ b/core/Model/CalendarModel.vala @@ -15,21 +15,21 @@ public class Maya.Model.CalendarModel : Object { /* The data_range is the range of dates for which this model is storing - * data. The month_range is a subset of this range corresponding to the - * calendar month that is being focused on. In summary: + * data. The display_range is a subset of this range corresponding to the + * calendar view that is being focused on (either month or week). In summary: * - * data_range.first_dt <= month_range.first_dt < month_range.last_dt <= data_range.last_dt + * data_range.first_dt <= display_range.first_dt < display_range.last_dt <= data_range.last_dt * * There is no way to set the ranges publicly. They can only be modified by - * changing one of the following properties: month_start, num_weeks, and + * changing one of the following properties: display_start, num_weeks, and * week_starts_on. */ public Util.DateRange data_range { get; private set; } - public Util.DateRange month_range { get; private set; } + public Util.DateRange display_range { get; private set; } public E.SourceRegistry registry { get; private set; } - /* The first day of the month */ - public DateTime month_start { get; set; } + /* The first day to be displayed */ + public DateTime display_start { get; set; } /* The number of weeks to show in this model */ public int num_weeks { get; private set; default = 6; } @@ -49,7 +49,7 @@ public class Maya.Model.CalendarModel : Object { public signal void connected (E.Source source); public signal void error_received (string error); - /* The month_start, num_weeks, or week_starts_on have been changed */ + /* The display_start, num_weeks, or week_starts_on have been changed */ public signal void parameters_changed (); HashTable source_client; @@ -68,12 +68,22 @@ public class Maya.Model.CalendarModel : Object { } private CalendarModel () { - int week_start = Posix.NLTime.FIRST_WEEKDAY.to_string ().data[0]; + int week_start = Util.get_first_weekday (); if (week_start >= 1 && week_start <= 7) { week_starts_on = (GLib.DateWeekday) (week_start - 1); } - this.month_start = Util.get_start_of_month (Settings.SavedState.get_default ().get_page ()); + var display_page = Settings.SavedState.get_default ().get_page (); + switch (Settings.SavedState.get_default ().get_mode ()) { + case Maya.DisplayMode.WEEK: + this.display_start = Util.get_start_of_week (display_page); + this.num_weeks = 1; + break; + + case Maya.DisplayMode.MONTH: + this.display_start = Util.get_start_of_month (display_page); + break; + } compute_ranges (); source_client = new HashTable (str_hash, str_equal); @@ -81,7 +91,7 @@ public class Maya.Model.CalendarModel : Object { source_view = new HashTable (str_hash, str_equal); calendar_trash = new GLib.Queue (); - notify["month-start"].connect (on_parameter_changed); + notify["display-start"].connect (on_parameter_changed); open.begin (); } @@ -221,12 +231,16 @@ public class Maya.Model.CalendarModel : Object { } } + public void change_week (int relative) { + display_start = display_start.add_weeks (relative); + } + public void change_month (int relative) { - month_start = month_start.add_months (relative); + display_start = display_start.add_months (relative); } public void change_year (int relative) { - month_start = month_start.add_years (relative); + display_start = display_start.add_years (relative); } public void load_all_sources () { @@ -284,11 +298,17 @@ public class Maya.Model.CalendarModel : Object { //--- Helper Methods ---// private void compute_ranges () { - Settings.SavedState.get_default ().month_page = month_start.format ("%Y-%m"); - var month_end = month_start.add_full (0, 1, -1); - month_range = new Util.DateRange (month_start, month_end); + Settings.SavedState.get_default ().display_page = display_start.format ("%Y-%m-%d"); + + DateTime display_end; + if (num_weeks > 1) { + display_end = display_start.add_full (0, 1, -1); + } else { + display_end = display_start.add_full (0, 0, 6); + } + display_range = new Util.DateRange (display_start, display_end); - int dow = month_start.get_day_of_week (); + int dow = display_start.get_day_of_week (); int wso = (int) week_starts_on; int offset = 0; @@ -298,9 +318,9 @@ public class Maya.Model.CalendarModel : Object { offset = 7 + dow - wso; } - var data_range_first = month_start.add_days (-offset); + var data_range_first = display_start.add_days (-offset); - dow = month_end.get_day_of_week (); + dow = display_end.get_day_of_week (); wso = (int) (week_starts_on + 6); // WSO must be between 1 and 7 @@ -314,12 +334,12 @@ public class Maya.Model.CalendarModel : Object { else if (wso > dow) offset = wso - dow; - var data_range_last = month_end.add_days (offset); + var data_range_last = display_end.add_days (offset); data_range = new Util.DateRange (data_range_first, data_range_last); num_weeks = data_range.to_list ().size / 7; - debug (@"Date ranges: ($data_range_first <= $month_start < $month_end <= $data_range_last)"); + debug (@"Date ranges: ($data_range_first <= $display_start < $display_end <= $data_range_last)"); } private void load_source (E.Source source) { diff --git a/core/Settings/SavedState.vala b/core/Settings/SavedState.vala index 2682f9ff5..5b0c33ba1 100644 --- a/core/Settings/SavedState.vala +++ b/core/Settings/SavedState.vala @@ -16,6 +16,7 @@ // namespace Maya.Settings { + public class SavedState : Granite.Services.Settings { private static Settings.SavedState? saved_state = null; @@ -25,21 +26,34 @@ namespace Maya.Settings { return saved_state; } - public string month_page { get; set; } + public string display_mode { get; set; } + public string display_page { get; set; } public string selected_day { get; set; } private SavedState () { base ("io.elementary.calendar.savedstate"); } + public Maya.DisplayMode get_mode () { + switch (display_mode) { + case "week": + return Maya.DisplayMode.WEEK; + default: + return Maya.DisplayMode.MONTH; + } + } + public DateTime get_page () { - if (month_page == null) + if (display_page == null) return new DateTime.now_local (); - if (month_page == "") + if (display_page == "") return new DateTime.now_local (); - var numbers = month_page.split ("-", 2); + var numbers = display_page.split ("-", 3); var dt = new DateTime.local (int.parse (numbers[0]), 1, 1, 0, 0, 0); dt = dt.add_months (int.parse (numbers[1]) - 1); + if (numbers.length > 2) { + dt = dt.add_days (int.parse (numbers[2]) - 1); + } return dt; } diff --git a/core/Utils.vala b/core/Utils.vala index eed908d9d..f14f996b7 100644 --- a/core/Utils.vala +++ b/core/Utils.vala @@ -182,6 +182,103 @@ namespace Maya.Util { return new DateTime.local (date.get_year (), date.get_month (), 1, 0, 0, 0); } + /** + * TODO: This implementation needs some more work + */ + public int get_days_in_month (DateTime datetime) { + DateMonth month; + + switch (datetime.get_month ()) { + case 1: + month = DateMonth.JANUARY; + break; + case 2: + month = DateMonth.FEBRUARY; + break; + case 3: + month = DateMonth.MARCH; + break; + case 4: + month = DateMonth.APRIL; + break; + case 5: + month = DateMonth.MAY; + break; + case 6: + month = DateMonth.JUNE; + break; + case 7: + month = DateMonth.JULY; + break; + case 8: + month = DateMonth.AUGUST; + break; + case 9: + month = DateMonth.SEPTEMBER; + break; + case 10: + month = DateMonth.OCTOBER; + break; + case 11: + month = DateMonth.NOVEMBER; + break; + case 12: + month = DateMonth.DECEMBER; + break; + default: + month = DateMonth.BAD_MONTH; + break; + } + + // TODO: Make DateYear dynamic: datetime.get_year () + // how do I convert int into ushort ...?! + DateYear year = 2020; + + return month.get_days_in_month (year); + } + + /** + * The implementation might not work on every platform. See GNOME Calendar's + * implementation for a more comprehensive approach if needed: + * https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/utils/gcal-utils.c#L301 + */ + public int get_first_weekday () { + return Posix.NLTime.FIRST_WEEKDAY.to_string ().data[0]; + } + + /** + * Retrieves the first day of the week @date is in, at 00:00 + * of the local timezone. + * + * This date is inclusive. + */ + public DateTime get_start_of_week (DateTime date) { + var first_weekday = get_first_weekday (); + var weekday = date.get_day_of_week () % 7; + var n_days_after_week_start = (weekday - first_weekday) % 7; + + var start_of_week = date.add_days (-n_days_after_week_start); + + return new DateTime.local ( + start_of_week.get_year (), + start_of_week.get_month (), + start_of_week.get_day_of_month (), + 0, 0, 0); + } + + + /** + * Retrieves the last day of the week @date is in, at 23:59:59 + * of the local timezone. + * + * Because this date is exclusive, it actually is start of the + * next week. + */ + public DateTime get_end_of_week (DateTime date) { + var week_start = get_start_of_week (date); + return week_start.add_weeks (1); + } + public DateTime strip_time (DateTime datetime) { return datetime.add_full (0, 0, 0, -datetime.get_hour (), -datetime.get_minute (), -datetime.get_second ()); } diff --git a/core/meson.build b/core/meson.build index 87280c33d..4c9362e7d 100644 --- a/core/meson.build +++ b/core/meson.build @@ -17,6 +17,7 @@ core_files = files( 'Model/CalendarModel.vala', 'Settings/SavedState.vala', 'DateRange.vala', + 'DisplayMode.vala', 'Utils.vala', 'GesturesUtils.vala' ) diff --git a/daemon/Daemon.vala b/daemon/Daemon.vala index 961760788..905c83a60 100644 --- a/daemon/Daemon.vala +++ b/daemon/Daemon.vala @@ -47,7 +47,7 @@ namespace Maya { model.events_added.connect (on_events_added); model.events_updated.connect (on_events_updated); model.events_removed.connect (on_events_removed); - model.month_start = Maya.Util.get_start_of_month (new DateTime.now_local ()); + model.display_start = Maya.Util.get_start_of_month (new DateTime.now_local ()); } private void on_events_added (E.Source source, Gee.Collection events) { diff --git a/data/io.elementary.calendar.gschema.xml b/data/io.elementary.calendar.gschema.xml index 58b57cb8d..357f8c5c7 100644 --- a/data/io.elementary.calendar.gschema.xml +++ b/data/io.elementary.calendar.gschema.xml @@ -27,10 +27,15 @@ Whether or not to show weeknumbers. Whether or not to show weeknumbers. - + "" - The current year-month that is shown. - The current year-month that is shown. + The current year-month-day that is shown. + The current year-month-day that is shown. + + + "month" + The calendars display mode. + In which display mode the calendar should be shown ("month", "week"). "" diff --git a/src/Application.vala b/src/Application.vala index 31268863a..f11e74b1f 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -68,7 +68,8 @@ namespace Maya { datetime = datetime.add_years ((int)date.get_year () - datetime.get_year ()); datetime = datetime.add_days ((int)date.get_day_of_year () - datetime.get_day_of_year ()); Settings.SavedState.get_default ().selected_day = datetime.format ("%Y-%j"); - Settings.SavedState.get_default ().month_page = datetime.format ("%Y-%m"); + Settings.SavedState.get_default ().display_page = datetime.format ("%Y-%m-%d"); + Settings.SavedState.get_default ().display_mode = "month"; } else { warning ("Invalid date '%s' - Ignoring", Option.show_day); } diff --git a/src/Grid/CalendarView.vala b/src/Grid/CalendarView.vala index 6da6c019c..95d34a118 100644 --- a/src/Grid/CalendarView.vala +++ b/src/Grid/CalendarView.vala @@ -133,8 +133,8 @@ public class Maya.View.CalendarView : Gtk.Grid { var today = Util.strip_time (new DateTime.now_local ()); var calmodel = Model.CalendarModel.get_default (); var start = Util.get_start_of_month (today); - if (!start.equal (calmodel.month_start)) - calmodel.month_start = start; + if (!start.equal (calmodel.display_start)) + calmodel.display_start = start; sync_with_model (); grid.focus_date (today); } @@ -212,11 +212,11 @@ public class Maya.View.CalendarView : Gtk.Grid { header.update_columns (model.week_starts_on); weeks.update (model.data_range.first_dt, model.num_weeks); - grid.set_range (model.data_range, model.month_start); + grid.set_range (model.data_range, model.display_start); // keep focus date on the same day of the month if (selected_date != null) { - var bumpdate = model.month_start.add_days (selected_date.get_day_of_month () - 1); + var bumpdate = model.display_start.add_days (selected_date.get_day_of_month () - 1); grid.focus_date (bumpdate); } diff --git a/src/Grid/Grid.vala b/src/Grid/Grid.vala index 100dff1b1..dae128046 100644 --- a/src/Grid/Grid.vala +++ b/src/Grid/Grid.vala @@ -6,12 +6,12 @@ * 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 . * @@ -68,8 +68,8 @@ public class Grid : Gtk.Grid { selection_changed (selected_date); Settings.SavedState.get_default ().selected_day = selected_date.format ("%Y-%j"); var calmodel = Maya.Model.CalendarModel.get_default (); - var date_month = selected_date.get_month () - calmodel.month_start.get_month (); - var date_year = selected_date.get_year () - calmodel.month_start.get_year (); + var date_month = selected_date.get_month () - calmodel.display_start.get_month (); + var date_year = selected_date.get_year () - calmodel.display_start.get_year (); if (date_month != 0 || date_year != 0) { calmodel.change_month (date_month); calmodel.change_year (date_year); diff --git a/src/Week/EventWidget.vala b/src/Week/EventWidget.vala new file mode 100644 index 000000000..1961e256a --- /dev/null +++ b/src/Week/EventWidget.vala @@ -0,0 +1,147 @@ +/*- + * Copyright (c) 2020 elementary, Inc. (https://elementary.io) + * + * 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 . + * + * Authored by: Marco Betschart + */ + +namespace Maya.Week { + + /** + * TODO: Documentation + * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/gui/gcal-event-widget.ui + */ + public class EventWidget : Gtk.GtkBin { + + private Gtk.Stack stack; + private Gtk.Grid horizontal_grid; + private Gtk.Grid vertical_grid; + + private Gtk.Label hour_label; + private Gtk.Label summary_label; + + public ECal.Component event { get; construct; } + public E.Source source { get; construct; } + + private DateTime date_start; + private DateTime date_end; + + private string css_class; + + public EventButton (ECal.Component event, E.Source source) { + Object (event: event, source: source); + } + + construct { + summary_label = new Gtk.Label (); + summary_label.can_focus = false; + summary_label.hexpand = true; + summary_label.xalign = 0.0; + summary_label.ellipsize = Pango.EllipsizeMode.END; + + hour_label = new Gtk.Label (); + hour_label.can_focus = false; + hour_label.no_show_all = true; + hour_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); + + /* -- Horizontal Page -- */ + + horizontal_grid = new Gtk.Grid (); + horizontal_grid.orientation = Gtk.Orientation.HORIZONTAL; + horizontal_grid.column_spacing = 4; + horizontal_grid.can_focus = false; + + horizontal_grid.attach (summary_label, 1, 0); + horizontal_grid.attach (hour_label, 2, 0); + + /* -- Vertical Page -- */ + + var vertical_hour_label = new Gtk.Label (); + vertical_hour_label.can_focus = false; + vertical_hour_label.xalign = 0.0; + vertical_hour_label.bind ("label", hour_label, "label", SettingsBindFlags.DEFAULT); + vertical_hour_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); + + var vertical_summary_label = new Gtk.Label (); + vertical_summary_label.can_focus = false; + vertical_summary_label.hexpand = true; + vertical_summary_label.xalign = 0.0; + vertical_summary_label.ellipsize = Pango.EllipsizeMode.END; + vertical_summary_label.bind ("label", summary_label, "label", SettingsBindFlags.DEFAULT); + + vertical_grid = new Gtk.Grid (); + vertical_grid.orientation = Gtk.Orientation.VERTICAL; + vertical_grid.can_focus = false; + + vertical_grid.attach (vertical_hour_label, 0, 0); + vertical_grid.attach (vertical_summary_label, 0, 1); + + /* -- Switch Page -- */ + + stack = new Gtk.Stack (); + stack.can_focus = false; + stack.hexpand = false; + stack.margin_top = stack.margin_bottom = 1; + stack.margin_start = 6; + stack.margin_end = 4; + stack.homogeneous = false; + + stack.add (horizontal_grid); + stack.add (vertical_grid); + + update_request (); + } + + private void update_request () { + unowned ICal.Component comp = event.get_icalcomponent (); + + date_start = Maya.Util.ical_to_date_time (comp.get_dtstart ()); + date_end = Maya.Util.ical_to_date_time (comp.get_dtend ()); + + /* Update color */ + update_color (); + + /* Summary label */ + summary_label.label = comp.get_summary (); + + /* Hour label */ + var local_start_time = date_start.to_local (); + + // TODO: if (self->clock_format_24h) + hour_label.label = local_start_time.format ("%R"); + // TODO: else: g_date_time_format (local_start_time, "%I:%M %P"); + } + + private void update_color () { + E.SourceCalendar cal = (E.SourceCalendar)source.get_extension (E.SOURCE_EXTENSION_CALENDAR); + + var style_context = get_style_context (); + var color = cal.color; + var now = new DateTime.now_local () + var date_compare = date_end.compare (now); + + /* Fades out an event that's earlier than the current date */ + opacity = date_compare < 0 ? 0.6 : 1.0; + + /* Remove the old style class */ + style_context.remove_class (css_class); + + var color_id = Quark.from_string (color); + + css_class = "color-%d".printf (color_id); + style_context.add_class (css_class); + } + } +} diff --git a/src/Week/Grid.vala b/src/Week/Grid.vala index 87b24f589..9c9183cce 100644 --- a/src/Week/Grid.vala +++ b/src/Week/Grid.vala @@ -299,6 +299,9 @@ namespace Maya.Week { * Puts the given event on the grid. */ public void add_event (ECal.Component event) { + critical ("add_event..."); + + /*foreach (var grid_day in data.values) { if (Util.calcomp_is_on_day (event, grid_day.date)) { var button = new EventButton (event); diff --git a/src/Week/Header.vala b/src/Week/Header.vala index 939c7c155..c1689fbc4 100644 --- a/src/Week/Header.vala +++ b/src/Week/Header.vala @@ -43,7 +43,7 @@ namespace Maya.Week { construct { active_date = new DateTime.now_local (); - first_weekday = Util.get_first_weekday (); + first_weekday = Maya.Util.get_first_weekday (); var style_context = get_style_context (); style_context.add_class ("week-header"); @@ -166,7 +166,7 @@ namespace Maya.Week { bold_font.set_weight (Pango.Weight.MEDIUM); pango_layout.set_font_description (bold_font); - week_start = Util.get_start_of_week (active_date); + week_start = Maya.Util.get_start_of_week (active_date); week_end = week_start.add_days (6); current_cell = active_date.get_day_of_week () - 1; @@ -186,7 +186,7 @@ namespace Maya.Week { for (i = 0; i < 7; i++) { var day = week_start.add_days (i); var n_day = day.get_day_of_month (); - var days_in_month = Util.get_days_in_month (week_start); + var days_in_month = Maya.Util.get_days_in_month (week_start); string weekday_abv, weekday; int font_width, day_num_font_height, day_num_font_baseline; diff --git a/src/Week/Util.vala b/src/Week/Util.vala index b701df102..56213dc23 100644 --- a/src/Week/Util.vala +++ b/src/Week/Util.vala @@ -27,97 +27,4 @@ namespace Maya.Week.Util { internal double aligned (double x) { return Math.round (x) + 0.5; } - - /** - * TODO: https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/utils/gcal-utils.c#L301 - */ - internal int get_first_weekday () { - return 0; - } - - - /** - * Retrieves the first day of the week @date is in, at 00:00 - * of the local timezone. - * - * This date is inclusive. - */ - internal DateTime get_start_of_week (DateTime date) { - var first_weekday = get_first_weekday (); - var weekday = date.get_day_of_week () % 7; - var n_days_after_week_start = (weekday - first_weekday) % 7; - - var start_of_week = date.add_days (-n_days_after_week_start); - - return new DateTime.local ( - start_of_week.get_year (), - start_of_week.get_month (), - start_of_week.get_day_of_month (), - 0, 0, 0); - } - - - /** - * Retrieves the last day of the week @date is in, at 23:59:59 - * of the local timezone. - * - * Because this date is exclusive, it actually is start of the - * next week. - */ - internal DateTime get_end_of_week (DateTime date) { - var week_start = get_start_of_week (date); - return week_start.add_weeks (1); - } - - internal int get_days_in_month (DateTime datetime) { - DateMonth month; - - switch (datetime.get_month ()) { - case 1: - month = DateMonth.JANUARY; - break; - case 2: - month = DateMonth.FEBRUARY; - break; - case 3: - month = DateMonth.MARCH; - break; - case 4: - month = DateMonth.APRIL; - break; - case 5: - month = DateMonth.MAY; - break; - case 6: - month = DateMonth.JUNE; - break; - case 7: - month = DateMonth.JULY; - break; - case 8: - month = DateMonth.AUGUST; - break; - case 9: - month = DateMonth.SEPTEMBER; - break; - case 10: - month = DateMonth.OCTOBER; - break; - case 11: - month = DateMonth.NOVEMBER; - break; - case 12: - month = DateMonth.DECEMBER; - break; - default: - month = DateMonth.BAD_MONTH; - break; - } - - // TODO: Make DateYear dynamic: datetime.get_year () - // how do I convert int into ushort ...?! - DateYear year = 2020; - - return month.get_days_in_month (year); - } } diff --git a/src/Widgets/HeaderBar.vala b/src/Widgets/HeaderBar.vala index fa1e82c25..1f58e1afa 100644 --- a/src/Widgets/HeaderBar.vala +++ b/src/Widgets/HeaderBar.vala @@ -65,7 +65,7 @@ namespace Maya.View { month_switcher = new Widgets.DateSwitcher (10); year_switcher = new Widgets.DateSwitcher (-1); var calmodel = Model.CalendarModel.get_default (); - set_switcher_date (calmodel.month_start); + set_switcher_date (calmodel.display_start); var contractor = new Widgets.ContractorButtonWithMenu (_("Export or Share the default Calendar")); @@ -89,7 +89,7 @@ namespace Maya.View { year_switcher.left_clicked.connect (() => Model.CalendarModel.get_default ().change_year (-1)); year_switcher.right_clicked.connect (() => Model.CalendarModel.get_default ().change_year (1)); calmodel.parameters_changed.connect (() => { - set_switcher_date (calmodel.month_start); + set_switcher_date (calmodel.display_start); }); } From a81dfb8c021d3f9b52f45e8fa929cd58c1317b49 Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Thu, 23 Apr 2020 07:24:11 +0000 Subject: [PATCH 19/22] Distinguish where to put an event --- core/Utils.vala | 6 ++++ src/Week/Grid.vala | 27 ++++++++++++++--- src/Week/Header.vala | 34 +++++++++++++++++++++ src/Week/View.vala | 72 ++++++++++++++------------------------------ 4 files changed, 86 insertions(+), 53 deletions(-) diff --git a/core/Utils.vala b/core/Utils.vala index f14f996b7..969e131e5 100644 --- a/core/Utils.vala +++ b/core/Utils.vala @@ -162,6 +162,12 @@ namespace Maya.Util { return false; } + public bool is_all_day_event (ICal.Component comp) { + DateTime start, end; + get_local_datetimes_from_icalcomponent (comp, out start, out end); + return is_all_day (start, end); + } + /** * Say if an event lasts all day. */ diff --git a/src/Week/Grid.vala b/src/Week/Grid.vala index 9c9183cce..13ac4ebb6 100644 --- a/src/Week/Grid.vala +++ b/src/Week/Grid.vala @@ -298,10 +298,9 @@ namespace Maya.Week { /** * Puts the given event on the grid. */ - public void add_event (ECal.Component event) { - critical ("add_event..."); - - + public void add_event (E.Source source, ECal.Component event) { + critical ("grid.add_event..."); + /*foreach (var grid_day in data.values) { if (Util.calcomp_is_on_day (event, grid_day.date)) { var button = new EventButton (event); @@ -310,6 +309,26 @@ namespace Maya.Week { } */ } + /** + * Removes the given event from the grid. + */ + public void remove_event (E.Source source, ECal.Component event) { + critical ("grid.remove_event..."); + /*foreach (var grid_day in data.values) { + grid_day.remove_event (event); + }*/ + } + + /** + * Removes all events from the grid. + */ + public void remove_all_events () { + critical ("grid.remove_all_events..."); + /*foreach (var grid_day in data.values) { + grid_day.clear_events (); + }*/ + } + public override void remove (Gtk.Widget widget) { if (widget.get_parent () != null) { widget.unparent (); diff --git a/src/Week/Header.vala b/src/Week/Header.vala index c1689fbc4..ee0cc8958 100644 --- a/src/Week/Header.vala +++ b/src/Week/Header.vala @@ -268,5 +268,39 @@ namespace Maya.Week { return false; } + + /** + * Puts the given event on the header. + */ + public void add_event (E.Source source, ECal.Component event) { + critical ("header.add_event..."); + + /*foreach (var grid_day in data.values) { + if (Util.calcomp_is_on_day (event, grid_day.date)) { + var button = new EventButton (event); + grid_day.add_event_button (button); + } + } */ + } + + /** + * Removes the given event from the header. + */ + public void remove_event (E.Source source, ECal.Component event) { + critical ("header.remove_event..."); + /*foreach (var grid_day in data.values) { + grid_day.remove_event (event); + }*/ + } + + /** + * Removes all events from the header. + */ + public void remove_all_events () { + critical ("header.remove_all_events..."); + /*foreach (var grid_day in data.values) { + grid_day.clear_events (); + }*/ + } } } diff --git a/src/Week/View.vala b/src/Week/View.vala index 1e78c35d4..e1ca711d5 100644 --- a/src/Week/View.vala +++ b/src/Week/View.vala @@ -37,7 +37,9 @@ namespace Maya.Week { private Sidebar sidebar; private Gtk.SizeGroup sidebar_sizegroup; + private Grid grid; + private Header header; static construct { css_provider = new Gtk.CssProvider (); @@ -69,14 +71,14 @@ namespace Maya.Week { scrolled_window.expand = true; scrolled_window.add (viewport); - var header = new Header (sidebar_sizegroup); + header = new Header (sidebar_sizegroup); add (header); add (scrolled_window); update_hours_sidebar_size (); - sync_with_model (); + //sync_with_model (); var model = Model.CalendarModel.get_default (); model.parameters_changed.connect (on_model_parameters_changed); @@ -165,61 +167,33 @@ namespace Maya.Week { //--- Helper Methods ---// - /* Sets the calendar widgets to the date range of the model */ - void sync_with_model () { - /* - var model = Model.CalendarModel.get_default (); - if (grid.grid_range != null && (model.data_range.equals (grid.grid_range) || grid.grid_range.first_dt.compare (model.data_range.first_dt) == 0)) - return; // nothing to do - - DateTime previous_first = null; - if (grid.grid_range != null) - previous_first = grid.grid_range.first_dt; - - big_grid = create_big_grid (); - stack.add (big_grid); - - header.update_columns (model.week_starts_on); - weeks.update (model.data_range.first_dt, model.num_weeks); - grid.set_range (model.data_range, model.month_start); + /* Render new event in the view */ + private void add_event (E.Source source, ECal.Component event) { + unowned ICal.Component comp = event.get_icalcomponent (); - // keep focus date on the same day of the month - if (selected_date != null) { - var bumpdate = model.month_start.add_days (selected_date.get_day_of_month () - 1); - grid.focus_date (bumpdate); + if (Maya.Util.is_multiday_event (comp) || Maya.Util.is_all_day_event (comp)) { + header.add_event (source, event); + } else { + grid.add_event (source, event); } - - if (previous_first != null) { - if (previous_first.compare (grid.grid_range.first_dt) == -1) { - stack.transition_type = Gtk.StackTransitionType.SLIDE_UP; - } else { - stack.transition_type = Gtk.StackTransitionType.SLIDE_DOWN; - } - } - - stack.set_visible_child (big_grid); */ - } - - /* Render new event on the grid */ - void add_event (E.Source source, ECal.Component event) { - critical ("add_event"); - //event.set_data ("source", source); - grid.add_event (event); } - /* Update the event on the grid */ - void update_event (E.Source source, ECal.Component event) { - // grid.update_event (event); + /* Update the event in the view */ + private void update_event (E.Source source, ECal.Component event) { + remove_event (source, event); + add_event (source, event); } - /* Remove event from the grid */ - void remove_event (E.Source source, ECal.Component event) { - //grid.remove_event (event); + /* Remove event from the view */ + private void remove_event (E.Source source, ECal.Component event) { + header.remove_event (source, event); + grid.remove_event (source, event); } - /* Remove all events from the grid */ - void remove_all_events () { - //grid.remove_all_events (); + /* Remove all events from the view */ + private void remove_all_events () { + header.remove_all_events (); + grid.remove_all_events (); } } } From d01a919198c61c5210275c11f75e5f38e5f60464 Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Thu, 23 Apr 2020 09:53:36 +0000 Subject: [PATCH 20/22] Did some code cleanup --- src/MainWindow.vala | 7 +- src/Week/EventWidget.vala | 147 -------------------- src/Week/{Grid.vala => WeekGrid.vala} | 24 ++-- src/Week/{Header.vala => WeekHeader.vala} | 18 +-- src/Week/{Sidebar.vala => WeekSidebar.vala} | 12 +- src/Week/{Util.vala => WeekUtil.vala} | 2 +- src/Week/{View.vala => WeekView.vala} | 42 ++---- src/meson.build | 10 +- 8 files changed, 46 insertions(+), 216 deletions(-) delete mode 100644 src/Week/EventWidget.vala rename src/Week/{Grid.vala => WeekGrid.vala} (92%) rename src/Week/{Header.vala => WeekHeader.vala} (93%) rename src/Week/{Sidebar.vala => WeekSidebar.vala} (93%) rename src/Week/{Util.vala => WeekUtil.vala} (97%) rename src/Week/{View.vala => WeekView.vala} (81%) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 74d63e7ed..87b100fb9 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -21,7 +21,7 @@ public class Maya.MainWindow : Gtk.ApplicationWindow { private Gtk.Stack calview_stack; - private Week.View week_view; + private View.WeekView week_view; private Gtk.Paned hpaned; public View.CalendarView calview; @@ -83,7 +83,7 @@ public class Maya.MainWindow : Gtk.ApplicationWindow { calview = new View.CalendarView (); calview.vexpand = true; - week_view = new Week.View (); + week_view = new View.WeekView (); hpaned = new Gtk.Paned (Gtk.Orientation.HORIZONTAL); hpaned.pack1 (calview, true, false); @@ -107,9 +107,6 @@ public class Maya.MainWindow : Gtk.ApplicationWindow { calview.on_event_add.connect ((date) => on_tb_add_clicked (date)); calview.selection_changed.connect ((date) => sidebar.set_selected_date (date)); - week_view.on_event_add.connect ((date) => on_tb_add_clicked (date)); - week_view.selection_changed.connect ((date) => sidebar.set_selected_date (date)); - infobar.response.connect ((id) => infobar.hide ()); sidebar.event_removed.connect (on_remove); diff --git a/src/Week/EventWidget.vala b/src/Week/EventWidget.vala deleted file mode 100644 index 1961e256a..000000000 --- a/src/Week/EventWidget.vala +++ /dev/null @@ -1,147 +0,0 @@ -/*- - * Copyright (c) 2020 elementary, Inc. (https://elementary.io) - * - * 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 . - * - * Authored by: Marco Betschart - */ - -namespace Maya.Week { - - /** - * TODO: Documentation - * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/gui/gcal-event-widget.ui - */ - public class EventWidget : Gtk.GtkBin { - - private Gtk.Stack stack; - private Gtk.Grid horizontal_grid; - private Gtk.Grid vertical_grid; - - private Gtk.Label hour_label; - private Gtk.Label summary_label; - - public ECal.Component event { get; construct; } - public E.Source source { get; construct; } - - private DateTime date_start; - private DateTime date_end; - - private string css_class; - - public EventButton (ECal.Component event, E.Source source) { - Object (event: event, source: source); - } - - construct { - summary_label = new Gtk.Label (); - summary_label.can_focus = false; - summary_label.hexpand = true; - summary_label.xalign = 0.0; - summary_label.ellipsize = Pango.EllipsizeMode.END; - - hour_label = new Gtk.Label (); - hour_label.can_focus = false; - hour_label.no_show_all = true; - hour_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); - - /* -- Horizontal Page -- */ - - horizontal_grid = new Gtk.Grid (); - horizontal_grid.orientation = Gtk.Orientation.HORIZONTAL; - horizontal_grid.column_spacing = 4; - horizontal_grid.can_focus = false; - - horizontal_grid.attach (summary_label, 1, 0); - horizontal_grid.attach (hour_label, 2, 0); - - /* -- Vertical Page -- */ - - var vertical_hour_label = new Gtk.Label (); - vertical_hour_label.can_focus = false; - vertical_hour_label.xalign = 0.0; - vertical_hour_label.bind ("label", hour_label, "label", SettingsBindFlags.DEFAULT); - vertical_hour_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); - - var vertical_summary_label = new Gtk.Label (); - vertical_summary_label.can_focus = false; - vertical_summary_label.hexpand = true; - vertical_summary_label.xalign = 0.0; - vertical_summary_label.ellipsize = Pango.EllipsizeMode.END; - vertical_summary_label.bind ("label", summary_label, "label", SettingsBindFlags.DEFAULT); - - vertical_grid = new Gtk.Grid (); - vertical_grid.orientation = Gtk.Orientation.VERTICAL; - vertical_grid.can_focus = false; - - vertical_grid.attach (vertical_hour_label, 0, 0); - vertical_grid.attach (vertical_summary_label, 0, 1); - - /* -- Switch Page -- */ - - stack = new Gtk.Stack (); - stack.can_focus = false; - stack.hexpand = false; - stack.margin_top = stack.margin_bottom = 1; - stack.margin_start = 6; - stack.margin_end = 4; - stack.homogeneous = false; - - stack.add (horizontal_grid); - stack.add (vertical_grid); - - update_request (); - } - - private void update_request () { - unowned ICal.Component comp = event.get_icalcomponent (); - - date_start = Maya.Util.ical_to_date_time (comp.get_dtstart ()); - date_end = Maya.Util.ical_to_date_time (comp.get_dtend ()); - - /* Update color */ - update_color (); - - /* Summary label */ - summary_label.label = comp.get_summary (); - - /* Hour label */ - var local_start_time = date_start.to_local (); - - // TODO: if (self->clock_format_24h) - hour_label.label = local_start_time.format ("%R"); - // TODO: else: g_date_time_format (local_start_time, "%I:%M %P"); - } - - private void update_color () { - E.SourceCalendar cal = (E.SourceCalendar)source.get_extension (E.SOURCE_EXTENSION_CALENDAR); - - var style_context = get_style_context (); - var color = cal.color; - var now = new DateTime.now_local () - var date_compare = date_end.compare (now); - - /* Fades out an event that's earlier than the current date */ - opacity = date_compare < 0 ? 0.6 : 1.0; - - /* Remove the old style class */ - style_context.remove_class (css_class); - - var color_id = Quark.from_string (color); - - css_class = "color-%d".printf (color_id); - style_context.add_class (css_class); - } - } -} diff --git a/src/Week/Grid.vala b/src/Week/WeekGrid.vala similarity index 92% rename from src/Week/Grid.vala rename to src/Week/WeekGrid.vala index 13ac4ebb6..22a84726b 100644 --- a/src/Week/Grid.vala +++ b/src/Week/WeekGrid.vala @@ -17,13 +17,13 @@ * Authored by: Marco Betschart */ -namespace Maya.Week { +namespace Maya.View { /** * TODO: Documentation * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-grid.c */ - public class Grid : Gtk.Container { + public class WeekGrid : Gtk.Container { private Gdk.Window event_window; @@ -60,7 +60,7 @@ namespace Maya.Week { Gtk.drag_dest_set (this, Gtk.DestDefaults.ALL, null, Gdk.DragAction.MOVE); var style_context = get_style_context (); - style_context.add_provider (View.css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + style_context.add_provider (WeekView.style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); } public override void realize () { @@ -135,7 +135,7 @@ namespace Maya.Week { } /* Preliminary calculations */ - minutes_height = allocation.height / Util.MINUTES_PER_DAY; + minutes_height = allocation.height / WeekUtil.MINUTES_PER_DAY; column_width = allocation.width / 7.0; /* Temporary range tree to hold positioned events' indexes */ @@ -206,7 +206,7 @@ namespace Maya.Week { height = get_allocated_height (); double column_width = width / 7.0; - double minutes_height = height / Util.MINUTES_PER_DAY; + double minutes_height = height / WeekUtil.MINUTES_PER_DAY; context.set_line_width (0.65); @@ -224,7 +224,7 @@ namespace Maya.Week { start = start - end; } - column = start * 30 / Util.MINUTES_PER_DAY; + column = start * 30 / WeekUtil.MINUTES_PER_DAY; selection_height = (end - start + 1) * 30 * (int)minutes_height; x = column * column_width; @@ -232,7 +232,7 @@ namespace Maya.Week { style_context.save (); style_context.set_state (state | Gtk.StateFlags.SELECTED); - style_context.render_background (context, Util.aligned (x), Math.round ((start * 30 % Util.MINUTES_PER_DAY) * minutes_height), column_width, selection_height); + style_context.render_background (context, WeekUtil.aligned (x), Math.round ((start * 30 % WeekUtil.MINUTES_PER_DAY) * minutes_height), column_width, selection_height); style_context.restore (); } @@ -243,7 +243,7 @@ namespace Maya.Week { int column, row; cell_height = minutes_height * 30; - column = dnd_cell / (Util.MINUTES_PER_DAY / 30); + column = dnd_cell / (WeekUtil.MINUTES_PER_DAY / 30); row = dnd_cell - column * 48; style_context.render_background (context, column * column_width, row * cell_height, column_width, cell_height); @@ -257,23 +257,23 @@ namespace Maya.Week { x = width - column_width * i; } - context.move_to (Util.aligned (x), 0); + context.move_to (WeekUtil.aligned (x), 0); context.rel_line_to (0, height); } /* Horizontal lines */ for (i = 1; i < 24; i++) { - context.move_to (0, Util.aligned ((height / 24.0) * i)); + context.move_to (0, WeekUtil.aligned ((height / 24.0) * i)); context.rel_line_to (width, 0); } context.stroke (); /* Dashed lines between the vertical lines */ - context.set_dash (Util.dashed, 2); + context.set_dash (WeekUtil.dashed, 2); for (i = 0; i < 24; i++) { - context.move_to (0, Util.aligned((height / 24.0) * i + (height / 48.0))); + context.move_to (0, WeekUtil.aligned((height / 24.0) * i + (height / 48.0))); context.rel_line_to (width, 0); } diff --git a/src/Week/Header.vala b/src/Week/WeekHeader.vala similarity index 93% rename from src/Week/Header.vala rename to src/Week/WeekHeader.vala index ee0cc8958..fb1f7f855 100644 --- a/src/Week/Header.vala +++ b/src/Week/WeekHeader.vala @@ -17,13 +17,13 @@ * Authored by: Marco Betschart */ -namespace Maya.Week { +namespace Maya.View { /** * TODO: Documentation * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-header.ui */ - public class Header : Gtk.Box { + public class WeekHeader : Gtk.Box { public Gtk.SizeGroup sidebar_sizegroup { get; construct; } @@ -33,7 +33,7 @@ namespace Maya.Week { private Gtk.ScrolledWindow scrolled_window; private Gtk.Box expand_button_box; - public Header (Gtk.SizeGroup sidebar_sizegroup) { + public WeekHeader (Gtk.SizeGroup sidebar_sizegroup) { Object ( orientation: Gtk.Orientation.HORIZONTAL, spacing: 0, @@ -47,7 +47,7 @@ namespace Maya.Week { var style_context = get_style_context (); style_context.add_class ("week-header"); - style_context.add_provider (View.css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + style_context.add_provider (WeekView.style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); expand_button_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); sidebar_sizegroup.add_widget (expand_button_box); @@ -215,9 +215,9 @@ namespace Maya.Week { day_num_font_baseline = pango_layout.get_baseline () / Pango.SCALE; if (ltr) { - x = padding.left + cell_width * i + Util.COLUMN_PADDING + start_x; + x = padding.left + cell_width * i + WeekUtil.COLUMN_PADDING + start_x; } else { - x = alloc.width - (cell_width * i + font_width + Util.COLUMN_PADDING + start_x); + x = alloc.width - (cell_width * i + font_width + WeekUtil.COLUMN_PADDING + start_x); } style_context.render_layout (context, x, day_abv_font_height + padding.bottom + start_y, pango_layout); @@ -241,9 +241,9 @@ namespace Maya.Week { pango_layout.get_pixel_size (out font_width, null); if (ltr) { - x = padding.left + cell_width * i + Util.COLUMN_PADDING + start_x; + x = padding.left + cell_width * i + WeekUtil.COLUMN_PADDING + start_x; } else { - x = alloc.width - (cell_width * i + font_width + Util.COLUMN_PADDING + start_x); + x = alloc.width - (cell_width * i + font_width + WeekUtil.COLUMN_PADDING + start_x); } style_context.render_layout (context, x, start_y, pango_layout); @@ -256,7 +256,7 @@ namespace Maya.Week { color = style_context.get_color (state); context.set_source_rgba (color.red, color.green, color.blue, color.alpha); context.set_line_width (0.25); - context.move_to (Util.aligned (ltr ? (cell_width * i + start_x) : (alloc.width - (cell_width * i + start_x))), day_abv_font_height + padding.bottom + start_y); + context.move_to (WeekUtil.aligned (ltr ? (cell_width * i + start_x) : (alloc.width - (cell_width * i + start_x))), day_abv_font_height + padding.bottom + start_y); context.rel_line_to (0.0, get_allocated_height () - day_abv_font_height - start_y + padding.bottom); context.stroke (); diff --git a/src/Week/Sidebar.vala b/src/Week/WeekSidebar.vala similarity index 93% rename from src/Week/Sidebar.vala rename to src/Week/WeekSidebar.vala index 8319a8133..e39c0236d 100644 --- a/src/Week/Sidebar.vala +++ b/src/Week/WeekSidebar.vala @@ -17,17 +17,17 @@ * Authored by: Marco Betschart */ -namespace Maya.Week { +namespace Maya.View { /** * TODO: Documentation * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-view.c */ - public class Sidebar : Gtk.DrawingArea { + public class WeekSidebar : Gtk.DrawingArea { public Gtk.SizeGroup sidebar_sizegroup { get; construct; } - public Sidebar (Gtk.SizeGroup sidebar_sizegroup) { + public WeekSidebar (Gtk.SizeGroup sidebar_sizegroup) { Object ( sidebar_sizegroup: sidebar_sizegroup ); @@ -35,10 +35,8 @@ namespace Maya.Week { construct { height_request = 2568; - sidebar_sizegroup.add_widget (this); - - get_style_context ().add_provider (View.css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + get_style_context ().add_provider (WeekView.style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); } public override bool draw (Cairo.Context context) { @@ -115,7 +113,7 @@ namespace Maya.Week { } context.stroke (); - context.set_dash (Util.dashed, 2); + context.set_dash (WeekUtil.dashed, 2); /* Draws the horizontal dashed lines */ for (i = 0; i < 24; i++) { diff --git a/src/Week/Util.vala b/src/Week/WeekUtil.vala similarity index 97% rename from src/Week/Util.vala rename to src/Week/WeekUtil.vala index 56213dc23..1d0ed4f73 100644 --- a/src/Week/Util.vala +++ b/src/Week/WeekUtil.vala @@ -17,7 +17,7 @@ * Authored by: Marco Betschart */ -namespace Maya.Week.Util { +namespace Maya.View.WeekUtil { internal const int MINUTES_PER_DAY = 1440; internal const int MAX_MINUTES = (7 * MINUTES_PER_DAY); diff --git a/src/Week/View.vala b/src/Week/WeekView.vala similarity index 81% rename from src/Week/View.vala rename to src/Week/WeekView.vala index e1ca711d5..e005b4a2d 100644 --- a/src/Week/View.vala +++ b/src/Week/WeekView.vala @@ -17,47 +17,38 @@ * Authored by: Marco Betschart */ -namespace Maya.Week { +namespace Maya.View { /** * TODO: Documentation * - https://gitlab.gnome.org/GNOME/gnome-calendar/-/blob/master/src/views/gcal-week-view.ui */ - public class View : Gtk.Box { + public class WeekView : Gtk.Box { - /* - * Event emitted when the day is double clicked or the ENTER key is pressed. - */ - public signal void on_event_add (DateTime date); - public signal void selection_changed (DateTime new_date); + internal static Gtk.CssProvider style_provider; - public DateTime? selected_date { get; private set; } - - internal static Gtk.CssProvider css_provider; - - private Sidebar sidebar; + private WeekSidebar sidebar; private Gtk.SizeGroup sidebar_sizegroup; - private Grid grid; - private Header header; + private WeekGrid grid; + private WeekHeader header; static construct { - css_provider = new Gtk.CssProvider (); - css_provider.load_from_resource ("/io/elementary/calendar/WeekView.css"); + style_provider = new Gtk.CssProvider (); + style_provider.load_from_resource ("/io/elementary/calendar/WeekView.css"); } construct { - selected_date = Settings.SavedState.get_default ().get_selected (); orientation = Gtk.Orientation.VERTICAL; var style_context = get_style_context (); style_context.add_class ("week-view"); - style_context.add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + style_context.add_provider (style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); sidebar_sizegroup = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL); - sidebar = new Sidebar (sidebar_sizegroup); + sidebar = new WeekSidebar (sidebar_sizegroup); - grid = new Grid (); + grid = new WeekGrid (); grid.expand = true; var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); @@ -71,21 +62,12 @@ namespace Maya.Week { scrolled_window.expand = true; scrolled_window.add (viewport); - header = new Header (sidebar_sizegroup); + header = new WeekHeader (sidebar_sizegroup); add (header); add (scrolled_window); update_hours_sidebar_size (); - - //sync_with_model (); - - var model = Model.CalendarModel.get_default (); - model.parameters_changed.connect (on_model_parameters_changed); - - model.events_added.connect (on_events_added); - model.events_updated.connect (on_events_updated); - model.events_removed.connect (on_events_removed); } private void update_hours_sidebar_size () { diff --git a/src/meson.build b/src/meson.build index a9ba554c2..1a46ac675 100644 --- a/src/meson.build +++ b/src/meson.build @@ -27,11 +27,11 @@ calendar_files = files( 'SourceDialog/SourceDialog.vala', 'SourceDialog/SourceItem.vala', 'SourceDialog/SourceSelector.vala', - 'Week/Grid.vala', - 'Week/Header.vala', - 'Week/Sidebar.vala', - 'Week/Util.vala', - 'Week/View.vala', + 'Week/WeekGrid.vala', + 'Week/WeekHeader.vala', + 'Week/WeekSidebar.vala', + 'Week/WeekUtil.vala', + 'Week/WeekView.vala', 'Widgets/AgendaEventRow.vala', 'Widgets/CalendarButton.vala', 'Widgets/ContractorButtonWithMenu.vala', From e099f30e47e398d1d510053b82e0fa048c27fc8f Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Thu, 23 Apr 2020 11:59:29 +0000 Subject: [PATCH 21/22] Removed all non essential code for rendering a week --- src/Week/WeekHeader.vala | 90 ++++++++++++-------------- src/Week/WeekSidebar.vala | 130 +++++++++++++++++++------------------- src/Week/WeekView.vala | 107 +++++++++---------------------- 3 files changed, 136 insertions(+), 191 deletions(-) diff --git a/src/Week/WeekHeader.vala b/src/Week/WeekHeader.vala index fb1f7f855..d2d72bc14 100644 --- a/src/Week/WeekHeader.vala +++ b/src/Week/WeekHeader.vala @@ -27,31 +27,27 @@ namespace Maya.View { public Gtk.SizeGroup sidebar_sizegroup { get; construct; } - private DateTime active_date; - private int first_weekday; - private Gtk.ScrolledWindow scrolled_window; - private Gtk.Box expand_button_box; + private Gtk.Box top_edge_box; + + private DateTime active_date; public WeekHeader (Gtk.SizeGroup sidebar_sizegroup) { Object ( - orientation: Gtk.Orientation.HORIZONTAL, - spacing: 0, sidebar_sizegroup: sidebar_sizegroup ); } construct { active_date = new DateTime.now_local (); - first_weekday = Maya.Util.get_first_weekday (); var style_context = get_style_context (); style_context.add_class ("week-header"); style_context.add_provider (WeekView.style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); - expand_button_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); - sidebar_sizegroup.add_widget (expand_button_box); - add (expand_button_box); + top_edge_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); + sidebar_sizegroup.add_widget (top_edge_box); + add (top_edge_box); var grid = new Gtk.Grid (); grid.column_homogeneous = true; @@ -81,8 +77,6 @@ namespace Maya.View { add (event_box); } - // TODO: int get_today_column - private int get_weekday_names_height () { Pango.FontDescription font_desc; Gtk.Border padding; @@ -146,7 +140,7 @@ namespace Maya.View { var state = style_context.get_state (); var ltr = get_direction () != Gtk.TextDirection.RTL; - start_x = ltr ? expand_button_box.get_allocated_width () : 0; + start_x = ltr ? top_edge_box.get_allocated_width () : 0; start_y = 0; var padding = style_context.get_padding (state); @@ -155,7 +149,7 @@ namespace Maya.View { get_allocation (out alloc); if (!ltr) { - alloc.width -= expand_button_box.get_allocated_width (); + alloc.width -= top_edge_box.get_allocated_width (); } color = style_context.get_color (state); @@ -170,7 +164,7 @@ namespace Maya.View { week_end = week_start.add_days (6); current_cell = active_date.get_day_of_week () - 1; - current_cell = (7 + current_cell - first_weekday) % 7; + current_cell = (7 + current_cell - Util.get_first_weekday ()) % 7; today_column = 2; // TODO: get_today_column (); cell_width = (alloc.width - start_x) / 7.0; @@ -269,38 +263,38 @@ namespace Maya.View { return false; } - /** - * Puts the given event on the header. - */ - public void add_event (E.Source source, ECal.Component event) { - critical ("header.add_event..."); - - /*foreach (var grid_day in data.values) { - if (Util.calcomp_is_on_day (event, grid_day.date)) { - var button = new EventButton (event); - grid_day.add_event_button (button); - } - } */ - } - - /** - * Removes the given event from the header. - */ - public void remove_event (E.Source source, ECal.Component event) { - critical ("header.remove_event..."); - /*foreach (var grid_day in data.values) { - grid_day.remove_event (event); - }*/ - } - - /** - * Removes all events from the header. - */ - public void remove_all_events () { - critical ("header.remove_all_events..."); - /*foreach (var grid_day in data.values) { - grid_day.clear_events (); - }*/ - } + // /** + // * Puts the given event on the header. + // */ + // public void add_event (E.Source source, ECal.Component event) { + // critical ("header.add_event..."); + + // /*foreach (var grid_day in data.values) { + // if (Util.calcomp_is_on_day (event, grid_day.date)) { + // var button = new EventButton (event); + // grid_day.add_event_button (button); + // } + // } */ + // } + + // /** + // * Removes the given event from the header. + // */ + // public void remove_event (E.Source source, ECal.Component event) { + // critical ("header.remove_event..."); + // /*foreach (var grid_day in data.values) { + // grid_day.remove_event (event); + // }*/ + // } + + // /** + // * Removes all events from the header. + // */ + // public void remove_all_events () { + // critical ("header.remove_all_events..."); + // /*foreach (var grid_day in data.values) { + // grid_day.clear_events (); + // }*/ + // } } } diff --git a/src/Week/WeekSidebar.vala b/src/Week/WeekSidebar.vala index e39c0236d..ac837f2e1 100644 --- a/src/Week/WeekSidebar.vala +++ b/src/Week/WeekSidebar.vala @@ -40,91 +40,91 @@ namespace Maya.View { } public override bool draw (Cairo.Context context) { - Gdk.RGBA color; - int i; - //var time_format = ?? + Gdk.RGBA color; + int i; + //var time_format = ?? - var style_context = get_style_context (); - var state = style_context.get_state (); - var ltr = get_direction () != Gtk.TextDirection.RTL; + var style_context = get_style_context (); + var state = style_context.get_state (); + var ltr = get_direction () != Gtk.TextDirection.RTL; - style_context.save (); - style_context.add_class ("hours"); + style_context.save (); + style_context.add_class ("hours"); - color = style_context.get_color (state); - var padding = style_context.get_padding (state); + color = style_context.get_color (state); + var padding = style_context.get_padding (state); - Pango.FontDescription font_desc; - style_context.@get (state, "font", out font_desc, null); + Pango.FontDescription font_desc; + style_context.@get (state, "font", out font_desc, null); - var pango_layout = Pango.cairo_create_layout (context); - pango_layout.set_font_description (font_desc); + var pango_layout = Pango.cairo_create_layout (context); + pango_layout.set_font_description (font_desc); - context.set_source_rgba (color.red, color.green, color.blue, color.alpha); + context.set_source_rgba (color.red, color.green, color.blue, color.alpha); - /* Gets the size of the widget */ - var width = get_allocated_width (); - var height = get_allocated_height (); + /* Gets the size of the widget */ + var width = get_allocated_width (); + var height = get_allocated_height (); - /* Draws the hours in the sidebar */ - for (i = 0; i < 24; i++) { - string hours; + /* Draws the hours in the sidebar */ + for (i = 0; i < 24; i++) { + string hours; - // TODO: Honor User Time Format (12/24h): - // if (time_format == GCAL_TIME_FORMAT_24H): - hours = "%02d:00".printf(i); - // else: - /*hours = "%d %s".printf ( - i % 12 == 0 ? 12 : i % 12, - i >= 12 ? _("PM") : _("AM") - );*/ + // TODO: Honor User Time Format (12/24h): + // if (time_format == GCAL_TIME_FORMAT_24H): + hours = "%02d:00".printf(i); + // else: + /*hours = "%d %s".printf ( + i % 12 == 0 ? 12 : i % 12, + i >= 12 ? _("PM") : _("AM") + );*/ - pango_layout.set_text (hours, -1); + pango_layout.set_text (hours, -1); - int font_width; - pango_layout.get_pixel_size (out font_width, null); + int font_width; + pango_layout.get_pixel_size (out font_width, null); - style_context.render_layout ( - context, - ltr ? padding.left : width - font_width - padding.right, - (height / 24) * i + padding.top, - pango_layout - ); - } + style_context.render_layout ( + context, + ltr ? padding.left : width - font_width - padding.right, + (height / 24) * i + padding.top, + pango_layout + ); + } - style_context.restore (); - style_context.save (); + style_context.restore (); + style_context.save (); - style_context.add_class ("lines"); - color = style_context.get_color (state); + style_context.add_class ("lines"); + color = style_context.get_color (state); - context.set_source_rgba (color.red, color.green, color.blue, color.alpha); - context.set_line_width (0.65); + context.set_source_rgba (color.red, color.green, color.blue, color.alpha); + context.set_line_width (0.65); - if (!ltr) { - context.move_to (0.5, 0); - context.rel_line_to (0, height); - } + if (!ltr) { + context.move_to (0.5, 0); + context.rel_line_to (0, height); + } - /* Draws the horizontal complete lines */ - for (i = 1; i < 24; i++) { - context.move_to (0, (height / 24) * i + 0.4); - context.rel_line_to (width, 0); - } + /* Draws the horizontal complete lines */ + for (i = 1; i < 24; i++) { + context.move_to (0, (height / 24) * i + 0.4); + context.rel_line_to (width, 0); + } - context.stroke (); - context.set_dash (WeekUtil.dashed, 2); + context.stroke (); + context.set_dash (WeekUtil.dashed, 2); - /* Draws the horizontal dashed lines */ - for (i = 0; i < 24; i++) { - context.move_to (0, (height / 24) * i + (height / 48) + 0.4); - context.rel_line_to (width, 0); - } + /* Draws the horizontal dashed lines */ + for (i = 0; i < 24; i++) { + context.move_to (0, (height / 24) * i + (height / 48) + 0.4); + context.rel_line_to (width, 0); + } - context.stroke (); - style_context.restore (); + context.stroke (); + style_context.restore (); - return false; - } + return false; + } } } diff --git a/src/Week/WeekView.vala b/src/Week/WeekView.vala index e005b4a2d..b229cbaff 100644 --- a/src/Week/WeekView.vala +++ b/src/Week/WeekView.vala @@ -55,12 +55,9 @@ namespace Maya.View { box.add (sidebar); box.add (grid); - var viewport = new Gtk.Viewport (null, null); - viewport.add (box); - var scrolled_window = new Gtk.ScrolledWindow (null, null); scrolled_window.expand = true; - scrolled_window.add (viewport); + scrolled_window.add (box); header = new WeekHeader (sidebar_sizegroup); @@ -101,81 +98,35 @@ namespace Maya.View { /* Update the size requests */ sidebar.set_size_request (sidebar_width, 48 * cell_height); - - /* Sync with the week header sidebar */ - //gcal_week_header_get_sidebar_size_group (GCAL_WEEK_HEADER (self->header)); - //gtk_size_group_add_widget (sidebar_sizegroup, self->hours_bar); - } - - void on_events_added (E.Source source, Gee.Collection events) { - Idle.add ( () => { - foreach (var event in events) - add_event (source, event); - - return false; - }); - } - - void on_events_updated (E.Source source, Gee.Collection events) { - Idle.add ( () => { - foreach (var event in events) - update_event (source, event); - - return false; - }); - } - - void on_events_removed (E.Source source, Gee.Collection events) { - Idle.add ( () => { - foreach (var event in events) - remove_event (source, event); - - return false; - }); } - /* Indicates the month has changed */ - void on_model_parameters_changed () { - /*var model = Model.CalendarModel.get_default (); - if (grid.grid_range != null && model.data_range.equals (grid.grid_range)) - return; // nothing to do - - Idle.add ( () => { - remove_all_events (); - sync_with_model (); - return false; - });*/ - } - - //--- Helper Methods ---// - - /* Render new event in the view */ - private void add_event (E.Source source, ECal.Component event) { - unowned ICal.Component comp = event.get_icalcomponent (); - - if (Maya.Util.is_multiday_event (comp) || Maya.Util.is_all_day_event (comp)) { - header.add_event (source, event); - } else { - grid.add_event (source, event); - } - } - - /* Update the event in the view */ - private void update_event (E.Source source, ECal.Component event) { - remove_event (source, event); - add_event (source, event); - } - - /* Remove event from the view */ - private void remove_event (E.Source source, ECal.Component event) { - header.remove_event (source, event); - grid.remove_event (source, event); - } - - /* Remove all events from the view */ - private void remove_all_events () { - header.remove_all_events (); - grid.remove_all_events (); - } + // /* Render new event in the view */ + // private void add_event (E.Source source, ECal.Component event) { + // unowned ICal.Component comp = event.get_icalcomponent (); + + // if (Maya.Util.is_multiday_event (comp) || Maya.Util.is_all_day_event (comp)) { + // header.add_event (source, event); + // } else { + // grid.add_event (source, event); + // } + // } + + // /* Update the event in the view */ + // private void update_event (E.Source source, ECal.Component event) { + // remove_event (source, event); + // add_event (source, event); + // } + + // /* Remove event from the view */ + // private void remove_event (E.Source source, ECal.Component event) { + // header.remove_event (source, event); + // grid.remove_event (source, event); + // } + + // /* Remove all events from the view */ + // private void remove_all_events () { + // header.remove_all_events (); + // grid.remove_all_events (); + // } } } From d13ce5a1e151b46a69a59e16eaa061d535c6009d Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Thu, 23 Apr 2020 14:46:57 +0000 Subject: [PATCH 22/22] giving up :( --- data/style/WeekView.css | 21 +++++++++++ src/SimpleWeek/WeekBody.vala | 46 ++++++++++++++++++++++++ src/SimpleWeek/WeekGrid.vala | 64 +++++++++++++++++++++++++++++++++ src/SimpleWeek/WeekHead.vala | 47 ++++++++++++++++++++++++ src/SimpleWeek/WeekView.vala | 52 +++++++++++++++++++++++++++ src/SimpleWeek/WeekdayBody.vala | 36 +++++++++++++++++++ src/SimpleWeek/WeekdayHead.vala | 40 +++++++++++++++++++++ src/Week/WeekView.vala | 1 + 8 files changed, 307 insertions(+) create mode 100644 src/SimpleWeek/WeekBody.vala create mode 100644 src/SimpleWeek/WeekGrid.vala create mode 100644 src/SimpleWeek/WeekHead.vala create mode 100644 src/SimpleWeek/WeekView.vala create mode 100644 src/SimpleWeek/WeekdayBody.vala create mode 100644 src/SimpleWeek/WeekdayHead.vala diff --git a/data/style/WeekView.css b/data/style/WeekView.css index c8115db05..67df25080 100644 --- a/data/style/WeekView.css +++ b/data/style/WeekView.css @@ -15,6 +15,27 @@ * along with this program. If not, see . */ +/* +.week-head { + background-color: green; +} + +.week-body { + background-color: yellow; +} + +.week-sidebar { + background-color: purple; +} + +.weekday-head { + background-color: blue; +} + +.weekday-body { + background-color: red; +}*/ + .week-header .week-names { font-size: 10pt; font-weight: bold; diff --git a/src/SimpleWeek/WeekBody.vala b/src/SimpleWeek/WeekBody.vala new file mode 100644 index 000000000..298755648 --- /dev/null +++ b/src/SimpleWeek/WeekBody.vala @@ -0,0 +1,46 @@ +/*- + * Copyright (c) 2020 elementary, Inc. (https://elementary.io) + * + * 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 . + * + * Authored by: Marco Betschart + */ + +namespace Maya.View { + + public class WeekBody : WeekGrid { + + private WeekdayBody[] weekdays; + + construct { + weekdays = new WeekdayBody[7]; + for (var i = 0; i < 7; i++) { + weekdays[i] = new WeekdayBody (); + add_to_weekday_column (weekdays[i], i); + } + + var style_context = get_style_context (); + style_context.add_class ("week-body"); + style_context.add_provider (WeekView.style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + + var sidebar_style_context = sidebar.get_style_context (); + sidebar_style_context.add_class ("week-sidebar"); + sidebar_style_context.add_provider (WeekView.style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + } + + public WeekdayBody get_weekday (int i) { + return weekdays[i]; + } + } +} diff --git a/src/SimpleWeek/WeekGrid.vala b/src/SimpleWeek/WeekGrid.vala new file mode 100644 index 000000000..8df8778c7 --- /dev/null +++ b/src/SimpleWeek/WeekGrid.vala @@ -0,0 +1,64 @@ +/*- + * Copyright (c) 2020 elementary, Inc. (https://elementary.io) + * + * 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 . + * + * Authored by: Marco Betschart + */ + +namespace Maya.View { + + public class WeekGrid : Gtk.Box { + + public Gtk.Box sidebar { get; construct; } + private Gtk.Box[] weekday_columns; + + private bool is_ltr; + + construct { + orientation = Gtk.Orientation.HORIZONTAL; + expand = true; + + is_ltr = get_direction () != Gtk.TextDirection.RTL; + + sidebar = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); + sidebar.vexpand = true; + sidebar.hexpand = false; + + if (is_ltr) { + add (sidebar); + } + + weekday_columns = new Gtk.Box[7]; + for (var i = 0; i < 7; i++) { + weekday_columns[i] = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); + weekday_columns[i].expand = true; + + add (weekday_columns[i]); + } + + if (!is_ltr) { + add (sidebar); + } + } + + public void add_to_weekday_column (Gtk.Widget widget, int weekday_column) { + if (is_ltr) { + weekday_columns[weekday_column].add (widget); + } else { + weekday_columns[7 - weekday_column].add (widget); + } + } + } +} diff --git a/src/SimpleWeek/WeekHead.vala b/src/SimpleWeek/WeekHead.vala new file mode 100644 index 000000000..1e94b58eb --- /dev/null +++ b/src/SimpleWeek/WeekHead.vala @@ -0,0 +1,47 @@ +/*- + * Copyright (c) 2020 elementary, Inc. (https://elementary.io) + * + * 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 . + * + * Authored by: Marco Betschart + */ + +namespace Maya.View { + + public class WeekHead : WeekGrid { + + private WeekdayHead[] weekdays; + + construct { + weekdays = new WeekdayHead[7]; + for (var i = 0; i < 7; i++) { + weekdays[i] = new WeekdayHead (); + weekdays[i].title = "Montag"; + add_to_weekday_column (weekdays[i], i); + } + + var style_context = get_style_context (); + style_context.add_class ("week-head"); + style_context.add_provider (WeekView.style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + + var sidebar_style_context = sidebar.get_style_context (); + sidebar_style_context.add_class ("week-sidebar"); + sidebar_style_context.add_provider (WeekView.style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + } + + public WeekdayHead get_weekday (int i) { + return weekdays[i]; + } + } +} diff --git a/src/SimpleWeek/WeekView.vala b/src/SimpleWeek/WeekView.vala new file mode 100644 index 000000000..c93e9fd77 --- /dev/null +++ b/src/SimpleWeek/WeekView.vala @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2020 elementary, Inc. (https://elementary.io) + * + * 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 . + * + * Authored by: Marco Betschart + */ + +namespace Maya.View { + + public class WeekView : Gtk.Box { + + internal static Gtk.CssProvider style_provider; + + static construct { + style_provider = new Gtk.CssProvider (); + style_provider.load_from_resource ("/io/elementary/calendar/WeekView.css"); + } + + private WeekHead head; + private WeekBody body; + + construct { + orientation = Gtk.Orientation.VERTICAL; + homogeneous = false; + + head = new WeekHead (); + body = new WeekBody (); + + var scrolled_window = new Gtk.ScrolledWindow (null, null); + scrolled_window.add (body); + + add (head); + add (scrolled_window); + + var style_context = get_style_context (); + style_context.add_class ("week-view"); + style_context.add_provider (style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + } + } +} diff --git a/src/SimpleWeek/WeekdayBody.vala b/src/SimpleWeek/WeekdayBody.vala new file mode 100644 index 000000000..c461a03a7 --- /dev/null +++ b/src/SimpleWeek/WeekdayBody.vala @@ -0,0 +1,36 @@ +/*- + * Copyright (c) 2020 elementary, Inc. (https://elementary.io) + * + * 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 . + * + * Authored by: Marco Betschart + */ + +namespace Maya.View { + + public class WeekdayBody : Gtk.Grid { + + construct { + insert_row (48); + + column_homogeneous = false; + row_homogeneous = true; + expand = true; + + var style_context = get_style_context (); + style_context.add_class ("weekday-body"); + style_context.add_provider (WeekView.style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + } + } +} diff --git a/src/SimpleWeek/WeekdayHead.vala b/src/SimpleWeek/WeekdayHead.vala new file mode 100644 index 000000000..cf578fe2c --- /dev/null +++ b/src/SimpleWeek/WeekdayHead.vala @@ -0,0 +1,40 @@ +/*- + * Copyright (c) 2020 elementary, Inc. (https://elementary.io) + * + * 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 . + * + * Authored by: Marco Betschart + */ + +namespace Maya.View { + + public class WeekdayHead : Gtk.Grid { + + public string title { get; set; } + private Gtk.Label title_label; + + construct { + expand = true; + + title_label = new Gtk.Label (null); + add (title_label); + + bind_property ("title", title_label, "label"); + + var style_context = get_style_context (); + style_context.add_class ("weekday-head"); + style_context.add_provider (WeekView.style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + } + } +} diff --git a/src/Week/WeekView.vala b/src/Week/WeekView.vala index b229cbaff..50a33b4da 100644 --- a/src/Week/WeekView.vala +++ b/src/Week/WeekView.vala @@ -130,3 +130,4 @@ namespace Maya.View { // } } } +