Class: IterLayout

Inherits:
Object
  • Object
show all
Includes:
ManqodCommon
Defined in:
lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb

Overview

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint([email protected])

Constant Summary

Constants included from ManqodCommon

ManqodCommon::CRITICAL, ManqodCommon::DEBUG, ManqodCommon::ERROR, ManqodCommon::INFO, ManqodCommon::NORMAL, ManqodCommon::WARNING

Constants included from Eprint

Eprint::DOMAIN, Eprint::LEVEL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ManqodCommon

#add_where, #admin, #admin_cache, #admin_qrow, #admin_rows, #backtrace_to_debug, #cache, #changed_ids_of_base, #client, #client_fields, #client_image_of_id, #client_qrow, #client_query, #client_rows, #eeval, #escape_string, #getBinding, #guess_base, #guess_table, #image_of_id, #lzero, #manqod_db, #measure, #myexec, #nick, #nick_id, #number_format, #qrow, #query, #reconnect_manqod_db, #rows, #run_events, #send_message, #sendmail, #set_manqod_db_uri, #set_nick

Methods included from Eprint

#ecode, #edebug, #eerror, #einfo, #enormal, #eprint, #ewarn, #gtk_set_edebug, #set_edebug, #tell_exception

Constructor Details

#initialize(cr, iter, columns, pop, font) ⇒ IterLayout

Returns a new instance of IterLayout.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb', line 7

def initialize(cr,iter,columns,pop,font)
  @row_height=0
  @page=0
  @y=0
  @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) unless iter.nil?
        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

Instance Attribute Details

#cell_layoutsObject (readonly)

Returns the value of attribute cell_layouts.



57
58
59
# File 'lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb', line 57

def cell_layouts
  @cell_layouts
end

#pageObject (readonly)

Returns the value of attribute page.



57
58
59
# File 'lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb', line 57

def page
  @page
end

#popObject (readonly)

Returns the value of attribute pop.



57
58
59
# File 'lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb', line 57

def pop
  @pop
end

#row_heightObject (readonly)

Returns the value of attribute row_height.



57
58
59
# File 'lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb', line 57

def row_height
  @row_height
end

#yObject (readonly)

Returns the value of attribute y.



57
58
59
# File 'lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb', line 57

def y
  @y
end

Instance Method Details

#draw(cr) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb', line 79

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)
    cr.line_to(max_x,y+@crlw)
     cr.stroke
  end
  if @pop.row_underline>0
    cr.set_line_width(@pop.row_underline)
    cr.move_to(min_x,y+@row_height)
    cr.line_to(max_x,y+@row_height)
     cr.stroke
  end
end

#heightObject



67
68
69
# File 'lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb', line 67

def height
  @row_height
end

#inspectObject



163
164
165
# File 'lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb', line 163

def inspect
  @insptext+"\theight=#{height}\ty=#{y}\tpage=#{page}"
end

#set_line_above(line_above) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb', line 59

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) ⇒ Object



75
76
77
# File 'lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb', line 75

def set_page(page)
  @page=page
end

#set_y(newY) ⇒ Object



70
71
72
73
74
# File 'lib/ListHolder/EditableList/ListPrintOperation/IterLayout.rb', line 70

def set_y(newY)
  @y=newY
  @gr.py1=@y if @gr
  self
end