2012-03-02 02:55:32 +00:00
|
|
|
from pyqtgraph.Qt import QtGui, QtCore
|
|
|
|
import pyqtgraph.functions as fn
|
|
|
|
|
|
|
|
__all__ = ['ArrowItem']
|
|
|
|
class ArrowItem(QtGui.QGraphicsPolygonItem):
|
|
|
|
"""
|
|
|
|
For displaying scale-invariant arrows.
|
|
|
|
For arrows pointing to a location on a curve, see CurveArrow
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, **opts):
|
2012-03-02 03:17:55 +00:00
|
|
|
QtGui.QGraphicsPolygonItem.__init__(self, opts.get('parent', None))
|
2012-03-02 02:55:32 +00:00
|
|
|
defOpts = {
|
|
|
|
'style': 'tri',
|
|
|
|
'pxMode': True,
|
|
|
|
'size': 20,
|
2012-03-02 03:17:55 +00:00
|
|
|
'angle': -150, ## If the angle is 0, the arrow points left
|
2012-03-02 02:55:32 +00:00
|
|
|
'pos': (0,0),
|
2012-03-02 03:17:55 +00:00
|
|
|
'width': None, ## width is automatically size / 2.
|
2012-03-02 02:55:32 +00:00
|
|
|
'tipAngle': 25,
|
|
|
|
'baseAngle': 90,
|
|
|
|
'pen': (200,200,200),
|
|
|
|
'brush': (50,50,200),
|
|
|
|
}
|
|
|
|
defOpts.update(opts)
|
|
|
|
|
|
|
|
self.setStyle(**defOpts)
|
|
|
|
|
|
|
|
self.setPen(fn.mkPen(defOpts['pen']))
|
|
|
|
self.setBrush(fn.mkBrush(defOpts['brush']))
|
|
|
|
|
|
|
|
self.rotate(self.opts['angle'])
|
|
|
|
self.moveBy(*self.opts['pos'])
|
|
|
|
|
|
|
|
def setStyle(self, **opts):
|
|
|
|
self.opts = opts
|
|
|
|
|
|
|
|
if opts['style'] == 'tri':
|
2012-03-02 03:17:55 +00:00
|
|
|
if opts['width'] is None:
|
|
|
|
width = opts['size'] / 2.
|
|
|
|
else:
|
|
|
|
width = opts['width']
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
points = [
|
|
|
|
QtCore.QPointF(0,0),
|
2012-03-02 03:17:55 +00:00
|
|
|
QtCore.QPointF(opts['size'],-width/2.),
|
|
|
|
QtCore.QPointF(opts['size'],width/2.),
|
2012-03-02 02:55:32 +00:00
|
|
|
]
|
|
|
|
poly = QtGui.QPolygonF(points)
|
|
|
|
|
|
|
|
else:
|
|
|
|
raise Exception("Unrecognized arrow style '%s'" % opts['style'])
|
|
|
|
|
|
|
|
self.setPolygon(poly)
|
|
|
|
|
|
|
|
if opts['pxMode']:
|
|
|
|
self.setFlags(self.flags() | self.ItemIgnoresTransformations)
|
|
|
|
else:
|
|
|
|
self.setFlags(self.flags() & ~self.ItemIgnoresTransformations)
|
|
|
|
|
|
|
|
def paint(self, p, *args):
|
|
|
|
p.setRenderHint(QtGui.QPainter.Antialiasing)
|
|
|
|
QtGui.QGraphicsPolygonItem.paint(self, p, *args)
|