Example #1
0
def draw_curved_line(painter_path, dx, dy, c1_frac, c1_amp, c2_frac, c2_amp):
    length = sqrt(dx * dx + dy * dy)
    angle = atan2(dy, dx)
    c1 = QPointF(*rotate_vector(angle, c1_frac * length, c1_amp * length))
    c2 = QPointF(*rotate_vector(angle, c2_frac * length, c2_amp * length))
    pos = painter_path.currentPosition()
    painter_path.cubicTo(pos + c1, pos + c2, pos + QPointF(dx, dy))
Example #2
0
 def _paint_circles(self, painter):
     painter.save()
     if self.position.x() > 0:
         painter.setBrush(Defaults.single_color)
         painter.drawEllipse(QPointF(self.width() / 2, 0),
                             (self.width() / 4) * (self.position.x() /
                                                   (self.width() / 2)) / 2,
                             self.height() / 2 + self.height() * 0.1)
     else:
         painter.setBrush(Defaults.multi_color)
         painter.drawEllipse(QPointF(-self.width() / 2, 0),
                             (self.width() / 4) * (self.position.x() /
                                                   (self.width() / 2)) / 2,
                             self.height() / 2 + self.height() * 0.1)
     if self.position.y() < 0:
         painter.setBrush(Defaults.skip_color)
         painter.drawEllipse(QPointF(0, -self.height() / 2),
                             self.width() / 2 + self.width() * 0.1,
                             (self.height() / 4) *
                             (-self.position.y() / (self.height() / 2)) / 2)
     else:
         painter.setBrush(Defaults.skip_color)
         painter.drawEllipse(QPointF(0,
                                     self.height() / 2),
                             self.width() / 2 + self.width() * 0.1,
                             (self.height() / 4) *
                             (-self.position.y() / (self.height() / 2)) / 2)
     painter.restore()
    def recognize(self, gesture, watched, event):
        if event.type() == QEvent.MouseButtonPress:
            self.panning = True
            self.start_point = event.pos()
            gesture.setLastOffset(QPointF())
            gesture.setOffset(QPointF())
            return QGestureRecognizer.TriggerGesture

        if self.panning and event.type() == QEvent.MouseMove:
            gesture.setLastOffset(gesture.offset())
            gesture.setOffset(event.pos() - self.start_point)
            return QGestureRecognizer.TriggerGesture

        if event.type() == QEvent.MouseButtonRelease:
            end_point = event.pos()
            if self.start_point == end_point:
                self.panning = False
                return QGestureRecognizer.CancelGesture
            self.panning = False
            gesture.setLastOffset(gesture.offset())
            gesture.setOffset(end_point - self.start_point)
            return QGestureRecognizer.FinishGesture

        if event.type() == QEvent.MouseButtonDblClick:
            self.panning = False
            return QGestureRecognizer.FinishGesture

        if not event.type() == QEvent.MouseButtonPress or event.type(
        ) == QEvent.MouseMove or event.type(
        ) == QEvent.MouseButtonRelease or event.type(
        ) == QEvent.MouseButtonDblClick:
            return QGestureRecognizer.Ignore
Example #4
0
    def _reset(self, was_classified):
        if was_classified:
            self._show_title_card = False
            self.position = QPointF(0, 0)

            self.animation1 = QPropertyAnimation(self, b'opacity')
            self.animation1.setStartValue(0)
            self.animation1.setEndValue(1)
            self.animation1.setDuration(75)
            self.animation1.start()

            self.animation2 = QPropertyAnimation(self, b'scale')
            self.animation2.setStartValue(self.scale - 1)
            self.animation2.setEndValue(self.scale)
            self.animation2.setDuration(75)
            self.animation2.start()

        else:
            self.animation3 = QPropertyAnimation(self, b'position')
            self.animation3.setStartValue(self.position)
            self.animation3.setEndValue(QPointF(0, 0))
            self.animation3.setEasingCurve(QEasingCurve.OutBack)
            self.animation3.setDuration(
                (np.linalg.norm([self.position.x(),
                                 self.position.y()]) /
                 np.linalg.norm([self.width(), self.height()])) * 500)
            self.animation3.start()
