class PrintItem

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint(dpblnt@gmail.com)

Attributes

cell_line_width[R]
column_pos[R]
column_width[R]
cr[R]
draw_header_cell_borders[R]
fill_header_background[R]
font[R]
header_line_width[R]
height[R]
list[R]
next_iter[R]
page[R]
print_with_gantt[R]
row_underline[R]
sum_line_width[R]
text_alignment[R]
txt[R]
type[R]
width[R]
x[R]
y[R]

Public Class Methods

new(pop,itemdata,cr) click to toggle source
# File lib/Print/PrintItem.rb, line 8
def initialize(pop,itemdata,cr)
        @pop=pop
        @type=itemdata["gtktype"]
        @x=itemdata["x"].to_f
        @y=itemdata["y"].to_f
        @txt=itemdata["txt"]
        @font=itemdata["font"]
        @width=itemdata["width"].to_f
        @height=itemdata["height"].to_f
        @page=itemdata["page_number"].to_i
        @text_alignment=itemdata["text_alignment"]
        @item_id=itemdata["id"]
        @page_shift=0
        @start_iter=nil
        @cr=cr
end

Public Instance Methods

draw(cr_to_draw_to) click to toggle source
# File lib/Print/PrintItem.rb, line 28
def draw(cr_to_draw_to)
        @cr=cr_to_draw_to
        edebug("drawing item","printing","debug")
        case @type
                when "text" then
                        @layout.draw(cr)
                when "line" then
                        cr.move_to(x,y)
                        cr.line_to(x+width,y+height)
                when "rectangle" then
                        cr.rectangle(x,y,width,height)
                when "list" then
                        unless @layout.nil?
                                #still draw a rectangle
                                cr.rectangle(x,y,width,height)
                                @layout.draw(cr)
                        else
                                cr.set_line_width(@cell_line_width)
                                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],@sum_y) #FIXME
                                        end
                                }
                                cr.stroke
                                #draw a border around the list
                                cr.rectangle(x,y,width,@sum_y-y+@sum_height)
                                cr.stroke
                                #lay the layouts, including header
                                @layouts.each{|il| il.draw(cr)}
                        end
                when 'image' then
                        cr.set_source_pixbuf(@pixbuf,@x,@y)
                        cr.paint
                else
                        edebug("unknown print item #{@type}","printing","warning")
        end
        cr.stroke
end
extended?() click to toggle source
# File lib/Print/PrintItem.rb, line 208
def extended?
        @extended == true
end
inspect() click to toggle source
# File lib/Print/PrintItem.rb, line 234
def inspect
        "<PrintItem: id:#{@item_id}, type:#{@type}, page:#{@page}, txt:#{@txt}>"
end
page?(to_check) click to toggle source
# File lib/Print/PrintItem.rb, line 205
def page?(to_check)
        @page.to_i == to_check.to_i
end
set_height(new_height) click to toggle source
# File lib/Print/PrintItem.rb, line 229
def set_height(new_height)
        @height=new_height
        self
end
set_page_shift(new_page_shift) click to toggle source
# File lib/Print/PrintItem.rb, line 211
def set_page_shift(new_page_shift)
        @page_shift=new_page_shift
        @page+=@page_shift
        self
end
set_start_iter(new_start_iter) click to toggle source
# File lib/Print/PrintItem.rb, line 221
def set_start_iter(new_start_iter)
        @start_iter=new_start_iter
        self
end
set_txt(new_txt) click to toggle source
# File lib/Print/PrintItem.rb, line 217
def set_txt(new_txt)
        @txt=new_txt
        self
end
set_y(new_y) click to toggle source
# File lib/Print/PrintItem.rb, line 225
def set_y(new_y)
        @y=new_y
        self
end
to_s() click to toggle source
# File lib/Print/PrintItem.rb, line 237
def to_s
        inspect
end
type?(to_check) click to toggle source
# File lib/Print/PrintItem.rb, line 202
def type?(to_check)
        @type == to_check
