Class: PrintEditorItem
- Inherits:
-
Gtk::EventBox
- Object
- Gtk::EventBox
- PrintEditorItem
show all
- Includes:
- ManqodCommon
- Defined in:
- lib/PrintEditor/PrintEditorItem.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
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
-
#info ⇒ Object
-
#initialize(page_layout, page_num, id, x, y, width, height, gtk_type, text, font, text_alignment = "left") ⇒ PrintEditorItem
constructor
A new instance of PrintEditorItem.
-
#modify_font(new_font = @font) ⇒ Object
-
#moditemid ⇒ Object
-
#move_me(newx = @x, newy = @y, new_page = @page_num) ⇒ Object
-
#print_editor ⇒ Object
-
#remove_from_mysql ⇒ Object
-
#set_editable(editable) ⇒ Object
-
#set_size_request(new_width = @width, new_height = @height) ⇒ Object
-
#set_text(newtext = @text) ⇒ Object
-
#set_text_alignment(na = "left") ⇒ Object
-
#text ⇒ Object
-
#text_from_mysql(nt = text) ⇒ Object
-
#text_to_mysql ⇒ Object
-
#to_mysql ⇒ Object
-
#to_s ⇒ Object
-
#unfocus ⇒ Object
-
#zoom ⇒ Object
-
#zoomed ⇒ Object
#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(page_layout, page_num, id, x, y, width, height, gtk_type, text, font, text_alignment = "left") ⇒ PrintEditorItem
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
57
58
59
60
61
62
63
64
65
66
67
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
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 7
def initialize(page_layout,page_num,id,x,y,width,height,gtk_type,text,font,text_alignment="left")
@id=id
@x=x
@y=y
@pagenum=page_num
@page_layout=page_layout
@gtk_type=gtk_type
@editable=true
@width=width
@height=height
@text=text
@font=font
@dragging=false
@resizing=false
super()
@child=case gtk_type
when 'line','rectange' then Gtk::DrawingArea.new
when 'text' then Gtk::TextView.new
when 'list' then Gtk::Frame.new("list")
when 'image' then Gtk::Image.new(Gtk::Stock::MISSING_IMAGE,Gtk::IconSize::DIALOG)
else Gtk::Label.new("unknown object")
end
modify_font
@child.modify_base(Gtk::StateType::PRELIGHT,Gdk::Color.parse("#EFEFEF"))
@child.modify_base(Gtk::StateType::NORMAL,Gdk::Color.parse("#FBFBFB"))
set_text_alignment(text_alignment)
add(@child)
set_size_request(width,height)
set_can_focus(true)
set_visible_window(true)
set_border_width(0)
set_above_child(true)
show_all
@child.signal_connect('expose-event'){|me,event|
case gtk_type
when 'line'
cr=me.window.create_cairo_context
cr.scale(print_editor.zoom,print_editor.zoom)
cr.move_to(0,0).line_to(@width,@height)
cr.stroke
when 'rectangle'
cr=me.window.create_cairo_context
cr.scale(print_editor.zoom,print_editor.zoom)
cr.rectangle(0,0,@width,@height)
cr.stroke
when 'text',"list","image"
else
edebug("unknown print-type: #{gtk_type}","printing","warning")
end
}
signal_connect('button-press-event'){|me,event|
if event.event_type == Gdk::Event::BUTTON2_PRESS then
set_above_child(false) if @gtk_type == "text"
else
print_editor.set_focused_item(self)
if event.state.control_mask?
@xshift=event.x
@yshift=event.y
@owidth=@width*zoom
@oheight=@height*zoom
@pX,@pY=parent.pointer
case event.button
when 1 then @dragging=true
when 2 then @resizing=true
end
end
end
true
}
signal_connect('motion-notify-event'){|me,event|
snap=5
if @dragging or @resizing
pe=print_editor
pe.set_focused_item(self)
px=parent.pointer[0]
py=parent.pointer[1]
if @dragging
info.item_x.set_value(((px-@xshift)/zoom/snap).round*snap)
info.item_y.set_value(((py-@yshift)/zoom/snap).round*snap)
end
if @resizing
info.item_width.set_value(((@owidth+px-@pX)/zoom/snap).round*snap)
info.item_height.set_value(((@oheight+py-@pY)/zoom/snap).round*snap)
end
end
}
signal_connect('button-release-event'){|me,event| @dragging=false;@resizing=false;}
end
|
Instance Attribute Details
#dragging ⇒ Object
Returns the value of attribute dragging.
98
99
100
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 98
def dragging
@dragging
end
|
#drawing ⇒ Object
Returns the value of attribute drawing.
98
99
100
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 98
def drawing
@drawing
end
|
#editable ⇒ Object
Returns the value of attribute editable.
97
98
99
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 97
def editable
@editable
end
|
#font ⇒ Object
Returns the value of attribute font.
97
98
99
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 97
def font
@font
end
|
#gtk_type ⇒ Object
Returns the value of attribute gtk_type.
97
98
99
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 97
def gtk_type
@gtk_type
end
|
#height ⇒ Object
Returns the value of attribute height.
97
98
99
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 97
def height
@height
end
|
#id ⇒ Object
Returns the value of attribute id.
97
98
99
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 97
def id
@id
end
|
#page_layout ⇒ Object
Returns the value of attribute page_layout.
98
99
100
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 98
def page_layout
@page_layout
end
|
#pagenum ⇒ Object
Returns the value of attribute pagenum.
97
98
99
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 97
def pagenum
@pagenum
end
|
#text_alignment ⇒ Object
Returns the value of attribute text_alignment.
97
98
99
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 97
def text_alignment
@text_alignment
end
|
#width ⇒ Object
Returns the value of attribute width.
97
98
99
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 97
def width
@width
end
|
#x ⇒ Object
Returns the value of attribute x.
97
98
99
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 97
def x
@x
end
|
#y ⇒ Object
Returns the value of attribute y.
97
98
99
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 97
def y
@y
end
|
Instance Method Details
#info ⇒ Object
100
101
102
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 100
def info
print_editor.info
end
|
#modify_font(new_font = @font) ⇒ Object
158
159
160
161
162
163
164
165
166
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 158
def modify_font(new_font=@font)
if @gtk_type=="text"
@font=new_font
edebug("setting font :"+@font,"printing","info")
fontdesc=Pango::FontDescription.new(@font)
@child.modify_font(fontdesc) unless fontdesc.nil?
end
self
end
|
#moditemid ⇒ Object
219
220
221
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 219
def moditemid
print_editor.moditemid
end
|
#move_me(newx = @x, newy = @y, new_page = @page_num) ⇒ Object
111
112
113
114
115
116
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 111
def move_me(newx=@x,newy=@y,new_page=@page_num)
@x=newx
@y=newy
@page_num=new_page
page_layout.move(self)
end
|
#print_editor ⇒ Object
223
224
225
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 223
def print_editor
@page_layout.print_editor
end
|
#remove_from_mysql ⇒ Object
214
215
216
217
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 214
def remove_from_mysql
query("delete from gtkprintitems where id='#{id}'")
edebug("deleted","printing","info")
end
|
#set_editable(editable) ⇒ Object
150
151
152
153
154
155
156
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 150
def set_editable(editable)
if @gtk_type=="text"
@child.set_editable(editable)
@child.set_sensitive(editable)
end
self
end
|
#set_size_request(new_width = @width, new_height = @height) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 118
def set_size_request(new_width=@width,new_height=@height)
if @gtk_type == "image" and !@image_iter.nil?
im=DrbImages.instance.client_image_of_id(@image_iter[0])
if @width != new_width then
@width=new_width
@height=im.height*@width / im.width
info.item_height.set_value(@height)
else
@height=new_height
@width=im.width*@height / im.height
info.item_width.set_value(@width)
end
super(width*zoom,height*zoom)
@child.set_pixbuf(im.scale(@width*zoom,@height*zoom))
page_layout.print_editor.tips.set_tip(self,"#{im.width}x#{im.height} (#{sprintf('%.2f',@width / im.width)})",'extra hint')
else
@width=new_width
@height=new_height
super(width*zoom,height*zoom)
end
end
|
#set_text(newtext = @text) ⇒ Object
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 180
def set_text(newtext=@text)
@text=newtext
case @gtk_type
when "text" then text_from_mysql(@text)
when "image" then
@image_iter=nil
info.item_image.model.each{|model,path,iter|
@image_iter=iter if @text.to_i == iter[0]
}
if @image_iter.nil?
@child=Gtk::Image.new(Gtk::Stock::MISSING_IMAGE,Gtk::IconSize::DIALOG)
else
@child.set_pixbuf(DrbImages.instance.client_image_of_id(@image_iter[0]).scale(@width,@height))
end
end
self
end
|
#set_text_alignment(na = "left") ⇒ Object
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 167
def set_text_alignment(na="left")
@text_alignment=na
if @gtk_type == "text"
@child.set_justification(
case na
when "right" then Gtk::Justification::RIGHT
when "center" then Gtk::Justification::CENTER
else Gtk::Justification::LEFT
end
)
end
end
|
#text ⇒ Object
142
143
144
145
146
147
148
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 142
def text
case @gtk_type
when "text" then @text=text_to_mysql
when "list","image" then @text
else ""
end
end
|
#text_from_mysql(nt = text) ⇒ Object
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 227
def text_from_mysql(nt=text)
if @gtk_type=="text"
ont=nt.clone
mydata=get_ancestor(WysiwygPrintEditor).mydata
found=false
while first=nt.index("{")
found=true
@child.buffer.insert_at_cursor(nt[0 .. first-1]) if first >= 1
if last=nt[first .. nt.length].index("}")
last=last+first
datak=nt[first+1 .. last-1]
if mydata.has_key?(datak)
mydata[datak]="N/A" if mydata[datak].nil? || mydata[datak] == ""
edebug("has key: [#{datak}] -> [#{mydata[datak]}]","printing","debug")
unless tag = @child.buffer.tag_table.lookup(datak)
tag=Gtk::TextTag.new(datak).set_foreground_gdk(Gdk::Color.new(65000,0,0))
@child.buffer.tag_table.add(tag)
end
@child.buffer.insert_at_cursor(mydata[datak])
bounds=@child.buffer.selection_bounds
bounds[0].backward_cursor_positions(mydata[datak].length)
@child.buffer.apply_tag(tag,bounds[0],bounds[1])
nt=nt[last+1 .. nt.length+1]
else
edebug("no key: #{datak}","printing","debug")
@child.buffer.insert_at_cursor(datak)
nt=nt[last+1 .. nt.length+1]
end
else
nt=nt[first+1 .. nt.length+1]
@child.buffer.insert_at_cursor("{"+nt)
end
end
@child.buffer.insert_at_cursor(nt) if nt.length>0
edebug("from_mysql: [#{ont.inspect}] -> buffer: [#{@child.buffer.text}]","printing","debug")
end
end
|
#text_to_mysql ⇒ Object
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 266
def text_to_mysql
if @gtk_type=="text"
i=@child.buffer.bounds[0]
tag="start"
plast=nil
while !tag.nil?
tag=nil
first=nil
if i.begins_tag?(nil) then
first=i.offset;
tag=i.toggled_tags(true)[0]
else
if i.forward_to_tag_toggle(nil) then
first=i.offset
tag=i.toggled_tags(true)[0]
end
end
if tag and i.forward_to_tag_toggle(tag) then last=i.offset;end
unless tag.nil?
if plast.nil?
ret=@child.buffer.get_text(@child.buffer.bounds[0],@child.buffer.get_iter_at_offset(first))
else
ret="#{ret}#{@child.buffer.get_text(@child.buffer.get_iter_at_offset(plast),@child.buffer.get_iter_at_offset(first))}"
end
ret="#{ret}{#{tag.name}}"
plast=last
end
end
if plast.nil?
ret=@child.buffer.text
else
ret="#{ret}#{@child.buffer.get_text(@child.buffer.get_iter_at_offset(plast),@child.buffer.bounds[1])}"
end
edebug("to_mysql: [#{@child.buffer.text}] -> [#{ret}]","printing","debug")
else
ret=text
end
ret
end
|
#to_mysql ⇒ Object
205
206
207
208
209
210
211
212
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 205
def to_mysql
if id.nil?
query("insert into gtkprintitems set printid='#{moditemid}', gtktype='#{gtk_type}', page_number='#{pagenum}', x='#{x}', y='#{y}', width='#{width}', height='#{height}', txt='#{text_to_mysql}', font='#{font}', text_alignment='#{text_alignment}'")
else
query("update gtkprintitems set printid='#{moditemid}', gtktype='#{gtk_type}', page_number='#{pagenum}', x='#{x}', y='#{y}', width='#{width}', height='#{height}', txt='#{text_to_mysql}', font='#{font}', text_alignment='#{text_alignment}' where id='#{id}'")
end
edebug("saved","printing","info")
end
|
#to_s ⇒ Object
306
307
308
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 306
def to_s
"PrintItem{#{@gtk_type},id:#{id}}"
end
|
#unfocus ⇒ Object
198
199
200
201
202
203
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 198
def unfocus
@dragging=false
set_state(Gtk::STATE_NORMAL)
set_above_child(true)
edebug("deselected","printing","info")
end
|
#zoom ⇒ Object
107
108
109
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 107
def zoom
print_editor.zoom
end
|
#zoomed ⇒ Object
103
104
105
106
|
# File 'lib/PrintEditor/PrintEditorItem.rb', line 103
def zoomed
move_me
set_size_request
end
|