[glide] Add basic print functionality
- From: Robert Carr <racarr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glide] Add basic print functionality
- Date: Sat, 5 Jun 2010 19:48:59 +0000 (UTC)
commit 71f2af5266cc788b87fad7cb638288012363447b
Author: Robert Carr <racarr Valentine localdomain>
Date: Mon May 24 18:56:12 2010 -0400
Add basic print functionality
data/ui/glide-window.ui | 48 +++++++++++++++++-------
libglide/Makefile.am | 2 +
libglide/glide-print-util.c | 84 +++++++++++++++++++++++++++++++++++++++++++
libglide/glide-print-util.h | 28 ++++++++++++++
libglide/glide-window.c | 14 +++++++-
5 files changed, 161 insertions(+), 15 deletions(-)
---
diff --git a/data/ui/glide-window.ui b/data/ui/glide-window.ui
index 82a9835..e4d7b2b 100644
--- a/data/ui/glide-window.ui
+++ b/data/ui/glide-window.ui
@@ -22,8 +22,8 @@
<child>
<object class="GtkImageMenuItem" id="new-menuitem">
<property name="visible">True</property>
- <property name="use_action_appearance">True</property>
<property name="related_action">new-action</property>
+ <property name="use_action_appearance">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<accelerator key="n" signal="activate" modifiers="GDK_CONTROL_MASK"/>
@@ -62,8 +62,8 @@
<child>
<object class="GtkImageMenuItem" id="export-pdf-menuitem">
<property name="visible">True</property>
- <property name="use_action_appearance">True</property>
<property name="related_action">pdf-export-action</property>
+ <property name="use_action_appearance">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
@@ -71,8 +71,8 @@
<child>
<object class="GtkImageMenuItem" id="export-image-menuitem">
<property name="visible">True</property>
- <property name="use_action_appearance">True</property>
<property name="related_action">png-export-action</property>
+ <property name="use_action_appearance">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
@@ -112,6 +112,19 @@
</object>
</child>
<child>
+ <object class="GtkImageMenuItem" id="print-menuitem">
+ <property name="visible">True</property>
+ <property name="related_action">print-action</property>
+ <property name="use_action_appearance">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparatorMenuItem" id="menuitem1">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <child>
<object class="GtkImageMenuItem" id="quit-menuitem">
<property name="label">gtk-quit</property>
<property name="visible">True</property>
@@ -136,8 +149,8 @@
<child>
<object class="GtkImageMenuItem" id="undo-menuitem">
<property name="visible">True</property>
- <property name="use_action_appearance">True</property>
<property name="related_action">undo-action</property>
+ <property name="use_action_appearance">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<accelerator key="z" signal="activate" modifiers="GDK_CONTROL_MASK"/>
@@ -146,8 +159,8 @@
<child>
<object class="GtkImageMenuItem" id="redo-menuitem">
<property name="visible">True</property>
- <property name="use_action_appearance">True</property>
<property name="related_action">redo-action</property>
+ <property name="use_action_appearance">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<accelerator key="z" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
@@ -171,8 +184,8 @@
<child>
<object class="GtkImageMenuItem" id="copy-menuitem">
<property name="visible">True</property>
- <property name="use_action_appearance">True</property>
<property name="related_action">copy-action</property>
+ <property name="use_action_appearance">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<accelerator key="c" signal="activate" modifiers="GDK_CONTROL_MASK"/>
@@ -244,8 +257,8 @@
<child>
<object class="GtkToolButton" id="present-toolbutton">
<property name="visible">True</property>
- <property name="use_action_appearance">True</property>
<property name="related_action">present-action</property>
+ <property name="use_action_appearance">True</property>
<property name="label" translatable="yes">Present</property>
<property name="use_underline">True</property>
</object>
@@ -257,8 +270,8 @@
<child>
<object class="GtkToolButton" id="insert-slide-toolbutton">
<property name="visible">True</property>
- <property name="use_action_appearance">True</property>
<property name="related_action">add-slide-action</property>
+ <property name="use_action_appearance">True</property>
<property name="label" translatable="yes">Insert slide</property>
<property name="use_underline">True</property>
</object>
@@ -278,8 +291,8 @@
<child>
<object class="GtkToolButton" id="undo-toolbutton">
<property name="visible">True</property>
- <property name="use_action_appearance">True</property>
<property name="related_action">undo-action</property>
+ <property name="use_action_appearance">True</property>
<property name="label" translatable="yes">Undo</property>
<property name="use_underline">True</property>
</object>
@@ -291,8 +304,8 @@
<child>
<object class="GtkToolButton" id="Redo">
<property name="visible">True</property>
- <property name="use_action_appearance">True</property>
<property name="related_action">redo-action</property>
+ <property name="use_action_appearance">True</property>
<property name="label" translatable="yes">Redo</property>
<property name="use_underline">True</property>
</object>
@@ -313,8 +326,8 @@
<object class="GtkToolButton" id="text-toolbutton">
<property name="visible">True</property>
<property name="sensitive">False</property>
- <property name="use_action_appearance">True</property>
<property name="related_action">new-text-action</property>
+ <property name="use_action_appearance">True</property>
<property name="label" translatable="yes">Text</property>
<property name="use_underline">True</property>
</object>
@@ -327,8 +340,8 @@
<object class="GtkToolButton" id="image-toolbutton">
<property name="visible">True</property>
<property name="sensitive">False</property>
- <property name="use_action_appearance">True</property>
<property name="related_action">new-image-action</property>
+ <property name="use_action_appearance">True</property>
<property name="label" translatable="yes">Image</property>
<property name="use_underline">True</property>
</object>
@@ -340,8 +353,8 @@
<child>
<object class="GtkToolButton" id="shape-toolbutton">
<property name="visible">True</property>
- <property name="use_action_appearance">True</property>
<property name="related_action">new-shape-action</property>
+ <property name="use_action_appearance">True</property>
<property name="label" translatable="yes">Shape</property>
<property name="use_underline">True</property>
</object>
@@ -361,8 +374,8 @@
<child>
<object class="GtkToolButton" id="inspector-button">
<property name="visible">True</property>
- <property name="use_action_appearance">True</property>
<property name="related_action">inspector-action</property>
+ <property name="use_action_appearance">True</property>
<property name="label" translatable="yes">Inspector</property>
<property name="use_underline">True</property>
</object>
@@ -738,4 +751,11 @@
<property name="sensitive">False</property>
<signal name="activate" handler="glide_window_new_shape_action_activate"/>
</object>
+ <object class="GtkAction" id="print-action">
+ <property name="label">Print</property>
+ <property name="short_label">Print</property>
+ <property name="tooltip">Prints the current document</property>
+ <property name="stock_id">gtk-print</property>
+ <signal name="activate" handler="glide_window_print_action_activate"/>
+ </object>
</interface>
diff --git a/libglide/Makefile.am b/libglide/Makefile.am
index dcc9d32..b83d55d 100644
--- a/libglide/Makefile.am
+++ b/libglide/Makefile.am
@@ -60,6 +60,7 @@ glideheaders_HEADERS = \
glide.h \
glide-theme.h \
glide-binding.h \
+ glide-print-util.h \
$(glide_VALABUILTHEADERS)
glideheadersdir = $(pkgincludedir)
@@ -96,6 +97,7 @@ libglide_la_SOURCES = \
glide.c \
glide-theme.c \
glide-binding.c \
+ glide-print-util.c \
$(glide_VALABUILTSOURCES)
libglide_la_CFLAGS = \
diff --git a/libglide/glide-print-util.c b/libglide/glide-print-util.c
new file mode 100644
index 0000000..327e78c
--- /dev/null
+++ b/libglide/glide-print-util.c
@@ -0,0 +1,84 @@
+/*
+ * glide-print-util.c
+ * Copyright (C) Robert Carr 2010 <racarr gnome org>
+ *
+ * Glide 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.
+ *
+ * Glide 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 <http://www.gnu.org/licenses/>.
+ */
+/**
+ * SECTION:glide-print-util
+ * @short_description: Glide print utility functions.
+ *
+ */
+
+#include "glide-print-util.h"
+#include "glide-actor.h"
+
+void
+glide_print_util_begin_print (GtkPrintOperation *print,
+ GtkPrintContext *context,
+ gpointer user_data)
+{
+ GlideStageManager *manager = (GlideStageManager *)user_data;
+
+ gtk_print_operation_set_n_pages (print, glide_document_get_n_slides (glide_stage_manager_get_document (manager)));
+}
+
+
+void
+glide_print_util_draw_page (GtkPrintOperation *print,
+ GtkPrintContext *context,
+ gint page_nr,
+ gpointer user_data)
+{
+ GlideStageManager *manager = (GlideStageManager *)user_data;
+ GlideSlide *slide;
+ GlideDocument *document;
+ cairo_t *cr;
+ gfloat width, height, s_width, s_height, p_height;
+
+ width = gtk_print_context_get_width (context);
+ height = .75 * width;
+
+ p_height = gtk_print_context_get_width (context);
+
+ document = glide_stage_manager_get_document (manager);
+ slide = glide_document_get_nth_slide (document, page_nr);
+
+ clutter_actor_get_size (CLUTTER_ACTOR (slide), &s_width,
+ &s_height);
+
+ cr = gtk_print_context_get_cairo_context (context);
+
+ cairo_move_to (cr, 0, p_height/2.0-height/2.0);
+ cairo_scale (cr, width/s_width, height/s_height);
+
+ glide_actor_print (GLIDE_ACTOR (slide), cr);
+}
+
+void
+glide_print_util_print (GlideStageManager *manager)
+{
+ GtkPrintOperation *print = gtk_print_operation_new ();
+ GtkPrintOperationResult res;
+
+ g_signal_connect (print, "begin_print",
+ G_CALLBACK (glide_print_util_begin_print), manager);
+ g_signal_connect (print, "draw_page",
+ G_CALLBACK (glide_print_util_draw_page), manager);
+ res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
+ NULL, NULL);
+
+ g_object_unref (print);
+
+}
diff --git a/libglide/glide-print-util.h b/libglide/glide-print-util.h
new file mode 100644
index 0000000..0821b59
--- /dev/null
+++ b/libglide/glide-print-util.h
@@ -0,0 +1,28 @@
+/*
+ * glide-print-util.h
+ * Copyright (C) Robert Carr 2010 <racarr gnome org>
+ *
+ * Glide 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.
+ *
+ * Glide 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 <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __GLIDE_PRINT_UTIL_H__
+#define __GLIDE_PRINT_UTIL_H__
+
+#include "glide-stage-manager.h"
+
+void glide_print_util_print (GlideStageManager *manager);
+
+
+#endif
diff --git a/libglide/glide-window.c b/libglide/glide-window.c
index e42ae17..b9aae09 100644
--- a/libglide/glide-window.c
+++ b/libglide/glide-window.c
@@ -48,6 +48,7 @@
#include "glide-pdf-exporter.h"
//#include "glide-png-exporter.h"
+#include "glide-print-util.h"
#include "glide-slide-box.h"
@@ -136,7 +137,7 @@ glide_window_enable_document_actions (GlideWindow *w)
glide_window_enable_action (w, "pdf-export-action");
glide_window_enable_action (w, "png-export-action");
glide_window_enable_action (w, "inspector-action");
-
+ glide_window_enable_action (w, "print-action");
}
static void
@@ -663,6 +664,15 @@ glide_window_hide_about_dialog (GtkWidget *w,
}
void
+glide_window_print_action_activate (GtkAction *a,
+ gpointer user_data)
+{
+ GlideWindow *w = (GlideWindow *)user_data;
+
+ glide_print_util_print (w->priv->manager);
+}
+
+void
glide_window_about_action_activate (GtkAction *a,
gpointer user_data)
{
@@ -1163,6 +1173,8 @@ glide_window_setup_accelerators (GlideWindow *w)
glide_window_add_accelerator (w, group, accels, "save-as-action", "<Control>w");
glide_window_add_accelerator (w, group, accels, "quit-action", "<Control>q");
+ glide_window_add_accelerator (w, group, accels, "print-action", "<Control>p");
+
glide_window_add_accelerator (w, group, accels, "copy-action", "<Control>c");
glide_window_add_accelerator (w, group, accels, "paste-action", "<Control>v");
glide_window_add_accelerator (w, group, accels, "cut-action", "<Control>x");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]