Exemplo n.º 1
0
    def paint( self, painter, option, widget ):
        """ Draws a filled rectangle and then adds a title """

        # Hide the dotted outline
        itemOption = QStyleOptionGraphicsItem( option )
        if itemOption.state & QStyle.State_Selected != 0:
            itemOption.state = itemOption.state & ~QStyle.State_Selected

        # Draw the rectangle
        pen = painter.pen()
        pen.setJoinStyle( Qt.RoundJoin )
        painter.setPen( pen )
        QGraphicsRectItem.paint( self, painter, itemOption, widget )

        # Draw text over the rectangle
        font = QFont( "Arial", 10 )
        painter.setFont( font )
        painter.setPen( QPen( QColor( 255, 255, 255 ) ) )
        painter.drawText( self.__node.posX - self.__node.width / 2.0,
                          self.__node.posY - self.__node.height / 2.0,
                          self.__node.width, self.__node.height,
                          Qt.AlignCenter,
                          self.__node.label.replace( '\\n', '\n' ) )

        if self.__outside:
            pixmap = PixmapCache().getPixmap( "nonprojectentrydgm.png" )
            pixmapPosX = self.__node.posX - self.__node.width / 2.0 + 2
            pixmapPosY = self.__node.posY + self.__node.height / 2.0 - \
                         pixmap.height() - 2
            painter.setRenderHint( QPainter.SmoothPixmapTransform )
            painter.drawPixmap( pixmapPosX, pixmapPosY, pixmap )
        return
Exemplo n.º 2
0
    def paint(self, painter, option, widget):
        """ Draws a filled rectangle and then adds a title """

        # Hide the dotted outline
        itemOption = QStyleOptionGraphicsItem(option)
        if itemOption.state & QStyle.State_Selected != 0:
            itemOption.state = itemOption.state & ~QStyle.State_Selected

        # Draw the rectangle
        QGraphicsRectItem.paint(self, painter, itemOption, widget)

        # Draw text over the rectangle
        font = QFont("Arial", 10)
        painter.setFont(font)
        painter.drawText(self.__node.posX - self.__node.width / 2.0,
                         self.__node.posY - self.__node.height / 2.0,
                         self.__node.width, self.__node.height, Qt.AlignCenter,
                         self.__srcobj.text)

        pixmap = PixmapCache().getPixmap("docstring.png")
        pixmapPosX = self.__node.posX + self.__node.width / 2.0 - \
                     pixmap.width() / 2.0
        pixmapPosY = self.__node.posY - self.__node.height / 2.0 - \
                     pixmap.height() / 2.0
        painter.setRenderHint(QPainter.SmoothPixmapTransform)
        painter.drawPixmap(pixmapPosX, pixmapPosY, pixmap)
        return
Exemplo n.º 3
0
    def paint( self, painter, option, widget ):
        """ Draws a filled rectangle and then adds a title """

        # Hide the dotted outline
        itemOption = QStyleOptionGraphicsItem( option )
        if itemOption.state & QStyle.State_Selected != 0:
            itemOption.state = itemOption.state & ~QStyle.State_Selected

        # Draw the rectangle
        QGraphicsRectItem.paint( self, painter, itemOption, widget )

        # Draw text over the rectangle
        font = QFont( "Arial", 10 )
        painter.setFont( font )
        painter.drawText( self.__node.posX - self.__node.width / 2.0,
                          self.__node.posY - self.__node.height / 2.0,
                          self.__node.width, self.__node.height,
                          Qt.AlignCenter, self.__srcobj.text )

        pixmap = PixmapCache().getPixmap( "docstring.png" )
        pixmapPosX = self.__node.posX + self.__node.width / 2.0 - \
                     pixmap.width() / 2.0
        pixmapPosY = self.__node.posY - self.__node.height / 2.0 - \
                     pixmap.height() / 2.0
        painter.setRenderHint( QPainter.SmoothPixmapTransform )
        painter.drawPixmap( pixmapPosX, pixmapPosY, pixmap )
        return
