Example #1
0
    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))
Example #2
0
 def paintEvent(self, event):
     """ Поскольку это полностью прозрачное фоновое окно, жесткая для поиска
         граница с прозрачностью 1 рисуется в событии перерисовывания, чтобы отрегулировать размер окна. """
     super(FramelessWindow, self).paintEvent(event)
     painter = QPainter(self)
     painter.setPen(QPen(QColor(255, 255, 255, 1), 2 * self.Margins))
     painter.drawRect(self.rect())
Example #3
0
    def paintEvent(self, event):
        size = self.size()

        # draw background
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(QColor(255, 255, 255, 255))
        painter.setBrush(self.fill_color)
        painter.drawRect(0, 0, size.width(), size.height())
        painter.end()
 def shape_to_pixelmap(item_type, pen, brush, shape) -> QPixmap:
     pixmap = QPixmap(50, 50)
     pixmap.fill(Qt.transparent)
     painter = QPainter(pixmap)
     painter.setRenderHint(QPainter.Antialiasing)
     painter.setPen(pen)
     painter.setBrush(brush)
     if item_type == QGraphicsRectItem.type(QGraphicsRectItem()):
         painter.drawRect(QRect(10, 15, 30, 20))
     elif item_type == QGraphicsEllipseItem.type(QGraphicsEllipseItem()):
         painter.drawEllipse(QRect(10, 10, 30, 30))
     elif item_type == QGraphicsPolygonItem.type(QGraphicsPolygonItem()):
         if shape.polygon().size() == 3:
             painter.drawPolygon(QPolygon([QPoint(10, 40), QPoint(40, 40), QPoint(25, 10)]))
         else:
             painter.drawPolygon(QPolygon([QPoint(12, 40), QPoint(23, 36),
                                           QPoint(37, 24), QPoint(23, 12), QPoint(7, 16)]))
     elif item_type == QGraphicsLineItem.type(QGraphicsLineItem()):
         painter.drawLine(QLine(10, 40, 40, 10))
     return pixmap
Example #5
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.fillRect(self.rect(), Qt.black)

        if self.pixmap.isNull():
            painter.setPen(Qt.white)
            painter.drawText(self.rect(), Qt.AlignCenter,
                             "Rendering initial image, please wait...")
            return

        if self.curScale == self.pixmapScale:
            painter.drawPixmap(self.pixmapOffset, self.pixmap)
        else:
            scaleFactor = self.pixmapScale / self.curScale
            newWidth = int(self.pixmap.width() * scaleFactor)
            newHeight = int(self.pixmap.height() * scaleFactor)
            newX = self.pixmapOffset.x() + (self.pixmap.width() - newWidth) / 2
            newY = self.pixmapOffset.y() + (self.pixmap.height() -
                                            newHeight) / 2

            painter.save()
            painter.translate(newX, newY)
            painter.scale(scaleFactor, scaleFactor)
            exposed, _ = painter.transform().inverted()
            exposed = exposed.mapRect(self.rect()).adjusted(-1, -1, 1, 1)
            painter.drawPixmap(exposed, self.pixmap, exposed)
            painter.restore()

        text = "Use mouse wheel or the '+' and '-' keys to zoom. Press and " \
                "hold left mouse button to scroll."
        metrics = painter.fontMetrics()
        textWidth = metrics.horizontalAdvance(text)

        painter.setPen(Qt.NoPen)
        painter.setBrush(QColor(0, 0, 0, 127))
        painter.drawRect((self.width() - textWidth) / 2 - 5, 0, textWidth + 10,
                         metrics.lineSpacing() + 5)
        painter.setPen(Qt.white)
        painter.drawText((self.width() - textWidth) / 2,
                         metrics.leading() + metrics.ascent(), text)
