Exemple #1
0
class ImageViewer(QWidget):
    def __init__(self):
        super(ImageViewer, self).__init__()
        self.painter = QPainter()
        self.my_pen = QPen(QColor("red"))
        self.my_pen.setWidth(5)

        self.my_brush = QBrush(QColor("#123456"))

        self.photo = QPixmap()
        self.photo_rect = QRect()

    def set_pixmap(self, image_path):
        self.photo.load(image_path)
        self.repaint()

    def paintEvent(self, event):
        self.painter.begin(self)
        self.draw()
        self.painter.end()

    def draw(self):
        rect = self.rect()

        self.painter.setPen(self.my_pen)
        self.painter.setBrush(self.my_brush)

        photo = self.photo.scaled(QSize(rect.width(), rect.height()), Qt.KeepAspectRatio, Qt.SmoothTransformation)
        self.photo_rect.setRect(rect.x(), rect.y(), photo.width(), photo.height())
        self.photo_rect.moveCenter(rect.center())

        self.painter.drawPixmap(self.photo_rect, photo)
Exemple #2
0
 def draw(cls, x, y, self: PreparedImage, painter: QPainter):
     img = QPixmap()
     img.loadFromData(self.picture)
     painter.drawPixmap(
         x + self.left, y + self.top,
         img.scaled(self.width, self.height, Qt.KeepAspectRatio,
                    Qt.SmoothTransformation))
    def paintEvent(self, event):
        """
        Redraw application.
        """
        super(TileSelector, self).paintEvent(event)

        painter = QPainter(self)

        painter.setPen(QColor(127, 127, 127))

        painter.drawPixmap(0, 0,
                           self.pixmap.size().width() * self.scale,
                           self.pixmap.size().height() * self.scale,
                           self.pixmap)

        for y in range(0, self.pixmap.size().height(), self.tile_size[1]):
            for x in range(0, self.pixmap.size().width(), self.tile_size[0]):
                painter.drawRect(x * self.scale, y * self.scale,
                                 self.tile_size[0] * self.scale,
                                 self.tile_size[1] * self.scale)

        x, y = self.get_tile_map_coords(self.main.tile)
        painter.setPen(QColor(200, 0, 0))
        painter.drawRect(x * self.scale, y * self.scale,
                         self.tile_size[0] * self.scale,
                         self.tile_size[1] * self.scale)

        painter.end()
Exemple #4
0
    def paint(self, painter: QPainter, model: ShipModel = None):
        assert self.is_set, 'Painter is not set'

        # Draw ship
        if model.is_alive:
            _ship = self._ship_alive
        else:
            _ship = self._ship_dead

        _pixmap = _ship.transformed(model.transform,
                                    mode=Qt.SmoothTransformation)
        _center_ship = self.transform(model.x - _pixmap.width() / 2,
                                      model.y + _pixmap.height() / 2,
                                      is_point=True)

        if 0 <= _center_ship.x() <= self.parent.width(
        ) and 0 <= _center_ship.y() <= self.parent.height():
            painter.drawPixmap(_center_ship, _pixmap)

            # Draw life bar
            _center_bar = self.transform(model.x - self._life_bar_xy[0],
                                         model.y + self._life_bar_xy[1],
                                         is_point=True)
            painter.setPen(QPen(QColor(255, 0, 0), 0, Qt.NoPen))
            painter.setBrush(QBrush(QColor(255, 0, 0)))
            painter.drawRect(_center_bar.x(), _center_bar.y(),
                             self._life_bar_width, 5)
            painter.setBrush(QBrush(QColor(0, 255, 0)))
            painter.drawRect(_center_bar.x(), _center_bar.y(),
                             int(self._life_bar_width * model.life), 5)
            painter.setPen(QPen(QColor(*model.color), 5, Qt.SolidLine))
            _center_title = self.transform(model.x - 100,
                                           model.y + 70,
                                           is_point=True)
            painter.setFont(
                QFont('Open Sans', weight=QFont.Normal, pointSize=8))
            painter.drawText(
                QRect(_center_title.x(), _center_title.y(), 200, 25),
                Qt.AlignHCenter | Qt.AlignTop, '<{}>'.format(model.name))
            painter.setBrush(QBrush(QColor(*model.color)))
            _center_point = self.transform(model.x, model.y, is_point=True)
            painter.drawPoint(_center_point)
        else:
            _xy = QPoint(_center_ship)
            if _center_ship.x() < 0:
                _xy.setX(0)
            if self.parent.width() < _center_ship.x():
                _xy.setX(self.parent.width())

            if _center_ship.y() < 0:
                _xy.setY(0)
            if self.parent.height() < _center_ship.y():
                _xy.setY(self.parent.height())

            painter.setPen(QPen(QColor(0, 0, 0), 30, Qt.SolidLine,
                                Qt.RoundCap))
            painter.drawPoint(_xy)
            painter.setPen(
                QPen(QColor(*model.color), 25, Qt.SolidLine, Qt.RoundCap))
            painter.drawPoint(_xy)
    def drawBg(self, painter: QPainter = None) -> None:
        painter.save()

        if not self.__bgPix.isNull():
            painter.drawPixmap(0, 0, self.__bgPix)

        painter.restore()
 def f():
     from bLUeTop.QtGui1 import window
     lastDir = str(window.settings.value('paths/dlgdir', '.'))
     dlg = QFileDialog(window, "select", lastDir,
                       " *".join(IMAGE_FILE_EXTENSIONS))
     if dlg.exec_():
         filenames = dlg.selectedFiles()
         newDir = dlg.directory().absolutePath()
         window.settings.setValue('paths/dlgdir', newDir)
         img = QImage(filenames[0])
         # scale img while keeping its aspect ratio
         # into a QPixmap having the same size as self layer
         sourcePixmap = QPixmap.fromImage(img).scaled(
             self.layer.size(), Qt.KeepAspectRatio)
         self.sourcePixmap = QPixmap(self.layer.size())
         self.sourcePixmap.fill(Qt.black)
         qp = QPainter(self.sourcePixmap)
         qp.drawPixmap(
             QRect(0, 0, sourcePixmap.width(), sourcePixmap.height()),
             sourcePixmap)
         qp.end()
         self.sourcePixmapThumb = self.sourcePixmap.scaled(
             self.pwSize, self.pwSize, aspectMode=Qt.KeepAspectRatio)
         self.widgetImg.setPixmap(self.sourcePixmapThumb)
         self.widgetImg.setFixedSize(self.sourcePixmapThumb.size())
         self.sourceFromFile = True
     self.widgetImg.show()
Exemple #7
0
    def draw_robots_and_goal(self):
        self.draw_grid()

        painter = QPainter(self.label.pixmap())

        goal_img_name = ICON_PATH + "/goal_" + str(
            self.game.goal.color) + ".png"
        painter.drawPixmap(
            QPoint(
                self.DIMENSION / self.game.board.height *
                self.game.goal.position[1], self.DIMENSION /
                self.game.board.width * self.game.goal.position[0]),
            QPixmap(goal_img_name, format="png").scaled(
                self.DIMENSION / self.game.board.width * 0.9,
                self.DIMENSION / self.game.board.height * 0.9))

        images = [
            QPixmap(ICON_PATH + "robot_" + str(color) + ".png", format="png")
            for color in self.game.color_keys
        ]

        for i, robot in enumerate(self.game.robots):

            painter.drawPixmap(
                QPoint(
                    self.DIMENSION / self.game.board.height *
                    self.game.robots[robot].position[1],
                    self.DIMENSION / self.game.board.width *
                    self.game.robots[robot].position[0]),
                images[i].scaled(self.DIMENSION / self.game.board.width * 0.8,
                                 self.DIMENSION / self.game.board.height))

        self.update()
        painter.end()