Exemplo n.º 4
0
    def paint(self, painter, option, widget):
        """ Draws a filled rectangle and then adds a title """

        # Hide the dotted outline
        itemOption = QStyleOptionGraphicsItem(option)
        if itemOption.state & QStyle.State_Selected != 0:
            itemOption.state = itemOption.state & ~QStyle.State_Selected

        # Draw the rectangle
        pen = painter.pen()
        pen.setJoinStyle(Qt.RoundJoin)
        painter.setPen(pen)
        QGraphicsRectItem.paint(self, painter, itemOption, widget)

        # Draw text over the rectangle
        font = QFont("Arial", 10)
        painter.setFont(font)
        painter.setPen(QPen(QColor(255, 255, 255)))
        painter.drawText(self.__node.posX - self.__node.width / 2.0,
                         self.__node.posY - self.__node.height / 2.0,
                         self.__node.width, self.__node.height, Qt.AlignCenter,
                         self.__node.label.replace('\\n', '\n'))

        if self.__outside:
            pixmap = PixmapCache().getPixmap("nonprojectentrydgm.png")
            pixmapPosX = self.__node.posX - self.__node.width / 2.0 + 2
            pixmapPosY = self.__node.posY + self.__node.height / 2.0 - \
                         pixmap.height() - 2
            painter.setRenderHint(QPainter.SmoothPixmapTransform)
            painter.drawPixmap(pixmapPosX, pixmapPosY, pixmap)
        return
Exemplo n.º 5
0
    def paint(self, painter, option, widget):
        """ Draws the edge text """

        # Hide the dotted outline
        itemOption = QStyleOptionGraphicsItem(option)
        if itemOption.state & QStyle.State_Selected != 0:
            itemOption.state = itemOption.state & ~QStyle.State_Selected

        QGraphicsTextItem.paint(self, painter, itemOption, widget)
        return
Exemplo n.º 6
0
    def paint( self, painter, option, widget ):
        """ Draws the edge text """

        # Hide the dotted outline
        itemOption = QStyleOptionGraphicsItem( option )
        if itemOption.state & QStyle.State_Selected != 0:
            itemOption.state = itemOption.state & ~QStyle.State_Selected

        QGraphicsTextItem.paint( self, painter, itemOption, widget )
        return
Exemplo n.º 7
0
    def paint(self, painter, option, widget=None):

        painter.setPen(self.pen())
        painter.setBrush( EDraw.EColor.DefaultFillColor )

        style = QStyleOptionGraphicsItem()
        style.state = ( QStyle.State_None )

        painter.drawPolygon( EDraw.DefaultPolygon( self.boundingRect().width(), self.boundingRect().height() ) )

        painter.translate( self.boundingRect().height() / 2  , 0.0)

        QGraphicsTextItem.paint(self, painter, style, widget)
Exemplo n.º 8
0
    def paint(self, painter, option, widget=None):

        painter.setPen(self.pen())
        painter.setBrush(EDraw.EColor.DefaultFillColor)

        style = QStyleOptionGraphicsItem()
        style.state = (QStyle.State_None)

        painter.drawPolygon(
            EDraw.DefaultPolygon(self.boundingRect().width(),
                                 self.boundingRect().height()))

        painter.translate(self.boundingRect().height() / 2, 0.0)

        QGraphicsTextItem.paint(self, painter, style, widget)
Exemplo n.º 9
0
    def paint( self, painter, option, widget ):
        " Draws a filled rectangle, adds title, classes/funcs/globs sections "

        # Hide the dotted outline
        itemOption = QStyleOptionGraphicsItem( option )
        if itemOption.state & QStyle.State_Selected != 0:
            itemOption.state = itemOption.state & ~QStyle.State_Selected

        # Draw the rectangle
        QGraphicsRectItem.paint( self, painter, itemOption, widget )


        # Start from the bottom to automatically take potential spare
        # pixels for the title
        font = QFont( "Arial", 10 )
        painter.setFont( font )
        posX = self.__node.posX - self.__node.width / 2.0
        posY = self.__node.posY + self.__node.height / 2.0 - 1.5 * self.__pixelsPerLine

        occupiedPixels = 0
        for index in xrange( len( self.__lines ) - 1, 0, -1 ):
            if self.__lines[ index ] is None:
                # Draw a separation line
                painter.drawLine( posX + 1, posY + self.__pixelsPerLine / 2.0,
                                  posX + self.__node.width,
                                  posY + self.__pixelsPerLine / 2.0)
            elif self.__lines[ index ] != "":
                # Draw a text line
                # Sometimes the bottom part of 'g' is not drawn so I add 2
                # spare pixels.
                painter.drawText( int( posX ), int( posY ),
                                  int( self.__node.width ), self.__pixelsPerLine + 2,
                                  Qt.AlignCenter, self.__lines[ index ] )
            occupiedPixels += self.__pixelsPerLine
            posY -= self.__pixelsPerLine

        # Draw the title in bold
        font.setBold( True )
        painter.setFont( font )

        available = self.__node.height - occupiedPixels
        posY = self.__node.posY - self.__node.height / 2.0
        painter.drawText( int( posX ), int( posY ),
                          int( self.__node.width ), int( available ),
                          Qt.AlignCenter, self.__lines[ 0 ] )
        return
