本文整理汇总了Python中PyQt5.QtGui.QTransform.map方法的典型用法代码示例。如果您正苦于以下问题:Python QTransform.map方法的具体用法?Python QTransform.map怎么用?Python QTransform.map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QTransform
的用法示例。
在下文中一共展示了QTransform.map方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _updateSequenceText
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import map [as 别名]
def _updateSequenceText(self):
seq_item = self._seq_item
is_on_top = self._is_on_top
index = self._insertion.idx()
base_text = self._seq_text
font = styles.SEQUENCEFONT
seq_font_h = styles.SEQUENCEFONTH
insert_w = styles.INSERTWIDTH
seq_font_char_w = styles.SEQUENCEFONTCHARWIDTH
# draw sequence on the insert
if base_text: # only draw sequences if they exist i.e. not None!
len_BT = len(base_text)
if is_on_top:
angle_offset = 0
else:
angle_offset = 180
if len_BT > 20:
base_text = base_text[:17] + '...'
len_BT = len(base_text)
fraction_arc_len_per_char = (1.0 - 2.0*_FRACTION_INSERT_TO_PAD) / (len_BT + 1)
seq_item.setPen(QPen(Qt.NoPen))
seq_item.setBrush(QBrush(Qt.black))
seq_path = QPainterPath()
loop_path = self.path()
for i in range(len_BT):
frac = _FRACTION_INSERT_TO_PAD + (i+1)*fraction_arc_len_per_char
pt = loop_path.pointAtPercent(frac)
tang_ang = loop_path.angleAtPercent(frac)
temp_path = QPainterPath()
# 1. draw the text
temp_path.addText(0, 0, font, base_text[i if is_on_top else -i-1])
# 2. center it at the zero point different for top and bottom
# strands
if not is_on_top:
temp_path.translate(0, -seq_font_h - insert_w)
temp_path.translate(QPointF(-seq_font_char_w / 2.,
-2 if is_on_top else seq_font_h))
mat = QTransform()
# 3. rotate it
mat.rotate(-tang_ang + angle_offset)
rotated_path = mat.map(temp_path)
# 4. translate the rotate object to it's position on the part
rotated_path.translate(pt)
seq_path.addPath(rotated_path)
# end for
seq_item.setPath(seq_path)
示例2: __init__
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import map [as 别名]
def __init__(self, corner, parent = None):
super().__init__(parent)
self.mArrow = createRotateArrow()
self.setZValue(10000 + 1)
transform = QTransform()
x = corner
if x==AnchorPosition.TopLeftAnchor:
transform.rotate(180)
elif x==AnchorPosition.TopRightAnchor:
transform.rotate(-90)
elif x==AnchorPosition.BottomLeftAnchor:
transform.rotate(90)
else:
pass # BottomRight
self.mArrow = transform.map(self.mArrow)
示例3: _createPreXoverPainterPath
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import map [as 别名]
def _createPreXoverPainterPath( elements: List[List[QPointF]],
end_poly: QPolygonF = None,
is_fwd: bool = True) -> QPainterPath:
path = QPainterPath()
next_pt = None
for element in elements:
start_pt = element[0]
path.moveTo(start_pt)
for next_pt in element[1:]:
path.lineTo(next_pt)
if end_poly is not None:
h = end_poly.boundingRect().height()/2
xoffset = -h if is_fwd else h
w = end_poly.boundingRect().width()
yoffset = w if is_fwd else -w
angle = -90 if is_fwd else 90
T = QTransform()
T.translate(next_pt.x()+xoffset, next_pt.y()+yoffset)
T.rotate(angle)
path.addPolygon(T.map(end_poly))
return path
示例4: QPolygonF
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import map [as 别名]
PXI_PP_ITEM_WIDTH = IW = 2.0 # 1.5
TRIANGLE = QPolygonF()
TRIANGLE.append(QPointF(0, 0))
TRIANGLE.append(QPointF(0.75*IW, 0.5*IW))
TRIANGLE.append(QPointF(0, IW))
TRIANGLE.append(QPointF(0, 0))
# TRIANGLE.translate(-0.75*IW, -0.5*IW)
TRIANGLE.translate(-0.25*IW, -0.5*IW)
PXI_RECT = QRectF(0, 0, IW, IW)
T90, T270 = QTransform(), QTransform()
T90.rotate(90)
T270.rotate(270)
FWDPXI_PP, REVPXI_PP = QPainterPath(), QPainterPath()
FWDPXI_PP.addPolygon(T90.map(TRIANGLE))
REVPXI_PP.addPolygon(T270.map(TRIANGLE))
# FWDPXI_PP.moveTo(-0.5*IW, 0.7*IW)
# FWDPXI_PP.lineTo(0., -0.2*IW)
# FWDPXI_PP.lineTo(0.5*IW, 0.7*IW)
# extra1 = QPainterPath()
# extra1.addEllipse(-0.5*IW, 0.5*IW, IW, 0.4*IW)
# extra2 = QPainterPath()
# extra2.addEllipse(-0.35*IW, 0.5*IW, 0.7*IW, 0.3*IW)
# FWDPXI_PP += extra1
# FWDPXI_PP -= extra2
# REVPXI_PP.moveTo(-0.5*IW, -0.7*IW)
# REVPXI_PP.lineTo(0., 0.2*IW)
# REVPXI_PP.lineTo(0.5*IW, -0.7*IW)
示例5: QRectF
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import map [as 别名]
BASE_WIDTH = styles.PATH_BASE_WIDTH
BASE_RECT = QRectF(0, 0, BASE_WIDTH, BASE_WIDTH)
PHOS_ITEM_WIDTH = 0.25*BASE_WIDTH
TRIANGLE = QPolygonF()
TRIANGLE.append(QPointF(0, 0))
TRIANGLE.append(QPointF(0.75 * PHOS_ITEM_WIDTH, 0.5 * PHOS_ITEM_WIDTH))
TRIANGLE.append(QPointF(0, PHOS_ITEM_WIDTH))
TRIANGLE.append(QPointF(0, 0))
TRIANGLE.translate(0, -0.5*PHOS_ITEM_WIDTH)
T180 = QTransform()
T180.rotate(-180)
FWDPHOS_PP, REVPHOS_PP = QPainterPath(), QPainterPath()
FWDPHOS_PP.addPolygon(TRIANGLE)
REVPHOS_PP.addPolygon(T180.map(TRIANGLE))
KEYINPUT_ACTIVE_FLAG = QGraphicsItem.ItemIsFocusable
PROX_ALPHA = 64
class PropertyWrapperObject(QObject):
"""
Attributes:
animations (dict): Description
brush_alpha (TYPE): Description
item (TYPE): Description
rotation (TYPE): Description
"""
def __init__(self, item: QGraphicsItem):
示例6: SchView
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import map [as 别名]
class SchView(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self._transform = QTransform()
# set up transform
self._transform.translate(0, 0)
# set to 100 px = 1 inch
self._transform.scale(100.0/Coord.inchToSch(1), -100.0/Coord.inchToSch(1))
self._mousePos = QPoint()
self._wheelAngle = 0
self._ctrl = None
self.setMouseTracking(True)
self.setFocusPolicy(Qt.StrongFocus)
def setCtrl(self, ctrl):
self._ctrl = ctrl
def paintEvent(self, event):
painter = QPainter(self)
# erase background
painter.setBackground(QBrush(Layer.color(LayerType.background)))
painter.setClipping(True)
painter.eraseRect(self.rect())
# draw document
if self._ctrl is not None:
# draw grid
painter.setRenderHint(QPainter.Antialiasing, False)
pen = QPen(Layer.color(LayerType.grid))
pen.setCapStyle(Qt.RoundCap)
pen.setJoinStyle(Qt.RoundJoin)
pen.setWidth(0)
painter.setTransform(self._transform)
painter.setPen(pen)
self._drawGrid(painter)
# draw drawables
# painter.setRenderHint(QPainter.Antialiasing)
for d in self._ctrl.getDrawables():
d.draw(painter)
painter.end()
def _drawGrid(self, painter):
g = self._ctrl.grid
if self._transform.map(QLine(QPoint(0, 0), QPoint(g, 0))).dx() <= 5:
return # grid points too close, don't draw grid
viewport = self._transform.inverted()[0].mapRect(self.rect())
startX = int(viewport.x() / g) * g
startY = int(viewport.y() / g) * g
endX = viewport.x() + viewport.width()
endY = viewport.y() + viewport.height()
pts = QPolygon((QPoint(i[0], i[1]) for i in product(range(startX, endX, g),
range(startY, endY, g))))
painter.drawPoints(pts)
def _handleEvent(self, event: Event):
if self._ctrl is not None:
self._ctrl.handleEvent(event)
def zoom(self, factor, pos):
self.recenter(pos)
p = self._transform.inverted()[0].map(self.rect().center())
test = QTransform(self._transform)
test.scale(factor, factor)
# check if the bounding rectangle does not enclose the view
# refuse to zoom out (factor < 1) if this is the case
# XXX TODO
self._transform.scale(factor, factor)
self.recenter(p, True)
def recenter(self, pt=None, world=False):
if pt is None:
pt = self._mousePos
ctr = self._transform.inverted()[0].map(self.rect().center())
if not world:
pt = self._transform.inverted()[0].map(pt)
ctr -= pt
self._transform.translate(ctr.x(), ctr.y())
# move cursor to center of window
QCursor.setPos(self.mapToGlobal(self.rect().center()))
self.update()
def mouseMoveEvent(self, e):
if e.buttons() & Qt.MidButton:
dl = QLine(QPoint(0, 0), e.pos() - self._mousePos)
dl = self._transform.inverted()[0].map(dl)
self._transform.translate(dl.dx(), dl.dy())
self.update()
self._handleEvent(Event(evType=Event.Type.MouseMoved,
pos=self._transform.inverted()[0].map(e.pos())))
self._mousePos = e.pos()
def mousePressEvent(self, e):
if e.button() == Qt.LeftButton:
self._handleEvent(Event(evType=Event.Type.MousePressed,
pos=self._transform.inverted()[0].map(e.pos())))
def mouseReleaseEvent(self, e):
if e.button() == Qt.LeftButton:
self._handleEvent(Event(evType=Event.Type.MouseReleased,
pos=self._transform.inverted()[0].map(e.pos())))
#.........这里部分代码省略.........
示例7: paintEvent
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import map [as 别名]
def paintEvent(self, event):
painter = QPainter(self)
width = self.width()
height = self.height()
if DEBUG:
painter.fillRect(0, 0, width, height, Qt.blue)
else:
painter.fillRect(event.rect(), self.plot.canvas_color)
y_min_scale = self.plot.y_scale.value_min
y_max_scale = self.plot.y_scale.value_max
factor_x = width / self.plot.x_diff
factor_y = (height - CURVE_HEIGHT_COMPENSATION) / max(y_max_scale - y_min_scale, EPSILON)
if self.plot.x_min != None and self.plot.x_max != None:
x_min = self.plot.x_min
x_max = self.plot.x_max
if self.plot.curve_start == 'left':
curve_x_offset = 0
else:
curve_x_offset = round((self.plot.x_diff - (x_max - x_min)) * factor_x)
transform = QTransform()
transform.translate(curve_x_offset, height - CURVE_Y_OFFSET_COMPENSATION)
transform.scale(factor_x, -factor_y)
transform.translate(-x_min, -y_min_scale)
self.plot.partial_update_width = math.ceil(transform.map(QLineF(0, 0, 1.5, 0)).length())
inverted_event_rect = transform.inverted()[0].mapRect(QRectF(event.rect()))
painter.save()
painter.setTransform(transform)
pen = QPen()
pen.setCosmetic(True)
pen.setWidth(0)
painter.setPen(pen)
if False and self.plot.curves_visible[0]:
# Currently unused support for bar graphs.
# If we need this later on we should add an option to the
# PlotWidget for it.
# I tested this for the Sound Pressure Level Bricklet and it works,
# but it didnt't look good.
curve_x = self.plot.curves_x[0]
curve_y = self.plot.curves_y[0]
t = time.time()
if self.max_points == None:
self.max_points = []
for y in curve_y:
self.max_points.append((t, y))
else:
for i in range(len(curve_y)):
if (curve_y[i] > self.max_points[i][1]) or ((t - self.max_points[i][0]) > 5):
self.max_points[i] = (t, curve_y[i])
for i in range(len(self.plot.curves_x[0])):
pen.setColor(self.plot.curve_configs[0].color)
painter.setPen(pen)
painter.drawLine(QPoint(curve_x[i], 0), QPoint(curve_x[i], curve_y[i]))
pen.setColor(Qt.white)
painter.setPen(pen)
painter.drawLine(QPoint(curve_x[i], curve_y[i]), QPoint(curve_x[i], y_max_scale))
pen.setColor(Qt.darkGreen)
painter.setPen(pen)
painter.drawPoint(QPoint(curve_x[i], self.max_points[i][1]))
else:
for c in range(len(self.plot.curves_x)):
if not self.plot.curves_visible[c]:
continue
curve_x = self.plot.curves_x[c]
curve_y = self.plot.curves_y[c]
curve_jump = self.plot.curves_jump[c]
path = QPainterPath()
lineTo = path.lineTo
moveTo = path.moveTo
start = max(min(bisect.bisect_left(curve_x, inverted_event_rect.left()), len(curve_x) - 1) - 1, 0)
if start >= len(curve_x):
continue
moveTo(curve_x[start], curve_y[start])
for i in range(start + 1, len(curve_x)):
if curve_jump[i]:
curve_x_diff_half = (curve_x[i] - curve_x[i - 1]) / 2
lineTo(curve_x[i - 1] + curve_x_diff_half, curve_y[i - 1])
moveTo(curve_x[i] - curve_x_diff_half, curve_y[i])
lineTo(curve_x[i], curve_y[i])
pen.setColor(self.plot.curve_configs[c].color)
#.........这里部分代码省略.........
示例8: draw
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import map [as 别名]
def draw(self, painter, height, factor):
painter.save()
painter.translate(0, -CURVE_Y_OFFSET_COMPENSATION)
painter.scale(1, -factor)
painter.translate(0, -self.value_min)
pen = QPen()
pen.setCosmetic(True)
pen.setWidth(0)
pen.setColor(Qt.black)
painter.setPen(pen)
if DEBUG:
painter.fillRect(QRectF(0, self.value_min,
-self.axis_line_thickness - self.tick_mark_size_large, self.value_max - self.value_min),
Qt.cyan)
# axis line
painter.drawLine(QLineF(-self.axis_line_thickness, self.value_min,
-self.axis_line_thickness, self.value_max))
# ticks
tick_text_values = []
value = self.value_min
while fuzzy_leq(value, self.value_max):
tick_text_values.append(value)
painter.drawLine(QLineF(-self.axis_line_thickness, value,
-self.axis_line_thickness - self.tick_mark_size_large, value))
for i in range(1, self.step_subdivision_count):
subvalue = value + (self.step_size * i / self.step_subdivision_count)
if not fuzzy_leq(subvalue, self.value_max):
break
if i % 2 == 0 and self.step_subdivision_count % 2 == 0:
tick_mark_size = self.tick_mark_size_medium
else:
tick_mark_size = self.tick_mark_size_small
painter.drawLine(QLineF(-self.axis_line_thickness, subvalue,
-self.axis_line_thickness - tick_mark_size, subvalue))
value += self.step_size
painter.restore()
painter.setFont(self.tick_text_font)
tick_text_x = -self.axis_line_thickness - \
self.tick_mark_size_large - \
self.tick_mark_to_tick_text - \
self.tick_text_max_width
tick_text_width = self.tick_text_max_width
tick_text_height = self.tick_text_height_half * 2
transform = QTransform()
transform.translate(0, -CURVE_Y_OFFSET_COMPENSATION)
transform.scale(1, -factor)
transform.translate(0, -self.value_min)
for value in tick_text_values:
tick_text_point = transform.map(QPointF(tick_text_x, value))
tick_text_x = tick_text_point.x()
tick_text_y = tick_text_point.y() - self.tick_text_height_half
if DEBUG:
painter.fillRect(tick_text_x, tick_text_y,
tick_text_width, tick_text_height,
Qt.yellow)
painter.drawText(tick_text_x, tick_text_y, tick_text_width, tick_text_height,
Qt.TextDontClip | Qt.AlignRight | Qt.AlignVCenter,
self.tick_value_to_str(value))
# title
title_width = height
title_height = self.title_text_height
if self.title_text_pixmap == None or self.title_text_pixmap.size() != QSize(title_width, title_height):
self.title_text_pixmap = QPixmap(title_width + 100, title_height + 100)
self.title_text_pixmap.fill(QColor(0, 0, 0, 0))
title_painter = QPainter(self.title_text_pixmap)
if DEBUG:
title_painter.fillRect(50, 50, title_width, title_height, Qt.yellow)
title_painter.setFont(self.title_text_font)
title_painter.drawText(50, 50, title_width, title_height,
Qt.TextWordWrap | Qt.TextDontClip | Qt.AlignHCenter | Qt.AlignTop,
self.title_text)
title_painter = None
#.........这里部分代码省略.........
示例9: updateHandles
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import map [as 别名]
def updateHandles(self):
if (self.mAction == Action.Moving or self.mAction == Action.Rotating or self.mAction == Action.Resizing):
return
objects = self.mapDocument().selectedObjects()
showHandles = objects.size() > 0
if (showHandles):
renderer = self.mapDocument().renderer()
boundingRect = objectBounds(objects.first(), renderer, objectTransform(objects.first(), renderer))
for i in range(1, objects.size()):
object = objects.at(i)
boundingRect |= objectBounds(object, renderer, objectTransform(object, renderer))
topLeft = boundingRect.topLeft()
topRight = boundingRect.topRight()
bottomLeft = boundingRect.bottomLeft()
bottomRight = boundingRect.bottomRight()
center = boundingRect.center()
handleRotation = 0
# If there is only one object selected, align to its orientation.
if (objects.size() == 1):
object = objects.first()
handleRotation = object.rotation()
if (resizeInPixelSpace(object)):
bounds = pixelBounds(object)
transform = QTransform(objectTransform(object, renderer))
topLeft = transform.map(renderer.pixelToScreenCoords_(bounds.topLeft()))
topRight = transform.map(renderer.pixelToScreenCoords_(bounds.topRight()))
bottomLeft = transform.map(renderer.pixelToScreenCoords_(bounds.bottomLeft()))
bottomRight = transform.map(renderer.pixelToScreenCoords_(bounds.bottomRight()))
center = transform.map(renderer.pixelToScreenCoords_(bounds.center()))
# Ugly hack to make handles appear nicer in this case
if (self.mapDocument().map().orientation() == Map.Orientation.Isometric):
handleRotation += 45
else:
bounds = objectBounds(object, renderer, QTransform())
transform = QTransform(objectTransform(object, renderer))
topLeft = transform.map(bounds.topLeft())
topRight = transform.map(bounds.topRight())
bottomLeft = transform.map(bounds.bottomLeft())
bottomRight = transform.map(bounds.bottomRight())
center = transform.map(bounds.center())
self.mOriginIndicator.setPos(center)
self.mRotateHandles[AnchorPosition.TopLeftAnchor].setPos(topLeft)
self.mRotateHandles[AnchorPosition.TopRightAnchor].setPos(topRight)
self.mRotateHandles[AnchorPosition.BottomLeftAnchor].setPos(bottomLeft)
self.mRotateHandles[AnchorPosition.BottomRightAnchor].setPos(bottomRight)
top = (topLeft + topRight) / 2
left = (topLeft + bottomLeft) / 2
right = (topRight + bottomRight) / 2
bottom = (bottomLeft + bottomRight) / 2
self.mResizeHandles[AnchorPosition.TopAnchor].setPos(top)
self.mResizeHandles[AnchorPosition.TopAnchor].setResizingOrigin(bottom)
self.mResizeHandles[AnchorPosition.LeftAnchor].setPos(left)
self.mResizeHandles[AnchorPosition.LeftAnchor].setResizingOrigin(right)
self.mResizeHandles[AnchorPosition.RightAnchor].setPos(right)
self.mResizeHandles[AnchorPosition.RightAnchor].setResizingOrigin(left)
self.mResizeHandles[AnchorPosition.BottomAnchor].setPos(bottom)
self.mResizeHandles[AnchorPosition.BottomAnchor].setResizingOrigin(top)
self.mResizeHandles[AnchorPosition.TopLeftAnchor].setPos(topLeft)
self.mResizeHandles[AnchorPosition.TopLeftAnchor].setResizingOrigin(bottomRight)
self.mResizeHandles[AnchorPosition.TopRightAnchor].setPos(topRight)
self.mResizeHandles[AnchorPosition.TopRightAnchor].setResizingOrigin(bottomLeft)
self.mResizeHandles[AnchorPosition.BottomLeftAnchor].setPos(bottomLeft)
self.mResizeHandles[AnchorPosition.BottomLeftAnchor].setResizingOrigin(topRight)
self.mResizeHandles[AnchorPosition.BottomRightAnchor].setPos(bottomRight)
self.mResizeHandles[AnchorPosition.BottomRightAnchor].setResizingOrigin(topLeft)
for i in range(AnchorPosition.CornerAnchorCount):
self.mRotateHandles[i].setRotation(handleRotation)
for i in range(AnchorPosition.AnchorCount):
self.mResizeHandles[i].setRotation(handleRotation)
self.updateHandleVisibility()