[gnome-calendar/new-year-view] year-view: added popover mode
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/new-year-view] year-view: added popover mode
- Date: Tue, 20 Jan 2015 15:01:39 +0000 (UTC)
commit bc7535104839aca58cfa82a6272ac34541f4eabd
Author: Erick Pérez Castellanos <erick red gmail com>
Date: Tue Jan 20 00:20:45 2015 -0500
year-view: added popover mode
data/theme/gtk-styles.css | 14 +++++++-
data/ui/year-view.ui | 49 +++++++++++++++++++++++++++-
src/gcal-year-view.c | 78 +++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 135 insertions(+), 6 deletions(-)
---
diff --git a/data/theme/gtk-styles.css b/data/theme/gtk-styles.css
index 200b951..db3d1fe 100644
--- a/data/theme/gtk-styles.css
+++ b/data/theme/gtk-styles.css
@@ -117,6 +117,10 @@
font-size: 11px;
}
+GtkListBox.sidebar {
+ background-color: @theme_bg_color;
+}
+
GcalYearView GtkScrolledWindow {
border-top-width: 0;
border-bottom-width: 0;
@@ -127,10 +131,18 @@ GcalYearView GtkButton {
border-bottom-width: 0;
}
-GcalYearView GtkListBox {
+GtkPopover.popover-sidebar {
background-color: @theme_bg_color;
}
+GtkScrolledWindow.popover-sidebar {
+ border-bottom-width: 0;
+}
+
+GtkButton.popover-sidebar {
+ border-radius: 0;
+}
+
GcalEventWidget.slanted-start:dir(ltr) {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
diff --git a/data/ui/year-view.ui b/data/ui/year-view.ui
index 8eedf4c..b06714f 100644
--- a/data/ui/year-view.ui
+++ b/data/ui/year-view.ui
@@ -24,13 +24,16 @@
<property name="width_request">200</property>
<property name="orientation">vertical</property>
<child>
- <object class="GtkScrolledWindow">
+ <object class="GtkScrolledWindow" id="navigator_sidebar">
<property name="visible">True</property>
<property name="shadow_type">out</property>
<property name="vexpand">True</property>
<child>
<object class="GtkListBox" id="events_sidebar">
<property name="visible">True</property>
+ <style>
+ <class name="sidebar" />
+ </style>
</object>
</child>
</object>
@@ -39,7 +42,7 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="add_event_button">
+ <object class="GtkButton">
<property name="visible">True</property>
<property name="valign">end</property>
<property name="label" translatable="yes">Add new event…</property>
@@ -52,5 +55,47 @@
</object>
</child>
</template>
+ <object class="GtkPopover" id="popover">
+ <property name="relative_to">navigator</property>
+ <style>
+ <class name="popover-sidebar" />
+ </style>
+ <signal name="closed" handler="popover_closed_cb" object="GcalYearView" swapped="yes" />
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="width_request">200</property>
+ <property name="orientation">vertical</property>
+ <property name="margin">6</property>
+ <child>
+ <object class="GtkScrolledWindow" id="popover_sidebar">
+ <property name="visible">True</property>
+ <property name="shadow_type">out</property>
+ <property name="vexpand">True</property>
+ <style>
+ <class name="popover-sidebar" />
+ </style>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton">
+ <property name="visible">True</property>
+ <property name="valign">end</property>
+ <property name="label" translatable="yes">Add new event…</property>
+ <style>
+ <class name="popover-sidebar" />
+ </style>
+ <signal name="clicked" handler="add_event_clicked_cb" object="GcalYearView" swapped="yes" />
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
</interface>
diff --git a/src/gcal-year-view.c b/src/gcal-year-view.c
index d209a7d..bf24dc4 100644
--- a/src/gcal-year-view.c
+++ b/src/gcal-year-view.c
@@ -47,8 +47,11 @@ struct _GcalYearViewPrivate
/* composite, GtkBuilder's widgets */
GtkWidget *navigator;
GtkWidget *sidebar;
- GtkWidget *add_event_button;
GtkWidget *events_sidebar;
+ GtkWidget *navigator_sidebar;
+
+ GtkWidget *popover; /* Popover for popover_mode */
+ GtkWidget *popover_sidebar;
/* manager singleton */
GcalManager *manager;
@@ -150,7 +153,10 @@ static void
event_activated (GcalEventWidget *widget,
gpointer user_data)
{
- /* FIXME: if popover_mode, hide popover */
+ GcalYearViewPrivate *priv = GCAL_YEAR_VIEW (user_data)->priv;
+
+ if (priv->popover_mode)
+ gtk_widget_hide (priv->popover);
g_signal_emit (GCAL_YEAR_VIEW (user_data), signals[EVENT_ACTIVATED], 0, widget);
}
@@ -774,6 +780,26 @@ navigator_button_release_cb (GcalYearView *year_view,
priv->selected_data->end_month = month;
gtk_widget_queue_draw (widget);
+ if (priv->popover_mode)
+ {
+ GdkRectangle rect;
+ GtkWidget *box;
+
+ /* sizing */
+ box = gtk_bin_get_child (GTK_BIN (priv->popover));
+ gtk_widget_set_size_request (box, 200, priv->navigator_grid->box_side * 2 * 7);
+
+ /* FIXME: improve rect */
+ rect.x = event->x;
+ rect.y = event->y;
+ rect.width = rect.height = 1;
+ gtk_popover_set_pointing_to (GTK_POPOVER (priv->popover), &rect);
+
+ /* FIXME: do no show over selected days */
+ gtk_popover_set_position (GTK_POPOVER (priv->popover), GTK_POS_RIGHT);
+ gtk_widget_show (priv->popover);
+ }
+
update_sidebar (year_view);
return TRUE;
@@ -838,6 +864,18 @@ add_event_clicked_cb (GcalYearView *year_view,
}
static void
+popover_closed_cb (GcalYearView *year_view,
+ GtkPopover *popover)
+{
+ GcalYearViewPrivate *priv = year_view->priv;
+
+ memset (priv->selected_data, 0, sizeof (ButtonData));
+ gtk_widget_queue_draw (priv->navigator);
+
+ update_sidebar (year_view);
+}
+
+static void
gcal_year_view_finalize (GObject *object)
{
GcalYearViewPrivate *priv = GCAL_YEAR_VIEW (object)->priv;
@@ -946,6 +984,37 @@ gcal_year_view_size_allocate (GtkWidget *widget,
if (gtk_widget_get_visible (priv->sidebar) == priv->popover_mode)
gtk_widget_set_visible (priv->sidebar, !priv->popover_mode);
+ if (priv->popover_mode && !gtk_widget_is_ancestor (priv->events_sidebar, priv->popover))
+ {
+ GtkWidget *parent = gtk_widget_get_parent (priv->events_sidebar);
+ g_object_ref (priv->events_sidebar);
+
+ gtk_container_remove (GTK_CONTAINER (parent), priv->events_sidebar);
+ gtk_container_add (GTK_CONTAINER (priv->popover_sidebar), priv->events_sidebar);
+
+ gtk_widget_show_all (priv->events_sidebar);
+ g_object_unref (priv->events_sidebar);
+ gtk_widget_destroy (parent);
+
+ popover_closed_cb (GCAL_YEAR_VIEW (widget), GTK_POPOVER (priv->popover));
+ }
+ else if (!priv->popover_mode && gtk_widget_is_ancestor (priv->events_sidebar, priv->popover))
+ {
+ GtkWidget *parent = gtk_widget_get_parent (priv->events_sidebar);
+ g_object_ref (priv->events_sidebar);
+
+ gtk_container_remove (GTK_CONTAINER (parent), priv->events_sidebar);
+ gtk_container_add (GTK_CONTAINER (priv->navigator_sidebar), priv->events_sidebar);
+
+ gtk_widget_show_all (priv->events_sidebar);
+ g_object_unref (priv->events_sidebar);
+ gtk_widget_destroy (parent);
+
+ g_signal_handlers_block_by_func (priv->popover, popover_closed_cb, widget);
+ gtk_widget_hide (priv->popover);
+ g_signal_handlers_unblock_by_func (priv->popover, popover_closed_cb, widget);
+ }
+
GTK_WIDGET_CLASS (gcal_year_view_parent_class)->size_allocate (widget, alloc);
}
@@ -1073,14 +1142,17 @@ gcal_year_view_class_init (GcalYearViewClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GcalYearView, navigator);
gtk_widget_class_bind_template_child_private (widget_class, GcalYearView, sidebar);
- gtk_widget_class_bind_template_child_private (widget_class, GcalYearView, add_event_button);
gtk_widget_class_bind_template_child_private (widget_class, GcalYearView, events_sidebar);
+ gtk_widget_class_bind_template_child_private (widget_class, GcalYearView, navigator_sidebar);
+ gtk_widget_class_bind_template_child_private (widget_class, GcalYearView, popover);
+ gtk_widget_class_bind_template_child_private (widget_class, GcalYearView, popover_sidebar);
gtk_widget_class_bind_template_callback (widget_class, draw_navigator);
gtk_widget_class_bind_template_callback (widget_class, navigator_button_press_cb);
gtk_widget_class_bind_template_callback (widget_class, navigator_button_release_cb);
gtk_widget_class_bind_template_callback (widget_class, navigator_motion_notify_cb);
gtk_widget_class_bind_template_callback (widget_class, add_event_clicked_cb);
+ gtk_widget_class_bind_template_callback (widget_class, popover_closed_cb);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]