Exemplo n.º 10
0
    def paint(self, painter, option, widget):
        " Draws a filled rectangle, adds title, classes/funcs/globs sections "

        # Hide the dotted outline
        itemOption = QStyleOptionGraphicsItem(option)
        if itemOption.state & QStyle.State_Selected != 0:
            itemOption.state = itemOption.state & ~QStyle.State_Selected

        # Draw the rectangle
        QGraphicsRectItem.paint(self, painter, itemOption, widget)

        # Start from the bottom to automatically take potential spare
        # pixels for the title
        font = QFont("Arial", 10)
        painter.setFont(font)
        posX = self.__node.posX - self.__node.width / 2.0
        posY = self.__node.posY + self.__node.height / 2.0 - 1.5 * self.__pixelsPerLine

        occupiedPixels = 0
        for index in xrange(len(self.__lines) - 1, 0, -1):
            if self.__lines[index] is None:
                # Draw a separation line
                painter.drawLine(posX + 1, posY + self.__pixelsPerLine / 2.0,
                                 posX + self.__node.width,
                                 posY + self.__pixelsPerLine / 2.0)
            elif self.__lines[index] != "":
                # Draw a text line
                # Sometimes the bottom part of 'g' is not drawn so I add 2
                # spare pixels.
                painter.drawText(int(posX), int(posY), int(self.__node.width),
                                 self.__pixelsPerLine + 2, Qt.AlignCenter,
                                 self.__lines[index])
            occupiedPixels += self.__pixelsPerLine
            posY -= self.__pixelsPerLine

        # Draw the title in bold
        font.setBold(True)
        painter.setFont(font)

        available = self.__node.height - occupiedPixels
        posY = self.__node.posY - self.__node.height / 2.0
        painter.drawText(int(posX), int(posY), int(self.__node.width),
                         int(available), Qt.AlignCenter, self.__lines[0])
        return
Exemplo n.º 11
0
 def genWINDPIXMAPS():
     """prepare wind tiles"""
     tileset = Tileset(Preferences.windTilesetName)
     for wind in WINDS:
         for prevailing in False, True:
             pwind = PlayerWind(wind, tileset, prevailing)
             pMap = QPixmap(40, 40)
             pMap.fill(Qt.transparent)
             painter = QPainter(pMap)
             painter.setRenderHint(QPainter.Antialiasing)
             painter.scale(0.40, 0.40)
             pwind.paint(painter, QStyleOptionGraphicsItem())
             for child in pwind.childItems():
                 if isinstance(child, QGraphicsSvgItem):
                     painter.save()
                     painter.translate(child.mapToParent(0.0, 0.0))
                     child.paint(painter, QStyleOptionGraphicsItem())
                     painter.restore()
             WINDPIXMAPS[(wind, prevailing)] = pMap
Exemplo n.º 12
0
 def paint(self, painter, option, widget):
     myOption = QStyleOptionGraphicsItem(option)
     if option.state & QStyle.State_Selected:
         myOption.state = myOption.state ^ QStyle.State_Selected
     super(DraggableItem, self).paint(painter, myOption, widget)