Example #5
0
    def draw_selection_rect(self, painter):
        cr, sr = self.target, self.selection_state.rect
        painter.setPen(self.SELECT_PEN)
        painter.setRenderHint(QPainter.Antialiasing, False)
        if self.selection_state.current_mode == 'selected':
            # Shade out areas outside the selection rect
            for r in (
                    QRectF(cr.topLeft(), QPointF(sr.left(),
                                                 cr.bottom())),  # left
                    QRectF(QPointF(sr.left(), cr.top()), sr.topRight()),  # top
                    QRectF(QPointF(sr.right(), cr.top()),
                           cr.bottomRight()),  # right
                    QRectF(sr.bottomLeft(), QPointF(sr.right(),
                                                    cr.bottom())),  # bottom
            ):
                painter.fillRect(r, self.SHADE_COLOR)

            dr = self.get_drag_rect()
            if self.selection_state.in_selection and dr is not None:
                # Draw the resize rectangle
                painter.save()
                painter.setCompositionMode(
                    QPainter.RasterOp_SourceAndNotDestination)
                painter.setClipRect(sr.adjusted(1, 1, -1, -1))
                painter.drawRect(dr)
                painter.restore()

        # Draw the selection rectangle
        painter.setCompositionMode(QPainter.RasterOp_SourceAndNotDestination)
        painter.drawRect(sr)
Example #6
0
 def draw(self, painter):
     for l in self.layouts:
         if hasattr(l, 'draw'):
             # Etch effect for the text
             painter.save()
             painter.setPen(QColor(255, 255, 255, 125))
             l.draw(painter, QPointF(1, 1))
             painter.restore()
             l.draw(painter, QPointF())
Example #7
0
    def parseXML(self):
        self.shapes = []
        assert self.filepath.endswith(XML_EXT), "Unsupport file format"
        parser = etree.XMLParser(encoding='utf-8')
        xmltree = ElementTree.parse(self.filepath, parser=parser).getroot()
        filename = xmltree.find('filename').text
        try:
            verified = xmltree.attrib['verified']
            if verified == 'yes':
                self.verified = True
        except KeyError:
            self.verified = False

        for object_iter in xmltree.findall('object'):
            points = []
            for vertex in object_iter.findall('vertex'):
                x = float(vertex.find('x').text)
                y = float(vertex.find('y').text)
                points.append((x, y))

            ellipse_points = []
            for vertex in object_iter.findall('ellipse_vertex'):
                x = float(vertex.find('x').text)
                y = float(vertex.find('y').text)
                ellipse_points.append((x, y))

            label = object_iter.find('name').text
            lineWidth = int(object_iter.find('lineWidth').text)

            rotate = 0
            try:
                rotate = int(object_iter.find('rotate').text)
            except AttributeError:
                rotate = 0

            r1 = 0.0
            r2 = 0.0
            try:
                r1 = float(object_iter.find('r1').text)
                r2 = float(object_iter.find('r2').text)
            except AttributeError:
                r1 = 0
                r2 = 0

            center_item = None
            center = QPointF(0, 0)
            try:
                center_item = object_iter.find('center')
            except AttributeError:
                center_item = None
            if center_item is not None:
                x = float(center_item.find('x').text)
                y = float(center_item.find('y').text)
                center = QPointF(x, y)
            self.shapes.append((label, lineWidth, points, ellipse_points,
                                rotate, r1, r2, center))
        return True
Example #8
0
 def adjust_line(self):
     self.setPos(QPointF(0.5 * (self.stick.top[0] + self.stick.bottom[0]), 0.5 * (self.stick.top[1] + self.stick.bottom[1])))
     vec = 0.5 * (self.stick.top - self.stick.bottom)
     self.line.setP1(QPointF(vec[0], vec[1]))
     self.line.setP2(-self.line.p1())
     self.gline.setLine(self.line)
     self.adjust_handles()
     self.stick_label_text.setPos(self.line.p1() - QPointF(0.5 * self.stick_label_text.boundingRect().width(),
                                                          1.3 * self.stick_label_text.boundingRect().height()))
     self.update()
