class IterLayout

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_layouts[R]
page[R]
pop[R]
row_height[R]
y[R]

Public Class Methods

new(cr,iter,columns,pop,font) click to toggle source
# File lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb, line 7
def initialize(cr,iter,columns,pop,font)
        @row_height=0
        @page=0
        @y=0
        @row_spacing=1
        @pop=pop
        @iter=iter.clone
        @cell_layouts=Hash.new
        @insptext=""
        @cr=cr
        @crlw=0
        @gr=nil
        #create the layouts for the cells, and find out the highest cell
        columns.each{|col| 
                if col.printable?
                        text_cell = cr.create_pango_layout
                        text_cell.set_font_description(Pango::FontDescription.new(font)).set_width((pop.column_width[col.data]-@pop.cell_line_width)*Pango::SCALE)
                        text_cell.set_alignment(col.pango_layout_alignment)
                        text_cell.set_wrap(Pango::Layout::WRAP_WORD_CHAR).set_ellipsize(Pango::Layout::ELLIPSIZE_NONE)
                        text_to_display=case col.header["type"]
                                when "gtk_ordering" then col.path_format(@iter) if iter && iter.class.name == "Gtk::TreeIter"
                                when "gtk_duration" then (@iter[col.colnum] || 0).to_i.strftime(col.duration_format)
                                when "gtk_timestamp" then Time.at(@iter[col.colnum] || 0).strftime(col.timestamp_format)
                                when "gtk_const_text" then col.renderer.get_display(@iter[col.colnum].to_s)
                                when "gtk_const_combo","gtk_combo" then col.renderer.get_text_from_value(@iter[col.colnum].to_s)
                                else
                                case col.data_type.to_s
                                                when "Bignum","Integer","Float" then number_format(@iter[col.colnum],col.decimals_attribute)
                                                else @iter[col.colnum].to_s
                                end
                        end
                        text_cell.set_text(text_to_display.to_s)
                        text_height = text_cell.size[1] / Pango::SCALE
                        @row_height = text_height+@pop.cell_line_width+@pop.row_underline if @row_height < text_height+@pop.cell_line_width+@pop.row_underline
                        cell_layouts[col.data] = text_cell
                        @insptext+="#{col.data_type}:#{text_cell.text}\t"
                end
        }
  if pop.print_with_gantt
      @gantt=pop.list.holder.gantt.gantt
      @gr=@gantt.rectangle_by_id?(@iter[@pop.list.list_model.column_of_id])
      min_x=pop.column_pos[:gantt]
  end
  if @gr
                gres=(@gantt.max_time-@gantt.min_time).to_f/pop.column_width[:gantt].to_f
                @gr.px1=min_x+(@gr.start-@gantt.min_time)/gres
                @gr.pwidth=@gr.dur/gres
                @gr.pheight=height
                @gr.py1=@y
  end
end

Public Instance Methods

