Class: TrackGraphicsPathItem
- Inherits:
-
Qt::GraphicsPathItem
- Object
- Qt::GraphicsPathItem
- TrackGraphicsPathItem
- Defined in:
- lib/main-dlg-impl.rb
Constant Summary collapse
- @@nodeinfo_array =
Array.new
Instance Attribute Summary collapse
-
#nodeinfo ⇒ Object
readonly
Returns the value of attribute nodeinfo.
-
#nodeinfo_widget ⇒ Object
readonly
Returns the value of attribute nodeinfo_widget.
Instance Method Summary collapse
- #colorize(data, dlg) ⇒ Object
- #contextMenuEvent(contextEvent) ⇒ Object
- #hoverLeaveEvent(hoverEvent) ⇒ Object
- #hoverMoveEvent(hoverEvent) ⇒ Object
-
#initialize(parent) ⇒ TrackGraphicsPathItem
constructor
A new instance of TrackGraphicsPathItem.
Constructor Details
#initialize(parent) ⇒ TrackGraphicsPathItem
Returns a new instance of TrackGraphicsPathItem.
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 |
# File 'lib/main-dlg-impl.rb', line 1045 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) = NodeinfoWidget.new(@nodeinfo) .setAttribute(Qt::WA_Hover) @nodeinfow.setWidget() @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, ] end |
Instance Attribute Details
#nodeinfo ⇒ Object (readonly)
Returns the value of attribute nodeinfo.
1041 1042 1043 |
# File 'lib/main-dlg-impl.rb', line 1041 def nodeinfo @nodeinfo end |
#nodeinfo_widget ⇒ Object (readonly)
Returns the value of attribute nodeinfo_widget.
1041 1042 1043 |
# File 'lib/main-dlg-impl.rb', line 1041 def end |
Instance Method Details
#colorize(data, dlg) ⇒ Object
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 |
# File 'lib/main-dlg-impl.rb', line 1070 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
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 |
# File 'lib/main-dlg-impl.rb', line 1111 def contextMenuEvent(contextEvent) dlg=contextEvent..parent.parent entries=["Colorize Altitude", "Colorize Speed"] =Qt::Menu.new entries.each{|e| if e=="-" then .addSeparator else .addAction(e) end } sel=.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
1193 1194 1195 1196 1197 1198 1199 |
# File 'lib/main-dlg-impl.rb', line 1193 def hoverLeaveEvent(hoverEvent) # ap "hoverleave in" if .hover_on then .hovertimer.start(HOVER_TIMER) end # ap "hoverleave out" end |
#hoverMoveEvent(hoverEvent) ⇒ Object
1141 1142 1143 1144 1145 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 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 |
# File 'lib/main-dlg-impl.rb', line 1141 def hoverMoveEvent(hoverEvent) # ap "hovermove in" dlg=hoverEvent..parent.parent if @addToScene then dlg.scene.addItem(@nodeinfo) @addToScene = false end if !.hover_on then @nodeinfo.setVisible(true) .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] .w.lBlon.text="%.3f°" % n.lon .w.lBlat.text="%.3f°" % n.lat .w.lBalt.text="%.1fm" % n.elevation .w.lBspeed.text="%.1fkm/h" % n.speed .w.lBdist.text="%.2fkm" % (@parent.distance(n) / 1000) .w.lBtime.text=@parent.duration_str pos = mapToScene(hoverEvent.pos) if !@nodeinfo.isVisible or ..nil? or (!..nil? \ and Qt::LineF.new(., 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) .=pos @nodeinfo.setPos(pos) .hovertimer.stop end end # ap "hovermove out" end |