Class: TrackGraphicsPathItem

Inherits:
Qt::GraphicsPathItem
  • Object
show all
Defined in:
lib/fgmapping/main-dlg-impl.rb

Constant Summary collapse

@@nodeinfo_array =
Array.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ TrackGraphicsPathItem

Returns a new instance of TrackGraphicsPathItem.



1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
# File 'lib/fgmapping/main-dlg-impl.rb', line 1080

def initialize(parent)
	super()
	@parent=parent
	@addToScene = true

	# needs to be embedded in other graphics element to circumvent a bug if the position of
	# the ProxyWidget is above, below 2**15 - 1, bug in QT
	@nodeinfo = Qt::GraphicsRectItem.new(0,0,100,100)
	@nodeinfo.setPen(Qt::Pen.new(Qt::NoPen))

	@nodeinfow = Qt::GraphicsProxyWidget.new(@nodeinfo)
	@nodeinfo_widget = NodeinfoWidget.new(@nodeinfo)
	@nodeinfo_widget.setAttribute(Qt::WA_Hover)
	@nodeinfow.setWidget(@nodeinfo_widget)
	@nodeinfo.setZValue(Z_VALUE_HUD)
	@nodeinfo.setAcceptHoverEvents(true)
	@nodeinfo.setVisible(false)
	setAcceptHoverEvents(true)
	setHandlesChildEvents(true)

	# store these elements in permanent array
	# otherwise GC will remove them and then causes core-dumps in QT
	@@nodeinfo_array << [@nodeinfow, @nodeinfo_widget]
end

Instance Attribute Details

#nodeinfoObject (readonly)

Returns the value of attribute nodeinfo.



1076
1077
1078
# File 'lib/fgmapping/main-dlg-impl.rb', line 1076

def nodeinfo
  @nodeinfo
end

#nodeinfo_widgetObject (readonly)

Returns the value of attribute nodeinfo_widget.



1076
1077
1078
# File 'lib/fgmapping/main-dlg-impl.rb', line 1076

def nodeinfo_widget
  @nodeinfo_widget
end

Instance Method Details

#colorize(data, dlg) ⇒ Object



1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
# File 'lib/fgmapping/main-dlg-impl.rb', line 1105

def colorize(data, dlg)
	scene=dlg.scene
	prev_x = path.elementAt(0).x
	prev_y = path.elementAt(0).y
	group = Qt::GraphicsItemGroup.new
	x = y = 0
	pen=Qt::Pen.new
	pen.setWidth(5)
	line=nil
	d=data.dup
	d.delete_if{|e| e<=0.0 }
	if d.length==0 then
		Qt::MessageBox::warning(nil, "Warning", "No elevation/speed data found in track.")
		return
	end
	max=d.max
	min=d.min
	delta=max-min
	color=nil
	1.upto(path.elementCount-2){|i|
		color=Qt::Color.new
		if data[i]>0.0 then
			color.setHsv((data[i]-min)/delta * COLORRANGE_DEG + COLOROFFSET_DEG,255,255)
		else
			color.setRgb(100,100,100)
		end
		pen.setColor(color)
		x = path.elementAt(i).x
		y = path.elementAt(i).y
		line = Qt::GraphicsLineItem.new(prev_x, prev_y, x, y)
		line.setPen(pen)
 		line.setZValue(Z_VALUE_TRACK_COLORED)
		group.addToGroup(line)
		prev_x = x
		prev_y = y
	}
		group.setZValue(Z_VALUE_TRACK_COLORED)
		scene.addItem(group)
	
end

#contextMenuEvent(contextEvent) ⇒ Object



1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
# File 'lib/fgmapping/main-dlg-impl.rb', line 1146

def contextMenuEvent(contextEvent)
	dlg=contextEvent.widget.parent.parent
	entries=["Colorize Altitude", "Colorize Speed"]
	menu=Qt::Menu.new
	entries.each{|e|
		if e=="-" then
			menu.addSeparator
		else
			menu.addAction(e)
		end
	}
	sel=menu.exec(contextEvent.screenPos)
	sel=sel.text if !sel.nil?
	data=[]
	case sel
		when entries[0]
			@parent.nodes.each{|n|
				data << n.elevation
			}
			colorize(data, dlg)
			
		when entries[1]
			@parent.nodes.each{|n|
				data << n.speed
			}
			colorize(data, dlg)
			
	end # case
end

#hoverLeaveEvent(hoverEvent) ⇒ Object



1228
1229
1230
1231
1232
1233
1234
# File 'lib/fgmapping/main-dlg-impl.rb', line 1228

def hoverLeaveEvent(hoverEvent)
#		ap "hoverleave in"
	if @nodeinfo_widget.hover_on then
		@nodeinfo_widget.hovertimer.start(HOVER_TIMER)
	end
#		ap "hoverleave out"
end

#hoverMoveEvent(hoverEvent) ⇒ Object



1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
# File 'lib/fgmapping/main-dlg-impl.rb', line 1176

def hoverMoveEvent(hoverEvent)
#		ap "hovermove in"
	dlg=hoverEvent.widget.parent.parent

	if @addToScene then
		dlg.scene.addItem(@nodeinfo)
		@addToScene = false
	end
	
	if !@nodeinfo_widget.hover_on then
		@nodeinfo.setVisible(true)
		@nodeinfo_widget.hover_on = true
	end
	x=hoverEvent.pos.x
	y=hoverEvent.pos.y
	e=nil
	hit=nil
	1.upto(self.path.elementCount-1){|i|
		e=self.path.elementAt(i)
		if ((e.x - x).abs < 3) and ((e.y - y).abs < 3)then
			hit=i
			break
		end
	}
	
	if !hit.nil? and !@parent.nil? then
		n=@parent.nodes[hit]
		@nodeinfo_widget.w.lBlon.text="%.3f°" % n.lon
		@nodeinfo_widget.w.lBlat.text="%.3f°" % n.lat
		@nodeinfo_widget.w.lBalt.text="%.1fm" % n.elevation
		@nodeinfo_widget.w.lBspeed.text="%.1fkm/h" % n.speed
		@nodeinfo_widget.w.lBdist.text="%.2fkm" % (@parent.distance(n) / 1000)
		@nodeinfo_widget.w.lBtime.text=@parent.duration_str
		pos = mapToScene(hoverEvent.pos)
		if !@nodeinfo.isVisible or @nodeinfo_widget.hover_widget_pos.nil? or (!@nodeinfo_widget.hover_widget_pos.nil? \
					and Qt::LineF.new(@nodeinfo_widget.hover_widget_pos, pos).length > 30) then
			dlg.scene.items.each {|item|
				if item.kind_of? Qt::GraphicsRectItem then
					if item != @nodeinfo then
				#		item.setVisible(false)
					end
				end
			}
			@nodeinfo.setVisible(true)
			@nodeinfo_widget.hover_widget_pos=pos
			@nodeinfo.setPos(pos)
			@nodeinfo_widget.hovertimer.stop
		end
	end
#		ap "hovermove out"
end