Python源码示例:PySide2.QtCore.QRectF()

示例1
def get_topleft_rect(rect):
    """
    this function return a manipulator rect for the transform
    handler.
      *__________________________
       |                        |
       |                        |
       |________________________|
    """
    if not rect:
        return None
    point = rect.topLeft()
    return QtCore.QRectF(
        point.x() - (POINT_RADIUS / 2.0) - POINT_OFFSET,
        point.y() - (POINT_RADIUS / 2.0) - POINT_OFFSET,
        POINT_RADIUS, POINT_RADIUS) 
示例2
def get_bottomleft_rect(rect):
    """
    this function return a manipulator rect for the transform
    handler.
       __________________________
       |                        |
       |                        |
       |________________________|
      *
    """
    if not rect:
        return None
    point = rect.bottomLeft()
    return QtCore.QRectF(
        point.x() - (POINT_RADIUS / 2.0) - POINT_OFFSET,
        point.y() + (POINT_RADIUS / 2.0) - POINT_OFFSET,
        POINT_RADIUS, POINT_RADIUS) 
示例3
def get_bottomright_rect(rect):
    """
    this function return a manipulator rect for the transform
    handler.
       __________________________
       |                        |
       |                        |
       |________________________|
                                 *
    """
    if not rect:
        return None
    point = rect.bottomRight()
    return QtCore.QRectF(
        point.x() + (POINT_RADIUS / 2.0) - POINT_OFFSET,
        point.y() + (POINT_RADIUS / 2.0) - POINT_OFFSET,
        POINT_RADIUS, POINT_RADIUS) 
示例4
def get_left_side_rect(rect):
    """
    this function return a manipulator rect for the transform
    handler.
       __________________________
       |                        |
      *|                        |
       |________________________|
    """
    if not rect:
        return None
    top = rect.top() + (rect.height() / 2.0)
    return QtCore.QRectF(
        rect.left() - (POINT_RADIUS / 2.0) - POINT_OFFSET,
        top - (POINT_RADIUS / 2.0),
        POINT_RADIUS, POINT_RADIUS) 
示例5
def get_right_side_rect(rect):
    """
    this function return a manipulator rect for the transform
    handler.
       __________________________
       |                        |
       |                        |*
       |________________________|
    """
    if not rect:
        return None
    top = rect.top() + (rect.height() / 2.0)
    return QtCore.QRectF(
        rect.right() + (POINT_RADIUS / 2.0) - POINT_OFFSET,
        top - (POINT_RADIUS / 2.0) ,
        POINT_RADIUS, POINT_RADIUS) 
示例6
def get_bottom_side_rect(rect):
    """
    this function return a manipulator rect for the transform
    handler.
       __________________________
       |                        |
       |                        |
       |________________________|
                    *
    """
    if not rect:
        return None
    return QtCore.QRectF(
        rect.left() + (rect.width() / 2.0) - (POINT_RADIUS / 2.0),
        rect.bottom() + (POINT_RADIUS / 2.0) - POINT_OFFSET,
        POINT_RADIUS, POINT_RADIUS) 
示例7
def get_combined_rects(rects):
    """
    this function analyse list of rects and return
    a rect with the smaller top and left and highest right and bottom
    __________________________________ ?
    |              | A               |
    |              |                 |
    |______________|      ___________| B
    |                     |          |
    |_____________________|__________|
    """
    if not rects:
        return None
    left = min([rect.left() for rect in rects])
    right = max([rect.right() for rect in rects])
    top = min([rect.top() for rect in rects])
    bottom = max([rect.bottom() for rect in rects])
    return QtCore.QRectF(left, top, right - left, bottom - top) 
示例8
def fitInView(self, scale=True):
		rect = self.getImageDims()
		if not rect.isNull():
			self.setSceneRect(rect)

			unity = self.transform().mapRect(QRectF(0, 0, 1, 1))
			self.scale(1 / unity.width(), 1 / unity.height())
			viewrect = self.viewport().rect()
			scenerect = self.transform().mapRect(rect)
			factor = min(viewrect.width() / scenerect.width(),
						 viewrect.height() / scenerect.height())
			self.scale(factor, factor)

			if self.hasImage():
				self.updateIndicatorSize()

			self._zoom = 0 