Example #9
0
def brush(p, xmax, ymax):
    x = 0
    y = 0
    w = xmax/2
    g = QLinearGradient(QPointF(x, y+w/3), QPointF(x, y+(2*w/3)))
    g.setColorAt(0, QColor('#f00'))
    g.setColorAt(0.5, QColor('#fff'))
    g.setColorAt(1, QColor('#00f'))
    g.setSpread(g.ReflectSpread)
    p.fillRect(x, y, w, w, QBrush(g))
    p.drawRect(x, y, w, w)
Example #10
0
 def draw(self, painter):
     for l in self.layouts:
         if hasattr(l, 'draw'):
             # Etch effect for the text
             painter.save()
             painter.setRenderHints(QPainter.TextAntialiasing | QPainter.Antialiasing)
             painter.save()
             painter.setPen(QColor(255, 255, 255, 125))
             l.draw(painter, QPointF(1, 1))
             painter.restore()
             l.draw(painter, QPointF())
             painter.restore()
Example #11
0
 def fset(self, xxx_todo_changeme):
     (x, y) = xxx_todo_changeme
     self._position = Point(x, y)
     if self.layouts:
         self.layouts[0].setPosition(QPointF(x, y))
         y += self.layouts[0].boundingRect().height()
         for l in self.layouts[1:]:
             if isinstance(l, (int, float)):
                 y += l
             else:
                 l.setPosition(QPointF(x, y))
                 y += l.boundingRect().height()
Example #12
0
 def fset(self, new_pos):
     (x, y) = new_pos
     self._position = Point(x, y)
     if self.layouts:
         self.layouts[0].setPosition(QPointF(x, y))
         y += self.layouts[0].boundingRect().height()
         for l in self.layouts[1:]:
             if isinstance(l, numbers.Number):
                 y += l
             else:
                 l.setPosition(QPointF(x, y))
                 y += l.boundingRect().height()
Example #13
0
 def draw_fold(x, m=1, corner=left_corner):
     ans = p = QPainterPath(QPointF(x, rtop))
     draw_curved_line(p, rwidth*m, 0, 0.1, 0.1*m, 0.5, -0.2*m)
     fold_upper = p.currentPosition()
     p.lineTo(p.currentPosition() + QPointF(-deltax*m, height))
     fold_corner = p.currentPosition()
     draw_curved_line(p, -rwidth*m, 0, 0.2, -0.1*m, 0.8, -0.1*m)
     draw_curved_line(p, deltax*m, -height, 0.2, 0.1*m, 0.8, 0.1*m)
     p = inner_fold = QPainterPath(corner)
     dp = fold_corner - p.currentPosition()
     draw_curved_line(p, dp.x(), dp.y(), 0.5, 0.3*m, 1, 0*m)
     p.lineTo(fold_upper), p.closeSubpath()
     return ans, inner_fold
Example #14
0
def full(p, xmax, ymax):
    p.drawRect(0, 0, xmax, ymax)
    p.drawPolyline(QPoint(0, 0), QPoint(xmax, 0), QPoint(xmax, ymax),
                    QPoint(0, ymax), QPoint(0, 0))
    pp = QPainterPath()
    pp.addRect(0, 0, xmax, ymax)
    p.drawPath(pp)
    p.save()
    for i in range(3):
        col = [0, 0, 0, 200]
        col[i] = 255
        p.setOpacity(0.3)
        p.fillRect(0, 0, xmax/10, xmax/10, QBrush(QColor(*col)))
        p.setOpacity(1)
        p.drawRect(0, 0, xmax/10, xmax/10)
        p.translate(xmax/10, xmax/10)
        p.scale(1, 1.5)
    p.restore()

    # p.scale(2, 2)
    # p.rotate(45)
    p.drawPixmap(0, 0, xmax/4, xmax/4, QPixmap(I('library.png')))
    p.drawRect(0, 0, xmax/4, xmax/4)

    f = p.font()
    f.setPointSize(20)
    # f.setLetterSpacing(f.PercentageSpacing, 200)
    f.setUnderline(True)
    # f.setOverline(True)
    # f.setStrikeOut(True)
    f.setFamily('Calibri')
    p.setFont(f)
    # p.setPen(QColor(0, 0, 255))
    # p.scale(2, 2)
    # p.rotate(45)
    p.drawText(QPoint(xmax/3.9, 30), 'Some—text not By’s ū --- Д AV ff ff')

    b = QBrush(Qt.HorPattern)
    b.setColor(QColor(Qt.blue))
    pix = QPixmap(I('lt.png'))
    w = xmax/4
    p.fillRect(0, ymax/3, w, w, b)
    p.fillRect(xmax/3, ymax/3, w, w, QBrush(pix))
    x, y = 2*xmax/3, ymax/3
    p.drawTiledPixmap(QRectF(x, y, w, w), pix, QPointF(10, 10))

    x, y = 1, ymax/1.9
    g = QLinearGradient(QPointF(x, y), QPointF(x+w, y+w))
    g.setColorAt(0, QColor('#00f'))
    g.setColorAt(1, QColor('#fff'))
    p.fillRect(x, y, w, w, QBrush(g))
