Class: RelationHandle

Inherits:
Gtk::EventBox
  • Object
show all
Defined in:
lib/RelationBuilder/Relation/RelationHandle.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])

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relation, x, y) ⇒ RelationHandle

Returns a new instance of RelationHandle.



6
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
# File 'lib/RelationBuilder/Relation/RelationHandle.rb', line 6

def initialize(relation,x,y)
	super()
	visible_window=false
	add(@widget=Gtk::ToggleButton.new)
	set_above_child(true)
	@widget.set_size_request(10,10)
	@dragging=false
	@relation=relation
	@x=x
	@y=y
	@widget.signal_connect("toggled"){|me,ev|
		@relation.parentM.review_all
		@relation.parentM.changed(@relation)
	}
	signal_connect('button-press-event'){|me,ev|
		@relation.parentM.set_focused_item(self)
		case ev.button 
			when 1
				@widget.set_active(!@widget.active?)
			when 2
				@xshift=ev.x
				@yshift=ev.y
				@dragging=true
			when 3
				menu=Gtk::Menu.new
				menu.signal_connect("deactivate"){|menu| @relation.parentM.set_focused_item(nil)}
				menu.append(er=Gtk::ImageMenuItem.new("properties").set_image(Gtk::Image.new(Gtk::Stock::PROPERTIES,Gtk::IconSize::MENU)))
					er.signal_connect("activate"){|me| @relation.edit}
				menu.append(rr=Gtk::ImageMenuItem.new("remove").set_image(Gtk::Image.new(Gtk::Stock::DISCONNECT,Gtk::IconSize::MENU)))
					rr.signal_connect("activate"){|me| @relation.remove}
				menu.show_all
				menu.popup(nil,nil,ev.button,ev.time)
		end
		true
	}
	signal_connect('motion-notify-event'){|me,event|
	if @dragging
		@x=@relation.parentM.widget.pointer[0]-@xshift 
		@y=@relation.parentM.widget.pointer[1]-@yshift 
		move_me
	end
	true
	}
	signal_connect('button-release-event'){|me,event|
		if @dragging
			@relation.save
			@dragging=false
		end
		@relation.parentM.set_focused_item(nil)
		true
	}
end

Instance Attribute Details

#draggingObject

Returns the value of attribute dragging.



59
60
61
# File 'lib/RelationBuilder/Relation/RelationHandle.rb', line 59

def dragging
  @dragging
end

#widgetObject (readonly)

Returns the value of attribute widget.



58
59
60
# File 'lib/RelationBuilder/Relation/RelationHandle.rb', line 58

def widget
  @widget
end

#xObject (readonly)

Returns the value of attribute x.



58
59
60
# File 'lib/RelationBuilder/Relation/RelationHandle.rb', line 58

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



58
59
60
# File 'lib/RelationBuilder/Relation/RelationHandle.rb', line 58

def y
  @y
end

Instance Method Details

#move_me(newx = x, newy = y) ⇒ Object



61
62
63
64
65
# File 'lib/RelationBuilder/Relation/RelationHandle.rb', line 61

def move_me(newx=x,newy=y)
	@x=newx
	@y=newy
	parent.move(self,x,y) if parent
end

#to_sObject



66
67
68
# File 'lib/RelationBuilder/Relation/RelationHandle.rb', line 66

def to_s
	"Handle of #{@relation}"
end