Пример #1
0
    def createPoly(self, n_points, radius, center_x, center_y):
        polygon = QPolygonF()
        w = 360 / n_points  # angle per step
        for i in range(n_points):  # add the points of polygon
            t = w * i
            x = radius * np.cos(np.deg2rad(t))
            y = radius * np.sin(np.deg2rad(t))
            polygon.append(QtCore.QPointF(center_x + x, center_y + y))

        return polygon
Пример #2
0
 def series_to_polyline(xdata, ydata):
     #inspired from https://github.com/PierreRaybaut/plotpy/wiki/Using-Qt-Charts-(PyQtChart)-to-plot-curves-efficiently-in-Python!
     size = len(xdata)
     polyline = QPolygonF()
     polyline.resize(size)
     address = shiboken6.getCppPointer(polyline.data())[0]
     buffer = (2 * size * ctypes.c_double).from_address(
         address)  #QPolygonF float type is qreal, which is double
     memory = np.frombuffer(buffer, xdata.dtype)
     memory[:(size - 1) * 2 + 1:2] = xdata
     memory[1:(size - 1) * 2 + 2:2] = ydata
     return polyline
Пример #3
0
    def __init__(self, starCount=1, maxStarCount=5):
        self.starCount = starCount
        self.maxStarCount = maxStarCount

        # Create the star shape we'll be drawing.
        self.starPolygon = QPolygonF()
        self.starPolygon.append(QPointF(1.0, 0.5))
        for i in range(1, 5):
            self.starPolygon.append(QPointF(0.5 + 0.5 * cos(0.8 * i * pi),
                                    0.5 + 0.5 * sin(0.8 * i * pi)))

        # Create the diamond shape we'll show in the editor
        self.diamondPolygon = QPolygonF()
        diamondPoints = [QPointF(0.4, 0.5), QPointF(0.5, 0.4),
                         QPointF(0.6, 0.5), QPointF(0.5, 0.6),
                         QPointF(0.4, 0.5)]
        self.diamondPolygon.append(diamondPoints)
Пример #4
0
 def draw_polygon(view: QGraphicsView, polygon_list: list[QPointF]):
     item = QGraphicsPolygonItem(QPolygonF(polygon_list))
     item.setPen(view.actual_pen)
     item.setBrush(view.actual_brush)
     items = view.scene().items()
     for i in range(len(polygon_list)):
         view.scene().removeItem(items[i])
     DrawTools.set_item_flags(item)
     view.scene().addItem(item)
     view.gim.append_shape(item, item.type(), view.actual_pen,
                           view.actual_brush)
 def input_to_polygon_item(self, input_stream: QDataStream,
                           item: QGraphicsPolygonItem):
     self.input_to_shape_item(input_stream, item)
     # Type
     fill_rule = Qt.FillRule()
     polygon = QPolygonF()
     # Read
     input_stream >> fill_rule
     input_stream >> polygon
     # Set
     item.setFillRule(fill_rule)
     item.setPolygon(polygon)
Пример #6
0
 def paint(self, painter, option, widget=None):
     qgp = self.getqgp()
     pen = QPen()
     pen.setWidth(2)
     qgp.setPen(pen)
     qgp.setBrush(QBrush(Qt.NoBrush))
     painter.setClipRect(option.exposedRect)
     qgp.paint(painter, option, widget)
     lastp = self.points[-1]
     angle = radians(qgp.path().angleAtPercent(1.0))
     angle = angle + pi
     p = lastp + QPointF(
         cos(angle - pi / 6.0) * 10, -sin(angle - pi / 6.0) * 10)
     q = lastp + QPointF(
         cos(angle + pi / 6.0) * 10, -sin(angle + pi / 6.0) * 10)
     painter.setBrush(QBrush(QColor("black")))
     self.head = QPolygonF([lastp, p, q])
     painter.drawPolygon(self.head)
Пример #7
0
class StarRating(object):
    """ Handle the actual painting of the stars themselves. """

    def __init__(self, starCount=1, maxStarCount=5):
        self.starCount = starCount
        self.maxStarCount = maxStarCount

        # Create the star shape we'll be drawing.
        self.starPolygon = QPolygonF()
        self.starPolygon.append(QPointF(1.0, 0.5))
        for i in range(1, 5):
            self.starPolygon.append(QPointF(0.5 + 0.5 * cos(0.8 * i * pi),
                                    0.5 + 0.5 * sin(0.8 * i * pi)))

        # Create the diamond shape we'll show in the editor
        self.diamondPolygon = QPolygonF()
        diamondPoints = [QPointF(0.4, 0.5), QPointF(0.5, 0.4),
                         QPointF(0.6, 0.5), QPointF(0.5, 0.6),
                         QPointF(0.4, 0.5)]
        self.diamondPolygon.append(diamondPoints)

    def sizeHint(self):
        """ Tell the caller how big we are. """
        return PAINTING_SCALE_FACTOR * QSize(self.maxStarCount, 1)

    def paint(self, painter, rect, palette, isEditable=False):
        """ Paint the stars (and/or diamonds if we're in editing mode). """
        painter.save()

        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setPen(Qt.NoPen)

        if isEditable:
            painter.setBrush(palette.highlight())
        else:
            painter.setBrush(palette.windowText())

        yOffset = (rect.height() - PAINTING_SCALE_FACTOR) / 2
        painter.translate(rect.x(), rect.y() + yOffset)
        painter.scale(PAINTING_SCALE_FACTOR, PAINTING_SCALE_FACTOR)

        for i in range(self.maxStarCount):
            if i < self.starCount:
                painter.drawPolygon(self.starPolygon, Qt.WindingFill)
            elif isEditable:
                painter.drawPolygon(self.diamondPolygon, Qt.WindingFill)
            painter.translate(1.0, 0.0)

        painter.restore()
Пример #8
0
 def draw_simple_shape_to_scene(view: QGraphicsView,
                                p_prev: QPointF,
                                p_act: QPointF,
                                to_gim: bool = True) -> None:
     if view.actual_selection.value in [2, 4]:
         width = math.fabs(p_prev.x() - p_act.x())
         height = math.fabs(p_prev.y() - p_act.y())
         xmin = min(p_prev.x(), p_act.x())
         ymin = min(p_prev.y(), p_act.y())
         item: QAbstractGraphicsShapeItem
         if view.actual_selection.value == 2:
             item = QGraphicsRectItem(0, 0, width, height)
         else:
             item = QGraphicsEllipseItem(0, 0, width, height)
         item.setPos(QPointF(xmin, ymin))
         item.setPen(view.actual_pen)
         item.setBrush(view.actual_brush)
         DrawTools.set_item_flags(item)
         view.scene().addItem(item)
         view.gim.append_shape(item, item.type(), view.actual_pen,
                               view.actual_brush)
     elif view.actual_selection.value in [3, 5, 6]:
         x = p_act.x() - p_prev.x()
         y = p_act.y() - p_prev.y()
         item: QGraphicsItem
         if view.actual_selection.value == 3:
             item = QGraphicsPolygonItem(
                 QPolygonF(
                     [QPointF(0, 0),
                      QPointF(0 + x, 0),
                      QPointF(x / 2, y)]))
             item.setBrush(view.actual_brush)
         else:
             item = QGraphicsLineItem(QLineF(0, 0, x, y))
         item.setPos(p_prev)
         item.setPen(view.actual_pen)
         DrawTools.set_item_flags(item)
         view.scene().addItem(item)
         if to_gim:
             view.gim.append_shape(item, item.type(), view.actual_pen,
                                   view.actual_brush)