def draw(self, endPoint_x, endPoint_y):
        painter = QPainter(self.image)

        painter.setPen(QPen(
            self.myPenColor, self.myPenWidth, QtCore.Qt.SolidLine,
            QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin))
        painter.setClipping(True)

        painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
        painter.setRenderHint(QPainter.HighQualityAntialiasing, True)
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setCompositionMode(QPainter.CompositionMode())

        if self.tools['circle']:
            x1 = self.firstPoint_x
            y1 = self.firstPoint_y
            x2 = endPoint_x
            y2 = endPoint_y
            painter.drawEllipse(x1, y1, (x2 - x1), (y2 - y1))

        if self.tools['eraser']:
            painter.setPen(QPen(QtCore.Qt.white, 10, QtCore.Qt.SolidLine))
            painter.drawLine(
                self.firstPoint_x, self.firstPoint_y, endPoint_x, endPoint_y)
            self.firstPoint_x = endPoint_x
            self.firstPoint_y = endPoint_y

        if self.tools['pen']:
            painter.drawLine(
                self.firstPoint_x, self.firstPoint_y, endPoint_x, endPoint_y)
            self.firstPoint_x = endPoint_x
            self.firstPoint_y = endPoint_y

        if self.tools['line'] and self.flag:
            painter.drawLine(
                self.firstPoint_x, self.firstPoint_y, endPoint_x, endPoint_y)

        if self.tools['rect']:
            dx = endPoint_x - self.firstPoint_x
            dy = endPoint_y - self.firstPoint_y
            painter.drawRect(self.firstPoint_x, self.firstPoint_y, dx, dy)

        if self.tools['roundRect']:
            x1 = self.firstPoint_x
            y1 = self.firstPoint_y
            dx = endPoint_x - self.firstPoint_x
            dy = endPoint_y - self.firstPoint_y
            if x1 > endPoint_x and y1 > endPoint_y:
                painter.drawRoundedRect(
                    endPoint_x, endPoint_y, -dx, -dy, 20, 20, 0)
            else:
                painter.drawRoundedRect(x1, y1, dx, dy, 20., 20.)

        self.modified = True
        self.update()
    def paintEvent(self, event):
        mouse_pos = self.mapFromGlobal(QCursor.pos())
        is_hover = self.contentsRect().contains(mouse_pos)

        QPushButton.paintEvent(self, event)

        painter = QPainter(self)
        painter.drawPixmap(2, 1, self.icon)
        if is_hover:
            painter.setCompositionMode(QPainter.CompositionMode_Screen)
            painter.drawPixmap(2, 1, self.icon)
    def paintEvent(self, event):
        mouse_pos = self.mapFromGlobal(QCursor.pos())
        is_hover = self.contentsRect().contains(mouse_pos)

        if not self.new_ui:
            QPushButton.paintEvent(self, event)

        painter = QPainter(self)
        if self.new_ui and self.isChecked():
            painter.setRenderHint(QPainter.Antialiasing)
            painter.setPen(QPen(Qt.NoPen))
            painter.setBrush(self.highlight)
            painter.drawRoundedRect(event.rect(), 2, 2)

        painter.drawPixmap(2, 2, self.icon)

        if is_hover:
            painter.setCompositionMode(QPainter.CompositionMode_Screen)
            painter.drawPixmap(2, 2, self.icon)
Пример #4
0
 def fill_pixmap(self, pixmap, origin, position):
     origin = self.snap_pos(origin)
     pos = self.snap_pos(position)
     ox, oy = origin.x(), origin.y()
     cx, cy = pos.x(), pos.y()
     p = QPainter(pixmap)
     p.setCompositionMode(QPainter.CompositionMode_Source)
     if self._connect_points:
         ## This method of extending a line between points works quite well
         ## but it is very slow when the radius of the circle is large, which
         ## essential results in a lot of duplicate drawing.
         p.translate(ox, oy)
         px, py = 0, 0
         for x, y in zip(*ski.draw.line(0, 0, cx-ox, cy-oy)):
             p.translate(x-px, y-py)
             px, py = x, y
             self._paint_cursor(p)
     else:
         p.translate(cx, cy)
         self._paint_cursor(p)
     p.end()
Пример #5
0
    def drawIconWithShadow(icon, rect, p, iconMode, radius, color, offset):
        cache = QPixmap()
        pixmapName = "icon {0} {1} {2}".format(icon.cacheKey(), iconMode, rect.height())

        if not QPixmapCache.find(pixmapName, cache):
            px = icon.pixmap(rect.size())
            cache = QPixmap(px.size() + QSize(radius * 2, radius * 2))
            cache.fill(Qt.transparent)

            cachePainter = QPainter(cache)
            if iconMode == QIcon.Disabled:
                im = px.toImage().convertToFormat(QImage.Format_ARGB32)
                for y in range(im.height()):
                    scanLine = im.scanLine(y)
                    for x in range(im.width()):
                        pixel = scanLine
                        intensity = qGray(pixel)
                        scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel))
                        scanLine += 1
                px = QPixmap.fromImage(im)

            # Draw shadow
            tmp = QImage(px.size() + QSize(radius * 2, radius * 2 + 1), QImage.Format_ARGB32_Premultiplied)
            tmp.fill(Qt.transparent)

            tmpPainter = QPainter(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_Source)
            tmpPainter.drawPixmap(QPoint(radius, radius), px)
            tmpPainter.end()

            # blur the alpha channel
            blurred = QImage(tmp.size(), QImage.Format_ARGB32_Premultiplied)
            blurred.fill(Qt.transparent)
            blurPainter = QPainter(blurred)
            # todo : blur image
            blurPainter.end()

            tmp = blurred

            # blacken the image
            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            # draw the blurred drop shadow...
            cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp)

            # Draw the actual pixmap...
            cachePainter.drawPixmap(QPoint(radius, radius) + offset, px)
            QPixmapCache.insert(pixmapName, cache)

        targetRect = cache.rect()
        targetRect.moveCenter(rect.center())
        p.drawPixmap(targetRect.topLeft() - offset, cache)