Example #15
0
    def __call__(self, painter, rect, color_theme, title_block, subtitle_block,
                 footer_block):
        if not self.PATH_CACHE:
            from calibre.utils.speedups import svg_path_to_painter_path
            try:
                self.__class__.PATH_CACHE['corner'] = svg_path_to_painter_path(
                    self.CORNER_VECTOR)
            except Exception:
                import traceback
                traceback.print_exc()
        p = painter
        painter.setRenderHint(QPainter.RenderHint.Antialiasing)
        g = QRadialGradient(QPointF(rect.center()), rect.width())
        g.setColorAt(0, self.color1), g.setColorAt(1, self.color2)
        painter.fillRect(rect, QBrush(g))
        painter.save()
        painter.setWindow(0, 0, *self.VIEWPORT)
        try:
            path = self.PATH_CACHE['corner']
        except KeyError:
            path = QPainterPath()
        pen = p.pen()
        pen.setColor(self.ccolor1)
        p.setPen(pen)

        def corner():
            b = QBrush(self.ccolor1)
            p.fillPath(path, b)
            p.rotate(90), p.translate(100, -100), p.scale(1, -1), p.translate(
                -103, -97)
            p.fillPath(path, b)
            p.setWorldTransform(QTransform())

        # Top-left corner
        corner()
        # Top right corner
        p.scale(-1, 1), p.translate(-400, 0), corner()
        # Bottom left corner
        p.scale(1, -1), p.translate(0, -500), corner()
        # Bottom right corner
        p.scale(-1, -1), p.translate(-400, -500), corner()
        for y in (28.4, 471.7):
            p.drawLine(QPointF(160, y), QPointF(240, y))
        for x in (31.3, 368.7):
            p.drawLine(QPointF(x, 155), QPointF(x, 345))
        pen.setWidthF(1.8)
        p.setPen(pen)
        for y in (23.8, 476.7):
            p.drawLine(QPointF(160, y), QPointF(240, y))
        for x in (26.3, 373.7):
            p.drawLine(QPointF(x, 155), QPointF(x, 345))
        painter.restore()

        return self.ccolor2, self.ccolor2, self.ccolor1
Example #16
0
    def position(self):
        def fget(self):
            return self._position

        def fset(self, (x, y)):
            self._position = Point(x, y)
            if self.layouts:
                self.layouts[0].setPosition(QPointF(x, y))
                y += self.layouts[0].boundingRect().height()
                for l in self.layouts[1:]:
                    if isinstance(l, (int, float)):
                        y += l
                    else:
                        l.setPosition(QPointF(x, y))
                        y += l.boundingRect().height()
