예제 #1
0
    def paint(self, painter, option, widget=None):
        """QGraphicsRectItem virtual
        """
        # TODO LH Is there a way to clip to overlapping
        # QAbstractGraphicsItems with a larger zorder

        # TODO LH Get pixmap without tight coupling to scene
        if not self.has_mouse():
            painter.drawPixmap(self.boundingRect(),
                               self.scene().pixmap,
                               self.sceneBoundingRect())

        with painter_state(painter):
            outline_colour, fill_colour = self.colours

            # Cosmetic pens "...draw strokes that have a constant width
            # regardless of any transformations applied to the QPainter they are
            # used with."
            pen = QPen(outline_colour, self.BOX_WIDTH, Qt.SolidLine)
            pen.setCosmetic(True)
            painter.setPen(pen)

            r = self.boundingRect()
            painter.drawRect(r)

            if fill_colour:
                painter.fillRect(r, fill_colour)
예제 #2
0
    def paint(self, painter, option, widget):
        """QGraphicsItem virtual
        """
        with painter_state(painter):
            painter.setRenderHint(QPainter.Antialiasing)
            bounding = self.boundingRect()

            # Black circle, with partially transparent white fill
            painter.setPen(self.PEN)
            painter.setBrush(self.FILL)
            painter.drawEllipse(bounding)

            # Filled black circle at centre
            painter.setBrush(QBrush(Qt.black))
            painter.drawEllipse(bounding.center(), 2, 2)

            # Black crosshair
            size = self.SIZE
            half_size = self.HALF_SIZE
            painter.drawLine(
                bounding.topLeft() + QPoint(0, half_size),
                bounding.topLeft() + QPoint(size, half_size)
            )
            painter.drawLine(
                bounding.topLeft() + QPoint(half_size, 0),
                bounding.topLeft() + QPoint(half_size, size)
            )
예제 #3
0
    def paint(self, painter, option, widget=None):
        """QGraphicsRectItem virtual
        """
        # TODO LH Is there a way to clip to overlapping
        # QAbstractGraphicsItems with a larger zorder

        # TODO LH Get pixmap without tight coupling to scene
        if not self.has_mouse():
            painter.drawPixmap(self.boundingRect(),
                               self.scene().pixmap, self.sceneBoundingRect())

        with painter_state(painter):
            outline_colour, fill_colour = self.colours

            # Cosmetic pens "...draw strokes that have a constant width
            # regardless of any transformations applied to the QPainter they are
            # used with."
            pen = QPen(outline_colour, self.BOX_WIDTH, Qt.SolidLine)
            pen.setCosmetic(True)
            painter.setPen(pen)

            r = self.boundingRect()
            painter.drawRect(r)

            if fill_colour:
                painter.fillRect(r, fill_colour)
예제 #4
0
    def paint(self, painter, option, widget=None):
        """QGraphicsRectItem virtual
        """
        # TODO LH Is there a way to clip to overlapping
        # QAbstractGraphicsItems with a larger zorder

        # TODO LH Get pixmap without tight coupling to scene
        if not self.has_mouse():
            painter.drawPixmap(self.boundingRect(),
                               self.scene().pixmap,
                               self.sceneBoundingRect())

        with painter_state(painter):
            # Zero thickness indicates a cosmetic pen, which is drawn with the
            # same thickness regardless of the view's scale factor
            outline_colour, fill_colour = self.colours
            painter.setPen(QPen(outline_colour, 0, Qt.SolidLine))
            r = self.boundingRect()
            painter.drawRect(r)

            if self._seeds:
                # Draw sub-segmentation seed points
                painter.setBrush(QBrush(Qt.black))
                painter.setPen(QPen(Qt.white, 5, Qt.SolidLine))
                for point in self._seeds:
                    painter.drawEllipse(point, 5, 5)

            if fill_colour:
                painter.fillRect(r, fill_colour)
예제 #5
0
 def _paint_box(self, painter, option, index):
     """The grey box
     """
     selected = QStyle.State_Selected & option.state
     with painter_state(painter):
         painter.setBrush(self.GREY if selected else self.DARK_GREY)
         painter.drawRect(option.rect)