Exemple #8
0
    def paintEvent(self, event):
        super().paintEvent(event)
        frame = self.camera.frame
        if frame is not None:
            painter = QPainter(self)

            (h, w) = frame.shape[:2]

            if self.selected_color_rgb[0] is not None:
                _, frame = apply_mask(
                    frame=frame,
                    r=self.selected_color_rgb[0],
                    g=self.selected_color_rgb[1],
                    b=self.selected_color_rgb[2],
                    negdh=self.hsv_min_hue,
                    posdh=self.hsv_max_hue,
                    mins=self.hsv_min_saturation,
                    maxs=self.hsv_max_saturation,
                    minv=self.hsv_min_value,
                    maxv=self.hsv_max_value,
                )

            q_image = QImage(frame, w, h, QImage.Format_RGB888)
            q_pixmap = QPixmap.fromImage(q_image)
            painter.drawPixmap(0, 0, q_pixmap)
    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))
Exemple #10
0
    def paintEvent(self, event):
        super(PixmapWidget, self).paintEvent(event)
        if not self.pixmap or self.pixmap.isNull():
            return
        p = QPainter(self)

        source = QRect(0, 0, self.pixmap.width(), self.pixmap.height())

        sw = float(source.width())
        sh = float(source.height())
        tw = float(self.width())+1
        th = float(self.height())+1
        tx = 0
        ty = 0
        if sw/tw > sh/th:
            ntw = tw
            nth = sh/sw*tw
            ty = (th-nth)/2
        else:
            nth = th
            ntw = sw/sh*th
            tx = (tw-ntw)/2

        target = QRect(tx, ty, ntw, nth)

        p.setBrush(self.bgBrush)
        p.setPen(self.bgPen)
        p.drawRect(self.rect())

        p.drawPixmap(target, self.pixmap, source)
    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))
Exemple #12
0
    def draw_grid(self):
        """
        Dessine la grille de jeu en juxtaposant les images contenant chaque case. Chaque image est redimensionnée et ajustée à la taille de la grille.
        """
        painter = QPainter(self.label.pixmap())
        names = [
            "Empty", "N", "E", "EN", "S", "NS", "ES", "ENS", "W", "NW", "EW",
            "ENW", "SW", "NSW", "ESW", "ENSW"
        ]
        images = [
            QPixmap(IMAGES_PATH + name + ".bmp", format="bmp")
            for name in names
        ]

        for x in range(0, self.game.board.width):
            for y in range(0, self.game.board.height):
                painter.drawPixmap(
                    QPoint(self.DIMENSION / self.game.board.height * y,
                           self.DIMENSION / self.game.board.width * x),
                    images[int(str(self.game.board.grid[x][y]))].scaled(
                        self.DIMENSION / self.game.board.width,
                        self.DIMENSION / self.game.board.height))

        self.update()
        painter.end()
Exemple #13
0
 def __init__(self):
     img = config.ImgRes.base
     image = QPixmap(img.width() * 2, img.height())
     painter = QPainter(image)
     painter.drawPixmap(0, 0, img)
     painter.drawPixmap(img.width(), 0, img)
     super().__init__(image)
Exemple #14
0
 def paintEvent(self, event):
     p = QPainter(self)
     if self._minus | self._plus:
         p.drawPixmap(0, 10, self._el_pix, 143, 62, 20, 6)
     if self._plus:
         p.drawPixmap(8,  0, self._el_pix, 156, 50, 5, 11)
         p.drawPixmap(8, 15, self._el_pix, 156, 50, 5, 11)
Exemple #15
0
    def printImage(self):  #Ok
        """Imprimir Imagem
        """
        printer = QPrinter()
        printer.setOutputFormat(QPrinter.NativeFormat)

        prnt_dlg = QPrintDialog(printer)

        if (prnt_dlg.exec_() == QPrintDialog.Accepted):

            painter = QPainter()

            painter.begin(printer)

            rect = QRect(painter.viewport())

            size = QSize(self.img_lbl.pixmap().size())
            size.scale(rect.size(), Qt.KeepAspectRatio)

            painter.setViewport(rect.x(), rect.y(), size.width(),
                                size.height())
            painter.setWindow(self.img_lbl.pixmap().rect())

            painter.drawPixmap(0, 0, self.img_lbl.pixmap())

            painter.end()
Exemple #16
0
    def paintEvent(self, event):
        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing)

        r = event.rect()   #dessine juste dans le Qwidget
        p.drawPixmap(r, QPixmap(PIXMAPS[str(self.game.board.grid[x][y])]))
        p.end()
Exemple #17
0
    def update_screen(self) -> None:
        use_live_screen = (
            self.live_screen_checkbox.checkState() == Qt.CheckState.Checked)
        is_powered_on = self.power_checkbox.checkState(
        ) == Qt.CheckState.Checked
        image_display = (self.image_display_on
                         if is_powered_on else self.image_display_off)
        result = QPixmap(image_display.size())
        result.fill(Qt.transparent)
        painter = QPainter(result)
        painter.drawPixmap(QPoint(0, 0), image_display)

        if is_powered_on:
            screenshot = get_screenshot(
            ) if use_live_screen else self.screenshot
            screenshot = screenshot.scaled(800, 800, Qt.KeepAspectRatio,
                                           Qt.SmoothTransformation)
            screenshot = screenshot.copy(QRect(0, 0, 800, 480 * 0.94))
            offset_x = (image_display.size().width() -
                        screenshot.size().width()) / 2
            offset_y = (image_display.size().height() -
                        screenshot.size().height()) / 2
            painter.setOpacity(self.backlight.brightness / 100)
            painter.drawPixmap(QPoint(offset_x, offset_y), screenshot)

        painter.end()
        result = result.scaled(600, 600, Qt.KeepAspectRatio,
                               Qt.SmoothTransformation)
        self.screen_image.setPixmap(result)
Exemple #18
0
    def paintEvent(self, e):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        the_size = min(self.width(), self.height())

        gradient = QRadialGradient(QPointF(2 * the_size / 3, the_size / 3),
                                   the_size)
        if self.is_on:
            painter.drawPixmap(
                0, 0, the_size, the_size,
                QIcon(str(FILE_PATH /
                          "../resources/images/greenlight.svg")).pixmap(
                              QSize(the_size, the_size)))
        else:
            painter.drawPixmap(
                0, 0, the_size, the_size,
                QIcon(str(FILE_PATH /
                          "../resources/images/redlight.svg")).pixmap(
                              QSize(the_size, the_size)))

        # INNER Gradient
        # lgradien = QLinearGradient(the_size/2, 0, the_size/3, the_size)
        # lgradien.setColorAt(0.0, QColor(255, 255, 255, 200))
        # lgradien.setColorAt(.5, QColor(255, 255, 255, 0))
        # painter.setBrush(lgradien)
        # painter.setPen(Qt.NoPen)
        # painter.drawEllipse(0, 2, the_size, the_size/3)

        painter.end()
Exemple #19
0
    def doubleBufferPaint(self, buffer=None):
        self.blockSignals(True)
        #self.drawFrame(painter)
        if buffer is None:
            buffer = QImage(self.width(), self.height(), QImage.Format_RGB888)
        buffer.fill(Qt.black)
        # calculate offset and scale of droplet image pixmap
        scale_x, scale_y, offset_x, offset_y = self.get_from_image_transform()

        db_painter = QPainter(buffer)
        db_painter.setRenderHints(QPainter.Antialiasing
                                  | QPainter.NonCosmeticDefaultPen)
        db_painter.setBackground(QBrush(Qt.black))
        db_painter.setPen(QPen(Qt.black, 0))
        db_painter.drawPixmap(offset_x, offset_y, self._pixmap)
        pen = QPen(Qt.magenta, 1)
        pen_fine = QPen(Qt.blue, 1)
        pen.setCosmetic(True)
        db_painter.setPen(pen)
        # draw droplet outline and tangent only if evaluate_droplet was successful
        if self._droplet.is_valid:
            try:
                # transforming true image coordinates to scaled pixmap coordinates
                db_painter.translate(offset_x, offset_y)
                db_painter.scale(scale_x, scale_y)

                # drawing tangents and baseline
                db_painter.drawLine(*self._droplet.line_l)
                db_painter.drawLine(*self._droplet.line_r)
                db_painter.drawLine(*self._droplet.int_l, *self._droplet.int_r)

                # move origin to ellipse origin
                db_painter.translate(*self._droplet.center)

                # draw diagnostics
                # db_painter.setPen(pen_fine)
                # #  lines parallel to coordinate axes
                # db_painter.drawLine(0,0,20*scale_x,0)
                # db_painter.drawLine(0,0,0,20*scale_y)
                # # angle arc
                # db_painter.drawArc(-5*scale_x, -5*scale_y, 10*scale_x, 10*scale_y, 0, -self._droplet.tilt_deg*16)

                # rotate coordinates to ellipse tilt
                db_painter.rotate(self._droplet.tilt_deg)

                # draw ellipse
                # db_painter.setPen(pen)
                db_painter.drawEllipse(-self._droplet.maj / 2,
                                       -self._droplet.min / 2,
                                       self._droplet.maj, self._droplet.min)

                # # major and minor axis for diagnostics
                # db_painter.drawLine(0, 0, self._droplet.maj/2, 0)
                # db_painter.drawLine(0, 0, 0, self._droplet.min/2)
            except Exception as ex:
                logging.error(ex)
        db_painter.end()
        self.blockSignals(False)
        return buffer