Example #17
0
    def __init__(self, text='', width=0, font=None, img=None, max_height=100, align=Qt.AlignCenter):
        self.layouts = []
        self._position = Point(0, 0)
        self.leading = self.line_spacing = 0
        if font is not None:
            fm = QFontMetrics(font, img)
            self.leading = fm.leading()
            self.line_spacing = fm.lineSpacing()
        for text in text.split('<br>') if text else ():
            text, formats = parse_text_formatting(sanitize(text))
            l = QTextLayout(unescape_formatting(text), font, img)
            l.setAdditionalFormats(formats)
            to = QTextOption(align)
            to.setWrapMode(QTextOption.WrapAtWordBoundaryOrAnywhere)
            l.setTextOption(to)

            l.beginLayout()
            height = 0
            while height + 3*self.leading < max_height:
                line = l.createLine()
                if not line.isValid():
                    break
                line.setLineWidth(width)
                height += self.leading
                line.setPosition(QPointF(0, height))
                height += line.height()
            max_height -= height
            l.endLayout()
            if self.layouts:
                self.layouts.append(self.leading)
            else:
                self._position = Point(l.position().x(), l.position().y())
            self.layouts.append(l)
        if self.layouts:
            self.layouts.append(self.leading)
Example #18
0
def isometric(x: float, y: float) -> QPointF:
    """Convert rectangular coordinates to isometric."""

    # (iso_x + iso_y) * ISOMETRIC_HEIGHT1 = y
    # (iso_x - iso_y) * ISOMETRIC_WIDTH = x
    return QPointF(((y / ISOMETRIC_HEIGHT1) + (x / ISOMETRIC_WIDTH)),
                   ((y / ISOMETRIC_HEIGHT1) - (x / ISOMETRIC_WIDTH))) / 2
Example #19
0
    def __init__(self, gui):
        QWidget.__init__(self, gui)
        self.setObjectName('jobs_pointer')
        self.setVisible(False)
        self.resize(100, 80)
        self.animation = QPropertyAnimation(self, "geometry", self)
        self.animation.setDuration(750)
        self.animation.setLoopCount(2)
        self.animation.setEasingCurve(QEasingCurve.Linear)
        self.animation.finished.connect(self.hide)

        taily, heady = 0, 55
        self.arrow_path = QPainterPath(QPointF(40, taily))
        self.arrow_path.lineTo(40, heady)
        self.arrow_path.lineTo(20, heady)
        self.arrow_path.lineTo(50, self.height())
        self.arrow_path.lineTo(80, heady)
        self.arrow_path.lineTo(60, heady)
        self.arrow_path.lineTo(60, taily)
        self.arrow_path.closeSubpath()

        c = self.palette().color(QPalette.Active, QPalette.WindowText)
        self.color = QColor(c)
        self.color.setAlpha(100)
        self.brush = QBrush(self.color, Qt.SolidPattern)
Example #20
0
    def __init__(self, parent=None):
        super(WebView, self).__init__(parent)
        self._currentZoomLevel = 0
        self._progress = 0
        self._backgroundActivity = False

        self._clickedUrl = QUrl()
        self._clickedPos = QPointF()

        self._page = None  # WebPage
        self._firstLoad = False  # False

        self._rwhvqt = None  # QPointer<QWidget>
        self._wheelHelper = WheelHelper()

        self.loadStarted.connect(lambda: WebView._slotLoadStarted(self))
        self.loadProgress.connect(lambda progress: WebView._slotLoadProgress(self, progress))
        self.loadFinished.connect(lambda ok: WebView._slotLoadFinished(self, ok))
        self.iconChanged.connect(lambda: WebView._slotIconChanged(self))
        self.urlChanged.connect(lambda url: WebView._slotUrlChanged(self, url))
        self.titleChanged.connect(lambda title: WebView._slotTitleChanged(self, title))

        self._currentZoomLevel = self.zoomLevels().index(100)

        self.setAcceptDrops(True)
        self.installEventFilter(self)
        if self.parentWidget():
            self.parentWidget().installEventFilter(self)

        WebInspector.registerView(self)
Example #21
0
 def paintEvent(self, ev):
     if self.last_layout_rect != self.rect():
         self.do_layout()
     p = QPainter(self)
     br = self.layout.boundingRect()
     y = 0
     if br.height() < self.height():
         y = (self.height() - br.height()) / 2
     self.layout.draw(p, QPointF(0, y))