예제 #6
0
    def _paint_controls(self, painter, option, index):
        """Arrows to rotate crops
        """

        with painter_state(painter):
            selected = QStyle.State_Selected & option.state
            painter.setBrush(self.WHITE if selected else self.GREY)
            f = option.font
            f.setPointSize(19)  # TODO LH Arbitrary font size
            painter.setFont(f)

            # \u293e and \u293f are unicode characters for 'lower right
            # semicircular clockwise arrow' and 'lower right semicircular
            # anticlockwise arrow' respectively
            clockwise = self.rotate_clockwise_rect.translated(
                option.rect.topLeft())
            painter.drawRect(clockwise)
            painter.drawText(clockwise, Qt.AlignVCenter | Qt.AlignHCenter,
                             u'\u293e')

            clockwise = self.rotate_counterclockwise_rect.translated(
                option.rect.topLeft())
            painter.drawRect(clockwise)
            painter.drawText(clockwise, Qt.AlignVCenter | Qt.AlignHCenter,
                             u'\u293f')
예제 #7
0
    def paint(self, painter, option, widget=None):
        """QGraphicsRectItem virtual
        """
        # TODO LH Is there a way to clip to overlapping
        # QAbstractGraphicsItems with a larger zorder

        # TODO LH Get pixmap without tight coupling to scene
        painter.drawPixmap(self.boundingRect(),
                           self.scene().pixmap, self.sceneBoundingRect())

        with painter_state(painter):
            # Zero thickness indicates a cosmetic pen, which is drawn with the
            # same thickness regardless of the view's scale factor
            painter.setPen(QPen(self.colour, 0, Qt.SolidLine))
            r = self.boundingRect()
            painter.drawRect(r)

            if self._seeds:
                # Draw sub-segmentation seed points
                painter.setBrush(QBrush(Qt.black))
                painter.setPen(QPen(Qt.white, 5, Qt.SolidLine))
                for point in self._seeds:
                    painter.drawEllipse(point, 5, 5)

            if self.DRAW_INNER:
                painter.setPen(QPen(self.inner_colour, 1, Qt.SolidLine))
                r.adjust(1, 1, -1, -1)
                painter.drawRect(r)
예제 #8
0
파일: object.py 프로젝트: edwbaker/inselect
 def _paint_box(self, painter, option, index):
     """Paints the grey box
     """
     valid = index.data(MetadataValidRole)
     selected = QStyle.State_Selected & option.state
     with painter_state(painter):
         if not valid:
             painter.setBrush(self.INVALID_SELECTED if selected else self.INVALID)
         else:
             painter.setBrush(self.GREY if selected else self.DARK_GREY)
         painter.drawRect(option.rect)
예제 #9
0
 def _paint_box(self, painter, option, index):
     """Paints background
     """
     valid = index.data(MetadataValidRole)
     selected = QStyle.State_Selected & option.state
     with painter_state(painter):
         if not valid:
             painter.setBrush(
                 self.INVALID_SELECTED if selected else self.INVALID)
         else:
             painter.setBrush(self.GREY if selected else self.DARK_GREY)
         painter.setPen(Qt.black)
         painter.drawRect(option.rect)
예제 #10
0
파일: object.py 프로젝트: edwbaker/inselect
    def _paint_title(self, painter, option, index):
        """Paints the title of this crop
        """
        with painter_state(painter):
            font = painter.font()
            font.setPointSize(13)  # TODO LH Arbitrary font size
            font.setWeight(QFont.Black)
            painter.setFont(font)
            rect = self.title_rect.translated(option.rect.topLeft())

            # Textual title in black at top left
            painter.drawText(rect, Qt.AlignTop | Qt.AlignLeft,
                             index.data(Qt.DisplayRole))
예제 #11
0
    def _paint_title(self, painter, option, index):
        """Paints the title of this crop
        """
        with painter_state(painter):
            font = painter.font()
            font.setPointSize(14)  # TODO LH Arbitrary font size
            font.setWeight(QFont.Black)
            painter.setFont(font)
            rect = self.title_rect.translated(option.rect.topLeft())

            # Textual title in black at top left
            painter.setPen(Qt.black)
            painter.drawText(rect, Qt.AlignTop | Qt.AlignLeft,
                             index.data(Qt.DisplayRole))
예제 #12
0
    def paint(self, painter, option, widget):
        """QGraphicsItem virtual
        """
        with painter_state(painter):
            painter.setRenderHint(QPainter.Antialiasing)
            bounding = self.boundingRect()

            # Black circle, with partially transparent white fill
            painter.setPen(self.PEN)
            painter.setBrush(self.FILL)
            painter.drawEllipse(bounding)

            # Filled black circle at centre
            painter.setBrush(QBrush(Qt.black))
            painter.drawEllipse(bounding.center(), 2, 2)

            # Black crosshair
            size = self.SIZE
            half_size = self.HALF_SIZE
            painter.drawLine(bounding.topLeft() + QPoint(0, half_size),
                             bounding.topLeft() + QPoint(size, half_size))
            painter.drawLine(bounding.topLeft() + QPoint(half_size, 0),
                             bounding.topLeft() + QPoint(half_size, size))