Exemplo n.º 13
0
    def testPaintDelay( self ):
        t = Tiling((100, 100))
        assert( len(t.tileRectFs) == 1 )

        delay=datetime.timedelta(milliseconds=300)
        # fudge should prevent hitting the delay time exactly
        # during the while loops below;
        # if your computer is verrry slow and the fudge too small
        # the test will fail...
        fudge=datetime.timedelta(milliseconds=50)
        d = DirtyIndicator( t, delay=delay )

        # make the image a little bit larger to accomodate the tile overlap
        img = QImage(110,110,QImage.Format_ARGB32_Premultiplied)
        img.fill(0)
        img_saved = QImage(img)

        painter = QPainter()
        style = QStyleOptionGraphicsItem()
        style.exposedRect = t.tileRectFs[0]

        start = datetime.datetime.now()
        d.setTileProgress( 0, 0 ) # resets delay timer

        # 1. do not update the progress during the delay time
        actually_checked = False
        while( datetime.datetime.now() - start < delay - fudge ):
            # nothing should be painted
            self.assertEqual( img, img_saved )
            actually_checked = True
        self.assertTrue(actually_checked)
        time.sleep(fudge.total_seconds()*2)
        # after the delay, the pie chart is painted
        painter.begin(img)
        d.paint( painter, style, None )
        self.assertNotEqual( img, img_saved )
        painter.end()

        # 2. update the progress during delay (this exposed a bug:
        #    the delay was ignored in that case and the pie chart
        #    painted nevertheless)
        d = DirtyIndicator( t, delay=delay )
        img.fill(0)
        start = datetime.datetime.now()
        d.setTileProgress( 0, 0 ) # resets delay timer

        actually_checked = False
        self.assertEqual(img, img_saved) # precondition
        while( datetime.datetime.now() - start < delay - fudge ):
            # the painted during the delay time should have no effect
            painter.begin(img)
            d.setTileProgress( 0, 0.5 )
            d.paint( painter, style, None )
            painter.end()
            self.assertEqual( img, img_saved )
            actually_checked = True
        self.assertTrue(actually_checked)
        time.sleep(fudge.total_seconds()*2)
        # now the pie should be painted
        painter.begin(img)
        d.paint( painter, style, None )
        self.assertNotEqual( img, img_saved )
        painter.end()
Exemplo n.º 14
0
    def testPaintDelay(self):
        t = Tiling((100, 100))
        assert (len(t.tileRectFs) == 1)

        delay = datetime.timedelta(milliseconds=300)
        # fudge should prevent hitting the delay time exactly
        # during the while loops below;
        # if your computer is verrry slow and the fudge too small
        # the test will fail...
        fudge = datetime.timedelta(milliseconds=50)
        d = DirtyIndicator(t, delay=delay)

        # make the image a little bit larger to accomodate the tile overlap
        img = QImage(110, 110, QImage.Format_ARGB32_Premultiplied)
        img.fill(0)
        img_saved = QImage(img)

        painter = QPainter()
        style = QStyleOptionGraphicsItem()
        style.exposedRect = t.tileRectFs[0]

        start = datetime.datetime.now()
        d.setTileProgress(0, 0)  # resets delay timer

        # 1. do not update the progress during the delay time
        actually_checked = False
        while (datetime.datetime.now() - start < delay - fudge):
            # nothing should be painted
            self.assertEqual(img, img_saved)
            actually_checked = True
        self.assertTrue(actually_checked)
        time.sleep(fudge.total_seconds() * 2)
        # after the delay, the pie chart is painted
        painter.begin(img)
        d.paint(painter, style, None)
        self.assertNotEqual(img, img_saved)
        painter.end()

        # 2. update the progress during delay (this exposed a bug:
        #    the delay was ignored in that case and the pie chart
        #    painted nevertheless)
        d = DirtyIndicator(t, delay=delay)
        img.fill(0)
        start = datetime.datetime.now()
        d.setTileProgress(0, 0)  # resets delay timer

        actually_checked = False
        self.assertEqual(img, img_saved)  # precondition
        while (datetime.datetime.now() - start < delay - fudge):
            # the painted during the delay time should have no effect
            painter.begin(img)
            d.setTileProgress(0, 0.5)
            d.paint(painter, style, None)
            painter.end()
            self.assertEqual(img, img_saved)
            actually_checked = True
        self.assertTrue(actually_checked)
        time.sleep(fudge.total_seconds() * 2)
        # now the pie should be painted
        painter.begin(img)
        d.paint(painter, style, None)
        self.assertNotEqual(img, img_saved)
        painter.end()