def _draw_arrow(self, event, painter): if self.info["mouth_is_opened"][0] == False or self.prediction == 4: return angles = [135, 90, 45, 180, None, 0, 225, 270, 0] angleline = QLineF() angleline.setP1(QPointF(*_mouse_controller.position)) angleline.setAngle(angles[self.prediction]) angleline.setLength(100) painter.setPen(QPen(Qt.red, 5, Qt.SolidLine)) painter.drawLine(angleline)
def drawWidget(self, qp): c = self.rect().center() c_coords = c.x(), c.y() background_color = self.palette().color(QPalette.Background) # paint inner trackpad qp.setPen(QPen(self.fishbowl_color, self.fishbowl_border_size, Qt.SolidLine)) # draw fishbowl qp.setBrush(QBrush(Qt.gray, Qt.SolidPattern)) qp.drawEllipse(c, *([self.fishbowl_size] * 2)) # draw axis lines qp.setPen(QPen(self.fishbowl_color, self.fishbowl_thin_border_size, Qt.DashDotDotLine)) for angle in range(0, 420, 45): line = QLineF(); line.setP1(c); line.setAngle(angle); line.setLength(self.fishbowl_size) qp.drawLine(line) # draw wheel separators line = QLineF(); line.setP1(c + QPoint(self.wheel_size, 0)); line.setAngle(0); line.setLength(self.wheel_width) qp.drawLine(line) line = QLineF(); line.setP1(c + QPoint(0, -self.wheel_size)); line.setAngle(90); line.setLength(self.wheel_width) qp.drawLine(line) line = QLineF(); line.setP1(c + QPoint(-self.wheel_size, 0)); line.setAngle(180); line.setLength(self.wheel_width) qp.drawLine(line) line = QLineF(); line.setP1(c + QPoint(0, self.wheel_size)); line.setAngle(270); line.setLength(self.wheel_width) qp.drawLine(line) qp.setPen(QPen(self.fishbowl_color, self.fishbowl_border_size, Qt.SolidLine)) # draw dead enemies for i, enemy in enumerate([x for x in self.enemies if x.dead]): qp.setBrush(QBrush(enemy.color, Qt.SolidPattern)) qp.drawEllipse(c + QPoint(*self.scale_point(enemy.coords)), *([self.npc_size] * 2)) # draw alive enemies for i, enemy in enumerate([x for x in self.enemies if not x.dead]): qp.setBrush(QBrush(enemy.color, Qt.SolidPattern)) qp.drawEllipse(c + QPoint(*self.scale_point(enemy.coords)), *([self.npc_size] * 2)) # draw player qp.setBrush(QBrush(self.player.color, Qt.SolidPattern)) qp.drawEllipse(c + QPoint(*self.scale_point(self.player.coords)), *([self.npc_size] * 2))
def __init__(self, position, angle, arrow_size, value, unit): super(StressRepresentation, self).__init__() arrow_line = QLineF() arrow_line.setP1(position) arrow_line.setLength(arrow_size) arrow_line.setAngle(angle) arrow = QGraphicsLineItem() arrow.setLine(arrow_line) self.addToGroup(arrow) arrow_head1_line = QLineF() arrow_head1_line.setP1(arrow_line.p1()) arrow_head1_line.setLength(arrow_size / 4) arrow_head1_line.setAngle(arrow_line.angle() + 45) arrow_head1 = QGraphicsLineItem() arrow_head1.setLine(arrow_head1_line) self.addToGroup(arrow_head1) arrow_head2_line = QLineF() arrow_head2_line.setP1(arrow_line.p1()) arrow_head2_line.setLength(arrow_size / 4) arrow_head2_line.setAngle(arrow_line.angle() - 45) arrow_head2 = QGraphicsLineItem() arrow_head2.setLine(arrow_head2_line) self.addToGroup(arrow_head2) text = QGraphicsTextItem() text.setPlainText(f'{str(value)}{unit}') text.setPos(arrow_line.p2()) self.addToGroup(text) self._set_color()
def showWedge(self, angle, color, extended=False, rev_gradient=False, outline_only=False): """Summary Args: angle (TYPE): Description color (TYPE): Description extended (bool, optional): Description rev_gradient (bool, optional): Description outline_only (bool, optional): Description """ # Hack to keep wedge in front # self.setRotation(self.pre_xover_item_group.rotation()) self._last_params = (angle, color, extended, rev_gradient, outline_only) radius = self._radius span = self.pre_xover_item_group.partCrossoverSpanAngle() / 2 radius_adjusted = radius + (_WEDGE_RECT_GAIN / 2) tip = QPointF(radius_adjusted, radius_adjusted) EXT = 1.35 if extended else 1.0 # print("wtf", tip, pos) base_p2 = QPointF(1, 1) line0 = QLineF(tip, QPointF(base_p2)) line1 = QLineF(tip, QPointF(base_p2)) line2 = QLineF(tip, QPointF(base_p2)) quad_scale = 1 + (.22 * (span - 5) / 55) # lo+(hi-lo)*(val-min)/(max-min) line0.setLength(radius_adjusted * EXT * quad_scale) # for quadTo control point line1.setLength(radius_adjusted * EXT) line2.setLength(radius_adjusted * EXT) line0.setAngle(angle) line1.setAngle(angle - span) line2.setAngle(angle + span) path = QPainterPath() if outline_only: self.setPen(getPenObj(color, 0.5, alpha=128, capstyle=Qt.RoundCap)) path.moveTo(line1.p2()) path.quadTo(line0.p2(), line2.p2()) else: gradient = QRadialGradient(tip, radius_adjusted * EXT) color1 = getColorObj(color, alpha=80) color2 = getColorObj(color, alpha=0) if rev_gradient: color1, color2 = color2, color1 if extended: gradient.setColorAt(0, color1) gradient.setColorAt(radius_adjusted / (radius_adjusted * EXT), color1) gradient.setColorAt( radius_adjusted / (radius_adjusted * EXT) + 0.01, color2) gradient.setColorAt(1, color2) else: gradient.setColorAt(0, getColorObj(color, alpha=50)) brush = QBrush(gradient) self.setBrush(brush) path.moveTo(line1.p1()) path.lineTo(line1.p2()) path.quadTo(line0.p2(), line2.p2()) path.lineTo(line2.p1()) self.setPath(path) self.show()
def _drawGuidelines(painter, glyph, scale, rect, guidelines, drawLines=True, drawText=True, drawSelection=True, color=None): if not (drawLines or drawText): return xMin, yMin, width, height = rect xMax = xMin + width yMax = yMin + height for line in guidelines: color_ = color if color_ is None: if line.color: color_ = colorToQColor(line.color) else: color_ = defaultColor("glyphGuideline") painter.save() painter.setPen(color) line1 = None if None not in (line.x, line.y): if line.angle is not None: # make an infinite line that intersects *(line.x, line.y)* # 1. make horizontal line from *(line.x, line.y)* of length # *diagonal* diagonal = math.sqrt(width**2 + height**2) line1 = QLineF(line.x, line.y, line.x + diagonal, line.y) # 2. set the angle # defcon guidelines are clockwise line1.setAngle(line.angle) # 3. reverse the line and set length to 2 * *diagonal* line1.setPoints(line1.p2(), line1.p1()) line1.setLength(2 * diagonal) else: line1 = QLineF(xMin, line.y, xMax, line.y) textX = 0 textY = 0 if drawLines: if line1 is not None: # line drawLine(painter, line1.x1(), line1.y1(), line1.x2(), line1.y2()) # point x, y = line.x, line.y smoothWidth = 8 * scale smoothHalf = smoothWidth / 2.0 painter.save() pointPath = QPainterPath() x -= smoothHalf y -= smoothHalf pointPath.addEllipse(x, y, smoothWidth, smoothWidth) pen = QPen(color_) pen.setWidthF(1 * scale) painter.setPen(pen) if drawSelection and line.selected: painter.fillPath(pointPath, color_) painter.drawPath(pointPath) painter.restore() else: if line.y is not None: drawLine(painter, xMin, line.y, xMax, line.y) elif line.x is not None: drawLine(painter, line.x, yMin, line.x, yMax) if drawText and line.name: if line1 is not None: textX = line.x textY = line.y - 6 * scale xAlign = "center" else: if line.y is not None: fontSize = painter.font().pointSize() textX = glyph.width + 6 * scale textY = line.y - (fontSize / 3.5) * scale elif line.x is not None: textX = line.x + 6 * scale textY = 0 xAlign = "left" drawTextAtPoint(painter, line.name, textX, textY, scale, xAlign=xAlign) painter.restore()
def _drawGuidelines(painter, glyph, scale, rect, guidelines, drawLines=True, drawText=True, drawSelection=True, color=None): if not (drawLines or drawText): return xMin, yMin, width, height = rect xMax = xMin + width yMax = yMin + height fontSize = painter.font().pointSize() for line in guidelines: color_ = color if color_ is None: if line.color: color_ = colorToQColor(line.color) else: color_ = defaultColor("glyphGuideline") painter.save() painter.setPen(color) line1 = None if None not in (line.x, line.y): if line.angle is not None: # make an infinite line that intersects *(line.x, line.y)* # 1. make horizontal line from *(line.x, line.y)* of length # *diagonal* diagonal = math.sqrt(width**2 + height**2) line1 = QLineF(line.x, line.y, line.x + diagonal, line.y) # 2. set the angle # defcon guidelines are clockwise line1.setAngle(line.angle) # 3. reverse the line and set length to 2 * *diagonal* line1.setPoints(line1.p2(), line1.p1()) line1.setLength(2 * diagonal) else: line1 = QLineF(xMin, line.y, xMax, line.y) textX = 0 textY = 0 if drawLines: if line1 is not None: # line drawLine( painter, line1.x1(), line1.y1(), line1.x2(), line1.y2()) # point x, y = line.x, line.y smoothWidth = 8 * scale smoothHalf = smoothWidth / 2.0 painter.save() pointPath = QPainterPath() x -= smoothHalf y -= smoothHalf pointPath.addEllipse(x, y, smoothWidth, smoothWidth) pen = QPen(color_) pen.setWidthF(1 * scale) painter.setPen(pen) if drawSelection and line.selected: painter.fillPath(pointPath, color_) painter.drawPath(pointPath) painter.restore() else: if line.y is not None: drawLine(painter, xMin, line.y, xMax, line.y) elif line.x is not None: drawLine(painter, line.x, yMin, line.x, yMax) if drawText and line.name: if line1 is not None: textX = line.x textY = line.y - 6 * scale xAlign = "center" else: if line.y is not None: textX = glyph.width + 6 * scale textY = line.y - (fontSize / 3.5) * scale elif line.x is not None: textX = line.x + 6 * scale textY = 0 xAlign = "left" drawTextAtPoint( painter, line.name, textX, textY, scale, xAlign=xAlign) painter.restore()
def showWedge(self, angle, color, extended=False, rev_gradient=False, outline_only=False): """Summary Args: angle (TYPE): Description color (TYPE): Description extended (bool, optional): Description rev_gradient (bool, optional): Description outline_only (bool, optional): Description """ # Hack to keep wedge in front # self.setRotation(self.pre_xover_item_group.rotation()) self._last_params = (angle, color, extended, rev_gradient, outline_only) radius = self._radius span = self.pre_xover_item_group.partCrossoverSpanAngle() / 2 radius_adjusted = radius + (_WEDGE_RECT_GAIN / 2) tip = QPointF(radius_adjusted, radius_adjusted) EXT = 1.35 if extended else 1.0 # print("wtf", tip, pos) base_p2 = QPointF(1, 1) line0 = QLineF(tip, QPointF(base_p2)) line1 = QLineF(tip, QPointF(base_p2)) line2 = QLineF(tip, QPointF(base_p2)) quad_scale = 1 + (.22*(span - 5) / 55) # lo+(hi-lo)*(val-min)/(max-min) line0.setLength(radius_adjusted * EXT*quad_scale) # for quadTo control point line1.setLength(radius_adjusted * EXT) line2.setLength(radius_adjusted * EXT) line0.setAngle(angle) line1.setAngle(angle - span) line2.setAngle(angle + span) path = QPainterPath() if outline_only: self.setPen(getPenObj(color, 0.5, alpha=128, capstyle=Qt.RoundCap)) path.moveTo(line1.p2()) path.quadTo(line0.p2(), line2.p2()) else: gradient = QRadialGradient(tip, radius_adjusted * EXT) color1 = getColorObj(color, alpha=80) color2 = getColorObj(color, alpha=0) if rev_gradient: color1, color2 = color2, color1 if extended: gradient.setColorAt(0, color1) gradient.setColorAt(radius_adjusted / (radius_adjusted * EXT), color1) gradient.setColorAt(radius_adjusted / (radius_adjusted * EXT) + 0.01, color2) gradient.setColorAt(1, color2) else: gradient.setColorAt(0, getColorObj(color, alpha=50)) brush = QBrush(gradient) self.setBrush(brush) path.moveTo(line1.p1()) path.lineTo(line1.p2()) path.quadTo(line0.p2(), line2.p2()) path.lineTo(line2.p1()) self.setPath(path) self.show()
def drawArrows(self, painter): """Draws arrows on the board.""" for highlight in self.highlights: if highlight.Type == self.Arrow.Type: lineWidth = 10 sqSize = self.squareSize painter.setPen( QPen(highlight.color, lineWidth, Qt.SolidLine, Qt.RoundCap)) origin = highlight.origin target = highlight.target dx = target.x() - origin.x() dy = target.y() - origin.y() # Knight jumps if dx == sqSize.width() and dy == -2 * sqSize.height(): corner = QPoint(origin.x(), origin.y() - 2 * sqSize.height()) line = QLineF(origin, corner) painter.drawLine(line) origin = corner elif dx == 2 * sqSize.width() and dy == -sqSize.height(): corner = QPoint(origin.x() + 2 * sqSize.width(), origin.y()) line = QLineF(origin, corner) painter.drawLine(line) origin = corner elif dx == 2 * sqSize.width() and dy == sqSize.height(): corner = QPoint(origin.x() + 2 * sqSize.width(), origin.y()) line = QLineF(origin, corner) painter.drawLine(line) origin = corner elif dx == sqSize.width() and dy == 2 * sqSize.height(): corner = QPoint(origin.x(), origin.y() + 2 * sqSize.height()) line = QLineF(origin, corner) painter.drawLine(line) origin = corner elif dx == -sqSize.width() and dy == 2 * sqSize.height(): corner = QPoint(origin.x(), origin.y() + 2 * sqSize.height()) line = QLineF(origin, corner) painter.drawLine(line) origin = corner elif dx == -2 * sqSize.width() and dy == sqSize.height(): corner = QPoint(origin.x() - 2 * sqSize.width(), origin.y()) line = QLineF(origin, corner) painter.drawLine(line) origin = corner elif dx == -2 * sqSize.width() and dy == -sqSize.height(): corner = QPoint(origin.x() - 2 * sqSize.width(), origin.y()) line = QLineF(origin, corner) painter.drawLine(line) origin = corner elif dx == -sqSize.width() and dy == -2 * sqSize.height(): corner = QPoint(origin.x(), origin.y() - 2 * sqSize.height()) line = QLineF(origin, corner) painter.drawLine(line) origin = corner # Other moves (and second part of knight jump) line = QLineF(origin, target) angle = line.angle() tip = line.p2() line.setLength(line.length() - 2 * lineWidth) painter.drawLine(line) tipOffset = line.p2() leftBase = QLineF() leftBase.setP1(tipOffset) leftBase.setLength(lineWidth) leftBase.setAngle(angle - 90) left = leftBase.p2() rightBase = QLineF() rightBase.setP1(tipOffset) rightBase.setLength(lineWidth) rightBase.setAngle(angle + 90) right = rightBase.p2() arrowHead = QPolygonF([left, right, tip]) path = QPainterPath() path.addPolygon(arrowHead) painter.fillPath(path, QBrush(highlight.color))
def drawRadar(selfself, qp): #set frame: qp.setBrush(QBrush(QColor(0, 0, 0), Qt.SolidPattern)) qp.drawRect(20, 10, 700, 700) pen_bold = QPen(QColor(102, 204, 255), 0.8, Qt.SolidLine) pen = QPen(QColor(102, 204, 255), 0.8, Qt.DashDotLine) pen_hide = QPen(QColor(0, 0, 0), 1.5, Qt.SolidLine) #add circle: qp.setPen(pen) qp.drawEllipse(QPointF(370, 360), 347, 347) #add scales: for i in range(1, 360): if i % 30 == 0: pass else: if i % 10 == 0: scaleLine = QLineF() scaleLine.setP1(QPointF(370, 360)) scaleLine.setAngle(i) scaleLine.setLength(347) qp.setPen(pen_bold) qp.drawLine(scaleLine) hideLine = QLineF() hideLine.setP1(QPointF(370, 360)) hideLine.setAngle(i) hideLine.setLength(337) qp.setPen(pen_hide) qp.drawLine(hideLine) else: scaleLine = QLineF() scaleLine.setP1(QPointF(370, 360)) scaleLine.setAngle(i) scaleLine.setLength(347) qp.setPen(pen_bold) qp.drawLine(scaleLine) hideLine = QLineF() hideLine.setP1(QPointF(370, 360)) hideLine.setAngle(i) hideLine.setLength(342) qp.setPen(pen_hide) qp.drawLine(hideLine) #add other circles: qp.setPen(pen) qp.drawEllipse(QPointF(370, 360), 277, 277) qp.setPen(pen) qp.drawEllipse(QPointF(370, 360), 207, 207) qp.setPen(pen) qp.drawEllipse(QPointF(370, 360), 137, 137) qp.setPen(pen) qp.drawEllipse(QPointF(370, 360), 67, 67) #add lines: qp.setPen(pen_bold) qp.drawLine(20, 360, 720, 360) qp.setPen(pen_bold) qp.drawLine(370, 10, 370, 710) angleLine1 = QLineF() angleLine1.setP1(QPointF(370, 360)) angleLine1.setAngle(30) angleLine1.setLength(347) qp.setPen(pen) qp.drawLine(angleLine1) angleLine2 = QLineF() angleLine2.setP1(QPointF(370, 360)) angleLine2.setAngle(60) angleLine2.setLength(347) qp.setPen(pen) qp.drawLine(angleLine2) angleLine3 = QLineF() angleLine3.setP1(QPointF(370, 360)) angleLine3.setAngle(120) angleLine3.setLength(347) qp.setPen(pen) qp.drawLine(angleLine3) angleLine4 = QLineF() angleLine4.setP1(QPointF(370, 360)) angleLine4.setAngle(150) angleLine4.setLength(347) qp.setPen(pen) qp.drawLine(angleLine4) angleLine5 = QLineF() angleLine5.setP1(QPointF(370, 360)) angleLine5.setAngle(210) angleLine5.setLength(347) qp.setPen(pen) qp.drawLine(angleLine5) angleLine6 = QLineF() angleLine6.setP1(QPointF(370, 360)) angleLine6.setAngle(240) angleLine6.setLength(347) qp.setPen(pen) qp.drawLine(angleLine6) angleLine7 = QLineF() angleLine7.setP1(QPointF(370, 360)) angleLine7.setAngle(300) angleLine7.setLength(347) qp.setPen(pen) qp.drawLine(angleLine7) angleLine8 = QLineF() angleLine8.setP1(QPointF(370, 360)) angleLine8.setAngle(330) angleLine8.setLength(347) qp.setPen(pen) qp.drawLine(angleLine8)