Exemple #1
0
 def drawGlyphBackground(self, painter, glyph, rect, selected=False):
     if glyph.name == ".notdef":
         painter.fillRect(QRectF(*rect), self._notdefBackgroundColor)
     if selected:
         if self._glyphSelectionColor is not None:
             selectionColor = self._glyphSelectionColor
         else:
             palette = self.palette()
             active = palette.currentColorGroup() != QPalette.Inactive
             opacityMultiplier = platformSpecific.colorOpacityMultiplier()
             selectionColor = palette.color(QPalette.Highlight)
             selectionColor.setAlphaF(0.2 *
                                      opacityMultiplier if active else 0.9)
         xMin, yMin, width, height = rect
         painter.save()
         if self._drawMetrics:
             pen = painter.pen()
             pen.setStyle(Qt.DotLine)
             pen.setColor(self._metricsColor)
             painter.setPen(pen)
             drawing.drawLine(painter, xMin, yMin, xMin, yMin + height)
             drawing.drawLine(painter, xMin + width, yMin, xMin + width,
                              yMin + height)
         painter.fillRect(xMin, yMin, width, -26, selectionColor)
         painter.restore()
 def drawGlyphBackground(self, painter, glyph, rect, selected=False):
     if glyph.name == ".notdef":
         painter.fillRect(QRectF(*rect), self._notdefBackgroundColor)
     if selected:
         if self._glyphSelectionColor is not None:
             selectionColor = self._glyphSelectionColor
         else:
             palette = self.palette()
             active = palette.currentColorGroup() != QPalette.Inactive
             opacityMultiplier = platformSpecific.colorOpacityMultiplier()
             selectionColor = palette.color(QPalette.Highlight)
             selectionColor.setAlphaF(
                 .2 * opacityMultiplier if active else .9)
         xMin, yMin, width, height = rect
         painter.save()
         if self._drawMetrics:
             pen = painter.pen()
             pen.setStyle(Qt.DotLine)
             pen.setColor(self._metricsColor)
             painter.setPen(pen)
             drawing.drawLine(painter, xMin, yMin, xMin, yMin + height)
             drawing.drawLine(
                 painter, xMin + width, yMin, xMin + width, yMin + height)
         painter.fillRect(xMin, yMin, width, -26, selectionColor)
         painter.restore()
Exemple #3
0
    def paintEvent(self, event):
        painter = QPainter(self)
        visibleRect = event.rect()
        columnCount, rowCount = self._columnCount, self._rowCount
        cellWidth, cellHeight = self._cellWidth, self._cellHeight
        glyphCount = len(self._glyphs)
        if columnCount:
            paintHeight = math.ceil(glyphCount / columnCount) * cellHeight
            paintWidth = min(glyphCount, columnCount) * cellWidth
        else:
            paintHeight = paintWidth = 0
        left = 0
        top = cellHeight
        realPixel = 1 / self.devicePixelRatio()

        for index, glyph in enumerate(self._glyphs):
            t = top - cellHeight
            rect = (left, t, cellWidth, cellHeight)

            painter.fillRect(*(rect+(backgroundColor,)))

            if visibleRect.intersects(visibleRect.__class__(*rect)):
                pixmap = self._getCurrentRepresentation(glyph)
                painter.drawPixmap(left, t, pixmap)

                if index in self._selection:
                    palette = self.palette()
                    active = palette.currentColorGroup() != QPalette.Inactive
                    opacityMultiplier = platformSpecific.colorOpacityMultiplier()
                    selectionColor = palette.color(QPalette.Highlight)
                    # TODO: alpha values somewhat arbitrary (here and in
                    # glyphLineView)
                    selectionColor.setAlphaF(
                        .2 * opacityMultiplier if active else .6)
                    pixelRatio = self.devicePixelRatio()
                    painter.fillRect(QRectF(
                        left + realPixel, t + realPixel,
                        cellWidth - 3 * realPixel, cellHeight - 3 * realPixel),
                        selectionColor)

            left += cellWidth
            if left + cellWidth > paintWidth:
                left = 0
                top += cellHeight

        # h/v lines
        emptyCells = columnCount * rowCount - len(self._glyphs)
        rem = columnCount - emptyCells
        painter.setPen(cellGridColor)
        for i in range(1, self._rowCount+1):
            top = i * cellHeight - realPixel
            # don't paint on empty cells
            w = paintWidth - realPixel
            if i == self._rowCount:
                w -= cellWidth * emptyCells
            drawing.drawLine(painter, 0, top, w, top)
        for i in range(1, self._columnCount+1):
            left = i * cellWidth - realPixel
            # don't paint on empty cells
            h = paintHeight - realPixel
            if i > rem:
                h -= cellHeight
            drawing.drawLine(painter, left, 0, left, h)

        # drop insertion position
        dropIndex = self._currentDropIndex
        if dropIndex is not None:
            if columnCount:
                x = (dropIndex % columnCount) * cellWidth
                y = (dropIndex // columnCount) * cellHeight
                # special-case the end-column
                if dropIndex == glyphCount and \
                        glyphCount < self.width() // self._cellWidth or \
                        self.mapFromGlobal(QCursor.pos()).y() < y:
                    x = columnCount * cellWidth
                    y -= cellHeight
            else:
                x = y = 0
            path = QPainterPath()
            path.addRect(x - 2, y, 3, cellHeight)
            path.addEllipse(x - 5, y - 5, 9, 9)
            path.addEllipse(x - 5, y + cellHeight - 5, 9, 9)
            path.setFillRule(Qt.WindingFill)
            pen = painter.pen()
            pen.setColor(Qt.white)
            pen.setWidth(2)
            painter.setPen(pen)
            painter.setRenderHint(QPainter.Antialiasing)
            painter.drawPath(path)
            painter.fillPath(path, insertionPositionColor)
Exemple #4
0
    def paintEvent(self, event):
        painter = QPainter(self)
        visibleRect = event.rect()
        columnCount = self._columnCount
        extra = self._cellWidthExtra
        cellWidth, cellHeight = self._cellWidth + 2 * extra, self._cellHeight
        glyphCount = len(self._glyphs)
        if columnCount:
            paintWidth = min(glyphCount, columnCount) * cellWidth
        else:
            paintWidth = 0
        left = 0
        top = cellHeight

        painter.fillRect(visibleRect, Qt.white)
        for index, glyph in enumerate(self._glyphs):
            t = top - cellHeight
            rect = (left, t, cellWidth, cellHeight)

            if visibleRect.intersects(visibleRect.__class__(*rect)):
                if index in self._selection:
                    palette = self.palette()
                    active = palette.currentColorGroup() != QPalette.Inactive
                    opacityMultiplier = platformSpecific.colorOpacityMultiplier(
                    )
                    selectionColor = palette.color(QPalette.Highlight)
                    # TODO: alpha values somewhat arbitrary (here and in
                    # glyphLineView)
                    selectionColor.setAlphaF(
                        0.2 * opacityMultiplier if active else 0.7)
                    painter.fillRect(QRectF(left, t, cellWidth, cellHeight),
                                     selectionColor)

                pixmap = self._getCurrentRepresentation(glyph)
                painter.drawPixmap(left, t, pixmap)

                # XXX: this hacks around the repr internals
                if (index in self._selection
                        and cellHeight >= GlyphCellMinHeightForHeader):
                    painter.fillRect(
                        QRectF(
                            left,
                            t + cellHeight - GlyphCellHeaderHeight,
                            cellWidth,
                            GlyphCellHeaderHeight,
                        ),
                        selectionColor,
                    )

            left += cellWidth
            if left + cellWidth > paintWidth:
                left = 0
                top += cellHeight

        # drop insertion position
        dropIndex = self._currentDropIndex
        if dropIndex is not None:
            if columnCount:
                x = (dropIndex % columnCount) * cellWidth
                y = (dropIndex // columnCount) * cellHeight
                # special-case the end-column
                if (dropIndex == glyphCount
                        and glyphCount < self.width() // self._cellWidth
                        or self.mapFromGlobal(QCursor.pos()).y() < y):
                    x = columnCount * cellWidth
                    y -= cellHeight
            else:
                x = y = 0
            path = QPainterPath()
            path.addRect(x - 2, y, 3, cellHeight)
            path.addEllipse(x - 5, y - 5, 9, 9)
            path.addEllipse(x - 5, y + cellHeight - 5, 9, 9)
            path.setFillRule(Qt.WindingFill)
            pen = painter.pen()
            pen.setColor(Qt.white)
            pen.setWidth(2)
            painter.setPen(pen)
            painter.setRenderHint(QPainter.Antialiasing)
            painter.drawPath(path)
            painter.fillPath(path, insertionPositionColor)
    def paintEvent(self, event):
        painter = QPainter(self)
        visibleRect = event.rect()
        columnCount = self._columnCount
        extra = self._cellWidthExtra
        cellWidth, cellHeight = self._cellWidth + 2 * extra, self._cellHeight
        glyphCount = len(self._glyphs)
        if columnCount:
            paintWidth = min(glyphCount, columnCount) * cellWidth
        else:
            paintWidth = 0
        left = 0
        top = cellHeight

        painter.fillRect(visibleRect, Qt.white)
        for index, glyph in enumerate(self._glyphs):
            t = top - cellHeight
            rect = (left, t, cellWidth, cellHeight)

            if visibleRect.intersects(visibleRect.__class__(*rect)):
                if index in self._selection:
                    palette = self.palette()
                    active = palette.currentColorGroup() != QPalette.Inactive
                    opacityMultiplier = platformSpecific.colorOpacityMultiplier()
                    selectionColor = palette.color(QPalette.Highlight)
                    # TODO: alpha values somewhat arbitrary (here and in
                    # glyphLineView)
                    selectionColor.setAlphaF(
                        .2 * opacityMultiplier if active else .7)
                    painter.fillRect(QRectF(
                        left, t, cellWidth, cellHeight),
                        selectionColor)

                pixmap = self._getCurrentRepresentation(glyph)
                painter.drawPixmap(left, t, pixmap)

                # XXX: this hacks around the repr internals
                if index in self._selection and \
                        cellHeight >= GlyphCellMinHeightForHeader:
                    painter.fillRect(QRectF(
                        left, t + cellHeight - GlyphCellHeaderHeight,
                        cellWidth, GlyphCellHeaderHeight),
                        selectionColor)

            left += cellWidth
            if left + cellWidth > paintWidth:
                left = 0
                top += cellHeight

        # drop insertion position
        dropIndex = self._currentDropIndex
        if dropIndex is not None:
            if columnCount:
                x = (dropIndex % columnCount) * cellWidth
                y = (dropIndex // columnCount) * cellHeight
                # special-case the end-column
                if dropIndex == glyphCount and \
                        glyphCount < self.width() // self._cellWidth or \
                        self.mapFromGlobal(QCursor.pos()).y() < y:
                    x = columnCount * cellWidth
                    y -= cellHeight
            else:
                x = y = 0
            path = QPainterPath()
            path.addRect(x - 2, y, 3, cellHeight)
            path.addEllipse(x - 5, y - 5, 9, 9)
            path.addEllipse(x - 5, y + cellHeight - 5, 9, 9)
            path.setFillRule(Qt.WindingFill)
            pen = painter.pen()
            pen.setColor(Qt.white)
            pen.setWidth(2)
            painter.setPen(pen)
            painter.setRenderHint(QPainter.Antialiasing)
            painter.drawPath(path)
            painter.fillPath(path, insertionPositionColor)