Commit 65bfd21c authored by Germán Poo-Caamaño's avatar Germán Poo-Caamaño

previewer: Use GtkHeaderBar in print preview

* Makes the UI looks like the main application
* Replace and remove deprecated widgets

Addresses issues on #405
parent 12ffec45
......@@ -36,6 +36,7 @@ libview/ev-view.c
libview/ev-view-presentation.c
org.gnome.Evince.appdata.xml.in
previewer/ev-previewer.c
previewer/ev-previewer-toolbar.c
previewer/ev-previewer-window.c
properties/ev-properties-main.c
properties/ev-properties-view.c
......
......@@ -4,6 +4,8 @@ bin_PROGRAMS = evince-previewer
evince_previewer_SOURCES = \
ev-previewer.c \
ev-previewer-toolbar.h \
ev-previewer-toolbar.c \
ev-previewer-window.h \
ev-previewer-window.c \
$(NULL)
......@@ -42,7 +44,7 @@ ev-previewer-resources.c: previewer.gresource.xml Makefile $(shell $(GLIB_COMPIL
EXTRA_DIST = \
previewer.gresource.xml \
evince-previewer.css \
previewer-ui.xml \
previewer.ui \
$(NULL)
CLEANFILES = \
......
/* ev-toolbar.h
* this file is part of evince, a gnome document viewer
*
* Copyright (C) 2012-2014 Carlos Garcia Campos <carlosgc@gnome.org>
* Copyright (C) 2014-2018 Germán Poo-Caamaño <gpoo@gnome.org>
*
* Evince 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 2 of the License, or
* (at your option) any later version.
*
* Evince 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <glib/gi18n.h>
#include "ev-previewer-toolbar.h"
/*
#include "ev-stock-icons.h"
#include "ev-zoom-action.h"
#include "ev-application.h"
*/
#include "ev-page-action-widget.h"
#include <math.h>
enum
{
PROP_0,
PROP_WINDOW
};
struct _EvPreviewerToolbarPrivate {
EvPreviewerWindow *window;
GtkWidget *page_selector;
GtkWidget *print_button;
GtkWidget *previous_button;
GtkWidget *next_button;
GtkWidget *zoom_in_button;
GtkWidget *zoom_out_button;
GtkWidget *zoom_default_button;
};
G_DEFINE_TYPE (EvPreviewerToolbar, ev_previewer_toolbar, GTK_TYPE_HEADER_BAR)
static void
ev_previewer_toolbar_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
EvPreviewerToolbar *ev_previewer_toolbar = EV_PREVIEWER_TOOLBAR (object);
switch (prop_id) {
case PROP_WINDOW:
ev_previewer_toolbar->priv->window = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
ev_previewer_toolbar_constructed (GObject *object)
{
EvPreviewerToolbar *ev_previewer_toolbar = EV_PREVIEWER_TOOLBAR (object);
GtkWidget *tool_item;
GtkWidget *button;
GtkWidget *hbox;
GtkBuilder *builder;
G_OBJECT_CLASS (ev_previewer_toolbar_parent_class)->constructed (object);
builder = gtk_builder_new_from_resource ("/org/gnome/evince/previewer/ui/previewer.ui");
hbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_EXPAND);
gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE);
priv->previous_button = GTK_WIDGET (gtk_builder_get_object (builder, "go-previous-page"));
gtk_box_pack_start (GTK_BOX (hbox), priv->previous_button, FALSE, FALSE, 0);
gtk_widget_show (priv->previous_button);
priv->next_button = GTK_WIDGET (gtk_builder_get_object (builder, "go-next-page"));
gtk_box_pack_start (GTK_BOX (hbox), priv->next_button, FALSE, FALSE, 0);
gtk_widget_show (priv->next_button);
gtk_header_bar_pack_start (GTK_HEADER_BAR (ev_previewer_toolbar), hbox);
gtk_widget_show (hbox);
/* Page selector */
tool_item = GTK_WIDGET (g_object_new (EV_TYPE_PAGE_ACTION_WIDGET, NULL));
gtk_widget_set_tooltip_text (tool_item, _("Select page or search in the index"));
atk_object_set_name (gtk_widget_get_accessible (tool_item), _("Select page"));
ev_page_action_widget_set_model (EV_PAGE_ACTION_WIDGET (tool_item),
ev_previewer_window_get_document_model (ev_previewer_toolbar->priv->window));
ev_previewer_toolbar->priv->page_selector = tool_item;
gtk_header_bar_pack_start (GTK_HEADER_BAR (ev_previewer_toolbar), tool_item);
gtk_widget_show (tool_item);
/* Print */
button = GTK_WIDGET (gtk_builder_get_object (builder, "print"));
ev_previewer_toolbar->priv->print_button = button;
gtk_header_bar_pack_end (GTK_HEADER_BAR (ev_previewer_toolbar), button);
gtk_widget_show (button);
/* Zoom */
hbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_EXPAND);
gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE);
button = GTK_WIDGET (gtk_builder_get_object (builder, "zoom-in"));
ev_previewer_toolbar->priv->zoom_in_button = button;
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
button = GTK_WIDGET (gtk_builder_get_object (builder, "zoom-default"));
ev_previewer_toolbar->priv->zoom_default_button = button;
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
button = GTK_WIDGET (gtk_builder_get_object (builder, "zoom-out"));
ev_previewer_toolbar->priv->zoom_out_button = button;
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
gtk_header_bar_pack_end (GTK_HEADER_BAR (ev_previewer_toolbar), hbox);
gtk_widget_show (hbox);
g_object_unref (builder);
}
static void
ev_previewer_toolbar_class_init (EvPreviewerToolbarClass *klass)
{
GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
g_object_class->set_property = ev_previewer_toolbar_set_property;
g_object_class->constructed = ev_previewer_toolbar_constructed;
g_object_class_install_property (g_object_class,
PROP_WINDOW,
g_param_spec_object ("window",
"Window",
"The evince previewer window",
EV_TYPE_PREVIEWER_WINDOW,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_type_class_add_private (g_object_class, sizeof (EvPreviewerToolbarPrivate));
}
static void
ev_previewer_toolbar_init (EvPreviewerToolbar *ev_previewer_toolbar)
{
ev_previewer_toolbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (ev_previewer_toolbar, EV_TYPE_PREVIEWER_TOOLBAR, EvPreviewerToolbarPrivate);
}
GtkWidget *
ev_previewer_toolbar_new (EvPreviewerWindow *window)
{
g_return_val_if_fail (EV_IS_PREVIEWER_WINDOW (window), NULL);
return GTK_WIDGET (g_object_new (EV_TYPE_PREVIEWER_TOOLBAR,
"window", window,
NULL));
}
GtkWidget *
ev_previewer_toolbar_get_page_selector (EvPreviewerToolbar *ev_previewer_toolbar)
{
g_return_val_if_fail (EV_IS_PREVIEWER_TOOLBAR (ev_previewer_toolbar), NULL);
return ev_previewer_toolbar->priv->page_selector;
}
/* ev-toolbar.h
* this file is part of evince, a gnome document viewer
*
* Copyright (C) 2012 Carlos Garcia Campos <carlosgc@gnome.org>
* Copyright (C) 2018 Germán Poo-Caamaño <gpoo@gnome.org>
*
* Evince 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 2 of the License, or
* (at your option) any later version.
*
* Evince 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __EV_PREVIEWER_TOOLBAR_H__
#define __EV_PREVIEWER_TOOLBAR_H__
#include <gtk/gtk.h>
#include "ev-previewer-window.h"
G_BEGIN_DECLS
#define EV_TYPE_PREVIEWER_TOOLBAR (ev_previewer_toolbar_get_type())
#define EV_PREVIEWER_TOOLBAR(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_PREVIEWER_TOOLBAR, EvPreviewerToolbar))
#define EV_IS_PREVIEWER_TOOLBAR(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_PREVIEWER_TOOLBAR))
#define EV_PREVIEWER_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_PREVIEWER_TOOLBAR, EvPreviewerToolbarClass))
#define EV_IS_PREVIEWER_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_PREVIEWER_TOOLBAR))
#define EV_PREVIEWER_TOOLBAR_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), EV_TYPE_PREVIEWER_TOOLBAR, EvPreviewerToolbarClass))
typedef struct _EvPreviewerToolbar EvPreviewerToolbar;
typedef struct _EvPreviewerToolbarClass EvPreviewerToolbarClass;
typedef struct _EvPreviewerToolbarPrivate EvPreviewerToolbarPrivate;
struct _EvPreviewerToolbar {
GtkHeaderBar base_instance;
EvPreviewerToolbarPrivate *priv;
};
struct _EvPreviewerToolbarClass {
GtkHeaderBarClass base_class;
};
GType ev_previewer_toolbar_get_type (void);
GtkWidget *ev_previewer_toolbar_new (EvPreviewerWindow *window);
GtkWidget *ev_previewer_toolbar_get_page_selector (EvPreviewerToolbar *ev_previewer_toolbar);
G_END_DECLS
#endif /* __EV_PREVIEWER_TOOLBAR_H__ */
This diff is collapsed.
......@@ -41,6 +41,8 @@ typedef struct _EvPreviewerWindowClass EvPreviewerWindowClass;
GType ev_previewer_window_get_type (void) G_GNUC_CONST;
EvPreviewerWindow *ev_previewer_window_new (EvDocumentModel *model);
EvDocumentModel *ev_previewer_window_get_document_model (EvPreviewerWindow *window);
void ev_previewer_window_set_print_settings (EvPreviewerWindow *window,
const gchar *print_settings);
void ev_previewer_window_set_source_file (EvPreviewerWindow *window,
......
......@@ -142,6 +142,18 @@ main (gint argc, gchar **argv)
gchar *path;
int status = 1;
const gchar *action_accels[] = {
"win.select-page", "<Ctrl>L", NULL,
"win.go-previous-page", "p", "<Ctrl>Page_Up", NULL,
"win.go-next-page", "n", "<Ctrl>Page_Down", NULL,
"win.print", "<Ctrl>P", NULL,
"win.zoom-in", "plus", "<Ctrl>plus", "KP_Add", "<Ctrl>KP_Add", "equal", "<Ctrl>equal", NULL,
"win.zoom-out", "minus", "<Ctrl>minus", "KP_Subtract", "<Ctrl>KP_Subtract", NULL,
"win.zoom-default", "a", NULL,
NULL,
};
const char **it;
#ifdef G_OS_WIN32
if (fileno (stdout) != -1 &&
_get_osfhandle (fileno (stdout)) != -1)
......@@ -216,6 +228,9 @@ main (gint argc, gchar **argv)
g_signal_connect (application, "activate", G_CALLBACK (activate_cb), NULL);
g_signal_connect (application, "open", G_CALLBACK (open_cb), NULL);
for (it = action_accels; it[0]; it += g_strv_length ((gchar **)it) + 1)
gtk_application_set_accels_for_action (GTK_APPLICATION (application), it[0], &it[1]);
status = g_application_run (G_APPLICATION (application), argc, argv);
if (unlink_temp_file)
......
sources = files(
'ev-previewer.c',
'ev-previewer-toolbar.c',
'ev-previewer-window.c',
)
resource_data = files(
'../data/thumbnail-frame.png',
'evince-previewer.css',
'previewer-ui.xml',
'previewer.ui',
)
sources += gnome.compile_resources(
......
<ui>
<toolbar name="PreviewToolbar">
<toolitem name="GoPreviousPage" action="GoPreviousPage"/>
<toolitem name="GoNextPage" action="GoNextPage"/>
<separator/>
<toolitem name="PageSelector" action="PageSelector"/>
<separator/>
<toolitem name="ViewFitWidth" action="ViewFitWidth"/>
<toolitem name="ViewFitPage" action="ViewFitPage"/>
<toolitem name="ViewZoomIn" action="ViewZoomIn"/>
<toolitem name="ViewZoomOut" action="ViewZoomOut"/>
<separator/>
<toolitem name="PreviewPrint" action="PreviewPrint"/>
</toolbar>
<accelerator name="FileCloseWindowAccel" action="FileCloseWindow"/>
<accelerator name="pAccel" action="p"/>
<accelerator name="nAccel" action="n"/>
<accelerator name="FocusPageSelectorAccel" action="FocusPageSelector"/>
<accelerator name="PlusAccel" action="Plus"/>
<accelerator name="MinusAccel" action="Minus"/>
<accelerator name="Equal" action="Equal"/>
<accelerator name="CtrlEqualAccel" action="CtrlEqual"/>
<accelerator name="KpPlusAccel" action="KpPlus"/>
<accelerator name="KpMinusAccel" action="KpMinus"/>
<accelerator name="CtrlKpPlusAccel" action="CtrlKpPlus"/>
<accelerator name="CtrlKpMinusAccel" action="CtrlKpMinus"/>
</ui>
......@@ -17,7 +17,7 @@
-->
<gresources>
<gresource prefix="/org/gnome/evince/previewer">
<file alias="ui/previewer.xml" compressed="true" preprocess="xml-stripblanks">previewer-ui.xml</file>
<file alias="ui/previewer.ui" compressed="true" preprocess="xml-stripblanks">previewer.ui</file>
<file alias="ui/evince-previewer.css" compressed="true">evince-previewer.css</file>
<file alias="ui/thumbnail-frame.png" compressed="true">thumbnail-frame.png</file>
</gresource>
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.0 -->
<!--*- mode: xml -*-->
<interface>
<requires lib="gtk+" version="3.22"/>
<object class="GtkButton" id="print">
<property name="label" translatable="yes">_Print</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Print this document</property>
<property name="action_name">win.print</property>
<property name="use_underline">True</property>
<style>
<class name="suggested-action"/>
</style>
</object>
<object class="GtkButton" id="go-previous-page">
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Previous Page</property>
<property name="action_name">win.go-previous-page</property>
<property name="image">go-previous-symbolic</property>
</object>
<object class="GtkButton" id="go-next-page">
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Next Page</property>
<property name="action_name">win.go-next-page</property>
<property name="image">go-next-symbolic</property>
</object>
<object class="GtkButton" id="zoom-in">
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Enlarge the document</property>
<property name="action_name">win.zoom-in</property>
<property name="image">zoom-in-symbolic</property>
<property name="always_show_image">True</property>
</object>
<object class="GtkButton" id="zoom-out">
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Shrink the document</property>
<property name="action_name">win.zoom-out</property>
<property name="image">zoom-out-symbolic</property>
</object>
<object class="GtkButton" id="zoom-default">
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Reset zoom and make the page fit in the window</property>
<property name="action_name">win.zoom-default</property>
<property name="image">zoom-default-symbolic</property>
</object>
<object class="GtkImage" id="go-previous-symbolic">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">go-up-symbolic</property>
</object>
<object class="GtkImage" id="go-next-symbolic">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">go-down-symbolic</property>
</object>
<object class="GtkImage" id="zoom-in-symbolic">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">zoom-in-symbolic</property>
</object>
<object class="GtkImage" id="zoom-default-symbolic">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">zoom-fit-best-symbolic</property>
</object>
<object class="GtkImage" id="zoom-out-symbolic">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">zoom-out-symbolic</property>
</object>
</interface>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment