def draw_NI_minimalistic(painter, c, w, h, bounding_rect): """ :param painter: painter from paint event :param c: color :param w: width :param h: height :param bounding_rect: NodeInstance's bounding rect """ path = QPainterPath() path.moveTo(-w / 2, 0) path.cubicTo(-w / 2, -h / 2, -w / 2, -h / 2, 0, -h / 2) path.cubicTo(+w / 2, -h / 2, +w / 2, -h / 2, +w / 2, 0) path.cubicTo(+w / 2, +h / 2, +w / 2, +h / 2, 0, +h / 2) path.cubicTo(-w / 2, +h / 2, -w / 2, +h / 2, -w / 2, 0) path.closeSubpath() body_gradient = QLinearGradient(bounding_rect.bottomLeft(), bounding_rect.topRight()) body_gradient.setColorAt(0, QColor(c.red(), c.green(), c.blue(), 150)) body_gradient.setColorAt(1, QColor(c.red(), c.green(), c.blue(), 80)) painter.setBrush(body_gradient) painter.setPen(QPen(QColor(30, 43, 48))) painter.drawPath(path)
def paintEvent(self, event): rect = QRect(10, 20, 80, 60) path = QPainterPath() path.moveTo(20, 80) path.lineTo(20, 30) path.cubicTo(80, 0, 50, 50, 80, 80) startAngle = 30 * 16 arcLength = 120 * 16 painter = QPainter(self) painter.setPen(self.pen) painter.setBrush(self.brush) if self.antialiased: painter.setRenderHint(QPainter.Antialiasing) for x in range(0, self.width(), 100): for y in range(0, self.height(), 100): painter.save() painter.translate(x, y) if self.transformed: painter.translate(50, 50) painter.rotate(60.0) painter.scale(0.6, 0.9) painter.translate(-50, -50) if self.shape == RenderArea.Line: painter.drawLine(rect.bottomLeft(), rect.topRight()) elif self.shape == RenderArea.Points: painter.drawPoints(RenderArea.points) elif self.shape == RenderArea.Polyline: painter.drawPolyline(RenderArea.points) elif self.shape == RenderArea.Polygon: painter.drawPolygon(RenderArea.points) elif self.shape == RenderArea.Rect: painter.drawRect(rect) elif self.shape == RenderArea.RoundedRect: painter.drawRoundedRect(rect, 25, 25, Qt.RelativeSize) elif self.shape == RenderArea.Ellipse: painter.drawEllipse(rect) elif self.shape == RenderArea.Arc: painter.drawArc(rect, startAngle, arcLength) elif self.shape == RenderArea.Chord: painter.drawChord(rect, startAngle, arcLength) elif self.shape == RenderArea.Pie: painter.drawPie(rect, startAngle, arcLength) elif self.shape == RenderArea.Path: painter.drawPath(path) elif self.shape == RenderArea.Text: painter.drawText(rect, Qt.AlignCenter, "PySide 2\nQt %s" % qVersion()) elif self.shape == RenderArea.Pixmap: painter.drawPixmap(10, 10, self.pixmap) painter.restore() painter.setPen(self.palette().dark().color()) painter.setBrush(Qt.NoBrush) painter.drawRect(QRect(0, 0, self.width() - 1, self.height() - 1))
def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: Optional[QWidget] = ...): painter.setPen(self.pen()) brush = self.brush() painter.setBrush(brush) path = QPainterPath() path.moveTo(self.__sourcePoint) path.cubicTo(self._edge1, self._edge2, self.__destPoint) if self._isDigraph: painter.setBrush(Qt.gray) painter.drawPolygon(self.drawArrow()) path.addPolygon(self.drawArrow()) painter.setBrush(Qt.NoBrush) if self.isSelected(): pen = painter.pen() pen.setColor(self.get_isSelectedPenColor()) else: pen = painter.pen() pen.setColor(self.get_noSelectedPenColor()) painter.setPen(pen) painter.drawPath(path) self.__path = path
def drawBezierCurve(self, qp): path = QPainterPath() path.moveTo(30, 30) path.cubicTo(30, 30, 200, 350, 350, 30) # 二阶贝塞尔曲线(cubic: 立方体) # 起始点, 控制点, 终止点 qp.drawPath(path) # 让画家照着path描画
def path(self): """Compute and return QPainterPath that is used to draw the curved line. Internal function use this to reset their path in response to external changes. """ if self._source_pos is None or self._target_pos is None: return QPainterPath() result = QPainterPath() result.moveTo(self._source_pos) result.cubicTo(self._bezier_point_1(), self._bezier_point_2(), self._target_pos) return result
def connection_path(p1: QPointF, p2: QPointF): """Returns the nice looking QPainterPath of a connection for two given points.""" path = QPainterPath() path.moveTo(p1) distance_x = abs(p1.x()) - abs(p2.x()) distance_y = abs(p1.y()) - abs(p2.y()) if ((p1.x() < p2.x() - 30) or math.sqrt((distance_x**2) + (distance_y**2)) < 100) and (p1.x() < p2.x()): path.cubicTo(p1.x() + ((p2.x() - p1.x()) / 2), p1.y(), p1.x() + ((p2.x() - p1.x()) / 2), p2.y(), p2.x(), p2.y()) elif p2.x() < p1.x() - 100 and abs(distance_x) / 2 > abs(distance_y): path.cubicTo(p1.x() + 100 + (p1.x() - p2.x()) / 10, p1.y(), p1.x() + 100 + (p1.x() - p2.x()) / 10, p1.y() - (distance_y / 2), p1.x() - (distance_x / 2), p1.y() - (distance_y / 2)) path.cubicTo(p2.x() - 100 - (p1.x() - p2.x()) / 10, p2.y() + (distance_y / 2), p2.x() - 100 - (p1.x() - p2.x()) / 10, p2.y(), p2.x(), p2.y()) else: path.cubicTo(p1.x() + 100 + (p1.x() - p2.x()) / 3, p1.y(), p2.x() - 100 - (p1.x() - p2.x()) / 3, p2.y(), p2.x(), p2.y()) return path
def draw_dark_minimalistic(self, painter): path = QPainterPath() path.moveTo(-self.width / 2, 0) path.cubicTo(-self.width / 2, -self.height / 2, -self.width / 2, -self.height / 2, 0, -self.height / 2) path.cubicTo(+self.width / 2, -self.height / 2, +self.width / 2, -self.height / 2, +self.width / 2, 0) path.cubicTo(+self.width / 2, +self.height / 2, +self.width / 2, +self.height / 2, 0, +self.height / 2) path.cubicTo(-self.width / 2, +self.height / 2, -self.width / 2, +self.height / 2, -self.width / 2, 0) path.closeSubpath() c = self.parent_node.color body_gradient = QLinearGradient(self.boundingRect().bottomLeft(), self.boundingRect().topRight()) body_gradient.setColorAt(0, QColor(c.red(), c.green(), c.blue(), 150)) body_gradient.setColorAt(1, QColor(c.red(), c.green(), c.blue(), 80)) painter.setBrush(body_gradient) painter.setPen(QPen(QColor(30, 43, 48))) painter.drawPath(path)
def _update_path(self): """Creates a new bezier path from `self.start` to `self.end`.""" path = QPainterPath(self.start) diffx = self.end.x() - self.start.x() c0x = self.start.x() + (diffx / 3) c0y = self.start.y() c1x = self.end.x() - (diffx / 3) c1y = self.end.y() path.cubicTo(c0x, c0y, c1x, c1y, self.end.x(), self.end.y()) self.setPath(path)
def updateShape(self): p1 = QPointF(0, 0) p2 = QPointF(self.width(), self.height()) ctrlPt = QPointF(abs(self.width() * self.curveScale), 0) path = QPainterPath(p1) path.cubicTo(p1 + ctrlPt, p2 - ctrlPt, p2) # Compute offset on x and y axis halfThickness = self._thickness / 2.0 v = QVector2D(p2 - p1).normalized() offset = QPointF(halfThickness * -v.y(), halfThickness * v.x()) self._path = QPainterPath(path.toReversed()) self._path.translate(-offset) path.translate(offset) self._path.connectPath(path)
def paintEvent(self, event: QPaintEvent) -> None: path = QPainterPath() path.moveTo(20, 80) path.lineTo(20, 30) path.cubicTo(80, 0, 50, 50, 80, 80) painter = QPainter(self) painter.setPen(self.pen) painter.setBrush(self.brush) painter.setRenderHint(QPainter.Antialiasing, True) x_inc = int(self.width() / (len(self.sb20.chainrings()) + len(self.sb20.cogs()) + 3)) w = int(2 * x_inc / 3) x = x_inc h_max = self.height() * 0.9 y_0 = self.height() * 0.05 factor = h_max / self.sb20.chainrings()[-1] for chainring in self.sb20.chainrings(): h = chainring * factor r = QRect(x, int(y_0 + (h_max - h) / 2), w, int(h)) if self.sb20.service_connected( ) and chainring == self.sb20.chainring_size(): painter.setBrush(Qt.SolidPattern) else: painter.setBrush(Qt.NoBrush) painter.drawRoundedRect(r, 25, 25, Qt.RelativeSize) x += x_inc x = self.width() - (len(self.sb20.cogs()) + 1) * x_inc factor = h_max / self.sb20.cogs()[0] for cog in self.sb20.cogs(): h = cog * factor r = QRect(x, int(y_0 + (h_max - h) / 2), w, int(h)) if self.sb20.service_connected() and cog == self.sb20.cog_size(): painter.setBrush(Qt.SolidPattern) else: painter.setBrush(Qt.NoBrush) painter.drawRoundedRect(r, 25, 25, Qt.RelativeSize) x += x_inc painter.setRenderHint(QPainter.Antialiasing, False) painter.setPen(self.palette().dark().color()) painter.setBrush(Qt.NoBrush) painter.drawRect(QRect(0, 0, self.width() - 1, self.height() - 1))
def _make_guide_path(self, curved_links): """Returns a 'narrow' path connecting this item's source and destination. Args: curved_links (bool): Whether the path should follow a curved line or just a straight line Returns: QPainterPath """ path = QPainterPath(self.src_center) if not curved_links: path.lineTo(self.dst_center) return path c_min = 2 * self.magic_number c_max = 8 * self.magic_number c_factor = QLineF(self.src_center, self.dst_center).length() / 2 c_factor = min(c_factor, c_max) c_factor = max(c_factor, c_min) c1 = self.src_center + c_factor * self._get_src_offset() c2 = self.dst_center + c_factor * self._get_dst_offset(c1) path.cubicTo(c1, c2, self.dst_center) return path
def buildPath(self, x1, x2, y1, y2): """ This function is used to build the path for the visibility behavior. It has some basic arrow routing algorithm: 1. src is at right, dest is at left, just cubic to it #. src is at left, dest is at right a. y is almost the same, cubic to it #. distance is bigger than 1/3 * root.width, go around the root component i. src is higher than dest, go around from the top #. bb src is lower than dest, go around from the bottom #. horizontal distance is smaller than 1/3 * root.width, zigzag to it .. todo:: Improve on the algorithm (add collision detector) :param x1: the x coordinate for the src component :type x1: float :param x2: the x coordinate for the dest component :type x2: float :param y1: the y coordinate for the src component :type y1: float :param y2: the x coordinate for the dest component :type y2: float :return path: return the path of the visibility behavior :rtype path: QPainterPath """ baseComponent = self.getOneComponentDownRoot() baseBR = self.scene().getGraphics(baseComponent).boundingRect( withMargins=False) basePos = self.scene().getGraphics(baseComponent).scenePos() baseComponentWidth = baseBR.width() baseComponentHeight = baseBR.height() path = QPainterPath() #TODO: If the component is the root component, VBGraphics may overlap with other components easily.FIX IT if x1 > x2: path.moveTo(x1, y1) path.cubicTo(x1 + 100, y1 + 100, x2 - 200, y2 - 200, x2, y2) leftInTrue = False elif abs(y2 - y1) < 50: path.moveTo(x1, y1) path.cubicTo(x1 + 100, y1 + 100, x2 - 200, y2 - 200, x2, y2) leftInTrue = True elif (x2 - x1) < (1 / 3 * baseComponentWidth): path.moveTo(x1, y1) path.lineTo(x1 - 200, y1) path.lineTo(x1 - 200, y2) path.lineTo(x2, y2) leftInTrue = True elif (x2 - x1) > (1 / 3 * baseComponentWidth) and y1 <= y2: path.moveTo(x1, y1) path.lineTo(basePos.x() - x1 / 3, y1) path.lineTo(basePos.x() - x1 / 3, basePos.y() - y1 / 3) path.lineTo(baseComponentWidth + x1, basePos.y() - y1 / 3) path.lineTo(baseComponentWidth + x1, y2) path.lineTo(x2, y2) leftInTrue = False elif (x2 - x1) > (1 / 3 * baseComponentWidth) and y1 > y2: path.moveTo(x1, y1) path.lineTo(basePos.x() - x1 / 3, y1) path.lineTo(basePos.x() - x1 / 3, baseComponentHeight + y1 / 3) path.lineTo(baseComponentWidth + x1, baseComponentHeight + y1 / 3) path.lineTo(baseComponentWidth + x1, y2) path.lineTo(x2, y2) leftInTrue = False else: #exception, then fix it path.moveTo(x1, y1) path.lineTo(x1, 30) path.lineTo(x2, 30) path.lineTo(x2, y2) leftInTrue = False boundingRect = path.boundingRect() return path, leftInTrue, boundingRect
keyS = (shapes[i].name).decode("utf-8") current = QCPScatterStyle.ScatterShape.values[keyS] #print("bla=", shapes[i]) #print("blak=", current.name) # ToDo: customPlot.graph().setName(QCPScatterStyle.staticMetaObject.enumerator(QCPScatterStyle.staticMetaObject.indexOfEnumerator("ScatterShape")).valueToKey(shapes[i])) customPlot.graph().setName(keyS) customPlot.graph().setLineStyle(QCPGraph.lsLine) # set scatter style: if shapes[i] != QCPScatterStyle.ssCustom: customPlot.graph().setScatterStyle(QCPScatterStyle(shapes[i], 10)) else: customScatterPath = QPainterPath() for i in range(0, 3): customScatterPath.cubicTo( math.cos(2 * math.pi * i / 3.0) * 9, math.sin(2 * math.pi * i / 3.0) * 9, math.cos(2 * math.pi * (i + 0.9) / 3.0) * 9, math.sin(2 * math.pi * (i + 0.9) / 3.0) * 9, 0, 0) customPlot.graph().setScatterStyle( QCPScatterStyle(customScatterPath, QPen(Qt.black, 0), QColor(40, 70, 255, 50), 10)) # set blank axis lines: customPlot.rescaleAxes() customPlot.xAxis.setTicks(False) customPlot.yAxis.setTicks(False) customPlot.xAxis.setTickLabels(False) customPlot.yAxis.setTickLabels(False) # make top right axes clones of bottom left axes: customPlot.axisRect().setupFullAxesBox()
def __init__(self, targetImage=None, axeSize=500, layer=None, parent=None): super().__init__(layer=layer, targetImage=targetImage, parent=parent) self.options = None pushButton1 = QPushButton(' Undo ') pushButton1.adjustSize() pushButton2 = QPushButton(' Redo ') pushButton2.adjustSize() pushButton1.clicked.connect(self.undo) pushButton2.clicked.connect(self.redo) spacingSlider = QSlider(Qt.Horizontal) spacingSlider.setObjectName('spacingSlider') spacingSlider.setRange(1,60) spacingSlider.setTickPosition(QSlider.TicksBelow) spacingSlider.setSliderPosition(10) spacingSlider.sliderReleased.connect(self.parent().label.brushUpdate) self.spacingSlider = spacingSlider jitterSlider = QSlider(Qt.Horizontal) jitterSlider.setObjectName('jitterSlider') jitterSlider.setRange(0, 100) jitterSlider.setTickPosition(QSlider.TicksBelow) jitterSlider.setSliderPosition(0) jitterSlider.sliderReleased.connect(self.parent().label.brushUpdate) self.jitterSlider = jitterSlider orientationSlider = QSlider(Qt.Horizontal) orientationSlider.setObjectName('orientationSlider') orientationSlider.setRange(0, 360) orientationSlider.setTickPosition(QSlider.TicksBelow) orientationSlider.setSliderPosition(180) orientationSlider.sliderReleased.connect(self.parent().label.brushUpdate) self.orientationSlider = orientationSlider # sample self.sample = QLabel() #self.sample.setMinimumSize(200, 100) pxmp = QPixmap(250,100) pxmp.fill(QColor(255, 255, 255, 255)) self.sample.setPixmap(pxmp) qpp = QPainterPath() qpp.moveTo(QPointF(20, 50)) qpp.cubicTo(QPointF(80, 25), QPointF(145, 70), QPointF(230, 60)) # c1, c2, endPoint self.samplePoly = qpp.toFillPolygon(QTransform()) # we want an unclosed polygon self.samplePoly.removeLast() # layout l = QVBoxLayout() l.setAlignment(Qt.AlignTop) hl = QHBoxLayout() hl.setAlignment(Qt.AlignHCenter) hl.addWidget(pushButton1) hl.addWidget(pushButton2) l.addLayout(hl) l.addWidget(QLabel('Brush Dynamics')) hl1 = QHBoxLayout() hl1.addWidget(QLabel('Spacing')) hl1.addWidget(spacingSlider) l.addLayout(hl1) hl2 = QHBoxLayout() hl2.addWidget(QLabel('Jitter')) hl2.addWidget(jitterSlider) l.addLayout(hl2) hl3 = QHBoxLayout() hl3.addWidget(QLabel('Orientation')) hl3.addWidget(self.orientationSlider) l.addLayout(hl3) l.addWidget(self.sample) self.setLayout(l) self.adjustSize() self.setDefaults() self.setWhatsThis( """ <b>Drawing :</b><br> Choose a brush family, flow, hardness and opacity. """ ) # end of setWhatsThis
def paint(self, painter, option, widget=None): painter.setRenderHint(QPainter.Antialiasing) brush = QBrush(QColor(100, 100, 100, 150)) # QBrush(QColor('#3B9CD9')) painter.setBrush(brush) std_pen = QPen( QColor(30, 43, 48) ) # QColor(30, 43, 48) # used for header title and minimal std dark border std_pen.setWidthF(1.5) # painter.setPen(std_pen) if self.parent_node.design_style == 'extended': if GlobalStorage.storage['design style'] == 'dark std': c = self.parent_node.color # main rect body_gradient = QRadialGradient( self.boundingRect().topLeft(), self.flow.pythagoras(self.height, self.width)) body_gradient.setColorAt( 0, QColor(c.red() / 10 + 100, c.green() / 10 + 100, c.blue() / 10 + 100, 200)) body_gradient.setColorAt( 1, QColor(c.red() / 10 + 100, c.green() / 10 + 100, c.blue() / 10 + 100, 0)) painter.setBrush(body_gradient) painter.setPen(Qt.NoPen) painter.drawRoundedRect(self.boundingRect(), 12, 12) header_gradient = QLinearGradient( self.get_header_rect().topRight(), self.get_header_rect().bottomLeft()) header_gradient.setColorAt( 0, QColor(c.red(), c.green(), c.blue(), 255)) header_gradient.setColorAt( 1, QColor(c.red(), c.green(), c.blue(), 0)) painter.setBrush(header_gradient) painter.setPen(Qt.NoPen) painter.drawRoundedRect(self.get_header_rect(), 12, 12) elif GlobalStorage.storage['design style'] == 'dark tron': # main rect c = QColor('#212224') painter.setBrush(c) pen = QPen(self.parent_node.color) pen.setWidth(2) painter.setPen(pen) body_path = self.get_extended_body_path_TRON_DESIGN(10) painter.drawPath(body_path) # painter.drawRoundedRect(self.boundingRect(), 12, 12) c = self.parent_node.color header_gradient = QLinearGradient( self.get_header_rect().topRight(), self.get_header_rect().bottomLeft()) header_gradient.setColorAt( 0, QColor(c.red(), c.green(), c.blue(), 255)) header_gradient.setColorAt( 0.5, QColor(c.red(), c.green(), c.blue(), 100)) header_gradient.setColorAt( 1, QColor(c.red(), c.green(), c.blue(), 0)) painter.setBrush(header_gradient) header_path = self.get_extended_header_path_TRON_DESIGN(10) painter.drawPath(header_path) painter.setFont(self.display_name_font) painter.setPen(std_pen) painter.drawText(self.get_title_rect(), Qt.AlignVCenter | Qt.AlignLeft, self.parent_node.title) painter.setBrush(Qt.NoBrush) painter.setPen(QPen(Qt.white, 1)) # painter.drawRect(self.get_header_rect()) elif self.parent_node.design_style == 'minimalistic': path = QPainterPath() path.moveTo(-self.width / 2, 0) if GlobalStorage.storage['design style'] == 'dark std': path.cubicTo(-self.width / 2, -self.height / 2, -self.width / 2, -self.height / 2, 0, -self.height / 2) path.cubicTo(+self.width / 2, -self.height / 2, +self.width / 2, -self.height / 2, +self.width / 2, 0) path.cubicTo(+self.width / 2, +self.height / 2, +self.width / 2, +self.height / 2, 0, +self.height / 2) path.cubicTo(-self.width / 2, +self.height / 2, -self.width / 2, +self.height / 2, -self.width / 2, 0) path.closeSubpath() c = self.parent_node.color body_gradient = QLinearGradient( self.boundingRect().bottomLeft(), self.boundingRect().topRight()) # 2*self.flow.pythagoras(self.height, self.width)) body_gradient.setColorAt( 0, QColor(c.red(), c.green(), c.blue(), 150)) body_gradient.setColorAt( 1, QColor(c.red(), c.green(), c.blue(), 80)) painter.setBrush(body_gradient) painter.setPen(std_pen) elif GlobalStorage.storage['design style'] == 'dark tron': corner_size = 10 path.lineTo(-self.width / 2 + corner_size / 2, -self.height / 2 + corner_size / 2) path.lineTo(0, -self.height / 2) path.lineTo(+self.width / 2 - corner_size / 2, -self.height / 2 + corner_size / 2) path.lineTo(+self.width / 2, 0) path.lineTo(+self.width / 2 - corner_size / 2, +self.height / 2 - corner_size / 2) path.lineTo(0, +self.height / 2) path.lineTo(-self.width / 2 + corner_size / 2, +self.height / 2 - corner_size / 2) path.closeSubpath() c = QColor('#36383B') painter.setBrush(c) pen = QPen(self.parent_node.color) pen.setWidth(2) painter.setPen(pen) painter.drawPath(path) painter.setFont(self.display_name_font) painter.drawText(self.boundingRect(), Qt.AlignCenter, self.parent_node.title)