Example #22
0
 def click(self):
     pointf = self.target.mapToScene(QPointF(0.0, 0.0))
     x = pointf.x()
     y = pointf.y()
     x += self.value_or_default("width", 0.0) / 2.0
     y += self.value_or_default("height", 0.0) / 2.0
     point = QPoint(x, y)
     root_widget = pqaut.server.get_root_widget()
     pqaut.server.clicker.click_on(root_widget.target, point)
Example #23
0
    def __call__(self, painter, rect, color_theme, title_block, subtitle_block, footer_block):
        painter.fillRect(rect, self.color1)
        top = title_block.position.y + 2
        extra_spacing = subtitle_block.line_spacing // 2 if subtitle_block.line_spacing else title_block.line_spacing // 3
        height = title_block.height + subtitle_block.height + extra_spacing + title_block.leading
        right = rect.right() - self.hmargin
        width = right - self.hmargin

        # Draw main banner
        p = main = QPainterPath(QPointF(self.hmargin, top))
        draw_curved_line(p, rect.width() - 2 * self.hmargin, 0, 0.1, -0.1, 0.9, -0.1)
        deltax = self.GRADE * height
        p.lineTo(right + deltax, top + height)
        right_corner = p.currentPosition()
        draw_curved_line(p, - width - 2 * deltax, 0, 0.1, 0.05, 0.9, 0.05)
        left_corner = p.currentPosition()
        p.closeSubpath()

        # Draw fold rectangles
        rwidth = self.fold_width
        yfrac = 0.1
        width23 = int(0.67 * rwidth)
        rtop = top + height * yfrac

        def draw_fold(x, m=1, corner=left_corner):
            ans = p = QPainterPath(QPointF(x, rtop))
            draw_curved_line(p, rwidth*m, 0, 0.1, 0.1*m, 0.5, -0.2*m)
            fold_upper = p.currentPosition()
            p.lineTo(p.currentPosition() + QPointF(-deltax*m, height))
            fold_corner = p.currentPosition()
            draw_curved_line(p, -rwidth*m, 0, 0.2, -0.1*m, 0.8, -0.1*m)
            draw_curved_line(p, deltax*m, -height, 0.2, 0.1*m, 0.8, 0.1*m)
            p = inner_fold = QPainterPath(corner)
            dp = fold_corner - p.currentPosition()
            draw_curved_line(p, dp.x(), dp.y(), 0.5, 0.3*m, 1, 0*m)
            p.lineTo(fold_upper), p.closeSubpath()
            return ans, inner_fold

        left_fold, left_inner = draw_fold(self.hmargin - width23)
        right_fold, right_inner = draw_fold(right + width23, m=-1, corner=right_corner)

        painter.save()
        painter.setRenderHint(QPainter.Antialiasing)
        pen = QPen(self.ccolor2)
        pen.setWidth(3)
        pen.setJoinStyle(Qt.RoundJoin)
        painter.setPen(pen)
        for r in (left_fold, right_fold):
            painter.fillPath(r, QBrush(self.color2))
            painter.drawPath(r)
        for r in (left_inner, right_inner):
            painter.fillPath(r, QBrush(self.color2.darker()))
            painter.drawPath(r)
        painter.fillPath(main, QBrush(self.color2))
        painter.drawPath(main)
        painter.restore()
        return self.ccolor2, self.ccolor2, self.ccolor1
Example #24
0
 def copy(self):
     ans = GraphicsState()
     ans.fill = QBrush(self.fill)
     ans.stroke = QPen(self.stroke)
     ans.opacity = self.opacity
     ans.transform = self.transform * QTransform()
     ans.brush_origin = QPointF(self.brush_origin)
     ans.clip_updated = self.clip_updated
     ans.do_fill, ans.do_stroke = self.do_fill, self.do_stroke
     return ans
Example #25
0
 def is_offscreen(self):
     first_child = pqaut.server.get_root_widget()
     root_width = first_child.value_or_default('width', 0.0)
     root_height = first_child.value_or_default('height', 0.0)
     pointf = self._target.mapToScene(QPointF(0.0, 0.0))
     x = pointf.x()
     y = pointf.y()
     width = self.value_or_default("width", 0.0)
     height = self.value_or_default("height", 0.0)
     return x + width <= 0 or x >= root_width or y + height <= 0 or y >= root_height
