Class: PrintItem

Inherits:
Object
  • Object
show all
Includes:
ManqodCommon
Defined in:
lib/Print/PrintItem.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(pop, itemdata, cr) ⇒ PrintItem

Returns a new instance of PrintItem.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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

Instance Attribute Details

#cell_line_widthObject (readonly)

Returns the value of attribute cell_line_width.



26
27
28
# File 'lib/Print/PrintItem.rb', line 26

def cell_line_width
  @cell_line_width
end

#column_posObject (readonly)

Returns the value of attribute column_pos.



25
26
27
# File 'lib/Print/PrintItem.rb', line 25

def column_pos
  @column_pos
end

#column_widthObject (readonly)

Returns the value of attribute column_width.



25
26
27
# File 'lib/Print/PrintItem.rb', line 25

def column_width
  @column_width
end

#crObject (readonly)

Returns the value of attribute cr.



24
25
26
# File 'lib/Print/PrintItem.rb', line 24

def cr
  @cr
end

#draw_header_cell_bordersObject (readonly)

Returns the value of attribute draw_header_cell_borders.



25
26
27
# File 'lib/Print/PrintItem.rb', line 25

def draw_header_cell_borders
  @draw_header_cell_borders
end

#fill_header_backgroundObject (readonly)

Returns the value of attribute fill_header_background.



25
26
27
# File 'lib/Print/PrintItem.rb', line 25

def fill_header_background
  @fill_header_background
end

#fontObject (readonly)

Returns the value of attribute font.



24
25
26
# File 'lib/Print/PrintItem.rb', line 24

def font
  @font
end

#header_line_widthObject (readonly)

Returns the value of attribute header_line_width.



25
26
27
# File 'lib/Print/PrintItem.rb', line 25

def header_line_width
  @header_line_width
end

#heightObject (readonly)

Returns the value of attribute height.



24
25
26
# File 'lib/Print/PrintItem.rb', line 24

def height
  @height
end

#listObject (readonly)

Returns the value of attribute list.



26
27
28
# File 'lib/Print/PrintItem.rb', line 26

def list
  @list
end

#next_iterObject (readonly)

Returns the value of attribute next_iter.



26
27
28
# File 'lib/Print/PrintItem.rb', line 26

def next_iter
  @next_iter
end

#pageObject (readonly)

Returns the value of attribute page.



24
25
26
# File 'lib/Print/PrintItem.rb', line 24

def page
  @page
end

Returns the value of attribute print_with_gantt.



26
27
28
# File 'lib/Print/PrintItem.rb', line 26

def print_with_gantt
  @print_with_gantt
end

#row_underlineObject (readonly)

Returns the value of attribute row_underline.



25
26
27
# File 'lib/Print/PrintItem.rb', line 25

def row_underline
  @row_underline
end

#sum_line_widthObject (readonly)

Returns the value of attribute sum_line_width.



26
27
28
# File 'lib/Print/PrintItem.rb', line 26

def sum_line_width
  @sum_line_width
end

#text_alignmentObject (readonly)

Returns the value of attribute text_alignment.



24
25
26
# File 'lib/Print/PrintItem.rb', line 24

def text_alignment
  @text_alignment
end

#txtObject (readonly)

Returns the value of attribute txt.



24
25
26
# File 'lib/Print/PrintItem.rb', line 24

def txt
  @txt
end

#typeObject (readonly)

Returns the value of attribute type.



24
25
26
# File 'lib/Print/PrintItem.rb', line 24

def type
  @type
end

#widthObject (readonly)

Returns the value of attribute width.



24
25
26
# File 'lib/Print/PrintItem.rb', line 24

def width
  @width
end

#xObject (readonly)

Returns the value of attribute x.



24
25
26
# File 'lib/Print/PrintItem.rb', line 24

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



24
25
26
# File 'lib/Print/PrintItem.rb', line 24

def y
  @y
end

Instance Method Details

#draw(cr_to_draw_to) ⇒ Object



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
57
58
59
60
61
62
63
64
65
66
# 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?Boolean

Returns:

  • (Boolean)


208
209
210
# File 'lib/Print/PrintItem.rb', line 208

def extended?
	@extended == true
end

#inspectObject



234
235
236
# File 'lib/Print/PrintItem.rb', line 234

def inspect
	"<PrintItem: id:#{@item_id}, type:#{@type}, page:#{@page}, txt:#{@txt}>"
end

#page?(to_check) ⇒ Boolean

Returns:

  • (Boolean)


205
206
207
# File 'lib/Print/PrintItem.rb', line 205

def page?(to_check)
	@page.to_i == to_check.to_i
end

#set_height(new_height) ⇒ Object



229
230
231
232
# File 'lib/Print/PrintItem.rb', line 229

def set_height(new_height)
	@height=new_height
	self
end

#set_page_shift(new_page_shift) ⇒ Object



211
212
213
214
215
# 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) ⇒ Object



221
222
223
224
# 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) ⇒ Object



217
218
219
220
# File 'lib/Print/PrintItem.rb', line 217

def set_txt(new_txt)
	@txt=new_txt
	self
end

#set_y(new_y) ⇒ Object



225
226
227
228
# File 'lib/Print/PrintItem.rb', line 225

def set_y(new_y)
	@y=new_y
	self
end

#to_sObject



237
238
239
# File 'lib/Print/PrintItem.rb', line 237

def to_s
	inspect
end

#type?(to_check) ⇒ Boolean

Returns:

  • (Boolean)


202
203
204
# File 'lib/Print/PrintItem.rb', line 202

def type?(to_check)
	@type == to_check
end

#updateObject



68
69
70
71
72
73
74
75
76
77
78
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# 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