示例9
def __init__(self, name=None):

        pen = QtGui.QPen(QtCore.Qt.SolidLine)
        pen.setColor(QtGui.QColor(0, 0, 0, 255))
        pen.setWidthF(0.2)
        pen.setJoinStyle(QtCore.Qt.MiterJoin)
        self.pen = pen

        self.brush = QtGui.QBrush(QtGui.QColor(255, 255, 0, 255))
        self.font = QtGui.QFont('Decorative', 12)

        self.rect = QtCore.QRectF()
        self.shape = QtGui.QPainterPath()
        self.path = QtGui.QPainterPath()

        self.scale = (1, 1)
        self.tooltip = ''

        self.method = ''
        self.args = [] 
示例10
def _boundingRect(self):
        height, width = 0, 0

        width += self._addr_width
        width += self.LINEAR_INSTRUCTION_OFFSET

        if self._bytes_text:
            height += Conf.disasm_font_height * len(self._bytes_text) * self.currentDevicePixelRatioF()
        else:
            height += Conf.disasm_font_height * self.currentDevicePixelRatioF()

        if self._bytes_text:
            width += max(len(line) for line in self._bytes_text) * Conf.disasm_font_width * self.currentDevicePixelRatioF()
        else:
            width += Conf.disasm_font_metrics.width(QUnknownBlock.DEFAULT_TEXT) * self.currentDevicePixelRatioF()
        return QRectF(0, 0, width, height)

    #
    # Private methods
    # 
示例11
def boundingRect(self):
        extra = (self.pen().width() + 20) / 2.0
        p1 = self.line().p1()
        p2 = self.line().p2()
        size = QtCore.QSizeF(p2.x() - p1.x(), p2.y() - p1.y())
        return QtCore.QRectF(p1, size).normalized().adjusted(-extra, -extra, extra, extra) 
示例12
def clicked(self, cursor):
        self.handeling = True
        self.rect = QtCore.QRectF(cursor, cursor) 
示例13
def get_shape_rect_from_options(options):
    return QtCore.QRectF(
        options['shape.left'],
        options['shape.top'],
        options['shape.width'],
        options['shape.height']) 
示例14
def get_top_side_rect(rect):
    """
    this function return a manipulator rect for the transform
    handler.        
       _____________*____________
       |                        |
       |                        |
       |________________________|
    """
    if not rect:
        return None
    return QtCore.QRectF(
        rect.left() + (rect.width() / 2.0) - (POINT_RADIUS / 2.0),
        rect.top() - (POINT_RADIUS / 2.0) - POINT_OFFSET,
        POINT_RADIUS, POINT_RADIUS) 
示例15
def apply_relative_transformation(self, rects):
        for rect in rects:
            resize_rect_with_reference(
                rect, self.reference_rect, self.rect)

        self.reference_rect = QtCore.QRectF(
            self.rect.topLeft(), self.rect.bottomRight()) 
示例16
def mousePressEvent(self, _):
        self.setFocus(QtCore.Qt.MouseFocusReason)
        cursor = get_cursor(self)
        direction = self.manipulator.get_direction(cursor)
        self.clicked = True
        self.transform.direction = direction

        self.manipulator_moved = False
        rect = self.manipulator.rect
        if rect is not None:
            self.transform.set_rect(rect)
            self.transform.reference_rect = QtCore.QRectF(rect)

        self.clicked_shape = None
        for shape in reversed(self.shapes):
            if shape.rect.contains(cursor):
                self.clicked_shape = shape
                break

        if rect and rect.contains(cursor):
            self.transform.set_reference_point(cursor)
        handeling = bool(direction or rect.contains(cursor) if rect else False)

        self.handeling = handeling
        if not self.handeling:
            self.selection_square.clicked(cursor)

        self.repaint() 