Example #6
0
class ScreenSelection(QtWidgets.QGroupBox):
    def __init__(self, parent: DisplayCalibration):
        QtWidgets.QGroupBox.__init__(self,
                                     'Fullscreen selection (double click)')
        self.main = parent

        self.setSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding,
                           QtWidgets.QSizePolicy.Policy.Expanding)

        self.painter = QPainter()

    def mouseDoubleClickEvent(self, ev, *args, **kwargs):
        for screen_id, screen_coords in enumerate(
                self._get_widget_screen_coords()):
            rect = QtCore.QRectF(*screen_coords)

            if not rect.contains(QtCore.QPoint(ev.pos().x(), ev.pos().y())):
                continue

            print(f'Set display to fullscreen on screen {screen_id}')

            screen = access.application.screens()[screen_id]
            px_ratio = screen.devicePixelRatio()
            self.main.global_settings.screen_id.set_value(screen_id)
            self.main.global_settings.win_x_pos.set_value(
                screen.geometry().x())
            self.main.global_settings.win_y_pos.set_value(
                screen.geometry().y())
            self.main.global_settings.win_width.set_value(
                int(screen.geometry().width() * px_ratio))
            self.main.global_settings.win_height.set_value(
                int(screen.geometry().height() * px_ratio))

            access.application.processEvents()

    @staticmethod
    def _get_norm_screen_coords() -> np.ndarray:

        # Get connected screens
        avail_screens = access.application.screens()

        # Calculate total display area bounding box
        area = [[
            s.geometry().width() * s.devicePixelRatio(),
            s.geometry().height() * s.devicePixelRatio()
        ] for s in avail_screens]
        area = np.sum(area, axis=0)

        xmin = np.min([s.geometry().x() for s in avail_screens])
        ymin = np.min([s.geometry().y() for s in avail_screens])

        # Define normalization functions
        xnorm = lambda x: (x - xmin) / area[0]
        ynorm = lambda y: (y - ymin) / area[1]

        # Add screen dimensions
        screens = []
        for s in avail_screens:
            g = s.geometry()
            screens.append([
                xnorm(g.x() * s.devicePixelRatio()),  # x
                ynorm(g.y() * s.devicePixelRatio()),  # y
                xnorm(g.width() * s.devicePixelRatio()),  # width
                ynorm(g.height() * s.devicePixelRatio())
            ])  # height

        return np.array(screens)

    def _get_widget_screen_coords(self):
        s = self._get_norm_screen_coords()
        s[:, 0] *= self.size().width()
        s[:, 1] *= self.size().height()
        s[:, 2] *= self.size().width()
        s[:, 3] *= self.size().height()

        return s.astype(int)

    def paintEvent(self, QPaintEvent):

        for i, screen in enumerate(self._get_widget_screen_coords()):

            rect = QtCore.QRect(*screen)

            self.painter.begin(self)

            self.painter.setBrush(QtCore.Qt.BrushStyle.Dense4Pattern)
            self.painter.drawRect(rect)

            self.painter.setPen(QColor(168, 34, 3))
            self.painter.setFont(QFont('Decorative', 30))
            self.painter.drawText(rect, QtCore.Qt.AlignmentFlag.AlignCenter,
                                  str(i))

            self.painter.end()
