diff options
author | Sebastian Reichel <sre@ring0.de> | 2012-08-09 00:51:47 +0200 |
---|---|---|
committer | Sebastian Reichel <sre@ring0.de> | 2012-08-09 00:51:47 +0200 |
commit | 427c3a37764890d9bd3facc8cc0a5d8a33511d79 (patch) | |
tree | 8cbad9356b3b084e2b7ec8f7397773208cabc953 | |
parent | ea9ea2673df404ad2dbf5718eaa3ded4b2956f79 (diff) | |
download | serial-barcode-scanner-427c3a37764890d9bd3facc8cc0a5d8a33511d79.tar.bz2 |
implement print button on stock dialog
-rw-r--r-- | ui.vala | 74 | ||||
-rw-r--r-- | user-interface.ui | 3 |
2 files changed, 65 insertions, 12 deletions
@@ -99,9 +99,8 @@ public void stock_dialog_handle_response(Gtk.Dialog dialog, int responseid) { public void stock_dialog_print(Gtk.Window parentw) { var operation = new Gtk.PrintOperation(); - operation.begin_print.connect(begin_print); + operation.n_pages = 1; // FIXME: implement correct paging operation.draw_page.connect(draw_page); - operation.end_print.connect(end_print); try { operation.run(Gtk.PrintOperationAction.PRINT_DIALOG, parentw); @@ -110,16 +109,71 @@ public void stock_dialog_print(Gtk.Window parentw) { } } -public void begin_print(Gtk.PrintContext context) { - /* TODO: find out how many pages we need */ -} - public void draw_page(Gtk.PrintContext context, int nr) { - /* TODO: do some cairo magic */ -} + uint8 HEADER_HEIGHT = 100; + uint8 LEFT_MARGIN = 25; + + var cr = context.get_cairo_context(); + int height, x, y = HEADER_HEIGHT; + Value value; + Gdk.Rectangle rect; + var layout = context.create_pango_layout(); + var desc = Pango.FontDescription.from_string("Monospace"); + desc.set_size(10 * Pango.SCALE); + layout.set_font_description(desc); + layout.set_text("Current KtT Shop Stock", -1); + layout.set_width(-1); + layout.set_alignment(Pango.Alignment.LEFT); + layout.get_size(null, out height); + var text_height = height / Pango.SCALE; + + cr.move_to(LEFT_MARGIN, (HEADER_HEIGHT - text_height) / 2); + Pango.cairo_show_layout(cr, layout); + + var view = builder.get_object("stock-view") as Gtk.TreeView; + var model = view.get_model(); + Gtk.TreeIter iter = {}; + Gtk.TreeViewColumn column; + var path = new Gtk.TreePath.first(); // keep the same for the whole document + string text = ""; + + for(int i = 0; i < 100 && model.get_iter(out iter, path); i++) { + x = LEFT_MARGIN; + + for(int col_num=0; col_num < model.get_n_columns(); col_num++) { + column = view.get_column(col_num); + + if(column.visible) { + model.get_value(iter,col_num,out value); + + if(value.holds(typeof(string))) { + text = value.get_string(); + if(text == null) text = ""; + } else if(value.holds(typeof(int))) { + text = "%d".printf(value.get_int()); + } else { + text = ""; + } + + value.unset(); + } + + view.get_background_area(path,column,out rect); + + layout.set_text(text, -1); + + layout.set_width(rect.width * Pango.SCALE); + layout.set_wrap(Pango.WrapMode.CHAR); + layout.set_ellipsize(Pango.EllipsizeMode.END); + cr.move_to(x, y); + Pango.cairo_show_layout(cr, layout); + + x += (rect.width+3); + } -public void end_print(Gtk.PrintContext context) { - /* TODO: free allocated resources */ + y += text_height; + path.next(); + } } [PrintfFormat] diff --git a/user-interface.ui b/user-interface.ui index ff33923..3f70b6d 100644 --- a/user-interface.ui +++ b/user-interface.ui @@ -637,7 +637,6 @@ Lennart Weller <lhw@ring0.de></property> <property name="label">gtk-print</property> <property name="use_action_appearance">False</property> <property name="visible">True</property> - <property name="sensitive">False</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <property name="use_action_appearance">False</property> @@ -679,7 +678,7 @@ Lennart Weller <lhw@ring0.de></property> <property name="can_focus">True</property> <property name="shadow_type">in</property> <child> - <object class="GtkTreeView" id="treeview"> + <object class="GtkTreeView" id="stock-view"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="model">stock-store</property> |