示例17
def updateIndicatorSize(self, stroke=3, offset=2, crossSize=10):
		"""
		draw a box and crosshair under mouse cursor as rectangle of size latentSize
		"""
		multiplier = 1 #TODO optional: scale indicator with zoom level

		stroke *= multiplier
		offset *= multiplier
		crossSize *= multiplier

		halfStroke = stroke / 2
		rect = self.getImageDims()
		latentSize = self.latentSize * rect.width() / self.gridSize.width()
		halfSize = latentSize / 2
		crossSize = min(crossSize, int(halfSize - 3))

		pixmap = QPixmap(QSize(int(latentSize + stroke + offset), int(latentSize + stroke + offset)))
		#fill rectangle with transparent color
		pixmap.fill(QColor(0,0,0,0)) #transparent

		painter = QPainter(pixmap)
		r = QRectF(QPoint(), QSizeF(latentSize, latentSize))
		r.adjust(offset+halfStroke, offset+halfStroke, -halfStroke, -halfStroke)
		#draw shadow under rectangle
		pen = QPen(QColor(50, 50, 50, 100), stroke) #shadow
		painter.setPen(pen)
		painter.drawRect(r)
		if crossSize > 4:
			painter.drawLine(QPointF(offset+halfSize, offset+halfSize-crossSize), QPointF(offset+halfSize, offset+halfSize+crossSize))
			painter.drawLine(QPointF(offset+halfSize-crossSize, offset+halfSize), QPointF(offset+halfSize+crossSize, offset+halfSize))
		r.adjust(-offset, -offset, -offset, -offset)
		pen = QPen(QColor(styleColor[0], styleColor[1], styleColor[2], 200), stroke)
		painter.setPen(pen)
		painter.drawRect(r)
		if crossSize > 4:
			painter.drawLine(QPointF(halfSize, halfSize - crossSize), QPointF(halfSize, halfSize + crossSize))
			painter.drawLine(QPointF(halfSize - crossSize, halfSize), QPointF(halfSize + crossSize, halfSize))
		painter.end()

		self._latentIndicator.setPixmap(pixmap) 
示例18
def getImageDims(self):
		return QRectF(self._image.pixmap().rect()) 
示例19
def Point(self, x, y):
        # add some pixels to the point rect, so that it can be selected
        eps = 0.02
        self.rect = QtCore.QRectF(x-eps, y-eps, 2.*eps, 2.*eps)
        self.shape.addRect(self.rect)
        self.method = 'drawPoint'
        self.args = [x, y] 
示例20
def Line(self, x1, y1, x2, y2):
        eps = 0.01
        p1 = QtCore.QPointF(x1-eps, y1-eps)
        p2 = QtCore.QPointF(x2+eps, y2+eps)
        self.rect = QtCore.QRectF(p1, p2)
        self.shape.addRect(self.rect)
        self.method = 'drawLine'
        self.args = [x1, y1, x2, y2] 
示例21
def Circle(self, x, y, r):
        self.rect = QtCore.QRectF(x-r, y-r, 2.*r, 2.*r)
        self.shape.addEllipse(self.rect)
        self.method = 'drawEllipse'
        self.args = [self.rect] 
示例22
def Rectangle(self, x, y, w, h):
        self.rect = QtCore.QRectF(x, y, w, h)
        self.shape.addRect(self.rect)
        self.method = 'drawRect'
        self.args = [self.rect] 