end
update() click to toggle source
# File lib/Print/PrintItem.rb, line 68
def update
        case @type
                when "text" then @layout=TextLayout.new(cr,@txt,@font,@width,@x,@y,@text_alignment)
                when 'image' then
                        pb = if client.nil?
                                DrbImages.instance.image_of_id(@txt.to_i,nil)
                        else
                                MyImage.new(@txt,true).pixbuf #FIXME! use the cache
                        end
                        @pixbuf = pb.scale(@width,@height)
                when "list" then
                        list_id=@txt
                        @list=@pop.caller_object.holder.notebook.moditem_by_id(list_id) unless @pop.is_test
                        if @pop.is_test? or list.nil?
                                #printing a rectangle insted
                                @layout=TextLayout.new(cr,
                                        if @pop.is_test?
                                                "list ##{list_id} is here"
                                        else
                                                edebug("list ##{list_id} not found","printing","warning")
                                                "list ##{list_id} not found"
                                        end,
                                        @font,@width,@x,@y)
                                        else
                                                #building the list
                                                @print_sums=list.gtk_attribute("print_sums")=="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"
                                                @row_spacing=(list.gtk_attribute("row_spacing") || 1.0).to_f
                                                @column_spacing=(list.gtk_attribute("column_spacing") || 1.0).to_f
                                                @draw_header_cell_borders=list.gtk_attribute("draw_header_cell_borders")=="true"
                                                @fill_header_background=list.gtk_attribute("fill_header_background")=="true"
                                                @header_line_width=(list.gtk_attribute("header_line_width") || 0.5).to_f
                                                @draw_header_line=list.gtk_attribute("draw_header_line") == "true"
                                                @cell_line_width=(list.gtk_attribute("cell_line_width") || 0.1).to_f
                                                @sum_line_width=(list.gtk_attribute("sum_line_width") || 0.3).to_f
                                                @print_title=list.gtk_attribute("print_title")=="true"
                                                @row_underline=(list.gtk_attribute("row_underline") || 0.0).to_f
                                                @print_with_gantt=(list.gtk_attribute("print_with_gantt") || "false") == "true"
                                                
                                                @layouts=Array.new
                                                @current_height=y
                                                if @print_title
                                                        title_layout=TextLayout.new(cr,"#{list.title}",@font,@width,@x,@current_height,'center')
                                                        @layouts.push(title_layout)
                                                        @current_height+=title_layout.height
                                                end
                                                

                                                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
                                                
                                                eerror("no printable columns for #{list}") if columns_width_sum==0
                                                coef=(width-col_cnt*@column_spacing)/columns_width_sum
                                                edebug("colums width sum: #{columns_width_sum}","printing","debug")

                                                #@column_width will store the column positions on the context
                                                @column_width=Hash.new
                                                @column_pos=Hash.new #column positions
                                                @sums=Hash.new #cell value sums are calculated here
                                                col_cur_x=@x
                                                list.columns.each{|col|
                                                        if col.printable?
                                                                @column_pos[col.data]=col_cur_x
                                                                @column_width[col.data]=col.width.to_f*coef
                                                                col_cur_x+=@column_width[col.data]+@column_spacing
                                                                @sums[col.colnum]=0 if col.header['type']=="gtk_int" or col.header['type']=="gtk_float"
                                                        end
                                                }
                                                
                                                @columns_header=ColumnsHeaderLayout.new(self,cr,list.columns,@columns_header_font).set_y(@current_height)
                                                @layouts.push(@columns_header)
                                                @current_height += @columns_header.height + @header_line_width + @row_spacing

                                                @sum_y=@y+height #max y for iters, when less rows than designed, we'll have the footer @ design position
                                                
                                                @sum_height=if @print_sums then @columns_header.height else 0 end #FIXME: calculating with header_height for sum_height
                                                @sum_y-=@sum_height
                                                
                                                iter=@start_iter
                                                while true
                                                        if iter.nil?
                                                                iter=list.list_model.sorter.iter_first
                                                        else 
                                                                prev_iter=iter.clone
                                                                iter=nil if !iter.next!
                                                        end
                                                        while !iter.nil? and not (iter[list.list_model.column_of_child_key].to_i == @pop.myrows[@pop.current_row][list.list_model.key_parent].to_i or (!list.list_model.column_of_child_key2.nil? and iter[list.list_model.column_of_child_key2].to_i == @pop.myrows[@pop.current_row][list.list_model.key_parent2].to_i)) do
                                                                iter=nil if !iter.next!
                                                        end
                                                        if iter.nil?
                                                                break
                                                        else
                                                                il=IterLayout.new(cr,iter,list.columns, self,@cell_font)

                                                                #extend the sublist till the bottom of page
                                                                if @current_height + il.row_height > @sum_y and !@extended
                                                                        @sum_y=@pop.paper_height - @sum_height
                                                                        @extended=true
                                                                        edebug("forcing page_shift for list #{list}","printing","info")
                                                                end
                                                                if @current_height + il.row_height > @pop.paper_height - @sum_height
                                                                        #no more space
                                                                        page_full=true
                                                                        @next_iter=prev_iter
                                                                        edebug("breaking list #{list} to the next page","printing","info")
                                                                        break
                                                                end
                                                                il.set_y(@current_height).set_row_spacing(@row_spacing)
                                                                @current_height+=il.row_height+2*@row_spacing
                                                                @layouts.push(il)
                                                                edebug("row :#{il.inspect}","printing")
                                                                @sums.each_key{|key| @sums[key]=@sums[key]+iter[key].to_f}
                                                        end
                                                end
                                                
                                                if @print_sums
                                                        il=IterLayout.new(cr,@sums,list.columns, self,@sum_font).set_y(@sum_y).set_line_above(@print_sums)
                                                        @layouts.push(il)
                                                end
                                                
                                        end

        end
        
        self
end