Example #7
0
    def paintEvent(self, event):
        p = QPainter(self.viewport())
        render = self.createRenderContext()
        render.init(p)
        charWidth = render.getFontWidth()
        charHeight = render.getFontHeight()

        # Compute range that needs to be updated
        topY = event.rect().y()
        botY = topY + event.rect().height()
        topY = (topY - 2) // charHeight
        botY = ((botY - 2) // charHeight) + 1

        # Compute selection range
        selection = False
        selStart, selEnd = self.getSelectionOffsets()
        if selStart != selEnd:
            selection = True

        # Draw selection
        if selection:
            startY = None
            endY = None
            startX = None
            endX = None
            for i in range(0, len(self.lines)):
                if selStart >= self.lines[i].address:
                    startY = i - self.topLine
                    startX = selStart - self.lines[i].address
                    if startX > self.cols:
                        startX = self.cols
                if selEnd >= self.lines[i].address:
                    endY = i - self.topLine
                    endX = selEnd - self.lines[i].address
                    if endX > self.cols:
                        endX = self.cols

            if startY is not None and endY is not None:
                p.setPen(binaryninjaui.getThemeColor(
                    ThemeColor.SelectionColor))
                p.setBrush(
                    binaryninjaui.getThemeColor(ThemeColor.SelectionColor))
                if startY == endY:
                    p.drawRect(2 + (self.addrWidth + 2 + startX) * charWidth,
                               2 + startY * charHeight,
                               (endX - startX) * charWidth, charHeight + 1)
                else:
                    p.drawRect(2 + (self.addrWidth + 2 + startX) * charWidth,
                               2 + startY * charHeight,
                               (self.cols - startX) * charWidth,
                               charHeight + 1)
                    if endX > 0:
                        p.drawRect(2 + (self.addrWidth + 2) * charWidth,
                                   2 + endY * charHeight, endX * charWidth,
                                   charHeight + 1)
                if (endY - startY) > 1:
                    p.drawRect(2 + (self.addrWidth + 2) * charWidth,
                               2 + (startY + 1) * charHeight,
                               self.cols * charWidth,
                               ((endY - startY) - 1) * charHeight + 1)

        # Paint each line
        color = self.palette().color(QPalette.WindowText)
        for y in range(topY, botY):
            if (y + self.topLine) < 0:
                continue
            if (y + self.topLine) >= len(self.lines):
                break
            if self.lines[y + self.topLine].separator:
                render.drawLinearDisassemblyLineBackground(
                    p,
                    LinearDisassemblyLineType.NonContiguousSeparatorLineType,
                    QRect(0, 2 + y * charHeight,
                          event.rect().width(), charHeight), 0)
                continue

            lineStartAddr = self.lines[y + self.topLine].address
            addrStr = "%.8x" % lineStartAddr
            length = self.lines[y + self.topLine].length
            text = self.lines[y + self.topLine].text

            cursorCol = None
            if (((self.cursorAddr >= lineStartAddr) and
                 (self.cursorAddr < (lineStartAddr + length)))
                    or (((y + self.topLine + 1) >= len(self.lines)) and
                        (self.cursorAddr == (lineStartAddr + length)))):
                cursorCol = self.cursorAddr - lineStartAddr

            render.drawText(
                p, 2, 2 + y * charHeight,
                binaryninjaui.getThemeColor(ThemeColor.AddressColor), addrStr)
            render.drawText(p, 2 + (self.addrWidth + 2) * charWidth,
                            2 + y * charHeight, color, text)

            if self.caretVisible and self.caretBlink and not selection and cursorCol is not None:
                p.setPen(Qt.NoPen)
                p.setBrush(self.palette().color(QPalette.WindowText))
                p.drawRect(2 + (self.addrWidth + 2 + cursorCol) * charWidth,
                           2 + y * charHeight, charWidth, charHeight + 1)
                caretTextColor = self.palette().color(QPalette.Base)
                byteValue = self.data.read(lineStartAddr + cursorCol, 1)
                if len(byteValue) == 1:
                    byteStr = self.byte_mapping[byteValue[0]]
                    render.drawText(
                        p, 2 + (self.addrWidth + 2 + cursorCol) * charWidth,
                        2 + y * charHeight, caretTextColor, byteStr)
Example #8
0
    def paintEvent(self, ev):
        p = QPainter(self)
        p.setFont(self.font)
        #p.fillRect(self.rect(), QBrush(Qt.blue))

        length = len(self.display_data)

        # Reduce to the number of lines that are available in the data
        num_rows = length // self.bytes_per_line
        if length % self.bytes_per_line > 0:
            num_rows += 1

        for l in range(num_rows):
            p.setPen(self.label_color)
            # Draw address label
            # self.instance.get_local_label(self.start_offset + l * self.bytes_per_line)
            position_string = self.display_labels[l]
            p.drawText(QPoint(self.label_offset_x, (l + 1) * self.line_height),
                       position_string)

            for i in range(
                    0,
                    min(self.bytes_per_line,
                        length - self.bytes_per_line * l)):

                #virtual_address = self.start_offset + l*self.bytes_per_line + i

                p.setPen(self.byte_color)

                current_byte = self.display_data[i + l * self.bytes_per_line]
                if current_byte.background is not None:
                    p.setBackground(current_byte.background)
                    p.setBackgroundMode(Qt.OpaqueMode)

                p.drawText(
                    QPoint(self.label_length + i * self.byte_width,
                           (l + 1) * self.line_height), current_byte.text)
                p.setBackgroundMode(Qt.TransparentMode)

                # Draw selection rects
                if current_byte.is_selected:
                    p.setPen(self.selection_color)
                    p.drawRect(
                        # TODO make these offsets configurable/dependent on font?
                        self.label_length + i * self.byte_width - 3,
                        (l) * self.line_height + 3,
                        self.byte_width,
                        self.line_height)

                # Draw annotation underlines
                if len(current_byte.annotations) > 0:
                    y_offset = 0
                    for annotation in current_byte.annotations:
                        self.annotation_pen.setColor(annotation.color)
                        p.setPen(self.annotation_pen)
                        x = self.label_length + i * self.byte_width
                        y = (l + 1) * self.line_height + y_offset + 2
                        p.drawLine(x, y, x + self.byte_width, y)
                        y_offset += 2

                # Draw constraint pipes
                if len(current_byte.constraints) > 0:
                    enabled = False
                    for constraint in current_byte.constraints:
                        if constraint.enabled:
                            enabled = True
                            break
                    if enabled:
                        p.setPen(self.enabled_constraint_pen)
                    else:
                        p.setPen(self.disabled_constraint_pen)
                    x = self.label_length + i * self.byte_width - 2
                    y = (l) * self.line_height + 3
                    p.drawLine(x, y, x, y + self.line_height)
Example #9
0
    def paintEvent(self, pe) -> None:

        mainradius, fontsizefactor, center_x, center_y_pp, width = self.computeCenter(
        )

        painter = QPainter(self)
        # So that we can use the background color
        painter.setBackgroundMode(Qt.OpaqueMode)
        # Smooth out the circle
        painter.setRenderHint(QPainter.Antialiasing)
        # Use background color
        textBgColor = QColor(painter.background().color())
        # print("bgcolor = ", bgColor)
        bgColor = QColor("transparent")
        pointColor = QColor(painter.pen().color())

        self.pointColor = pointColor
        self.bgColor = textBgColor

        alpha = 150

        if self.parent().displayPp == 'all' or self.parent(
        ).displayPp == self.io:
            pointColor.setAlpha(255)
        else:
            pointColor.setAlpha(alpha)

        # draw text
        if not self._hasFixedFontSize:
            fontsize = mainradius * fontsizefactor
        else:
            fontsize = self._fixedFontSize
        self.fontsize = fontsize
        textRect_ = QtCore.QRectF(0, center_y_pp - mainradius - 2 * fontsize,
                                  width, 2 * fontsize)
        f = painter.font()
        f.setPointSizeF(fontsize)

        # self._io = 'in'
        if self.io == 'out':
            fm = QFontMetrics(f).boundingRect(self._text)
            # print("fm = ", fm)
            painter.setBrush(pointColor)
            painter.setPen(QPen(pointColor))
            painter.drawRect(
                QtCore.QRectF(center_x - fm.width() / 2,
                              center_y_pp - mainradius - 2 * fontsize,
                              fm.width(), fm.height()))
            painter.setPen(QPen(textBgColor))

        painter.setFont(f)
        painter.setBackgroundMode(Qt.TransparentMode)
        painter.drawText(textRect_, Qt.AlignHCenter | Qt.AlignTop, self._text)

        # draw hexagon
        painter.setBrush(bgColor)
        painter.setPen(pointColor)
        painter.drawPolygon(
            self.createPoly(6, mainradius, center_x, center_y_pp))

        # draw outer circle
        radius_outer = mainradius * .8
        if self.title not in implementedPatchPoints:
            painter.setBrush(QtGui.QBrush(QtGui.QColor(int("0x999999", 0))))
        painter.drawEllipse(QtCore.QPointF(center_x, center_y_pp),
                            radius_outer, radius_outer)

        # draw inner circle
        radius_inner = mainradius * .5
        # painter.setBrush(QBrush(pointColor))
        painter.setBrush(QColor(self._ppColor))
        painter.drawEllipse(QtCore.QPointF(center_x, center_y_pp),
                            radius_inner, radius_inner)
Example #10
0
 def paintEvent(self, event):
     p = QPainter(self)
     p.drawImage(self.rect(), self.image)
     p.drawRect(self.rect())