示例23
def adjustMarkerSize(self):
        """Adjust marker size during zoom. Marker items are circles
        which are otherwise affected by zoom. Using MARKERSIZE from
        Settings a fixed markersize (e.g. 3 pixels) can be kept.
        This method immitates the behaviour of pen.setCosmetic()
        """

        if not self.parent.airfoil:
            return

        # markers are drawn in GraphicsItem using scene coordinates
        # in order to keep them constant size, also when zooming
        # a fixed pixel size (MARKERSIZE from settings) is mapped to
        # scene coordinates
        # depending on the zoom, this leads to always different
        # scene coordinates
        # map a square with side length of MARKERSIZE to the scene coords
        mappedMarker = self.mapToScene(
            QtCore.QRect(0, 0, MARKERSIZE, MARKERSIZE))
        mappedMarkerWidth = mappedMarker.boundingRect().width()

        if self.parent.airfoil.contourPolygon:
            markers = self.parent.airfoil.polygonMarkers
            x, y = self.parent.airfoil.raw_coordinates
            for i, marker in enumerate(markers):
                # in case of circle, args is a QRectF
                marker.args = [QtCore.QRectF(x[i] - mappedMarkerWidth,
                                             y[i] - mappedMarkerWidth,
                                             2. * mappedMarkerWidth,
                                             2. * mappedMarkerWidth)]

        # if self.parent.airfoil.contourSpline:
        if hasattr(self.parent.airfoil, 'contourSpline'):
            markers = self.parent.airfoil.splineMarkers
            x, y = self.parent.airfoil.spline_data[0]
            for i, marker in enumerate(markers):
                # in case of circle, args is a QRectF
                marker.args = [QtCore.QRectF(x[i] - mappedMarkerWidth,
                                             y[i] - mappedMarkerWidth,
                                             2. * mappedMarkerWidth,
                                             2. * mappedMarkerWidth)] 
示例24
def getSceneFromView(self):
        """Cache view to be able to keep it during resize"""

        # map view rectangle to scene coordinates
        polygon = self.mapToScene(self.rect())

        # sceneview describes the rectangle which is currently
        # being viewed in scene coordinates
        # this is needed during resizing to be able to keep the view
        self.sceneview = QtCore.QRectF(polygon[0], polygon[2]) 
示例25
def __init__(self, item):
        """
        Args:
            item (object): GraphicsItemsCollection object
        """
        super().__init__()

        # get MainWindow instance (overcomes handling parents)
        self.mainwindow = QtCore.QCoreApplication.instance().mainwindow

        self.scene = self.mainwindow.scene

        self.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable, False)
        self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable, False)
        self.setFlag(QtWidgets.QGraphicsItem.ItemIsFocusable, True)

        # docs: For performance reasons, these notifications
        # are disabled by default.
        # needed for : ItemScaleHasChanged
        self.setFlag(QtWidgets.QGraphicsItem.ItemSendsGeometryChanges, True)

        self.setAcceptHoverEvents(True)

        # method of QPainter
        self.method = item.method
        self.args = item.args
        self.pen = item.pen
        self.penwidth = item.pen.width()
        self.brush = item.brush
        self.rect = QtCore.QRectF(item.rect)
        self.setToolTip(item.tooltip)
        self.scale = item.scale
        self.font = item.font
        self.item_shape = item.shape
        self.hoverstyle = QtCore.Qt.SolidLine
        self.hoverwidth = 0.1
        if hasattr(item, 'name'):
            self.name = item.name

        # initialize bounding rectangle (including penwidth)
        self.setBoundingRect() 
示例26
def setBoundingRect(self):
        # FIXME
        # FIXME how to calculate penwidth here since scene at the beginning
        # FIXME is not knwon
        pw = 0.0
        self.boundingrect = QtCore.QRectF(self.rect.left()-pw/2,
                                          self.rect.top()-pw/2,
                                          self.rect.width()+pw,
                                          self.rect.height()+pw) 
示例27
def _boundingRect(self):
        height = self._config.disasm_font_height * self.currentDevicePixelRatioF()
        if self._args_str:
            height += self._config.disasm_font_height * self.currentDevicePixelRatioF()

        width = max(
            self._prototype_width,
            self._args_str_width,
        )

        return QRectF(0, 0, width, height) 
示例28
def _boundingRect(self):
        return QRectF(0, 0, self._width, self._height) 
示例29
def _boundingRect(self):
        return QRectF(0, 0, self._width, self._height) 
示例30
def _boundingRect(self):
        return QRectF(0, 0, self._width, self._height)