Exemple #20
0
    def paintEvent(self, _event):
        # type: (QPaintEvent) -> None
        """Draws cached pixmap on the canvas - :meth:`__render` takes care of creating it in the first place

        :param _event: the paint event passed in by Qt, not actually used
        """
        painter = QPainter(self)
        painter.drawPixmap(self.rect(), self.__pixmap)
    def paintEvent(self, event):
        # self.image.setPixelColor(0, 0, QColor(0, 255, 0))

        painter = QPainter(self)
        # painter.translate(self.width() / 2, self.height() / 2)
        # painter.drawEllipse(-5, -5, 20, 20)
        r = QRect(0, 0, self.width(), self.height())
        painter.fillRect(r, QColor())
        painter.drawPixmap(r, self.pixmap)
Exemple #22
0
    def paintEvent(self, event):
        """
        Override to draw the console frame background image
        """
        painter = QPainter(self)
        painter.drawPixmap(0, 0,
                           QPixmap("assets/retroterm.png").scaled(self.size()))

        super().paintEvent(event)
    def drawBg(self, painter: QPainter) -> None:
        painter.save()

        # 设置边框颜色及宽度
        pen: QPen = QPen()
        pen.setColor(self.__borderColor)
        pen.setWidthF(self.__borderWidth)
        painter.setPen(pen)

        # 绘制区域要减去边框宽度
        rect: QRect = QRect()
        rect.setX(self.__borderWidth)
        rect.setY(self.__borderWidth)
        rect.setWidth(self.width() - self.__borderWidth * 2)
        rect.setHeight(self.height() - self.__borderWidth * 2)

        # 如果背景图片存在则显示背景图片,否则显示背景色
        if not self.__bgImage.isNull():
            # 等比例缩放绘制
            img: QPixmap = self.__bgImage.scaled(rect.width(), rect.height(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
            painter.drawPixmap((self.rect().width() - img.width()) / 2, (self.rect().height() - img.height()) / 2, img)
        else:
            if self.__colorMode == ColorButton.ColorMode.ColorMode_Normal:
                if self.__isPressed:
                    painter.setBrush(QBrush(self.__pressedColor))
                else:
                    painter.setBrush(QBrush(self.__normalColor))
            elif self.__colorMode == ColorButton.ColorMode.ColorMode_Replace:
                gradient: QLinearGradient = QLinearGradient(QPoint(0, 0), QPoint(0, self.height()))

                if self.__isPressed:
                    gradient.setColorAt(0.0, self.__pressedColor)
                    gradient.setColorAt(0.49, self.__pressedColor)
                    gradient.setColorAt(0.50, self.__normalColor)
                    gradient.setColorAt(1.0, self.__normalColor)
                else:
                    gradient.setColorAt(0.0, self.__normalColor)
                    gradient.setColorAt(0.49, self.__normalColor)
                    gradient.setColorAt(0.50, self.__pressedColor)
                    gradient.setColorAt(1.0, self.__pressedColor)

                painter.setBrush(gradient)
            elif self.__colorMode == ColorButton.ColorMode.ColorMode_Shade:
                gradient: QLinearGradient = QLinearGradient(QPoint(0, 0), QPoint(0, self.height()))

                if self.__isPressed:
                    gradient.setColorAt(0.0, self.__pressedColor)
                    gradient.setColorAt(1.0, self.__normalColor)
                else:
                    gradient.setColorAt(0.0, self.__normalColor)
                    gradient.setColorAt(1.0, self.__pressedColor)

                painter.setBrush(gradient)

            painter.drawRoundedRect(rect, self.__borderRadius, self.__borderRadius)

        painter.restore()
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.drawPixmap(event.rect(), self.pixmap)

        if self.enter:
            qp = QtGui.QPainter()
            qp.begin(self)
            self.drawRectangles(qp, event.rect())
            qp.end()
    def drawHeader(self):
        """Draw logo/copyright in the header"""
        pHeight = 90
        pMargin = 15
        icon_path = cm.DIR_ICONS + "app.png"

        self.header_lbl.setMinimumHeight(pHeight)
        self.header_lbl.setFrameShape(QFrame.StyledPanel)
        self.header_lbl.setContentsMargins(0, 0, 0, 0)

        pixmap = QPixmap(450, pHeight)
        pixmap.fill(Qt.transparent)

        iconY = (pHeight - 64) / 2
        logoRect = QRect(pMargin, iconY, 64, 64)

        painter = QPainter(pixmap)
        painter.setBrush(QBrush(Qt.red))
        painter.drawPixmap(
            logoRect,
            QPixmap(icon_path).scaled(
                logoRect.width(),
                logoRect.height(),
                Qt.KeepAspectRatio,
                Qt.SmoothTransformation,
            ),
        )

        titleRect = QRect(logoRect.right() + 10, iconY, 200, pHeight)

        font = QFont()
        font.setBold(True)
        font.setPixelSize(16)
        painter.setFont(font)
        painter.setPen(QPen(QApplication.instance().palette().text().color()))
        painter.drawText(titleRect, Qt.AlignTop, "Cutevariant")

        font_metrics = QFontMetrics(font)
        font.setBold(False)
        font.setPixelSize(12)
        painter.setFont(font)
        painter.setPen(QPen(Qt.darkGray))
        titleRect.setY(titleRect.y() + font_metrics.height())

        painter.drawText(
            titleRect,
            Qt.AlignTop,
            f"Version %s\nGPL3 Copyright (C) 2018-2020\nLabsquare.org" % __version__,
        )

        self.header_lbl.setPixmap(pixmap)

        # Painting is finished !
        # Avoid Segfault:
        # QPaintDevice: Cannot destroy paint device that is being painted
        painter.end()
Exemple #26
0
def paint_with_opacity(pixmap: QPixmap, opacity: float):
    transparent_image = QImage(QSize(36, 36),
                               QImage.Format_ARGB32_Premultiplied)
    transparent_image.fill(Qt.transparent)
    painter = QPainter(transparent_image)
    painter.setOpacity(opacity)
    painter.drawPixmap(18 - pixmap.width() / 2, 18 - pixmap.height() / 2,
                       pixmap)
    painter.end()
    return QPixmap.fromImage(transparent_image)
Exemple #27
0
 def paintEvent(self, event):
     painter = QPainter(self)
     rl = self.renderl.copy()
     rl.reverse()
     while rl:
         s = rl.pop()
         if isinstance(s, Iterable):
             rl.extend(list(reversed(s)))
         else:
             painter.drawPixmap(s.x, s.y, s.spriteImg)
Exemple #28
0
 def paint(self, painter: QPainter, model: BaseModel = None):
     _pix_map = self._pixel_map.scaledToHeight(model.radius * 1.025,
                                               mode=Qt.SmoothTransformation)
     _seed = hash(model.name)
     _transf = QTransform()
     _transf.rotate(_seed % 360)
     _pix_map = _pix_map.transformed(_transf, mode=Qt.SmoothTransformation)
     _x, _y = self.transform(model.x - _pix_map.width() / 2.0,
                             model.y + _pix_map.height() / 2.0)
     painter.drawPixmap(round(_x), round(_y), _pix_map)
Exemple #29
0
def pix_add_blurry(pix, transparency: float):
    temp_pix = QPixmap(pix.size())
    temp_pix.fill(Qt.transparent)
    painter = QPainter(temp_pix)
    painter.setCompositionMode(QPainter.CompositionMode_Source)
    painter.drawPixmap(0, 0, pix)
    painter.setCompositionMode(QPainter.CompositionMode_DestinationIn)
    painter.fillRect(temp_pix.rect(), QColor(0, 0, 0, int(255 * transparency)))
    painter.end()
    return temp_pix
Exemple #30
0
    def drawForeground(self, painter: QtGui.QPainter, rect: QtCore.QRectF):
        """Draw the foreground pixmap, updates if None."""
        if self.foreground_pixmap is None:
            self.updateForeground(rect)

        painter.save()
        painter.resetTransform()
        # Draw the actual overlay
        painter.drawPixmap(0, 0, self.foreground_pixmap)
        painter.restore()
Exemple #31
0
 def paintEvent(self, event):
     pixmap = self.pixmap
     painter = QPainter(self)
     if self.isChecked(
     ):  # Todo only if rotate button is clicked rotate. we have to fix this -> src.main.PdfConverter.rotate_button(self).isClicked()
         painter.translate(self.width(), 0)
         self.rotate += 90
         self.rotate %= 360
         painter.rotate(90)
     painter.drawPixmap(event.rect(), pixmap)
Exemple #32
0
 def getCurrentMaskedImage(self):
     """
     Reduces the layer stack up to self (included),
     taking into account the masks. if self.isClipping is True
     self.mask applies to all lower layers and to self only otherwise.
     The method uses the non color managed rPixmaps to build the masked image.
     For convenience, mainly to be able to use its color space buffers,
     the built image is of type QLayer. It is drawn on a container image,
     created only once.
     @return: masked image
     @rtype: QLayer
     """
     # init containers if needed
     if self.parentImage.useHald:
         return self.getHald()
     if self.maskedThumbContainer is None:
         self.maskedThumbContainer = QLayer.fromImage(
             self.getThumb(), parentImage=self.parentImage)
     if self.maskedImageContainer is None:
         self.maskedImageContainer = QLayer.fromImage(
             self, parentImage=self.parentImage)
     if self.parentImage.useThumb:
         img = self.maskedThumbContainer
     else:
         img = self.maskedImageContainer
     # no thumbnails for containers
     img.getThumb = lambda: img
     # draw lower stack
     qp = QPainter(img)
     top = self.parentImage.getStackIndex(self)
     bottom = 0
     for i, layer in enumerate(self.parentImage.layersStack[bottom:top +
                                                            1]):
         if layer.visible:
             if i == 0:
                 qp.setCompositionMode(QPainter.CompositionMode_Source)
             else:
                 qp.setOpacity(layer.opacity)
                 qp.setCompositionMode(layer.compositionMode)
             if layer.rPixmap is not None:
                 qp.drawPixmap(QRect(0, 0, img.width(), img.height()),
                               layer.rPixmap)
             else:
                 qp.drawImage(QRect(0, 0, img.width(), img.height()),
                              layer.getCurrentImage())
             # clipping
             if layer.isClipping and layer.maskIsEnabled:  #TODO modified 23/06/18
                 # draw mask as opacity mask
                 # mode DestinationIn (set dest opacity to source opacity)
                 qp.setCompositionMode(
                     QPainter.CompositionMode_DestinationIn)
                 omask = vImage.color2OpacityMask(layer.mask)
                 qp.drawImage(QRect(0, 0, img.width(), img.height()), omask)
     qp.end()
     return img
Exemple #33
0
 def _drawTiles(self, source):
     x = self.padding
     y = self.padding
     sx = 0
     sy = 0
     doReorder = self.forcePot & self.reorder
     painter = QPainter(self._target)
     for j in range(self._rows):
         for i in range(self._cols):
             painter.drawPixmap(x, y, source, sx, sy, self.tileWidth, self.tileHeight)
             x += self._gridWidth
             if doReorder and x >= self._targetWidth - self._gridWidth:
                 x = self.padding
                 y += self._gridHeight
             sx += self.tileWidth
         if not doReorder:
             x = self.padding
             y += self._gridHeight
         sx = 0
         sy += self.tileHeight
Exemple #34
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.matrix().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.width(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)