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.
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 |
# File 'lib/main-dlg-impl.rb', line 899 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 arry # otherwise GC will remove them and then causes core-dump in QT @@nodeinfo_array << [@nodeinfow, ] end |
Instance Attribute Details
#nodeinfo ⇒ Object (readonly)
Returns the value of attribute nodeinfo.
895 896 897 |
# File 'lib/main-dlg-impl.rb', line 895 def nodeinfo @nodeinfo end |
#nodeinfo_widget ⇒ Object (readonly)
Returns the value of attribute nodeinfo_widget.
895 896 897 |
# File 'lib/main-dlg-impl.rb', line 895 def end |
Instance Method Details
#colorize(data, dlg) ⇒ Object
924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 |
# File 'lib/main-dlg-impl.rb', line 924 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
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 |
# File 'lib/main-dlg-impl.rb', line 965 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
1047 1048 1049 1050 1051 1052 1053 |
# File 'lib/main-dlg-impl.rb', line 1047 def hoverLeaveEvent(hoverEvent) # ap "hoverleave in" if .hover_on then .hovertimer.start(HOVER_TIMER) end # ap "hoverleave out" end |
#hoverMoveEvent(hoverEvent) ⇒ Object
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 |
# File 'lib/main-dlg-impl.rb', line 995 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 |