From: Alexander Mikhaylenko Date: Thu, 15 Apr 2021 12:28:10 +0500 Subject: toolbar: Allow hiding zoom, annotation and page widgets This will be useful to make it adaptive. --- shell/ev-toolbar.c | 58 ++++++++++++++++++++++++++++++++++++++++++++---------- shell/ev-toolbar.h | 2 ++ 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/shell/ev-toolbar.c b/shell/ev-toolbar.c index 633102d..e18df20 100644 --- a/shell/ev-toolbar.c +++ b/shell/ev-toolbar.c @@ -50,6 +50,8 @@ typedef struct { GtkWidget *open_button; GtkWidget *annots_button; GtkWidget *sidebar_button; + GtkWidget *zoom_revealer; + GtkWidget *page_annots_revealer; EvToolbarMode toolbar_mode; } EvToolbarPrivate; @@ -191,6 +193,7 @@ ev_toolbar_constructed (GObject *object) GtkBuilder *builder; GtkWidget *tool_item; GtkWidget *vbox; + GtkWidget *hbox; GtkWidget *button; GMenuModel *menu; @@ -212,6 +215,16 @@ ev_toolbar_constructed (GObject *object) priv->sidebar_button = button; hdy_header_bar_pack_start (HDY_HEADER_BAR (ev_toolbar), button); + priv->page_annots_revealer = gtk_revealer_new (); + gtk_revealer_set_reveal_child (GTK_REVEALER (priv->page_annots_revealer), TRUE); + gtk_revealer_set_transition_type (GTK_REVEALER (priv->page_annots_revealer), + GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT); + hdy_header_bar_pack_start (HDY_HEADER_BAR (ev_toolbar), priv->page_annots_revealer); + + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + gtk_container_add (GTK_CONTAINER (priv->page_annots_revealer), hbox); + gtk_widget_show (hbox); + /* Page selector */ /* Use EvPageActionWidget for now, since the page selector action is also used by the previewer */ tool_item = GTK_WIDGET (g_object_new (EV_TYPE_PAGE_ACTION_WIDGET, NULL)); @@ -220,14 +233,16 @@ ev_toolbar_constructed (GObject *object) priv->page_selector = tool_item; ev_page_action_widget_set_model (EV_PAGE_ACTION_WIDGET (tool_item), ev_window_get_document_model (priv->window)); - hdy_header_bar_pack_start (HDY_HEADER_BAR (ev_toolbar), tool_item); + gtk_container_add (GTK_CONTAINER (hbox), tool_item); + gtk_widget_show (tool_item); /* Edit Annots */ button = ev_toolbar_create_toggle_button (ev_toolbar, "win.toggle-edit-annots", "document-edit-symbolic", _("Annotate the document")); atk_object_set_name (gtk_widget_get_accessible (button), _("Annotate document")); priv->annots_button = button; - hdy_header_bar_pack_start (HDY_HEADER_BAR (ev_toolbar), button); + gtk_container_add (GTK_CONTAINER (hbox), button); + gtk_widget_show (button); /* Action Menu */ menu = G_MENU_MODEL (gtk_builder_get_object (builder, "action-menu")); @@ -250,6 +265,12 @@ ev_toolbar_constructed (GObject *object) ev_toolbar); /* Zoom selector */ + priv->zoom_revealer = gtk_revealer_new (); + gtk_revealer_set_reveal_child (GTK_REVEALER (priv->zoom_revealer), TRUE); + gtk_revealer_set_transition_type (GTK_REVEALER (priv->zoom_revealer), + GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT); + hdy_header_bar_pack_end (HDY_HEADER_BAR (ev_toolbar), priv->zoom_revealer); + vbox = ev_zoom_action_new (ev_window_get_document_model (priv->window)); priv->zoom_action = vbox; atk_object_set_name (gtk_widget_get_accessible (vbox), _("Set zoom level")); @@ -256,7 +277,8 @@ ev_toolbar_constructed (GObject *object) g_signal_connect (vbox, "activated", G_CALLBACK (zoom_selector_activated), ev_toolbar); - hdy_header_bar_pack_end (HDY_HEADER_BAR (ev_toolbar), vbox); + gtk_container_add (GTK_CONTAINER (priv->zoom_revealer), vbox); + gtk_widget_show (priv->zoom_action); g_object_unref (builder); } @@ -341,19 +363,17 @@ ev_toolbar_set_mode (EvToolbar *ev_toolbar, case EV_TOOLBAR_MODE_FULLSCREEN: gtk_widget_show (priv->sidebar_button); gtk_widget_show (priv->action_menu_button); - gtk_widget_show (priv->zoom_action); - gtk_widget_show (priv->page_selector); + gtk_widget_show (priv->zoom_revealer); + gtk_widget_show (priv->page_annots_revealer); gtk_widget_show (priv->find_button); - gtk_widget_show (priv->annots_button); gtk_widget_hide (priv->open_button); break; case EV_TOOLBAR_MODE_RECENT_VIEW: gtk_widget_hide (priv->sidebar_button); gtk_widget_hide (priv->action_menu_button); - gtk_widget_hide (priv->zoom_action); - gtk_widget_hide (priv->page_selector); + gtk_widget_hide (priv->zoom_revealer); + gtk_widget_hide (priv->page_annots_revealer); gtk_widget_hide (priv->find_button); - gtk_widget_hide (priv->annots_button); gtk_widget_show (priv->open_button); break; } @@ -384,3 +404,21 @@ ev_toolbar_set_sidebar_visible (EvToolbar *ev_toolbar, gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button), visible); } + +void +ev_toolbar_set_mobile (EvToolbar *ev_toolbar, + gboolean mobile) +{ + EvToolbarPrivate *priv; + + g_return_if_fail (EV_IS_TOOLBAR (ev_toolbar)); + + priv = GET_PRIVATE (ev_toolbar); + mobile = !!mobile; + + gtk_revealer_set_reveal_child (GTK_REVEALER (priv->zoom_revealer), !mobile); + gtk_revealer_set_reveal_child (GTK_REVEALER (priv->page_annots_revealer), !mobile); + + if (mobile) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->annots_button), FALSE); +} diff --git a/shell/ev-toolbar.h b/shell/ev-toolbar.h index e1be165..eceaa4c 100644 --- a/shell/ev-toolbar.h +++ b/shell/ev-toolbar.h @@ -61,5 +61,7 @@ EvToolbarMode ev_toolbar_get_mode (EvToolbar *ev_toolbar); void ev_toolbar_set_sidebar_visible (EvToolbar *ev_toolbar, gboolean visible); +void ev_toolbar_set_mobile (EvToolbar *ev_toolbar, + gboolean mobile); G_END_DECLS