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 drawPreview(self, endPoint_x, endPoint_y): painter = QPainter(self.imagePreview) 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.setOpacity(0.5) 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['line']: painter.drawLine( self.firstPoint_x, self.firstPoint_y, endPoint_x, endPoint_y) if self.tools['rect']: painter.drawRect( self.firstPoint_x, self.firstPoint_y, endPoint_x - self.firstPoint_x, endPoint_y - self.firstPoint_y) 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.update()