class ListPrint::ListPrintOperation
Attributes
bottom[RW]
cell_font[RW]
cell_line_width[R]
child_cell_font[RW]
child_columns_header_font[RW]
child_indent[RW]
child_list[RW]
child_sum_font[RW]
column_pos[RW]
column_spacing[RW]
column_width[RW]
columns[RW]
columns_header_font[RW]
custom_page_setup[RW]
date_font[RW]
draw_header_cell_borders[RW]
draw_header_line[RW]
fill_header_background[RW]
gantt_cell_font[R]
header_font[RW]
header_line_width[RW]
height[RW]
left[RW]
line_above_parent[RW]
list[RW]
print_date[RW]
print_sub_sums[RW]
print_sums[RW]
print_title[R]
print_with_gantt[R]
right[RW]
row_spacing[RW]
row_underline[R]
sum_font[RW]
sum_line_width[R]
top[RW]
width[RW]
Public Class Methods
new(list)
click to toggle source
Calls superclass method
# File lib/ListHolder/EditableList/ListPrintOperation.rb, line 9 def initialize(list) @list=list @print_sums=(list.gtk_attribute("print_sums") || "true") =="true" @sum_font=list.gtk_attribute("sum_font") || "verdana bold 6" @cell_font=list.gtk_attribute("cell_font") || "verdana 6" @columns_header_font=list.gtk_attribute("columns_header_font") || "verdana bold 6" @header_font=list.gtk_attribute("header_font") || "verdana bold 10" @footer_font=list.gtk_attribute("footer_font") || "verdana 6" @date_font=list.gtk_attribute("date_font") || "verdana 5" @print_date=(list.gtk_attribute("print_date") || "true") == "true" @row_spacing=(list.gtk_attribute("row_spacing") || 1.0).to_f @column_spacing=(list.gtk_attribute("column_spacing") || 1.0).to_f @draw_footer_line=(list.gtk_attribute("draw_footer_line") || "true") == "true" @line_above_parent=(list.gtk_attribute("line_above_parent") || "true") == "true" @draw_header_line=(list.gtk_attribute("draw_header_line") || "true") == "true" @print_title=(list.gtk_attribute("print_title") || "true") == "true" @draw_header_cell_borders=(list.gtk_attribute("draw_header_cell_borders") || "true") == "true" @fill_header_background=(list.gtk_attribute("fill_header_background") || "true") == "true" @row_underline=(list.gtk_attribute("row_underline") || 0.0).to_f if @print_with_child=list.gtk_attribute("print_with_child") @child_list=list.child_by_id(@print_with_child.to_i) @child_model=Gtk::TreeModelSort.new(@child_list.list_model.data) @child_model.set_sort_column_id(@child_list.list_model.sorter.sort_column_id[0],@child_list.list_model.sorter.sort_column_id[1]) unless @child_list.list_model.sorter.sort_column_id.nil? end @print_sub_sums=(list.gtk_attribute("print_sub_sums") || "true") == "true" @child_indent=(list.gtk_attribute("child_indent") || 100).to_f @child_cell_font=list.gtk_attribute("child_cell_font") || "verdana 5" @child_sum_font=list.gtk_attribute("child_sum_font") || "verdana bold 5" @child_columns_header_font=list.gtk_attribute("child_columns_header_font") || "verdana bold 5" @header_line_width=(list.gtk_attribute("header_line_width") || 1.0).to_f @footer_line_width=(list.gtk_attribute("footer_line_width") || 1.0).to_f @cell_line_width=(list.gtk_attribute("cell_line_width") || 0.1).to_f @sum_line_width=(list.gtk_attribute("sum_line_width") || 0.6).to_f @print_with_gantt=(list.gtk_attribute("print_with_gantt") || "false") == "true" @gantt_cell_font=list.gtk_attribute("gantt_cell_font") || "verdana 5" @line_width=1 super() set_show_progress(true) set_use_full_page(false) set_unit(Gtk::PaperSize::UNIT_POINTS) # n_pages=1 signal_connect("begin-print",@list) { |pop, context,list| edebug("begin print","printing","info") cr = context.cairo_context cr.set_line_width(@line_width) @height = context.page_setup.get_page_height(Gtk::PaperSize::UNIT_POINTS).to_f @width = context.page_setup.get_page_width(Gtk::PaperSize::UNIT_POINTS).to_f columns_width_sum=0.0 col_cnt=0 list.columns.each{|col| if col.printable? columns_width_sum+=col.width.to_f col_cnt+=1 end } #summ the width of all columns columns_width_sum+=list.holder.widget.allocation.width - list.allocation.width if @print_with_gantt coef=(width-col_cnt*@column_spacing)/columns_width_sum einfo("colums width sum: #{columns_width_sum}","printing") #@column_width will store the column positions on the context @column_width=Hash.new @column_pos=Hash.new col_cur_pos=0.0 list.columns.each{|col| if col.printable? @column_pos[col.data]=col_cur_pos @column_width[col.data]=col.width.to_f*coef col_cur_pos+=@column_width[col.data]+@column_spacing end } if @print_with_gantt @column_pos[:gantt]=col_cur_pos @column_width[:gantt]=(list.holder.widget.allocation.width - list.allocation.width).to_f*coef end if child_list columns_width_sum=@child_indent.to_f col_cnt=0 child_list.columns.each{|col| if col.printable? columns_width_sum+=col.width.to_f col_cnt+=1 end } #summ the width of all columns coef=(width-col_cnt*@column_spacing)/columns_width_sum einfo("child colums width sum: #{columns_width_sum}","printing") #@column_width will store the column positions on the context col_cur_pos=@child_indent.to_f*coef child_list.columns.each{|col| if col.printable? @column_pos[col.data]=col_cur_pos @column_width[col.data]=col.width.to_f*coef col_cur_pos+=@column_width[col.data]+@column_spacing end } end @current_height=0 @header=HeaderLayout.new(cr,self) @current_height=@current_height+@header.height @columns_header=ColumnsHeaderLayout.new(self,cr,list.columns,@columns_header_font) @columns_header.set_y(@current_height) @current_height=@current_height+@columns_header.height+@row_spacing if child_list @child_columns_header=ColumnsHeaderLayout.new(self,cr,child_list.columns,@child_columns_header_font) if child_list @child_columns_header.set_y(@current_height) @current_height=@current_height+@child_columns_header.height+@row_spacing end @headers_height=@current_height @footer=FooterLayout.new(cr,self) @iter_layouts = [] @sums=Hash.new list.columns.each{|col| @sums[col.colnum]=0 if col.summable?} if child_list if print_sub_sums @sub_sums=Hash.new child_list.columns.each{|col| @sub_sums[col.colnum]=0 if col.summable?} end @citer=nil end @piter=nil #list.model.iter_first @past_last=false @page_n=0 } signal_connect("paginate",@list) { |pop, context,list| edebug("paginate: #{@page_n}","printing","info") page_full=false cr = context.cairo_context while true if @child_list #step first on citer if citer is nil if @citer.nil? @citer=@child_model.iter_first else @citer=nil unless @citer.next! end unless @piter.nil? #go to next valid citer which meets key-relation begin break if @citer.nil? go_next=false #check for parent_key go_next=true unless @citer[child_list.list_model.column_of_child_key] == @piter[child_list.list_model.column_of_parent_key] #check for parent_key2 go_next=true unless @citer[child_list.list_model.column_of_child_key2] == @piter[child_list.list_model.column_of_parent_key2] if !child_list.list_model.column_of_child_key2.nil? && go_next #check child's filters filter_count=0 filter_hits=0 @child_list.columns.each{|column| fl=get_conf(@child_list.get_id,column.header["id"],"filter").to_s.upcase case column.header['type'] when 'gtk_combo', 'gtk_const_combo' then fl = (fl=="-1" or fl=="") ? "" : "=#{fl}" end comp=@citer[column.header["model_col"]].to_s.upcase if fl.length>0 filter_count=filter_count+1 filter_hits=filter_hits+ if ['gtk_int','Integer','gtk_float','gtk_progress','gtk_duration','gtk_timestamp'].include? column.header['type'] case fl[0].chr when "<" then comp.to_f < fl[1 .. fl.length].to_f ? 1: 0 when ">" then comp.to_f > fl[1 .. fl.length].to_f ? 1: 0 when "!" then comp.to_f != fl[1 .. fl.length].to_f ? 1: 0 when "=" then comp.to_f == fl[1 .. fl.length].to_f ? 1: 0 else comp.to_f == fl[1 .. fl.length].to_f ? 1: 0 end else case fl[0].chr when "=" then comp == fl[1 .. fl.length] ? 1: 0 when "<" then comp < fl[1 .. fl.length] ? 1: 0 when ">" then comp > fl[1 .. fl.length] ? 1: 0 when "!" then comp != fl[1 .. fl.length] ? 1: 0 else comp.index(fl) ? 1: 0 end end end } go_next=filter_hits != filter_count unless go_next @citer=nil if !@citer.next! if go_next end while go_next #if citer is nil we go to next piter if @citer.nil? #print sub_sums if print_sub_sums and @sum_avail il=IterLayout.new(cr,@sub_sums,child_list.columns, self,child_sum_font ) # print il.inspect il.set_line_above(true) lay_it(il) #clear sums @sub_sums.each_key{|key| @sub_sums[key]=0} @sum_avail=false end #we print piter if @piter.nil? break if past_last=!@piter=list.model.iter_first else break if past_last=!@piter.next_with_children end @sums.each_key{|key| @sums[key]=@sums[key]+@piter[key].to_f} il=IterLayout.new(cr,@piter,list.columns, self,cell_font) il.set_line_above(line_above_parent) break if lay_it(il) else #calc sums if print_sub_sums @sub_sums.each_key{|key| @sub_sums[key]=@sub_sums[key]+@citer[key].to_f} @sum_avail=true end # p "citer: #{@citer[child_list.column_of_id]} #{@past_last} #{il.inspect}" #we print citer il=IterLayout.new(cr,@citer,child_list.columns, self,child_cell_font) break if lay_it(il) end else if @piter.nil? break if past_last=!@piter=list.model.iter_first end @sums.each_key{|key| @sums[key]=@sums[key]+@piter[key].to_f} if @piter il=IterLayout.new(cr,@piter,list.columns, self,cell_font) if lay_it(il) #do not print it twice past_last=!@piter.next_with_children break end break if past_last=!@piter=@piter.next_with_children edebug("piter: #{@piter[list.list_model.column_of_id]} #{@past_last}","printing","debug") end end if past_last and print_sums il=IterLayout.new(cr,@sums,list.columns, self,sum_font) il.set_line_above(true) lay_it(il) end pop.set_n_pages(@page_n+1) einfo("paginated #{pop.n_pages} pages","printing") past_last } #paginate signal_connect('draw-page'){|me,context,page_number| edebug("draw-page: #{page_number}","printing","info") cr = context.cairo_context @header.draw(cr) @columns_header.draw(cr) if child_list @child_columns_header.draw(cr) else cr.set_line_width(@cell_line_width) lcol=nil list.columns.each{|col| if col.printable? cr.move_to(@column_pos[col.data],@columns_header.y + @columns_header.height + @header_line_width) cr.line_to(@column_pos[col.data],@footer.y) #FIXME lcol=col end } cr.move_to(@column_pos[lcol.data]+@column_width[lcol.data],@columns_header.y + @columns_header.height + @header_line_width) cr.line_to(@column_pos[lcol.data]+@column_width[lcol.data],@footer.y) #FIXME cr.stroke end @footer.draw(cr,page_number) #draw cells @iter_layouts.each{|il| il.draw(cr) if il.page == page_number } cr.stroke } signal_connect('status-changed'){|pop| einfo("status:#{pop.status_string}","printing") } end
Public Instance Methods
lay_it(il)
click to toggle source
# File lib/ListHolder/EditableList/ListPrintOperation.rb, line 328 def lay_it(il) if @current_height + il.row_height > @footer.y #page full page_full=true einfo("page full","printing") edebug("current_height: #{@current_height}, row.height: #{il.height}, footer_position: #{@footer.y}","printing") @current_height=@headers_height @page_n=@page_n+1 end il.set_page(@page_n) il.set_y(@current_height).set_row_spacing(@row_spacing) @current_height=@current_height+il.row_height+2*@row_spacing @iter_layouts.push(il) edebug(il.inspect,"printing") page_full end
pango_height()
click to toggle source
# File lib/ListHolder/EditableList/ListPrintOperation.rb, line 348 def pango_height height * Pango::SCALE end
pango_width()
click to toggle source
# File lib/ListHolder/EditableList/ListPrintOperation.rb, line 345 def pango_width width * Pango::SCALE end
run_print_dialog()
click to toggle source
# File lib/ListHolder/EditableList/ListPrintOperation.rb, line 352 def run_print_dialog res = run(Gtk::PrintOperation::Action::PRINT_DIALOG, list.get_ancestor(Gtk::Window)) einfo("return: "+ case res when RESULT_ERROR "error" when RESULT_CANCEL "cancelled" when RESULT_APPLY "applied" when RESULT_IN_PROGRESS "in progress" end,"printing") end
to_s()
click to toggle source
# File lib/ListHolder/EditableList/ListPrintOperation.rb, line 367 def to_s;"<ListPrintOperation:#{@list.moditem["display"]}>";end