Example #26
0
 def start(self):
     if config['disable_animations']:
         return
     self.setVisible(True)
     self.raise_()
     end = self.abspos(self.gui.jobs_button)
     end = QPointF( end.x() + self.gui.jobs_button.width()/3.0, end.y()+20)
     start = QPointF(end.x(), end.y() - 0.5*self.height())
     self.path = QPainterPath(QPointF(start))
     self.path.lineTo(end)
     self.path.closeSubpath()
     self.animation.setStartValue(self.rect_at(0.0))
     self.animation.setEndValue(self.rect_at(1.0))
     self.animation.setDirection(self.animation.Backward)
     num_keys = 100
     for i in xrange(1, num_keys):
         i /= num_keys
         self.animation.setKeyValueAt(i, self.rect_at(i))
     self.animation.start()
Example #27
0
 def __init__(self):
     self.fill = QBrush(Qt.white)
     self.stroke = QPen()
     self.opacity = 1.0
     self.transform = QTransform()
     self.brush_origin = QPointF()
     self.clip_updated = False
     self.do_fill = False
     self.do_stroke = True
     self.qt_pattern_cache = {}
Example #28
0
 def from_json(self, json_properties):
     pattern = self.make()
     pattern.set_name(json_properties["name"])
     width = json_properties["properties"]["size"][0]
     height = json_properties["properties"]["size"][1]
     for pattern_object in json_properties["properties"]["objects"]:
         x = pattern_object["offset"][0] * width
         y = -pattern_object["offset"][1] * height
         starfish_type = self.starfish_type_from_string(
             pattern_object["name"])
         pattern.add_starfish_at_position(QPointF(x, y), starfish_type)
     return pattern
Example #29
0
 def get_starfish_at_position(self, position):
     for starfish in self._starfishes:
         top_left = QPointF(
             starfish.position().x() - PatternDrawer.IMAGE_SIZE[0] * 0.5,
             starfish.position().y() - PatternDrawer.IMAGE_SIZE[1] * 0.5)
         rect = QRectF(
             top_left,
             QSizeF(PatternDrawer.IMAGE_SIZE[0],
                    PatternDrawer.IMAGE_SIZE[1]))
         if rect.contains(position):
             return starfish
     return None
Example #30
0
 def format_data(data):
     pointlist = []
     index = 0
     minitem = 0
     maxitem = 0
     for item in data:
         if item > maxitem:
             maxitem = item
         if item < minitem:
             minitem = item
         pointlist.append(QPointF(index, item))
         index += 1
     return pointlist, maxitem, minitem
Example #31
0
 def move_selection_rect(self, x, y):
     sr = self.selection_state.rect
     half_width = sr.width() / 2.0
     half_height = sr.height() / 2.0
     c = sr.center()
     nx = c.x() + x
     ny = c.y() + y
     minx = self.target.left() + half_width
     maxx = self.target.right() - half_width
     miny, maxy = self.target.top() + half_height, self.target.bottom() - half_height
     nx = max(minx, min(maxx, nx))
     ny = max(miny, min(maxy, ny))
     sr.moveCenter(QPointF(nx, ny))
Example #32
0
class Curve(QWidget):
    '''
    class Curve
    '''
    def __init__(self, title, parent = None):
        super(Curve, self).__init__(parent)
        self._sheftCount = 100
        self._points = QPointF() * 256

    def setCount(self, count):
        self._points = QPointF() * count

    def count(self):
        return self._points.count()

    def append(self, point):
        pass

    def setSamples(self, points):
        pass

    def sheft(self, point):
        pass

    def sheftY(self, y):
        pass

    def samples(self):
        return self._points

    def sheftCount(self):
        return self._sheftCount

    def setSheftCount(self, value):
        self._sheftCount = value

    def setLinePen(self, pen):
        pass

    def update(self):
        pass
Example #33
0
 def setCount(self, count):
     self._points = QPointF() * count
Example #34
0
 def __init__(self, title, parent = None):
     super(Curve, self).__init__(parent)
     self._sheftCount = 100
     self._points = QPointF() * 256