예제 #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()
예제 #2
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(
                 .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()
예제 #3
0
 def drawCellHorizontalMetrics(self, painter, rect):
     xMin, yMin, width, height = rect
     font = self.font
     scale = self.scale
     yOffset = self.yOffset
     lines = set((0, font.info.descender, font.info.xHeight,
                  font.info.capHeight, font.info.ascender))
     painter.setPen(cellMetricsLineColor)
     for y in lines:
         if y is None:
             continue
         y = round((y * scale) + yMin + yOffset)
         drawing.drawLine(painter, xMin, y, xMin + width, y)
예제 #4
0
 def drawCellHeaderBackground(self, painter, rect):
     xMin, yMin, width, height = rect
     # background
     baseColor = cellHeaderBaseColor
     sidebearingsColor = cellHeaderSidebearingsColor
     if self.glyph.dirty:
         baseColor = baseColor.darker(125)
         sidebearingsColor = sidebearingsColor.darker(110)
     painter.fillRect(xMin, yMin, width, height, baseColor)
     # sidebearings
     realPixel = 1 / self.pixelRatio
     painter.fillRect(QRectF(xMin, yMin, realPixel, height),
                      sidebearingsColor)
     painter.fillRect(
         QRectF(xMin + width - 2 * realPixel, yMin, 2 * realPixel, height),
         sidebearingsColor)
     # bottom line
     y = yMin + height
     painter.setPen(cellHeaderLineColor)
     drawing.drawLine(painter, xMin, y, xMin + width, y)
예제 #5
0
    def lineNumberAreaPaintEvent(self, event):
        painter = QPainter()
        painter.begin(self.lineNumbers)
        rect = event.rect()
        painter.fillRect(rect, self.palette().color(QPalette.Base))
        d = rect.topRight()
        a = rect.bottomRight()
        painter.setPen(QColor(150, 150, 150))
        # Alright. Since we just did setPen() w the default color constructor
        # it set the pen to a cosmetic width (of zero), i.e. drawing one pixel
        # regardless of screen density.
        # The thing is, we want to paint the last pixels at width boundary.
        # So if devicePixelRatio is e.g. 3 (3 device pixels per screen pixel),
        # then we need to translate by 3-1 pixels, but since 3 device pixels
        # is just one pixel is painter units, we'd have to divide by device
        # pixels after, so we would translate by 2/3 "software" pixels.
        pixelRatio = self.lineNumbers.devicePixelRatio()
        delta = (pixelRatio - 1) / pixelRatio
        drawing.drawLine(painter, d.x() + delta, d.y(), a.x() + delta, a.y())
        painter.setFont(self.font())

        block = self.firstVisibleBlock()
        blockNumber = block.blockNumber()
        top = int(
            self.blockBoundingGeometry(block).translated(
                self.contentOffset()).top())
        bottom = top + int(self.blockBoundingRect(block).height())

        while block.isValid() and top <= event.rect().bottom():
            if block.isVisible() and bottom >= event.rect().top():
                number = str(blockNumber + 1)
                painter.drawText(4, top,
                                 self.lineNumbers.width() - 8,
                                 self.fontMetrics().height(), Qt.AlignRight,
                                 number)
            block = block.next()
            top = bottom
            bottom = top + int(self.blockBoundingRect(block).height())
            blockNumber += 1
        painter.end()
예제 #6
0
    def lineNumberAreaPaintEvent(self, event):
        painter = QPainter()
        painter.begin(self.lineNumbers)
        rect = event.rect()
        painter.fillRect(rect, self.palette().color(QPalette.Base))
        d = rect.topRight()
        a = rect.bottomRight()
        painter.setPen(QColor(150, 150, 150))
        # Alright. Since we just did setPen() w the default color constructor
        # it set the pen to a cosmetic width (of zero), i.e. drawing one pixel
        # regardless of screen density.
        # The thing is, we want to paint the last pixels at width boundary.
        # So if devicePixelRatio is e.g. 3 (3 device pixels per screen pixel),
        # then we need to translate by 3-1 pixels, but since 3 device pixels
        # is just one pixel is painter units, we'd have to divide by device
        # pixels after, so we would translate by 2/3 "software" pixels.
        pixelRatio = self.lineNumbers.devicePixelRatio()
        delta = (pixelRatio - 1) / pixelRatio
        drawing.drawLine(painter, d.x() + delta, d.y(), a.x() + delta, a.y())
        painter.setFont(self.font())

        block = self.firstVisibleBlock()
        blockNumber = block.blockNumber()
        top = int(
            self.blockBoundingGeometry(block).translated(
                self.contentOffset()).top())
        bottom = top + int(self.blockBoundingRect(block).height())

        while block.isValid() and top <= event.rect().bottom():
            if block.isVisible() and bottom >= event.rect().top():
                number = str(blockNumber + 1)
                painter.drawText(4, top, self.lineNumbers.width() - 8,
                                 self.fontMetrics().height(), Qt.AlignRight,
                                 number)
            block = block.next()
            top = bottom
            bottom = top + int(self.blockBoundingRect(block).height())
            blockNumber += 1
        painter.end()
예제 #7
0
 def drawLineBackground(self, painter, rect):
     if self._drawMetrics:
         descender = self._descender
         ascender = self._upm + descender
         x, _, width, _ = rect
         painter.save()
         pen = painter.pen()
         pen.setColor(self._metricsColor)
         painter.setPen(pen)
         drawing.drawLine(painter, x, ascender, width, ascender)
         drawing.drawLine(painter, x, 0, width, 0)
         drawing.drawLine(painter, x, descender, width, descender)
         painter.restore()
예제 #8
0
 def drawLineBackground(self, painter, rect):
     if self._drawMetrics:
         descender = self._descender
         ascender = self._upm + descender
         x, _, width, _ = rect
         painter.save()
         pen = painter.pen()
         pen.setColor(self._metricsColor)
         painter.setPen(pen)
         drawing.drawLine(painter, x, ascender, width, ascender)
         drawing.drawLine(painter, x, 0, width, 0)
         drawing.drawLine(painter, x, descender, width, descender)
         painter.restore()
예제 #9
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)