コード例 #1
0
    def _drawBackgroundGL(self, painter: QPainter, rect: QRectF):
        """This method is for overloading the QGraphicsScene.
        """
        if (painter.paintEngine().type() != QPaintEngine.OpenGL
                and painter.paintEngine().type() != QPaintEngine.OpenGL2):

            qWarning("OpenGLScene: drawBackground needs a QGLWidget to be"
                     "set as viewport on the graphics view")
            return
        # end if
        painter.beginNativePainting()
        GL.glDisable(GL.GL_DEPTH_TEST)  # disable for 2D drawing
        GL.glClearColor(1.0, 1.0, 1.0, 1.0)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)

        painter.endNativePainting()
コード例 #2
0
 def __grabRegion(self):
     """
     Private method to grab the selected region (i.e. do the snapshot).
     """
     pol = QPolygon(self.__selection)
     if not pol.isEmpty():
         self.__grabbing = True
         
         xOffset = self.__pixmap.rect().x() - pol.boundingRect().x()
         yOffset = self.__pixmap.rect().y() - pol.boundingRect().y()
         translatedPol = pol.translated(xOffset, yOffset)
         
         pixmap2 = QPixmap(pol.boundingRect().size())
         pixmap2.fill(Qt.transparent)
         
         pt = QPainter()
         pt.begin(pixmap2)
         if pt.paintEngine().hasFeature(QPaintEngine.PorterDuff):
             pt.setRenderHints(
                 QPainter.Antialiasing |
                 QPainter.HighQualityAntialiasing |
                 QPainter.SmoothPixmapTransform,
                 True)
             pt.setBrush(Qt.black)
             pt.setPen(QPen(QBrush(Qt.black), 0.5))
             pt.drawPolygon(translatedPol)
             pt.setCompositionMode(QPainter.CompositionMode_SourceIn)
         else:
             pt.setClipRegion(QRegion(translatedPol))
             pt.setCompositionMode(QPainter.CompositionMode_Source)
         
         pt.drawPixmap(pixmap2.rect(), self.__pixmap, pol.boundingRect())
         pt.end()
         
         self.grabbed.emit(pixmap2)
コード例 #3
0
ファイル: cngraphicsview.py プロジェクト: cadnano/cadnano2.5
    def _drawBackgroundGL(self, painter: QPainter, rect: QRectF):
        """This method is for overloading the QGraphicsScene.
        """
        if (painter.paintEngine().type() != QPaintEngine.OpenGL and
           painter.paintEngine().type() != QPaintEngine.OpenGL2):

            qWarning("OpenGLScene: drawBackground needs a QGLWidget to be"
                    "set as viewport on the graphics view")
            return
        # end if
        painter.beginNativePainting()
        GL.glDisable(GL.GL_DEPTH_TEST)  # disable for 2D drawing
        GL.glClearColor(1.0, 1.0, 1.0, 1.0)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)

        painter.endNativePainting()
コード例 #4
0
 def __grabRect(self):
     """
     Private method to grab the selected rectangle (i.e. do the snapshot).
     """
     if self.__mode == SnapshotRegionGrabber.Ellipse:
         ell = QRegion(self.__selection, QRegion.Ellipse)
         if not ell.isEmpty():
             self.__grabbing = True
             
             xOffset = self.__pixmap.rect().x() - ell.boundingRect().x()
             yOffset = self.__pixmap.rect().y() - ell.boundingRect().y()
             translatedEll = ell.translated(xOffset, yOffset)
             
             pixmap2 = QPixmap(ell.boundingRect().size())
             pixmap2.fill(Qt.transparent)
             
             pt = QPainter()
             pt.begin(pixmap2)
             if pt.paintEngine().hasFeature(QPaintEngine.PorterDuff):
                 pt.setRenderHints(
                     QPainter.Antialiasing |
                     QPainter.HighQualityAntialiasing |
                     QPainter.SmoothPixmapTransform,
                     True)
                 pt.setBrush(Qt.black)
                 pt.setPen(QPen(QBrush(Qt.black), 0.5))
                 pt.drawEllipse(translatedEll.boundingRect())
                 pt.setCompositionMode(QPainter.CompositionMode_SourceIn)
             else:
                 pt.setClipRegion(translatedEll)
                 pt.setCompositionMode(QPainter.CompositionMode_Source)
             
             pt.drawPixmap(pixmap2.rect(), self.__pixmap,
                           ell.boundingRect())
             pt.end()
             
             self.grabbed.emit(pixmap2)
     else:
         r = QRect(self.__selection)
         if not r.isNull() and r.isValid():
             self.__grabbing = True
             self.grabbed.emit(self.__pixmap.copy(r))
コード例 #5
0
    def __grabRect(self):
        """
        Private method to grab the selected rectangle (i.e. do the snapshot).
        """
        if self.__mode == SnapshotRegionGrabber.Ellipse:
            ell = QRegion(self.__selection, QRegion.Ellipse)
            if not ell.isEmpty():
                self.__grabbing = True

                xOffset = self.__pixmap.rect().x() - ell.boundingRect().x()
                yOffset = self.__pixmap.rect().y() - ell.boundingRect().y()
                translatedEll = ell.translated(xOffset, yOffset)

                pixmap2 = QPixmap(ell.boundingRect().size())
                pixmap2.fill(Qt.transparent)

                pt = QPainter()
                pt.begin(pixmap2)
                if pt.paintEngine().hasFeature(QPaintEngine.PorterDuff):
                    pt.setRenderHints(
                        QPainter.Antialiasing
                        | QPainter.HighQualityAntialiasing
                        | QPainter.SmoothPixmapTransform, True)
                    pt.setBrush(Qt.black)
                    pt.setPen(QPen(QBrush(Qt.black), 0.5))
                    pt.drawEllipse(translatedEll.boundingRect())
                    pt.setCompositionMode(QPainter.CompositionMode_SourceIn)
                else:
                    pt.setClipRegion(translatedEll)
                    pt.setCompositionMode(QPainter.CompositionMode_Source)

                pt.drawPixmap(pixmap2.rect(), self.__pixmap,
                              ell.boundingRect())
                pt.end()

                self.grabbed.emit(pixmap2)
        else:
            r = QRect(self.__selection)
            if not r.isNull() and r.isValid():
                self.__grabbing = True
                self.grabbed.emit(self.__pixmap.copy(r))