예제 #13
0
    def _paint_crop(self, painter, option, index):
        """Paints the crop
        """
        source_rect = index.data(RectRole)
        crop_rect = self.crop_rect.translated(option.rect.topLeft())
        angle = index.data(RotationRole)

        # Target rect with same aspect ratio as source
        source_aspect = float(source_rect.width()) / source_rect.height()
        crop_aspect = float(crop_rect.width()) / crop_rect.height()

        # True if the item has been rotated by a multiple of 90 degrees
        perpendicular = 1 == (angle / 90) % 2

        # Some nasty logic to compute the target rect
        if perpendicular:
            crop_aspect = 1.0 / crop_aspect

        if source_aspect > 1.0:
            # Crop is wider than is is tall
            if crop_aspect > source_aspect:
                fit_to = 'height'
                f = 1.0 / source_aspect
            else:
                fit_to = 'width'
                f = source_aspect
        else:
            # Crop is taller than is is wide
            if crop_aspect < source_aspect:
                fit_to = 'width'
                f = source_aspect
            else:
                fit_to = 'height'
                f = 1.0 / source_aspect

        if perpendicular:
            if 'width' == fit_to:
                size = QSize(crop_rect.height(),
                             crop_rect.height() / f)
            else:
                size = QSize(crop_rect.width() / f,
                             crop_rect.width())
        else:
            if 'width' == fit_to:
                size = QSize(crop_rect.width(),
                             crop_rect.width() / f)
            else:
                size = QSize(crop_rect.height() / f,
                             crop_rect.height())

        target_rect = QRect(crop_rect.topLeft(), size)
        target_rect.moveCenter(option.rect.center())

        # Draw rotated
        if angle:
            t = QTransform()
            t.translate(option.rect.width() / 2 + option.rect.left(),
                        option.rect.height() / 2 + option.rect.top())
            t.rotate(angle)
            t.translate(-option.rect.width() / 2 - option.rect.left(),
                        -option.rect.height() / 2 - option.rect.top())

        with painter_state(painter):
            if angle:
                painter.setTransform(t)
            painter.drawPixmap(target_rect, index.data(PixmapRole), source_rect)

            if QStyle.State_Selected & option.state:
                painter.setPen(QPen(Qt.white, 1, Qt.SolidLine))
                painter.drawRect(target_rect)
예제 #14
0
    def _paint_crop(self, painter, option, index):
        """Paints the crop
        """
        source_rect = index.data(RectRole)
        crop_rect = self.crop_rect.translated(option.rect.topLeft())
        angle = index.data(RotationRole)

        # Target rect with same aspect ratio as source
        source_aspect = float(source_rect.width()) / source_rect.height()
        crop_aspect = float(crop_rect.width()) / crop_rect.height()

        # True if the item has been rotated by a multiple of 90 degrees
        perpendicular = 1 == (angle / 90) % 2

        # Some nasty logic to compute the target rect
        if perpendicular:
            crop_aspect = 1.0 / crop_aspect

        if source_aspect > 1.0:
            # Crop is wider than is is tall
            if crop_aspect > source_aspect:
                fit_to = 'height'
                f = 1.0 / source_aspect
            else:
                fit_to = 'width'
                f = source_aspect
        else:
            # Crop is taller than is is wide
            if crop_aspect < source_aspect:
                fit_to = 'width'
                f = source_aspect
            else:
                fit_to = 'height'
                f = 1.0 / source_aspect

        if perpendicular:
            if 'width' == fit_to:
                size = QSize(crop_rect.height(), crop_rect.height() / f)
            else:
                size = QSize(crop_rect.width() / f, crop_rect.width())
        else:
            if 'width' == fit_to:
                size = QSize(crop_rect.width(), crop_rect.width() / f)
            else:
                size = QSize(crop_rect.height() / f, crop_rect.height())

        target_rect = QRect(crop_rect.topLeft(), size)
        target_rect.moveCenter(option.rect.center())

        # Draw rotated
        if angle:
            t = QTransform()
            t.translate(option.rect.width() / 2 + option.rect.left(),
                        option.rect.height() / 2 + option.rect.top())
            t.rotate(angle)
            t.translate(-option.rect.width() / 2 - option.rect.left(),
                        -option.rect.height() / 2 - option.rect.top())

        with painter_state(painter):
            if angle:
                painter.setTransform(t)
            painter.drawPixmap(target_rect, index.data(PixmapRole),
                               source_rect)

            if QStyle.State_Selected & option.state:
                painter.setPen(QPen(Qt.white, 1, Qt.SolidLine))
                painter.drawRect(target_rect)