draw(cr) click to toggle source
# File lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb, line 84
def draw(cr)
        min_x=60000
        max_x=0
        cr.set_line_width(1).set_source_rgb(0,0,0).set_dash(100000).set_line_cap(Cairo::LineCap::ROUND)
        cell_layouts.each_pair{|key,layout|
                min_x=pop.column_pos[key] if min_x>pop.column_pos[key]
                max_x=pop.column_pos[key]+pop.column_width[key] if max_x<pop.column_pos[key]+pop.column_width[key]
                cr.move_to(pop.column_pos[key]+@pop.cell_line_width,y+@crlw*3+@pop.cell_line_width)
                cr.show_pango_layout(layout)
      cr.stroke
  }
  if @gr
                if @gr.has_child? then
                        #draw a parent
                        cr.set_line_width(1).set_source_rgba(0.1,0.1,0.1,0.9).set_dash(100000)
                        cr.move_to(@gr.px1,@gr.py2).line_to(@gr.px1,@gr.py).line_to(@gr.px2,@gr.py).line_to(@gr.px2,@gr.py2)
                else
                        #fill rectangle
                        cr.set_line_width(0.3).set_dash(100000).set_source_rgba(0.1,0.1,0.1,0.04)
                        cr.rounded_rectangle(@gr.px1,@gr.py1+1,@gr.pwidth,@gr.pheight-2,2)
                        cr.fill
                        cr.stroke
                        #draw rectangle
                        cr.set_source_rgba(0.1,0.1,0.9,0.7)
                        cr.rounded_rectangle(@gr.px1,@gr.py1+1,@gr.pwidth,@gr.pheight-2,2)
                        cr.stroke
                        max_x=@gr.px2 if max_x<@gr.px2
                end
                cr.stroke
                #successors arrow
                @gr.successors.each_value{|pred|
                        if pred && pred.px1
                                cr.set_line_width(0.3).set_source_rgba(0.1,0.1,0.9,0.7).set_dash(100000)
                                xx1=[@gr.px1+10,@gr.px2].min
                                yy4=if @gr.py<pred.py1 then pred.py1-1 else pred.py2+1 end
                                yya=if @gr.py<pred.py then -2 else 2 end
                                cr.move_to(xx1,@gr.py)
                                cr.curve_to(pred.px,@gr.py,pred.px,@gr.py,pred.px,yy4)
                                #arrow
                                cr.move_to(pred.px,yy4).rel_line_to(-2,yya)
                                cr.move_to(pred.px,yy4).rel_line_to(2,yya)
                                cr.stroke
                        end
                }
                #start text
                cr.set_source_rgba(0,0,0,0.9)
                scell = cr.create_pango_layout.
              set_font_description(Pango::FontDescription.new(pop.gantt_cell_font)).
              set_text(@gr.fstart)
      sheight = scell.size[1] / Pango::SCALE
      swidth = scell.size[0] / Pango::SCALE
      if @gr.px1-(swidth+2) > pop.column_pos[:gantt]
            cr.move_to(@gr.px1-(swidth+2),@gr.py-sheight/2)
                        cr.show_pango_layout(scell)
            cr.stroke
         end
                #finish text
                fcell = cr.create_pango_layout.
              set_font_description(Pango::FontDescription.new(pop.gantt_cell_font)).
              set_text(@gr.ffinish)
      fheight = scell.size[1] / Pango::SCALE
      fwidth = scell.size[0] / Pango::SCALE
      if @gr.px2+(fwidth+2) < pop.column_pos[:gantt] + pop.column_width[:gantt]
            cr.move_to(@gr.px2+2,@gr.py-sheight/2)
                        cr.show_pango_layout(fcell)
            cr.stroke
         end
        end

        cr.set_source_rgba(0.1,0.1,0.1,0.7).set_dash(100000)
        if @line_above
                cr.set_line_width(@pop.sum_line_width)
                cr.move_to(min_x,y+@crlw-@row_spacing)
                cr.line_to(max_x,y+@crlw-@row_spacing)
      cr.stroke
        end
        if @pop.row_underline>0
                cr.set_line_width(@pop.row_underline)
                cr.move_to(min_x,y+@row_height+@row_spacing)
                cr.line_to(max_x,y+@row_height+@row_spacing)
      cr.stroke
        end
end
height() click to toggle source
# File lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb, line 68
def height
        @row_height
end
inspect() click to toggle source
# File lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb, line 168
def inspect
        @insptext+"\theight=#{height}\ty=#{y}\tpage=#{page}"
end
set_line_above(line_above) click to toggle source
# File lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb, line 60
def set_line_above(line_above)
        if @line_above=line_above
                @crlw=@pop.sum_line_width
                @row_height=@row_height+@crlw*3
        end
        self
end
set_page(page) click to toggle source
# File lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb, line 80
def set_page(page)
        @page=page
end
set_row_spacing(ns) click to toggle source
# File lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb, line 76
def set_row_spacing(ns)
        @row_spacing=ns
        self
end
set_y(newY) click to toggle source
# File lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb, line 71
def set_y(newY)
        @y=newY
        @gr.py1=@y if @gr
        self
end